aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/nvim/buffer.c11
-rw-r--r--src/nvim/ex_cmds.c64
-rw-r--r--src/nvim/ex_cmds2.c52
-rw-r--r--src/nvim/ex_getln.c2
-rw-r--r--src/nvim/testdir/test_profile.vim38
-rw-r--r--test/functional/ui/inccommand_spec.lua30
6 files changed, 120 insertions, 77 deletions
diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c
index 3080d4960d..f874268910 100644
--- a/src/nvim/buffer.c
+++ b/src/nvim/buffer.c
@@ -5279,13 +5279,14 @@ int bufhl_add_hl(buf_T *buf,
}
/// Add highlighting to a buffer, bounded by two cursor positions,
-/// with an offset
-/// @param buf The buffer to add highlights to
+/// with an offset.
+///
+/// @param buf Buffer to add highlights to
/// @param src_id src_id to use or 0 to use a new src_id group,
/// or -1 for ungrouped highlight.
-/// @param hl_id Id of the highlight group to use
-/// @param lpos_start Cursor position to start the hightlighting at
-/// @param lpos_end Cursor position to end the highlighting at
+/// @param hl_id Highlight group id
+/// @param pos_start Cursor position to start the hightlighting at
+/// @param pos_end Cursor position to end the highlighting at
/// @param offset Move the whole highlighting this many columns to the right
void bufhl_add_hl_pos_offset(buf_T *buf,
int src_id,
diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c
index 85e65f32c2..112f53247c 100644
--- a/src/nvim/ex_cmds.c
+++ b/src/nvim/ex_cmds.c
@@ -3940,34 +3940,30 @@ skip:
if (nmatch == -1)
lnum -= regmatch.startpos[0].lnum;
- // Push the match to preview_lines
- // TODO(KillTheMule): Code duplication at line 3961
- linenr_T match_lines = current_match.end.lnum
- - current_match.start.lnum +1;
- if (preview_lines.subresults.size > 0) {
- linenr_T last_lnum = kv_last(preview_lines.subresults).end.lnum;
- if (last_lnum == current_match.start.lnum) {
- preview_lines.lines_needed += match_lines - 1;
- }
- } else {
- preview_lines.lines_needed += match_lines;
- }
- kv_push(preview_lines.subresults, current_match);
+#define PUSH_PREVIEW_LINES() \
+ do { \
+ linenr_T match_lines = current_match.end.lnum \
+ - current_match.start.lnum +1; \
+ if (preview_lines.subresults.size > 0) { \
+ linenr_T last = kv_last(preview_lines.subresults).end.lnum; \
+ if (last == current_match.start.lnum) { \
+ preview_lines.lines_needed += match_lines - 1; \
+ } \
+ } else { \
+ preview_lines.lines_needed += match_lines; \
+ } \
+ kv_push(preview_lines.subresults, current_match); \
+ } while (0)
+
+ // Push the match to preview_lines.
+ PUSH_PREVIEW_LINES();
+
break;
}
}
- // Push the match to preview_lines
- linenr_T match_lines = current_match.end.lnum
- - current_match.start.lnum +1;
- if (preview_lines.subresults.size > 0) {
- linenr_T last_lnum = kv_last(preview_lines.subresults).end.lnum;
- if (last_lnum == current_match.start.lnum) {
- preview_lines.lines_needed += match_lines - 1;
- }
- } else {
- preview_lines.lines_needed += match_lines;
- }
- kv_push(preview_lines.subresults, current_match);
+ // Push the match to preview_lines.
+ PUSH_PREVIEW_LINES();
+
line_breakcheck();
}
@@ -4061,7 +4057,7 @@ skip:
pre_src_id = bufhl_add_hl(NULL, 0, -1, 0, 0, 0);
}
if (pre_hl_id == 0) {
- pre_hl_id = syn_check_group((char_u *)"Substitute", 13);
+ pre_hl_id = syn_check_group((char_u *)S_LEN("Substitute"));
}
curbuf->b_changed = save_b_changed; // preserve 'modified' during preview
preview_buf = show_sub(eap, old_cursor, &preview_lines,
@@ -4077,6 +4073,7 @@ skip:
return preview_buf;
#undef ADJUST_SUB_FIRSTLNUM
+#undef PUSH_PREVIEW_LINES
} // NOLINT(readability/fn_size)
/*
@@ -6133,7 +6130,6 @@ static buf_T *show_sub(exarg_T *eap, pos_T old_cusr,
curwin->w_p_fen = false;
if (lines.subresults.size > 0) {
- // Width of the "| lnum|..." column which displays the line numbers.
highest_num_line = kv_last(lines.subresults).end.lnum;
col_width = log10(highest_num_line) + 1 + 3;
}
@@ -6142,9 +6138,9 @@ static buf_T *show_sub(exarg_T *eap, pos_T old_cusr,
char *str = NULL; // construct the line to show in here
size_t old_line_size = 0;
size_t line_size = 0;
- linenr_T linenr_preview = 0; // # of last line added to preview buffer
- linenr_T linenr_origbuf = 0; // # of last line added to original number
- linenr_T next_linenr = 0; // # of the next line to show for the match
+ linenr_T linenr_preview = 0; // last line added to preview buffer
+ linenr_T linenr_origbuf = 0; // last line added to original buffer
+ linenr_T next_linenr = 0; // next line to show for the match
for (size_t matchidx = 0; matchidx < lines.subresults.size; matchidx++) {
SubResult match = lines.subresults.items[matchidx];
@@ -6172,12 +6168,12 @@ static buf_T *show_sub(exarg_T *eap, pos_T old_cusr,
if (next_linenr == match.end.lnum) {
p_end.lnum = linenr_preview + 1;
}
- char_u *line;
+ char *line;
if (next_linenr == orig_buf->b_ml.ml_line_count + 1) {
- line = (char_u *)"";
+ line = "";
} else {
- line = ml_get_buf(orig_buf, next_linenr, false);
- line_size = STRLEN(line) + col_width + 1;
+ line = (char *)ml_get_buf(orig_buf, next_linenr, false);
+ line_size = strlen(line) + col_width + 1;
// Reallocate if line not long enough
if (line_size > old_line_size) {
diff --git a/src/nvim/ex_cmds2.c b/src/nvim/ex_cmds2.c
index 371f7b3bce..9b8e463aee 100644
--- a/src/nvim/ex_cmds2.c
+++ b/src/nvim/ex_cmds2.c
@@ -1039,9 +1039,14 @@ static void profile_reset(void)
uf->uf_tm_total = profile_zero();
uf->uf_tm_self = profile_zero();
uf->uf_tm_children = profile_zero();
+
+ xfree(uf->uf_tml_count);
+ xfree(uf->uf_tml_total);
+ xfree(uf->uf_tml_self);
uf->uf_tml_count = NULL;
uf->uf_tml_total = NULL;
uf->uf_tml_self = NULL;
+
uf->uf_tml_start = profile_zero();
uf->uf_tml_children = profile_zero();
uf->uf_tml_wait = profile_zero();
@@ -1068,7 +1073,7 @@ static void profile_init(scriptitem_T *si)
si->sn_pr_nest = 0;
}
-/// save time when starting to invoke another script or function.
+/// Save time when starting to invoke another script or function.
void script_prof_save(
proftime_T *tm // place to store wait time
)
@@ -1141,12 +1146,14 @@ static void script_dump_profile(FILE *fd)
if (sfd == NULL) {
fprintf(fd, "Cannot open file!\n");
} else {
- for (int i = 0; i < si->sn_prl_ga.ga_len; i++) {
+ // Keep going till the end of file, so that trailing
+ // continuation lines are listed.
+ for (int i = 0; ; i++) {
if (vim_fgets(IObuff, IOSIZE, sfd)) {
break;
}
- pp = &PRL_ITEM(si, i);
- if (pp->snp_count > 0) {
+ if (i < si->sn_prl_ga.ga_len
+ && (pp = &PRL_ITEM(si, i))->snp_count > 0) {
fprintf(fd, "%5d ", pp->snp_count);
if (profile_equal(pp->sn_prl_total, pp->sn_prl_self)) {
fprintf(fd, " ");
@@ -2871,22 +2878,6 @@ int do_source(char_u *fname, int check_other, int is_vimrc)
save_sourcing_lnum = sourcing_lnum;
sourcing_lnum = 0;
- cookie.conv.vc_type = CONV_NONE; // no conversion
-
- // Read the first line so we can check for a UTF-8 BOM.
- firstline = getsourceline(0, (void *)&cookie, 0);
- if (firstline != NULL && STRLEN(firstline) >= 3 && firstline[0] == 0xef
- && firstline[1] == 0xbb && firstline[2] == 0xbf) {
- // Found BOM; setup conversion, skip over BOM and recode the line.
- convert_setup(&cookie.conv, (char_u *)"utf-8", p_enc);
- p = string_convert(&cookie.conv, firstline + 3, NULL);
- if (p == NULL) {
- p = vim_strsave(firstline + 3);
- }
- xfree(firstline);
- firstline = p;
- }
-
// start measuring script load time if --startuptime was passed and
// time_fd was successfully opened afterwards.
proftime_T rel_time;
@@ -2959,6 +2950,22 @@ int do_source(char_u *fname, int check_other, int is_vimrc)
}
}
+ cookie.conv.vc_type = CONV_NONE; // no conversion
+
+ // Read the first line so we can check for a UTF-8 BOM.
+ firstline = getsourceline(0, (void *)&cookie, 0);
+ if (firstline != NULL && STRLEN(firstline) >= 3 && firstline[0] == 0xef
+ && firstline[1] == 0xbb && firstline[2] == 0xbf) {
+ // Found BOM; setup conversion, skip over BOM and recode the line.
+ convert_setup(&cookie.conv, (char_u *)"utf-8", p_enc);
+ p = string_convert(&cookie.conv, firstline + 3, NULL);
+ if (p == NULL) {
+ p = vim_strsave(firstline + 3);
+ }
+ xfree(firstline);
+ firstline = p;
+ }
+
// Call do_cmdline, which will call getsourceline() to get the lines.
do_cmdline(firstline, getsourceline, (void *)&cookie,
DOCMD_VERBOSE|DOCMD_NOWAIT|DOCMD_REPEAT);
@@ -3068,6 +3075,8 @@ char_u *get_scriptname(scid_T id)
# if defined(EXITFREE)
void free_scriptnames(void)
{
+ profile_reset();
+
# define FREE_SCRIPTNAME(item) xfree((item)->sn_name)
GA_DEEP_CLEAR(&script_items, scriptitem_T, FREE_SCRIPTNAME);
}
@@ -3281,7 +3290,8 @@ void script_line_start(void)
if (si->sn_prof_on && sourcing_lnum >= 1) {
// Grow the array before starting the timer, so that the time spent
// here isn't counted.
- ga_grow(&si->sn_prl_ga, (int)(sourcing_lnum - si->sn_prl_ga.ga_len));
+ (void)ga_grow(&si->sn_prl_ga,
+ (int)(sourcing_lnum - si->sn_prl_ga.ga_len));
si->sn_prl_idx = sourcing_lnum - 1;
while (si->sn_prl_ga.ga_len <= si->sn_prl_idx
&& si->sn_prl_ga.ga_len < si->sn_prl_ga.ga_maxlen) {
diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c
index e79476ab53..c9567145e4 100644
--- a/src/nvim/ex_getln.c
+++ b/src/nvim/ex_getln.c
@@ -2784,7 +2784,7 @@ void ui_ext_cmdline_block_append(int indent, const char *line)
{
char *buf = xmallocz(indent + strlen(line));
memset(buf, ' ', indent);
- memcpy(buf+indent, line, strlen(line));
+ memcpy(buf + indent, line, strlen(line)); // -V575
Array item = ARRAY_DICT_INIT;
ADD(item, DICTIONARY_OBJ((Dictionary)ARRAY_DICT_INIT));
diff --git a/src/nvim/testdir/test_profile.vim b/src/nvim/testdir/test_profile.vim
index 183f52b8ac..4cbd800da5 100644
--- a/src/nvim/testdir/test_profile.vim
+++ b/src/nvim/testdir/test_profile.vim
@@ -115,7 +115,7 @@ func Test_profile_file()
call assert_match('^ Self time:\s\+\d\+\.\d\+$', lines[3])
call assert_equal('', lines[4])
call assert_equal('count total (s) self (s)', lines[5])
- call assert_equal(' func! Foo()', lines[6])
+ call assert_match(' 2 0.\d\+ func! Foo()', lines[6])
call assert_equal(' endfunc', lines[7])
" Loop iterates 10 times. Since script runs twice, body executes 20 times.
" First line of loop executes one more time than body to detect end of loop.
@@ -132,6 +132,42 @@ func Test_profile_file()
call delete('Xprofile_file.log')
endfunc
+func Test_profile_file_with_cont()
+ let lines = [
+ \ 'echo "hello',
+ \ ' \ world"',
+ \ 'echo "foo ',
+ \ ' \bar"',
+ \ ]
+
+ call writefile(lines, 'Xprofile_file.vim')
+ call system(v:progpath
+ \ . ' -es -u NONE -U NONE -i NONE --noplugin'
+ \ . ' -c "profile start Xprofile_file.log"'
+ \ . ' -c "profile file Xprofile_file.vim"'
+ \ . ' -c "so Xprofile_file.vim"'
+ \ . ' -c "qall!"')
+ call assert_equal(0, v:shell_error)
+
+ let lines = readfile('Xprofile_file.log')
+ call assert_equal(11, len(lines))
+
+ call assert_match('^SCRIPT .*Xprofile_file.vim$', lines[0])
+ call assert_equal('Sourced 1 time', lines[1])
+ call assert_match('^Total time:\s\+\d\+\.\d\+$', lines[2])
+ call assert_match('^ Self time:\s\+\d\+\.\d\+$', lines[3])
+ call assert_equal('', lines[4])
+ call assert_equal('count total (s) self (s)', lines[5])
+ call assert_match(' 1 0.\d\+ echo "hello', lines[6])
+ call assert_equal(' \ world"', lines[7])
+ call assert_match(' 1 0.\d\+ echo "foo ', lines[8])
+ call assert_equal(' \bar"', lines[9])
+ call assert_equal('', lines[10])
+
+ call delete('Xprofile_file.vim')
+ call delete('Xprofile_file.log')
+endfunc
+
func Test_profile_completion()
call feedkeys(":profile \<C-A>\<C-B>\"\<CR>", 'tx')
call assert_equal('"profile continue dump file func pause start stop', @:)
diff --git a/test/functional/ui/inccommand_spec.lua b/test/functional/ui/inccommand_spec.lua
index ceb2c83dd9..6646e65bad 100644
--- a/test/functional/ui/inccommand_spec.lua
+++ b/test/functional/ui/inccommand_spec.lua
@@ -948,7 +948,7 @@ describe(":substitute, inccommand=split", function()
]])
end)
- it('highlights nothing when there\'s no match', function()
+ it("highlights nothing when there's no match", function()
feed('gg')
feed(':%s/Inx')
screen:expect([[
@@ -1235,7 +1235,7 @@ describe("inccommand=nosplit", function()
feed('<Esc>')
end)
- it("does not show window after toggling :set inccomand", function()
+ it("does not show window after toggling :set inccommand", function()
feed(":%s/tw/OKOK")
feed("<Esc>")
command("set icm=split")
@@ -1800,7 +1800,7 @@ describe(":substitute", function()
clear()
end)
- it(", inccomand=split, highlights multiline substitutions", function()
+ it(", inccommand=split, highlights multiline substitutions", function()
common_setup(screen, "split", multiline_text)
feed("gg")
@@ -1862,7 +1862,7 @@ describe(":substitute", function()
]])
end)
- it(", inccomand=nosplit, highlights multiline substitutions", function()
+ it(", inccommand=nosplit, highlights multiline substitutions", function()
common_setup(screen, "nosplit", multiline_text)
feed("gg")
@@ -1905,7 +1905,7 @@ describe(":substitute", function()
]])
end)
- it(", inccomand=split, highlights multiple matches on a line", function()
+ it(", inccommand=split, highlights multiple matches on a line", function()
common_setup(screen, "split", multimatch_text)
command("set gdefault")
feed("gg")
@@ -1930,7 +1930,7 @@ describe(":substitute", function()
]])
end)
- it(", inccomand=nosplit, highlights multiple matches on a line", function()
+ it(", inccommand=nosplit, highlights multiple matches on a line", function()
common_setup(screen, "nosplit", multimatch_text)
command("set gdefault")
feed("gg")
@@ -1955,7 +1955,7 @@ describe(":substitute", function()
]])
end)
- it(", inccomand=split, with \\zs", function()
+ it(", inccommand=split, with \\zs", function()
common_setup(screen, "split", multiline_text)
feed("gg")
@@ -1979,7 +1979,7 @@ describe(":substitute", function()
]])
end)
- it(", inccomand=nosplit, with \\zs", function()
+ it(", inccommand=nosplit, with \\zs", function()
common_setup(screen, "nosplit", multiline_text)
feed("gg")
@@ -2003,7 +2003,7 @@ describe(":substitute", function()
]])
end)
- it(", inccomand=split, substitutions of different length",
+ it(", inccommand=split, substitutions of different length",
function()
common_setup(screen, "split", "T T123 T2T TTT T090804\nx")
@@ -2027,7 +2027,7 @@ describe(":substitute", function()
]])
end)
- it(", inccomand=nosplit, substitutions of different length", function()
+ it(", inccommand=nosplit, substitutions of different length", function()
common_setup(screen, "nosplit", "T T123 T2T TTT T090804\nx")
feed(":%s/T\\([0-9]\\+\\)/\\1\\1/g")
@@ -2050,7 +2050,7 @@ describe(":substitute", function()
]])
end)
- it(", inccomand=split, contraction of lines", function()
+ it(", inccommand=split, contraction of lines", function()
local text = [[
T T123 T T123 T2T TT T23423424
x
@@ -2099,7 +2099,7 @@ describe(":substitute", function()
]])
end)
- it(", inccomand=nosplit, contraction of lines", function()
+ it(", inccommand=nosplit, contraction of lines", function()
local text = [[
T T123 T T123 T2T TT T23423424
x
@@ -2211,7 +2211,7 @@ describe(":substitute", function()
]])
end)
- it(", inccomand=split, small cmdwinheight", function()
+ it(", inccommand=split, small cmdwinheight", function()
common_setup(screen, "split", long_multiline_text)
command("set cmdwinheight=2")
@@ -2273,7 +2273,7 @@ describe(":substitute", function()
]])
end)
- it(", inccomand=split, large cmdwinheight", function()
+ it(", inccommand=split, large cmdwinheight", function()
common_setup(screen, "split", long_multiline_text)
command("set cmdwinheight=11")
@@ -2335,7 +2335,7 @@ describe(":substitute", function()
]])
end)
- it(", inccomand=split, lookaround", function()
+ it(", inccommand=split, lookaround", function()
common_setup(screen, "split", "something\neverything\nsomeone")
feed([[:%s/\(some\)\@<lt>=thing/one/]])
screen:expect([[