diff options
-rw-r--r-- | runtime/filetype.vim | 10 | ||||
-rw-r--r-- | runtime/lua/vim/lsp/diagnostic.lua | 2 | ||||
-rw-r--r-- | runtime/lua/vim/lsp/handlers.lua | 64 | ||||
-rw-r--r-- | runtime/lua/vim/lsp/util.lua | 2 | ||||
-rw-r--r-- | src/nvim/edit.c | 22 | ||||
-rw-r--r-- | src/nvim/edit.h | 1 | ||||
-rw-r--r-- | src/nvim/eval/funcs.c | 2 | ||||
-rw-r--r-- | src/nvim/normal.c | 17 | ||||
-rw-r--r-- | src/nvim/testdir/test_filetype.vim | 4 | ||||
-rw-r--r-- | src/nvim/testdir/test_fold.vim | 29 |
10 files changed, 111 insertions, 42 deletions
diff --git a/runtime/filetype.vim b/runtime/filetype.vim index 52cd2dcbfd..b7157a14e7 100644 --- a/runtime/filetype.vim +++ b/runtime/filetype.vim @@ -1,7 +1,7 @@ " Vim support file to detect file types " " Maintainer: Bram Moolenaar <Bram@vim.org> -" Last Change: 2020 Apr 29 +" Last Change: 2021 Apr 05 " Listen very carefully, I will say this only once if exists("did_load_filetypes") @@ -1559,11 +1559,10 @@ au BufNewFile,BufRead catalog setf catalog " Shell scripts (sh, ksh, bash, bash2, csh); Allow .profile_foo etc. " Gentoo ebuilds and Arch Linux PKGBUILDs are actually bash scripts " NOTE: Patterns ending in a star are further down, these have lower priority. -au BufNewFile,BufRead .bashrc,bashrc,bash.bashrc,.bash[_-]profile,.bash[_-]logout,.bash[_-]aliases,bash-fc[-.],*.bash,*/{,.}bash[_-]completion{,.d,.sh}{,/*},*.ebuild,*.eclass,PKGBUILD call dist#ft#SetFileTypeSH("bash") +au BufNewFile,BufRead .bashrc,bashrc,bash.bashrc,.bash[_-]profile,.bash[_-]logout,.bash[_-]aliases,bash-fc[-.],*.ebuild,*.bash,*.eclass,PKGBUILD,APKBUILD call dist#ft#SetFileTypeSH("bash") au BufNewFile,BufRead .kshrc,*.ksh call dist#ft#SetFileTypeSH("ksh") au BufNewFile,BufRead */etc/profile,.profile,*.sh,*.env call dist#ft#SetFileTypeSH(getline(1)) - " Shell script (Arch Linux) or PHP file (Drupal) au BufNewFile,BufRead *.install \ if getline(1) =~ '<?php' | @@ -2237,8 +2236,11 @@ au BufNewFile,BufRead .reminders* call s:StarSetf('remind') " SGML catalog file au BufNewFile,BufRead sgml.catalog* call s:StarSetf('catalog') +" avoid doc files being recognized a shell files +au BufNewFile,BufRead */doc/{,.}bash[_-]completion{,.d,.sh}{,/*} setf text + " Shell scripts ending in a star -au BufNewFile,BufRead .bashrc*,.bash[_-]profile*,.bash[_-]logout*,.bash[_-]aliases*,bash-fc[-.]*,,PKGBUILD* call dist#ft#SetFileTypeSH("bash") +au BufNewFile,BufRead .bashrc*,.bash[_-]profile*,.bash[_-]logout*,.bash[_-]aliases*,bash-fc[-.]*,PKGBUILD*,APKBUILD*,*/{,.}bash[_-]completion{,.d,.sh}{,/*} call dist#ft#SetFileTypeSH("bash") au BufNewFile,BufRead .kshrc* call dist#ft#SetFileTypeSH("ksh") au BufNewFile,BufRead .profile* call dist#ft#SetFileTypeSH(getline(1)) diff --git a/runtime/lua/vim/lsp/diagnostic.lua b/runtime/lua/vim/lsp/diagnostic.lua index 4e82c46fef..bd7ef9cfdc 100644 --- a/runtime/lua/vim/lsp/diagnostic.lua +++ b/runtime/lua/vim/lsp/diagnostic.lua @@ -1147,7 +1147,7 @@ function M.show_line_diagnostics(opts, bufnr, line_nr, client_id) end end - local popup_bufnr, winnr = util.open_floating_preview(lines, 'plaintext') + local popup_bufnr, winnr = util.open_floating_preview(lines, 'plaintext', opts) for i, hi in ipairs(highlights) do local prefixlen, hiname = unpack(hi) -- Start highlight after the prefix diff --git a/runtime/lua/vim/lsp/handlers.lua b/runtime/lua/vim/lsp/handlers.lua index f52b76fa05..e0bb267e27 100644 --- a/runtime/lua/vim/lsp/handlers.lua +++ b/runtime/lua/vim/lsp/handlers.lua @@ -245,8 +245,30 @@ M['textDocument/completion'] = function(_, _, result) vim.fn.complete(textMatch+1, matches) end ---@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_hover -M['textDocument/hover'] = function(_, method, result) +--- |lsp-handler| for the method "textDocument/hover" +--- <pre> +--- vim.lsp.handlers["textDocument/hover"] = vim.lsp.with( +--- vim.lsp.handlers.hover, { +--- -- Use a sharp border with `FloatBorder` highlights +--- border = { +--- {"┌", "FloatBorder"}, +--- {"─", "FloatBorder"}, +--- {"┐", "FloatBorder"}, +--- {"│", "FloatBorder"}, +--- {"┘", "FloatBorder"}, +--- {"─", "FloatBorder"}, +--- {"└", "FloatBorder"}, +--- {"│", "FloatBorder"} +--- } +--- } +--- ) +--- </pre> +---@param config table Configuration table. +--- - border: (default=nil) +--- - Add borders to the floating window +--- - See |vim.api.nvim_open_win()| +function M.hover(_, method, result, _, _, config) + config = config or {} util.focusable_float(method, function() if not (result and result.contents) then -- return { 'No information available' } @@ -258,12 +280,17 @@ M['textDocument/hover'] = function(_, method, result) -- return { 'No information available' } return end - local bufnr, winnr = util.fancy_floating_markdown(markdown_lines) + local bufnr, winnr = util.fancy_floating_markdown(markdown_lines, { + border = config.border + }) util.close_preview_autocmd({"CursorMoved", "BufHidden", "InsertCharPre"}, winnr) return bufnr, winnr end) end +--@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_hover +M['textDocument/hover'] = M.hover + --@private --- Jumps to a location. Used as a handler for multiple LSP methods. --@param _ (not used) @@ -301,8 +328,30 @@ M['textDocument/typeDefinition'] = location_handler --@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_implementation M['textDocument/implementation'] = location_handler ---@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_signatureHelp -M['textDocument/signatureHelp'] = function(_, method, result, _, bufnr) +--- |lsp-handler| for the method "textDocument/signatureHelp" +--- <pre> +--- vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with( +--- vim.lsp.handlers.signature_help, { +--- -- Use a sharp border with `FloatBorder` highlights +--- border = { +--- {"┌", "FloatBorder"}, +--- {"─", "FloatBorder"}, +--- {"┐", "FloatBorder"}, +--- {"│", "FloatBorder"}, +--- {"┘", "FloatBorder"}, +--- {"─", "FloatBorder"}, +--- {"└", "FloatBorder"}, +--- {"│", "FloatBorder"} +--- } +--- } +--- ) +--- </pre> +---@param config table Configuration table. +--- - border: (default=nil) +--- - Add borders to the floating window +--- - See |vim.api.nvim_open_win()| +function M.signature_help(_, method, result, _, bufnr, config) + config = config or {} -- When use `autocmd CompleteDone <silent><buffer> lua vim.lsp.buf.signature_help()` to call signatureHelp handler -- If the completion item doesn't have signatures It will make noise. Change to use `print` that can use `<silent>` to ignore if not (result and result.signatures and result.signatures[1]) then @@ -317,11 +366,14 @@ M['textDocument/signatureHelp'] = function(_, method, result, _, bufnr) end local syntax = api.nvim_buf_get_option(bufnr, 'syntax') local p_bufnr, _ = util.focusable_preview(method, function() - return lines, util.try_trim_markdown_code_blocks(lines) + return lines, util.try_trim_markdown_code_blocks(lines), config end) api.nvim_buf_set_option(p_bufnr, 'syntax', syntax) end +--@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_signatureHelp +M['textDocument/signatureHelp'] = M.signature_help + --@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_documentHighlight M['textDocument/documentHighlight'] = function(_, _, result, _, bufnr, _) if not result then return end diff --git a/runtime/lua/vim/lsp/util.lua b/runtime/lua/vim/lsp/util.lua index f6d76dbcdd..a070cb5306 100644 --- a/runtime/lua/vim/lsp/util.lua +++ b/runtime/lua/vim/lsp/util.lua @@ -875,7 +875,7 @@ function M.make_floating_popup_options(width, height, opts) row = row + (opts.offset_y or 0), style = 'minimal', width = width, - border = { + border = opts.border or { {"", "NormalFloat"}, {"", "NormalFloat"}, {"", "NormalFloat"}, diff --git a/src/nvim/edit.c b/src/nvim/edit.c index be0ab33d08..ea13052f25 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -2319,7 +2319,11 @@ static int ins_compl_add(char_u *const str, int len, const Direction dir = (cdir == kDirectionNotSet ? compl_direction : cdir); int flags = flags_arg; - os_breakcheck(); + if (flags & CP_FAST) { + fast_breakcheck(); + } else { + os_breakcheck(); + } #define FREE_CPTEXT(cptext, cptext_allocated) \ do { \ if (cptext != NULL && cptext_allocated) { \ @@ -2523,7 +2527,8 @@ static void ins_compl_add_matches(int num_matches, char_u **matches, int icase) for (int i = 0; i < num_matches && add_r != FAIL; i++) { if ((add_r = ins_compl_add(matches[i], -1, NULL, NULL, false, NULL, dir, - icase ? CP_ICASE : 0, false)) == OK) { + CP_FAST | (icase ? CP_ICASE : 0), + false)) == OK) { // If dir was BACKWARD then honor it just once. dir = FORWARD; } @@ -2598,7 +2603,7 @@ void set_completion(colnr_T startcol, list_T *list) flags |= CP_ICASE; } if (ins_compl_add(compl_orig_text, -1, NULL, NULL, false, NULL, 0, - flags, false) != OK) { + flags | CP_FAST, false) != OK) { return; } @@ -3318,8 +3323,8 @@ static int ins_compl_bs(void) // allow the word to be deleted, we won't match everything. // Respect the 'backspace' option. if ((int)(p - line) - (int)compl_col < 0 - || ((int)(p - line) - (int)compl_col == 0 - && ctrl_x_mode != CTRL_X_OMNI) || ctrl_x_mode == CTRL_X_EVAL + || ((int)(p - line) - (int)compl_col == 0 && ctrl_x_mode != CTRL_X_OMNI) + || ctrl_x_mode == CTRL_X_EVAL || (!can_bs(BS_START) && (int)(p - line) - (int)compl_col - compl_length < 0)) { return K_BS; @@ -3934,7 +3939,7 @@ static void ins_compl_add_list(list_T *const list) // Go through the List with matches and add each of them. TV_LIST_ITER(list, li, { - if (ins_compl_add_tv(TV_LIST_ITEM_TV(li), dir) == OK) { + if (ins_compl_add_tv(TV_LIST_ITEM_TV(li), dir, true) == OK) { // If dir was BACKWARD then honor it just once. dir = FORWARD; } else if (did_emsg) { @@ -3973,17 +3978,18 @@ static void ins_compl_add_dict(dict_T *dict) /// /// @param[in] tv Object to get matches from. /// @param[in] dir Completion direction. +/// @param[in] fast use fast_breakcheck() instead of os_breakcheck(). /// /// @return NOTDONE if the given string is already in the list of completions, /// otherwise it is added to the list and OK is returned. FAIL will be /// returned in case of error. -int ins_compl_add_tv(typval_T *const tv, const Direction dir) +int ins_compl_add_tv(typval_T *const tv, const Direction dir, bool fast) FUNC_ATTR_NONNULL_ALL { const char *word; bool dup = false; bool empty = false; - int flags = 0; + int flags = fast ? CP_FAST : 0; char *(cptext[CPT_COUNT]); typval_T user_data; diff --git a/src/nvim/edit.h b/src/nvim/edit.h index 09f401ee82..ef5dce738a 100644 --- a/src/nvim/edit.h +++ b/src/nvim/edit.h @@ -19,6 +19,7 @@ typedef enum { CP_CONT_S_IPOS = 4, // use CONT_S_IPOS for compl_cont_status CP_EQUAL = 8, // ins_compl_equal() always returns true CP_ICASE = 16, // ins_compl_equal ignores case + CP_FAST = 32, // use fast_breakcheck instead of os_breakcheck } cp_flags_T; typedef int (*IndentGetter)(void); diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c index 1fbb2d8582..fb72b9425e 100644 --- a/src/nvim/eval/funcs.c +++ b/src/nvim/eval/funcs.c @@ -1098,7 +1098,7 @@ static void f_complete(typval_T *argvars, typval_T *rettv, FunPtr fptr) */ static void f_complete_add(typval_T *argvars, typval_T *rettv, FunPtr fptr) { - rettv->vval.v_number = ins_compl_add_tv(&argvars[0], 0); + rettv->vval.v_number = ins_compl_add_tv(&argvars[0], 0, false); } /* diff --git a/src/nvim/normal.c b/src/nvim/normal.c index 3b40689f3e..f016ef6813 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -3971,7 +3971,8 @@ static bool nv_screengo(oparg_T *oap, int dir, long dist) while (dist--) { if (dir == BACKWARD) { - if (curwin->w_curswant >= width1) { + if (curwin->w_curswant >= width1 + && !hasFolding(curwin->w_cursor.lnum, NULL, NULL)) { // Move back within the line. This can give a negative value // for w_curswant if width1 < width2 (with cpoptions+=n), // which will get clipped to column 0. @@ -4003,14 +4004,16 @@ static bool nv_screengo(oparg_T *oap, int dir, long dist) n = ((linelen - width1 - 1) / width2 + 1) * width2 + width1; else n = width1; - if (curwin->w_curswant + width2 < (colnr_T)n) - /* move forward within line */ + if (curwin->w_curswant + width2 < (colnr_T)n + && !hasFolding(curwin->w_cursor.lnum, NULL, NULL)) { + // move forward within line curwin->w_curswant += width2; - else { - /* to next line */ - /* Move to the end of a closed fold. */ + } else { + // to next line + + // Move to the end of a closed fold. (void)hasFolding(curwin->w_cursor.lnum, NULL, - &curwin->w_cursor.lnum); + &curwin->w_cursor.lnum); if (curwin->w_cursor.lnum == curbuf->b_ml.ml_line_count) { retval = false; break; diff --git a/src/nvim/testdir/test_filetype.vim b/src/nvim/testdir/test_filetype.vim index fa0bffd96c..1a98dc6451 100644 --- a/src/nvim/testdir/test_filetype.vim +++ b/src/nvim/testdir/test_filetype.vim @@ -417,7 +417,7 @@ let s:filename_checks = { \ 'sensors': ['/etc/sensors.conf', '/etc/sensors3.conf'], \ 'services': ['/etc/services'], \ 'setserial': ['/etc/serial.conf'], - \ 'sh': ['/etc/udev/cdsymlinks.conf'], + \ 'sh': ['.bashrc', 'file.bash', '/usr/share/doc/bash-completion/filter.sh','/etc/udev/cdsymlinks.conf', 'any/etc/udev/cdsymlinks.conf'], \ 'sieve': ['file.siv', 'file.sieve'], \ 'simula': ['file.sim'], \ 'sinda': ['file.sin', 'file.s85'], @@ -471,7 +471,7 @@ let s:filename_checks = { \ 'tex': ['file.latex', 'file.sty', 'file.dtx', 'file.ltx', 'file.bbl'], \ 'texinfo': ['file.texinfo', 'file.texi', 'file.txi'], \ 'texmf': ['texmf.cnf'], - \ 'text': ['file.text', 'README'], + \ 'text': ['file.text', 'README', '/usr/share/doc/bash-completion/AUTHORS'], \ 'tf': ['file.tf', '.tfrc', 'tfrc'], \ 'tidy': ['.tidyrc', 'tidyrc', 'tidy.conf'], \ 'tilde': ['file.t.html'], diff --git a/src/nvim/testdir/test_fold.vim b/src/nvim/testdir/test_fold.vim index 2d058e8e32..fcdf888b96 100644 --- a/src/nvim/testdir/test_fold.vim +++ b/src/nvim/testdir/test_fold.vim @@ -823,31 +823,36 @@ func Test_fold_create_delete() endfunc func Test_fold_relative_move() - enew! + new set fdm=indent sw=2 wrap tw=80 - let content = [ ' foo', ' bar', ' baz', - \ repeat('x', &columns + 1), - \ ' foo', ' bar', ' baz' + let longtext = repeat('x', &columns + 1) + let content = [ ' foo', ' ' .. longtext, ' baz', + \ longtext, + \ ' foo', ' ' .. longtext, ' baz' \ ] call append(0, content) normal zM - call cursor(3, 1) - call assert_true(foldclosed(line('.'))) - normal gj - call assert_equal(2, winline()) + for lnum in range(1, 3) + call cursor(lnum, 1) + call assert_true(foldclosed(line('.'))) + normal gj + call assert_equal(2, winline()) + endfor call cursor(2, 1) call assert_true(foldclosed(line('.'))) normal 2gj call assert_equal(3, winline()) - call cursor(5, 1) - call assert_true(foldclosed(line('.'))) - normal gk - call assert_equal(3, winline()) + for lnum in range(5, 7) + call cursor(lnum, 1) + call assert_true(foldclosed(line('.'))) + normal gk + call assert_equal(3, winline()) + endfor call cursor(6, 1) call assert_true(foldclosed(line('.'))) |