diff options
Diffstat (limited to 'runtime/lua/vim')
-rw-r--r-- | runtime/lua/vim/_defaults.lua | 74 | ||||
-rw-r--r-- | runtime/lua/vim/_editor.lua | 27 | ||||
-rw-r--r-- | runtime/lua/vim/_meta/api.lua | 18 | ||||
-rw-r--r-- | runtime/lua/vim/_meta/options.lua | 27 | ||||
-rw-r--r-- | runtime/lua/vim/diagnostic.lua | 3 | ||||
-rw-r--r-- | runtime/lua/vim/filetype.lua | 2 | ||||
-rw-r--r-- | runtime/lua/vim/lsp/buf.lua | 14 | ||||
-rw-r--r-- | runtime/lua/vim/lsp/protocol.lua | 2 | ||||
-rw-r--r-- | runtime/lua/vim/lsp/util.lua | 4 | ||||
-rw-r--r-- | runtime/lua/vim/termcap.lua | 7 | ||||
-rw-r--r-- | runtime/lua/vim/ui/clipboard/osc52.lua | 2 |
11 files changed, 118 insertions, 62 deletions
diff --git a/runtime/lua/vim/_defaults.lua b/runtime/lua/vim/_defaults.lua index c2e4e76dd6..c709f0a308 100644 --- a/runtime/lua/vim/_defaults.lua +++ b/runtime/lua/vim/_defaults.lua @@ -515,8 +515,8 @@ do if channel == 0 then return end - local fg_request = args.data == '\027]10;?' - local bg_request = args.data == '\027]11;?' + local fg_request = args.data.sequence == '\027]10;?' + local bg_request = args.data.sequence == '\027]11;?' if fg_request or bg_request then -- WARN: This does not return the actual foreground/background color, -- but rather returns: @@ -534,14 +534,59 @@ do end, }) + local nvim_terminal_prompt_ns = vim.api.nvim_create_namespace('nvim.terminal.prompt') + vim.api.nvim_create_autocmd('TermRequest', { + group = nvim_terminal_augroup, + desc = 'Mark shell prompts indicated by OSC 133 sequences for navigation', + callback = function(args) + if string.match(args.data.sequence, '^\027]133;A') then + local lnum = args.data.cursor[1] ---@type integer + vim.api.nvim_buf_set_extmark(args.buf, nvim_terminal_prompt_ns, lnum - 1, 0, {}) + end + end, + }) + + ---@param ns integer + ---@param buf integer + ---@param count integer + local function jump_to_prompt(ns, win, buf, count) + local row, col = unpack(vim.api.nvim_win_get_cursor(win)) + local start = -1 + local end_ ---@type 0|-1 + if count > 0 then + start = row + end_ = -1 + elseif count < 0 then + -- Subtract 2 because row is 1-based, but extmarks are 0-based + start = row - 2 + end_ = 0 + end + + if start < 0 then + return + end + + local extmarks = vim.api.nvim_buf_get_extmarks( + buf, + ns, + { start, col }, + end_, + { limit = math.abs(count) } + ) + if #extmarks > 0 then + local extmark = extmarks[math.min(#extmarks, math.abs(count))] + vim.api.nvim_win_set_cursor(win, { extmark[2] + 1, extmark[3] }) + end + end + vim.api.nvim_create_autocmd('TermOpen', { group = nvim_terminal_augroup, desc = 'Default settings for :terminal buffers', - callback = function() - vim.bo.modifiable = false - vim.bo.undolevels = -1 - vim.bo.scrollback = vim.o.scrollback < 0 and 10000 or math.max(1, vim.o.scrollback) - vim.bo.textwidth = 0 + callback = function(args) + vim.bo[args.buf].modifiable = false + vim.bo[args.buf].undolevels = -1 + vim.bo[args.buf].scrollback = vim.o.scrollback < 0 and 10000 or math.max(1, vim.o.scrollback) + vim.bo[args.buf].textwidth = 0 vim.wo[0][0].wrap = false vim.wo[0][0].list = false vim.wo[0][0].number = false @@ -555,6 +600,13 @@ do winhl = winhl .. ',' end vim.wo[0][0].winhighlight = winhl .. 'StatusLine:StatusLineTerm,StatusLineNC:StatusLineTermNC' + + vim.keymap.set('n', '[[', function() + jump_to_prompt(nvim_terminal_prompt_ns, 0, args.buf, -vim.v.count1) + end, { buffer = args.buf, desc = 'Jump [count] shell prompts backward' }) + vim.keymap.set('n', ']]', function() + jump_to_prompt(nvim_terminal_prompt_ns, 0, args.buf, vim.v.count1) + end, { buffer = args.buf, desc = 'Jump [count] shell prompts forward' }) end, }) @@ -712,7 +764,7 @@ do nested = true, desc = "Update the value of 'background' automatically based on the terminal emulator's background color", callback = function(args) - local resp = args.data ---@type string + local resp = args.data.sequence ---@type string local r, g, b = parseosc11(resp) if r and g and b then local rr = parsecolor(r) @@ -788,7 +840,7 @@ do group = group, nested = true, callback = function(args) - local resp = args.data ---@type string + local resp = args.data.sequence ---@type string local decrqss = resp:match('^\027P1%$r([%d;:]+)m$') if decrqss then @@ -834,9 +886,7 @@ do -- terminal responds to the DECRQSS with the same SGR sequence that we -- sent then the terminal supports truecolor. local decrqss = '\027P$qm\027\\' - if os.getenv('TMUX') then - decrqss = string.format('\027Ptmux;%s\027\\', decrqss:gsub('\027', '\027\027')) - end + -- Reset attributes first, as other code may have set attributes. io.stdout:write(string.format('\027[0m\027[48;2;%d;%d;%dm%s', r, g, b, decrqss)) diff --git a/runtime/lua/vim/_editor.lua b/runtime/lua/vim/_editor.lua index 975f3fea4a..e29d8f1c30 100644 --- a/runtime/lua/vim/_editor.lua +++ b/runtime/lua/vim/_editor.lua @@ -1142,6 +1142,21 @@ do end end +--- @param inspect_strings boolean use vim.inspect() for strings +function vim._print(inspect_strings, ...) + local msg = {} + for i = 1, select('#', ...) do + local o = select(i, ...) + if not inspect_strings and type(o) == 'string' then + table.insert(msg, o) + else + table.insert(msg, vim.inspect(o, { newline = '\n', indent = ' ' })) + end + end + print(table.concat(msg, '\n')) + return ... +end + --- "Pretty prints" the given arguments and returns them unmodified. --- --- Example: @@ -1155,17 +1170,7 @@ end --- @param ... any --- @return any # given arguments. function vim.print(...) - local msg = {} - for i = 1, select('#', ...) do - local o = select(i, ...) - if type(o) == 'string' then - table.insert(msg, o) - else - table.insert(msg, vim.inspect(o, { newline = '\n', indent = ' ' })) - end - end - print(table.concat(msg, '\n')) - return ... + return vim._print(false, ...) end --- Translates keycodes. diff --git a/runtime/lua/vim/_meta/api.lua b/runtime/lua/vim/_meta/api.lua index 15cdd8fc79..b890b64174 100644 --- a/runtime/lua/vim/_meta/api.lua +++ b/runtime/lua/vim/_meta/api.lua @@ -9,19 +9,16 @@ error('Cannot require a meta file') vim.api = {} ---- @private --- @param buffer integer --- @param keys boolean --- @param dot boolean --- @return string function vim.api.nvim__buf_debug_extmarks(buffer, keys, dot) end ---- @private --- @param buffer integer --- @return table<string,any> function vim.api.nvim__buf_stats(buffer) end ---- @private --- EXPERIMENTAL: this API may change in the future. --- --- Sets info for the completion item at the given index. If the info text was shown in a window, @@ -35,11 +32,9 @@ function vim.api.nvim__buf_stats(buffer) end --- - bufnr: (number) buffer id in floating window function vim.api.nvim__complete_set(index, opts) end ---- @private --- @return string function vim.api.nvim__get_lib_dir() end ---- @private --- Find files in runtime directories --- --- @param pat any[] pattern of files to search for @@ -48,7 +43,6 @@ function vim.api.nvim__get_lib_dir() end --- @return string[] # list of absolute paths to the found files function vim.api.nvim__get_runtime(pat, all, opts) end ---- @private --- Returns object given as argument. --- --- This API function is used for testing. One should not rely on its presence @@ -58,7 +52,6 @@ function vim.api.nvim__get_runtime(pat, all, opts) end --- @return any # its argument. function vim.api.nvim__id(obj) end ---- @private --- Returns array given as argument. --- --- This API function is used for testing. One should not rely on its presence @@ -68,7 +61,6 @@ function vim.api.nvim__id(obj) end --- @return any[] # its argument. function vim.api.nvim__id_array(arr) end ---- @private --- Returns dict given as argument. --- --- This API function is used for testing. One should not rely on its presence @@ -78,7 +70,6 @@ function vim.api.nvim__id_array(arr) end --- @return table<string,any> # its argument. function vim.api.nvim__id_dict(dct) end ---- @private --- Returns floating-point value given as argument. --- --- This API function is used for testing. One should not rely on its presence @@ -88,7 +79,6 @@ function vim.api.nvim__id_dict(dct) end --- @return number # its argument. function vim.api.nvim__id_float(flt) end ---- @private --- NB: if your UI doesn't use hlstate, this will not return hlstate first time. --- @param grid integer --- @param row integer @@ -96,12 +86,10 @@ function vim.api.nvim__id_float(flt) end --- @return any[] function vim.api.nvim__inspect_cell(grid, row, col) end ---- @private --- For testing. The condition in schar_cache_clear_if_full is hard to --- reach, so this function can be used to force a cache clear in a test. function vim.api.nvim__invalidate_glyph_cache() end ---- @private --- EXPERIMENTAL: this API will change in the future. --- --- Get the properties for namespace @@ -110,7 +98,6 @@ function vim.api.nvim__invalidate_glyph_cache() end --- @return vim.api.keyset.ns_opts # Map defining the namespace properties, see |nvim__ns_set()| function vim.api.nvim__ns_get(ns_id) end ---- @private --- EXPERIMENTAL: this API will change in the future. --- --- Set some properties for namespace @@ -120,7 +107,6 @@ function vim.api.nvim__ns_get(ns_id) end --- - wins: a list of windows to be scoped in function vim.api.nvim__ns_set(ns_id, opts) end ---- @private --- EXPERIMENTAL: this API may change in the future. --- --- Instruct Nvim to redraw various components. @@ -148,21 +134,17 @@ function vim.api.nvim__ns_set(ns_id, opts) end --- - tabline: Redraw the 'tabline'. function vim.api.nvim__redraw(opts) end ---- @private --- @return any[] function vim.api.nvim__runtime_inspect() end ---- @private --- @param path string function vim.api.nvim__screenshot(path) end ---- @private --- Gets internal stats. --- --- @return table<string,any> # Map of various internal stats. function vim.api.nvim__stats() end ---- @private --- @param str string --- @return any function vim.api.nvim__unpack(str) end diff --git a/runtime/lua/vim/_meta/options.lua b/runtime/lua/vim/_meta/options.lua index 8df174a838..59e65b0585 100644 --- a/runtime/lua/vim/_meta/options.lua +++ b/runtime/lua/vim/_meta/options.lua @@ -1083,15 +1083,15 @@ vim.go.cia = vim.go.completeitemalign --- match, e.g., what file it comes from. --- --- noinsert Do not insert any text for a match until the user selects ---- a match from the menu. Only works in combination with +--- a match from the menu. Only works in combination with --- "menu" or "menuone". No effect if "longest" is present. --- --- noselect Same as "noinsert", except that no menu item is ---- pre-selected. If both "noinsert" and "noselect" are +--- pre-selected. If both "noinsert" and "noselect" are --- present, "noselect" has precedence. --- --- nosort Disable sorting of completion candidates based on fuzzy ---- scores when "fuzzy" is enabled. Candidates will appear +--- scores when "fuzzy" is enabled. Candidates will appear --- in their original order. --- --- popup Show extra information about the currently selected @@ -1102,7 +1102,7 @@ vim.go.cia = vim.go.completeitemalign --- Preinsert the portion of the first candidate word that is --- not part of the current completion leader and using the --- `hl-ComplMatchIns` highlight group. In order for it to ---- work, "fuzzy" must not bet set and "menuone" must be set. +--- work, "fuzzy" must not be set and "menuone" must be set. --- --- preview Show extra information about the currently selected --- completion in the preview window. Only works in @@ -4640,7 +4640,7 @@ vim.go.pm = vim.go.patchmode --- ``` --- - A directory name may end in a ':' or '/'. --- - Environment variables are expanded `:set_env`. ---- - When using `netrw.vim` URLs can be used. For example, adding +--- - When using `netrw` URLs can be used. For example, adding --- "https://www.vim.org" will make ":find index.html" work. --- - Search upwards and downwards in a directory tree using "*", "**" and --- ";". See `file-searching` for info and syntax. @@ -7691,7 +7691,10 @@ vim.go.wmnu = vim.go.wildmenu --- "lastused" When completing buffer names and more than one buffer --- matches, sort buffers by time last used (other than --- the current buffer). ---- When there is only a single match, it is fully completed in all cases. +--- "noselect" Do not pre-select first menu item and start 'wildmenu' +--- if it is enabled. +--- When there is only a single match, it is fully completed in all cases +--- except when "noselect" is present. --- --- Examples of useful colon-separated values: --- "longest:full" Like "longest", but also start 'wildmenu' if it is @@ -7729,7 +7732,17 @@ vim.go.wmnu = vim.go.wildmenu --- ```vim --- set wildmode=longest,list --- ``` ---- Complete longest common string, then list alternatives. +--- Complete longest common string, then list alternatives +--- +--- ```vim +--- set wildmode=noselect:full +--- ``` +--- Display 'wildmenu' without completing, then each full match +--- +--- ```vim +--- set wildmode=noselect:lastused,full +--- ``` +--- Same as above, but sort buffers by time last used. --- More info here: `cmdline-completion`. --- --- @type string diff --git a/runtime/lua/vim/diagnostic.lua b/runtime/lua/vim/diagnostic.lua index 26f0011e82..4749f94b1b 100644 --- a/runtime/lua/vim/diagnostic.lua +++ b/runtime/lua/vim/diagnostic.lua @@ -1757,8 +1757,7 @@ local function render_virtual_lines(namespace, bufnr, diagnostics) string.rep( ' ', -- +1 because indexing starts at 0 in one API but at 1 in the other. - -- -1 for non-first lines, since the previous column was already drawn. - distance_between_cols(bufnr, diag.lnum, prev_col + 1, diag.col) - 1 + distance_between_cols(bufnr, diag.lnum, prev_col + 1, diag.col) ), }) else diff --git a/runtime/lua/vim/filetype.lua b/runtime/lua/vim/filetype.lua index c47ce5e761..2c058bc6bf 100644 --- a/runtime/lua/vim/filetype.lua +++ b/runtime/lua/vim/filetype.lua @@ -198,6 +198,7 @@ local extension = { abap = 'abap', abc = 'abc', abl = 'abel', + abnf = 'abnf', wrm = 'acedb', ads = 'ada', ada = 'ada', @@ -1206,6 +1207,7 @@ local extension = { tl = 'teal', templ = 'templ', tmpl = 'template', + tera = 'tera', ti = 'terminfo', dtx = 'tex', ltx = 'tex', diff --git a/runtime/lua/vim/lsp/buf.lua b/runtime/lua/vim/lsp/buf.lua index 47f41b43aa..2da591e9bb 100644 --- a/runtime/lua/vim/lsp/buf.lua +++ b/runtime/lua/vim/lsp/buf.lua @@ -1129,6 +1129,7 @@ local function on_code_action_results(results, opts) if not choice then return end + -- textDocument/codeAction can return either Command[] or CodeAction[] -- -- CodeAction @@ -1140,15 +1141,22 @@ local function on_code_action_results(results, opts) -- title: string -- command: string -- arguments?: any[] - -- + local client = assert(lsp.get_client_by_id(choice.ctx.client_id)) local action = choice.action local bufnr = assert(choice.ctx.bufnr, 'Must have buffer number') - if not action.edit and client:supports_method(ms.codeAction_resolve) then + -- Only code actions are resolved, so if we have a command, just apply it. + if type(action.title) == 'string' and type(action.command) == 'string' then + apply_action(action, client, choice.ctx) + return + end + + if not action.edit or not action.command and client:supports_method(ms.codeAction_resolve) then client:request(ms.codeAction_resolve, action, function(err, resolved_action) if err then - if action.command then + -- If resolve fails, try to apply the edit/command from the original code action. + if action.edit or action.command then apply_action(action, client, choice.ctx) else vim.notify(err.code .. ': ' .. err.message, vim.log.levels.ERROR) diff --git a/runtime/lua/vim/lsp/protocol.lua b/runtime/lua/vim/lsp/protocol.lua index 7975006f9d..feff9adbd0 100644 --- a/runtime/lua/vim/lsp/protocol.lua +++ b/runtime/lua/vim/lsp/protocol.lua @@ -424,7 +424,7 @@ function protocol.make_client_capabilities() isPreferredSupport = true, dataSupport = true, resolveSupport = { - properties = { 'edit' }, + properties = { 'edit', 'command' }, }, }, codeLens = { diff --git a/runtime/lua/vim/lsp/util.lua b/runtime/lua/vim/lsp/util.lua index 1219f71427..ef177e903f 100644 --- a/runtime/lua/vim/lsp/util.lua +++ b/runtime/lua/vim/lsp/util.lua @@ -1656,7 +1656,9 @@ function M.open_floating_preview(contents, syntax, opts) if not opts.height then -- Reduce window height if TS highlighter conceals code block backticks. local conceal_height = api.nvim_win_text_height(floating_winnr, {}).all - api.nvim_win_set_height(floating_winnr, conceal_height) + if conceal_height < api.nvim_win_get_height(floating_winnr) then + api.nvim_win_set_height(floating_winnr, conceal_height) + end end end diff --git a/runtime/lua/vim/termcap.lua b/runtime/lua/vim/termcap.lua index 4aa41bba9b..2789aacb90 100644 --- a/runtime/lua/vim/termcap.lua +++ b/runtime/lua/vim/termcap.lua @@ -34,7 +34,7 @@ function M.query(caps, cb) local id = vim.api.nvim_create_autocmd('TermResponse', { nested = true, callback = function(args) - local resp = args.data ---@type string + local resp = args.data.sequence ---@type string local k, rest = resp:match('^\027P1%+r(%x+)(.*)$') if k and rest then local cap = vim.text.hexdecode(k) @@ -71,11 +71,6 @@ function M.query(caps, cb) local query = string.format('\027P+q%s\027\\', table.concat(encoded, ';')) - -- If running in tmux, wrap with the passthrough sequence - if os.getenv('TMUX') then - query = string.format('\027Ptmux;%s\027\\', query:gsub('\027', '\027\027')) - end - io.stdout:write(query) timer:start(1000, 0, function() diff --git a/runtime/lua/vim/ui/clipboard/osc52.lua b/runtime/lua/vim/ui/clipboard/osc52.lua index 50afbe63a5..73f64c9743 100644 --- a/runtime/lua/vim/ui/clipboard/osc52.lua +++ b/runtime/lua/vim/ui/clipboard/osc52.lua @@ -25,7 +25,7 @@ function M.paste(reg) local contents = nil local id = vim.api.nvim_create_autocmd('TermResponse', { callback = function(args) - local resp = args.data ---@type string + local resp = args.data.sequence ---@type string local encoded = resp:match('\027%]52;%w?;([A-Za-z0-9+/=]*)') if encoded then contents = vim.base64.decode(encoded) |