diff options
-rw-r--r-- | runtime/lua/vim/lsp/diagnostic.lua | 44 | ||||
-rw-r--r-- | runtime/lua/vim/lsp/util.lua | 21 | ||||
-rw-r--r-- | src/nvim/eval/funcs.c | 2 | ||||
-rw-r--r-- | src/nvim/eval/userfunc.c | 4 | ||||
-rw-r--r-- | src/nvim/ex_session.c | 2 | ||||
-rw-r--r-- | src/nvim/indent_c.c | 2 | ||||
-rw-r--r-- | src/nvim/memline.c | 2 | ||||
-rw-r--r-- | src/nvim/normal.c | 4 | ||||
-rw-r--r-- | src/nvim/regexp.c | 2 | ||||
-rw-r--r-- | src/nvim/regexp_nfa.c | 8 | ||||
-rw-r--r-- | src/nvim/screen.c | 2 | ||||
-rw-r--r-- | src/nvim/sign.c | 6 | ||||
-rw-r--r-- | src/nvim/testdir/test_popup.vim | 101 | ||||
-rw-r--r-- | src/nvim/undo.c | 4 | ||||
-rw-r--r-- | src/nvim/version.c | 4 | ||||
-rw-r--r-- | src/nvim/window.c | 7 | ||||
-rw-r--r-- | test/functional/fixtures/streams-test.c | 17 |
17 files changed, 169 insertions, 63 deletions
diff --git a/runtime/lua/vim/lsp/diagnostic.lua b/runtime/lua/vim/lsp/diagnostic.lua index 6a7dc1bbb0..06f2babde4 100644 --- a/runtime/lua/vim/lsp/diagnostic.lua +++ b/runtime/lua/vim/lsp/diagnostic.lua @@ -1197,44 +1197,56 @@ end --- - Exclusive severity to consider. Overrides {severity_limit} --- - {severity_limit}: (DiagnosticSeverity) --- - Limit severity of diagnostics found. E.g. "Warning" means { "Error", "Warning" } will be valid. +--- - {workspace}: (boolean, default false) +--- - Set the list with workspace diagnostics function M.set_loclist(opts) opts = opts or {} local open_loclist = if_nil(opts.open_loclist, true) - local bufnr = vim.api.nvim_get_current_buf() - local buffer_diags = M.get(bufnr, opts.client_id) - - if opts.severity then - buffer_diags = filter_to_severity_limit(opts.severity, buffer_diags) - elseif opts.severity_limit then - buffer_diags = filter_by_severity_limit(opts.severity_limit, buffer_diags) - end + local win_id = vim.api.nvim_get_current_win() + local current_bufnr = vim.api.nvim_get_current_buf() + local diags = opts.workspace and M.get_all() or { + [current_bufnr] = M.get(current_bufnr, opts.client_id) + } local items = {} - local insert_diag = function(diag) + local insert_diag = function(bufnr, diag) local pos = diag.range.start local row = pos.line - local col = util.character_offset(bufnr, row, pos.character) - local line = (api.nvim_buf_get_lines(bufnr, row, row + 1, false) or {""})[1] + local col = util.character_offset(bufnr, row, pos.character) or 0 table.insert(items, { bufnr = bufnr, lnum = row + 1, col = col + 1, - text = line .. " | " .. diag.message, + text = diag.message, type = loclist_type_map[diag.severity or DiagnosticSeverity.Error] or 'E', }) end - for _, diag in ipairs(buffer_diags) do - insert_diag(diag) + for bufnr, diagnostic in pairs(diags) do + if opts.severity then + diagnostic = filter_to_severity_limit(opts.severity, diagnostic) + elseif opts.severity_limit then + diagnostic = filter_by_severity_limit(opts.severity_limit, diagnostic) + end + + for _, diag in ipairs(diagnostic) do + insert_diag(bufnr, diag) + end end - table.sort(items, function(a, b) return a.lnum < b.lnum end) + table.sort(items, function(a, b) + if a.bufnr == b.bufnr then + return a.lnum < b.lnum + else + return a.bufnr < b.bufnr + end + end) - util.set_loclist(items) + util.set_loclist(items, win_id) if open_loclist then vim.cmd [[lopen]] end diff --git a/runtime/lua/vim/lsp/util.lua b/runtime/lua/vim/lsp/util.lua index 1e6a4ebd41..d421a10011 100644 --- a/runtime/lua/vim/lsp/util.lua +++ b/runtime/lua/vim/lsp/util.lua @@ -40,9 +40,12 @@ local function get_border_size(opts) local width = 0 if type(border) == 'string' then - -- 'single', 'double', etc. - height = 2 - width = 2 + local border_size = {none = {0, 0}, single = {2, 2}, double = {2, 2}, shadow = {1, 1}} + if border_size[border] == nil then + error("floating preview border is not correct. Please refer to the docs |vim.api.nvim_open_win()|" + .. vim.inspect(border)) + end + height, width = unpack(border_size[border]) else local function border_width(id) if type(border[id]) == "table" then @@ -1603,12 +1606,13 @@ function M.locations_to_items(locations) return items end ---- Fills current window's location list with given list of items. +--- Fills target window's location list with given list of items. --- Can be obtained with e.g. |vim.lsp.util.locations_to_items()|. +--- Defaults to current window. --- --@param items (table) list of items -function M.set_loclist(items) - vim.fn.setloclist(0, {}, ' ', { +function M.set_loclist(items, win_id) + vim.fn.setloclist(win_id or 0, {}, ' ', { title = 'Language Server'; items = items; }) @@ -1849,8 +1853,9 @@ end --@param row 0-indexed line --@param col 0-indexed byte offset in line --@returns (number, number) UTF-32 and UTF-16 index of the character in line {row} column {col} in buffer {buf} -function M.character_offset(buf, row, col) - local line = api.nvim_buf_get_lines(buf, row, row+1, true)[1] +function M.character_offset(bufnr, row, col) + local uri = vim.uri_from_bufnr(bufnr) + local line = M.get_line(uri, row) -- If the col is past the EOL, use the line length. if col > #line then return str_utfindex(line) diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c index caaf675db2..ce09d268ea 100644 --- a/src/nvim/eval/funcs.c +++ b/src/nvim/eval/funcs.c @@ -2547,7 +2547,7 @@ static void f_fnamemodify(typval_T *argvars, typval_T *rettv, FunPtr fptr) } else { len = strlen(fname); size_t usedlen = 0; - if (mods != NULL && *mods != NUL) { + if (*mods != NUL) { (void)modify_fname((char_u *)mods, false, &usedlen, (char_u **)&fname, &fbuf, &len); } diff --git a/src/nvim/eval/userfunc.c b/src/nvim/eval/userfunc.c index dc7027980e..f5d1b1e870 100644 --- a/src/nvim/eval/userfunc.c +++ b/src/nvim/eval/userfunc.c @@ -144,10 +144,6 @@ static int get_function_args(char_u **argp, char_u endchar, garray_T *newargs, c = *p; *p = NUL; expr = vim_strsave(expr); - if (expr == NULL) { - *p = c; - goto err_ret; - } ((char_u **)(default_args->ga_data)) [default_args->ga_len] = expr; default_args->ga_len++; diff --git a/src/nvim/ex_session.c b/src/nvim/ex_session.c index 481febd16b..67b8e7e92f 100644 --- a/src/nvim/ex_session.c +++ b/src/nvim/ex_session.c @@ -835,7 +835,7 @@ static int makeopens(FILE *fd, char_u *dirnow) p_shm) < 0) { return FAIL; } - if (tab_firstwin->w_next != NULL) { + if (tab_firstwin != NULL && tab_firstwin->w_next != NULL) { // Restore 'winminheight' and 'winminwidth'. PUTLINE_FAIL("let &winminheight = s:save_winminheight"); PUTLINE_FAIL("let &winminwidth = s:save_winminwidth"); diff --git a/src/nvim/indent_c.c b/src/nvim/indent_c.c index 771bf923b2..25c27743f3 100644 --- a/src/nvim/indent_c.c +++ b/src/nvim/indent_c.c @@ -3552,7 +3552,7 @@ term_again: * Position the cursor over the rightmost paren, so that * matching it will take us back to the start of the line. */ - find_last_paren(l, '(', ')'); + (void)find_last_paren(l, '(', ')'); if ((trypos = find_match_paren(curbuf->b_ind_maxparen)) != NULL) curwin->w_cursor = *trypos; diff --git a/src/nvim/memline.c b/src/nvim/memline.c index 34d8eb0ffe..e42b138253 100644 --- a/src/nvim/memline.c +++ b/src/nvim/memline.c @@ -2238,7 +2238,7 @@ static int ml_append_int( */ lineadd = buf->b_ml.ml_locked_lineadd; buf->b_ml.ml_locked_lineadd = 0; - ml_find_line(buf, (linenr_T)0, ML_FLUSH); /* flush data block */ + (void)ml_find_line(buf, (linenr_T)0, ML_FLUSH); // flush data block /* * update pointer blocks for the new data block diff --git a/src/nvim/normal.c b/src/nvim/normal.c index 173d8d46d1..69afe1644e 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -5120,8 +5120,8 @@ static void nv_scroll(cmdarg_T *cap) /* Count a fold for one screen line. */ lnum = curwin->w_topline; while (n-- > 0 && lnum < curwin->w_botline - 1) { - hasFolding(lnum, NULL, &lnum); - ++lnum; + (void)hasFolding(lnum, NULL, &lnum); + lnum++; } n = lnum - curwin->w_topline; } diff --git a/src/nvim/regexp.c b/src/nvim/regexp.c index 6b84bb3207..c2ef217638 100644 --- a/src/nvim/regexp.c +++ b/src/nvim/regexp.c @@ -2912,7 +2912,7 @@ static int peekchr(void) at_start = false; // be able to say "/\*ptr" regparse++; after_slash++; - peekchr(); + (void)peekchr(); regparse--; after_slash--; curchr = toggle_Magic(curchr); diff --git a/src/nvim/regexp_nfa.c b/src/nvim/regexp_nfa.c index 5047e0db03..35c3285cda 100644 --- a/src/nvim/regexp_nfa.c +++ b/src/nvim/regexp_nfa.c @@ -1461,10 +1461,10 @@ static int nfa_regatom(void) if (nfa_regatom() == FAIL) return FAIL; } - getchr(); /* get the ] */ - if (n == 0) - EMSG2_RET_FAIL(_(e_empty_sb), - reg_magic == MAGIC_ALL); + (void)getchr(); // get the ] + if (n == 0) { + EMSG2_RET_FAIL(_(e_empty_sb), reg_magic == MAGIC_ALL); + } EMIT(NFA_OPT_CHARS); EMIT(n); diff --git a/src/nvim/screen.c b/src/nvim/screen.c index 90ac4ac7aa..844104e7d0 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -2101,7 +2101,7 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool search_attr_from_match = false; // if search_attr is from :match bool has_decor = false; // this buffer has decoration bool do_virttext = false; // draw virtual text for this line - int win_col_offset; // offsett for window columns + int win_col_offset = 0; // offset for window columns char_u buf_fold[FOLD_TEXT_LEN + 1]; // Hold value returned by get_foldtext diff --git a/src/nvim/sign.c b/src/nvim/sign.c index 97e64c6c4c..15fd25e096 100644 --- a/src/nvim/sign.c +++ b/src/nvim/sign.c @@ -2012,9 +2012,6 @@ int sign_place_from_dict( group = NULL; } else { group = vim_strsave(group); - if (group == NULL) { - return -1; - } } } @@ -2114,9 +2111,6 @@ int sign_unplace_from_dict(typval_T *group_tv, dict_T *dict) group = NULL; } else { group = vim_strsave(group); - if (group == NULL) { - return -1; - } } } diff --git a/src/nvim/testdir/test_popup.vim b/src/nvim/testdir/test_popup.vim index 9443958984..06bdb1236a 100644 --- a/src/nvim/testdir/test_popup.vim +++ b/src/nvim/testdir/test_popup.vim @@ -850,6 +850,34 @@ func Test_popup_position() call delete('Xtest') endfunc +func Test_popup_command() + if !CanRunVimInTerminal() || !has('menu') + return + endif + + call writefile([ + \ 'one two three four five', + \ 'and one two Xthree four five', + \ 'one more two three four five', + \ ], 'Xtest') + let buf = RunVimInTerminal('Xtest', {}) + call term_sendkeys(buf, ":source $VIMRUNTIME/menu.vim\<CR>") + call term_sendkeys(buf, "/X\<CR>:popup PopUp\<CR>") + call VerifyScreenDump(buf, 'Test_popup_command_01', {}) + + " Select a word + call term_sendkeys(buf, "jj") + call VerifyScreenDump(buf, 'Test_popup_command_02', {}) + + " Select a word + call term_sendkeys(buf, "j\<CR>") + call VerifyScreenDump(buf, 'Test_popup_command_03', {}) + + call term_sendkeys(buf, "\<Esc>") + call StopVimInTerminal(buf) + call delete('Xtest') +endfunc + func Test_popup_complete_backwards() new call setline(1, ['Post', 'Port', 'Po']) @@ -1077,4 +1105,77 @@ func Test_pum_getpos() unlet g:pum_pos endfunc +" Test for the popup menu with the 'rightleft' option set +func Test_pum_rightleft() + CheckFeature rightleft + CheckScreendump + + let lines =<< trim END + abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz + vim + victory + END + call writefile(lines, 'Xtest1') + let buf = RunVimInTerminal('--cmd "set rightleft" Xtest1', {}) + call term_wait(buf) + call term_sendkeys(buf, "Go\<C-P>") + call term_wait(buf) + call VerifyScreenDump(buf, 'Test_pum_rightleft_01', {'rows': 8}) + call term_sendkeys(buf, "\<C-P>\<C-Y>") + call term_wait(buf) + redraw! + call assert_match('\s*miv', Screenline(5)) + + " Test for expanding tabs to spaces in the popup menu + let lines =<< trim END + one two + one three + four + END + call writefile(lines, 'Xtest2') + call term_sendkeys(buf, "\<Esc>:e! Xtest2\<CR>") + call term_wait(buf) + call term_sendkeys(buf, "Goone\<C-X>\<C-L>") + call term_wait(buf) + redraw! + call VerifyScreenDump(buf, 'Test_pum_rightleft_02', {'rows': 7}) + call term_sendkeys(buf, "\<C-Y>") + call term_wait(buf) + redraw! + call assert_match('\s*eerht eno', Screenline(4)) + + call StopVimInTerminal(buf) + call delete('Xtest1') + call delete('Xtest2') +endfunc + +" Test for a popup menu with a scrollbar +func Test_pum_scrollbar() + CheckScreendump + let lines =<< trim END + one + two + three + END + call writefile(lines, 'Xtest1') + let buf = RunVimInTerminal('--cmd "set pumheight=2" Xtest1', {}) + call term_wait(buf) + call term_sendkeys(buf, "Go\<C-P>\<C-P>\<C-P>") + call term_wait(buf) + call VerifyScreenDump(buf, 'Test_pum_scrollbar_01', {'rows': 7}) + call term_sendkeys(buf, "\<C-E>\<Esc>dd") + call term_wait(buf) + + if has('rightleft') + call term_sendkeys(buf, ":set rightleft\<CR>") + call term_wait(buf) + call term_sendkeys(buf, "Go\<C-P>\<C-P>\<C-P>") + call term_wait(buf) + call VerifyScreenDump(buf, 'Test_pum_scrollbar_02', {'rows': 7}) + endif + + call StopVimInTerminal(buf) + call delete('Xtest1') +endfunc + " vim: shiftwidth=2 sts=2 expandtab diff --git a/src/nvim/undo.c b/src/nvim/undo.c index f52850f6f3..ffd613cec2 100644 --- a/src/nvim/undo.c +++ b/src/nvim/undo.c @@ -1018,9 +1018,7 @@ static ExtmarkUndoObject *unserialize_extmark(bufinfo_T *bi, bool *error, goto error; } - if (buf) { - xfree(buf); - } + xfree(buf); return extup; diff --git a/src/nvim/version.c b/src/nvim/version.c index deba3f6e49..f3a30630f8 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -406,13 +406,13 @@ static const int included_patches[] = { 1514, 1513, 1512, - // 1511, + 1511, 1510, 1509, 1508, 1507, 1506, - // 1505, + 1505, 1504, 1503, 1502, diff --git a/src/nvim/window.c b/src/nvim/window.c index cdeae2e294..aea60fe24c 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -2528,7 +2528,7 @@ int win_close(win_T *win, bool free_buf) // only resize that frame. Otherwise resize all windows. win_equal(curwin, curwin->w_frame->fr_parent == win_frame, dir); } else { - win_comp_pos(); + (void)win_comp_pos(); } } @@ -6296,9 +6296,10 @@ restore_snapshot ( && curtab->tp_snapshot[idx]->fr_height == topframe->fr_height && check_snapshot_rec(curtab->tp_snapshot[idx], topframe) == OK) { wp = restore_snapshot_rec(curtab->tp_snapshot[idx], topframe); - win_comp_pos(); - if (wp != NULL && close_curwin) + (void)win_comp_pos(); + if (wp != NULL && close_curwin) { win_goto(wp); + } redraw_all_later(NOT_VALID); } clear_snapshot(curtab, idx); diff --git a/test/functional/fixtures/streams-test.c b/test/functional/fixtures/streams-test.c index eec447153c..be40edfe7e 100644 --- a/test/functional/fixtures/streams-test.c +++ b/test/functional/fixtures/streams-test.c @@ -6,23 +6,22 @@ #include <uv.h> -uv_loop_t *loop; -uv_process_t child_req; -uv_process_options_t options; - int main(int argc, char **argv) { - loop = uv_default_loop(); + uv_loop_t *loop = uv_default_loop(); + uv_process_t child_req; char * args[3]; args[0] = "sleep"; args[1] = "10"; args[2] = NULL; - options.exit_cb = NULL; - options.file = "sleep"; - options.args = args; - options.flags = UV_PROCESS_DETACHED; + uv_process_options_t options = { + .exit_cb = NULL, + .file = "sleep", + .args = args, + .flags = UV_PROCESS_DETACHED, + }; int r; if ((r = uv_spawn(loop, &child_req, &options))) { |