aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/lua/vim')
-rw-r--r--runtime/lua/vim/_defaults.lua24
-rw-r--r--runtime/lua/vim/_meta/api.lua6
-rw-r--r--runtime/lua/vim/_meta/builtin.lua1
-rw-r--r--runtime/lua/vim/_meta/builtin_types.lua5
-rw-r--r--runtime/lua/vim/_meta/lpeg.lua4
-rw-r--r--runtime/lua/vim/_meta/options.lua13
-rw-r--r--runtime/lua/vim/_meta/vimfn.lua200
-rw-r--r--runtime/lua/vim/_options.lua11
-rw-r--r--runtime/lua/vim/filetype.lua2
-rw-r--r--runtime/lua/vim/filetype/detect.lua1
-rw-r--r--runtime/lua/vim/iter.lua2
-rw-r--r--runtime/lua/vim/lsp/_dynamic.lua4
-rw-r--r--runtime/lua/vim/lsp/client.lua21
-rw-r--r--runtime/lua/vim/lsp/completion.lua4
-rw-r--r--runtime/lua/vim/lsp/handlers.lua1
-rw-r--r--runtime/lua/vim/lsp/inlay_hint.lua2
-rw-r--r--runtime/lua/vim/lsp/log.lua2
-rw-r--r--runtime/lua/vim/lsp/protocol.lua342
-rw-r--r--runtime/lua/vim/lsp/rpc.lua8
-rw-r--r--runtime/lua/vim/lsp/semantic_tokens.lua3
-rw-r--r--runtime/lua/vim/lsp/util.lua29
-rw-r--r--runtime/lua/vim/text.lua10
-rw-r--r--runtime/lua/vim/treesitter/_fold.lua1
-rw-r--r--runtime/lua/vim/treesitter/_meta.lua2
-rw-r--r--runtime/lua/vim/treesitter/highlighter.lua6
-rw-r--r--runtime/lua/vim/treesitter/languagetree.lua10
26 files changed, 227 insertions, 487 deletions
diff --git a/runtime/lua/vim/_defaults.lua b/runtime/lua/vim/_defaults.lua
index 01dcd4bf74..630f2219c7 100644
--- a/runtime/lua/vim/_defaults.lua
+++ b/runtime/lua/vim/_defaults.lua
@@ -85,13 +85,13 @@ do
vim.keymap.set(
'x',
'Q',
- "mode() == 'V' ? ':normal! @<C-R>=reg_recorded()<CR><CR>' : 'Q'",
+ "mode() ==# 'V' ? ':normal! @<C-R>=reg_recorded()<CR><CR>' : 'Q'",
{ silent = true, expr = true, desc = ':help v_Q-default' }
)
vim.keymap.set(
'x',
'@',
- "mode() == 'V' ? ':normal! @'.getcharstr().'<CR>' : '@'",
+ "mode() ==# 'V' ? ':normal! @'.getcharstr().'<CR>' : '@'",
{ silent = true, expr = true, desc = ':help v_@-default' }
)
@@ -282,6 +282,26 @@ do
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
+ vim.wo[0][0].wrap = false
+ vim.wo[0][0].list = false
+
+ -- This is gross. Proper list options support when?
+ local winhl = vim.o.winhighlight
+ if winhl ~= '' then
+ winhl = winhl .. ','
+ end
+ vim.wo[0][0].winhighlight = winhl .. 'StatusLine:StatusLineTerm,StatusLineNC:StatusLineTermNC'
+ end,
+ })
+
vim.api.nvim_create_autocmd('CmdwinEnter', {
pattern = '[:>]',
desc = 'Limit syntax sync to maxlines=1 in the command window',
diff --git a/runtime/lua/vim/_meta/api.lua b/runtime/lua/vim/_meta/api.lua
index d91b2d08bf..1b70cc275f 100644
--- a/runtime/lua/vim/_meta/api.lua
+++ b/runtime/lua/vim/_meta/api.lua
@@ -1910,7 +1910,7 @@ function vim.api.nvim_set_current_win(window) end
--- Note: this function should not be called often. Rather, the callbacks
--- themselves can be used to throttle unneeded callbacks. the `on_start`
--- callback can return `false` to disable the provider until the next redraw.
---- Similarly, return `false` in `on_win` will skip the `on_lines` calls for
+--- Similarly, return `false` in `on_win` will skip the `on_line` calls for
--- that window (but any extmarks set in `on_win` will still be used). A
--- plugin managing multiple sources of decoration should ideally only set one
--- provider, and merge the sources internally. You can use multiple `ns_id`
@@ -1919,10 +1919,10 @@ function vim.api.nvim_set_current_win(window) end
--- Note: doing anything other than setting extmarks is considered
--- experimental. Doing things like changing options are not explicitly
--- forbidden, but is likely to have unexpected consequences (such as 100% CPU
---- consumption). doing `vim.rpcnotify` should be OK, but `vim.rpcrequest` is
+--- consumption). Doing `vim.rpcnotify` should be OK, but `vim.rpcrequest` is
--- quite dubious for the moment.
---
---- Note: It is not allowed to remove or update extmarks in 'on_line'
+--- Note: It is not allowed to remove or update extmarks in `on_line`
--- callbacks.
---
--- @param ns_id integer Namespace id from `nvim_create_namespace()`
diff --git a/runtime/lua/vim/_meta/builtin.lua b/runtime/lua/vim/_meta/builtin.lua
index 75737bd040..3aca3cdfa5 100644
--- a/runtime/lua/vim/_meta/builtin.lua
+++ b/runtime/lua/vim/_meta/builtin.lua
@@ -121,6 +121,7 @@ function vim.stricmp(a, b) end
--- @param str string
--- @param index integer
--- @param use_utf16? boolean
+--- @return integer
function vim.str_byteindex(str, index, use_utf16) end
--- Gets a list of the starting byte positions of each UTF-8 codepoint in the given string.
diff --git a/runtime/lua/vim/_meta/builtin_types.lua b/runtime/lua/vim/_meta/builtin_types.lua
index 53dd8d95e9..9afb8c84f4 100644
--- a/runtime/lua/vim/_meta/builtin_types.lua
+++ b/runtime/lua/vim/_meta/builtin_types.lua
@@ -34,6 +34,11 @@
--- @field filename? string
--- @field lnum integer
+--- @class vim.fn.getmarklist.ret.item
+--- @field mark string
+--- @field pos [integer, integer, integer, integer]
+--- @field file string
+
--- @class vim.fn.getmousepos.ret
--- @field screenrow integer
--- @field screencol integer
diff --git a/runtime/lua/vim/_meta/lpeg.lua b/runtime/lua/vim/_meta/lpeg.lua
index 73b3375c82..39a894aaeb 100644
--- a/runtime/lua/vim/_meta/lpeg.lua
+++ b/runtime/lua/vim/_meta/lpeg.lua
@@ -2,7 +2,7 @@
error('Cannot require a meta file')
-- These types were taken from https://github.com/LuaCATS/lpeg
--- (based on revision e6789e28e5b91a4a277a2a03081d708c403a3e34)
+-- (based on revision 82c6a8fc676bbc20722026afd952668f3919b11d)
-- with types being renamed to include the vim namespace and with some descriptions made less verbose.
--- @brief <pre>help
@@ -32,7 +32,7 @@ vim.lpeg = {}
--- @operator div(table): vim.lpeg.Capture
--- @operator div(function): vim.lpeg.Capture
--- @operator pow(number): vim.lpeg.Pattern
---- @operator mod(function): nil
+--- @operator mod(function): vim.lpeg.Capture
local Pattern = {}
--- @alias vim.lpeg.Capture vim.lpeg.Pattern
diff --git a/runtime/lua/vim/_meta/options.lua b/runtime/lua/vim/_meta/options.lua
index 155c93726b..902df8f7d6 100644
--- a/runtime/lua/vim/_meta/options.lua
+++ b/runtime/lua/vim/_meta/options.lua
@@ -3830,6 +3830,9 @@ vim.go.lw = vim.go.lispwords
--- between tabs and spaces and for trailing blanks. Further changed by
--- the 'listchars' option.
---
+--- When 'listchars' does not contain "tab" field, tabs are shown as "^I"
+--- or "<09>", like how unprintable characters are displayed.
+---
--- The cursor is displayed at the start of the space a Tab character
--- occupies, not at the end as usual in Normal mode. To get this cursor
--- position while displaying Tabs with spaces, use:
@@ -6373,8 +6376,7 @@ vim.go.sol = vim.go.startofline
--- Some of the items from the 'statusline' format are different for
--- 'statuscolumn':
---
---- %l line number of currently drawn line
---- %r relative line number of currently drawn line
+--- %l line number column for currently drawn line
--- %s sign column for currently drawn line
--- %C fold column for currently drawn line
---
@@ -6403,11 +6405,8 @@ vim.go.sol = vim.go.startofline
--- Examples:
---
--- ```vim
---- " Relative number with bar separator and click handlers:
---- set statuscolumn=%@SignCb@%s%=%T%@NumCb@%r│%T
----
---- " Right aligned relative cursor line number:
---- let &stc='%=%{v:relnum?v:relnum:v:lnum} '
+--- " Line number with bar separator and click handlers:
+--- set statuscolumn=%@SignCb@%s%=%T%@NumCb@%l│%T
---
--- " Line numbers in hexadecimal for non wrapped part of lines:
--- let &stc='%=%{v:virtnum>0?"":printf("%x",v:lnum)} '
diff --git a/runtime/lua/vim/_meta/vimfn.lua b/runtime/lua/vim/_meta/vimfn.lua
index a1600e1cb5..11dcbc010b 100644
--- a/runtime/lua/vim/_meta/vimfn.lua
+++ b/runtime/lua/vim/_meta/vimfn.lua
@@ -911,33 +911,33 @@ function vim.fn.cindent(lnum) end
function vim.fn.clearmatches(win) end
--- The result is a Number, which is the byte index of the column
---- position given with {expr}. The accepted positions are:
---- . the cursor position
---- $ the end of the cursor line (the result is the
---- number of bytes in the cursor line plus one)
---- 'x position of mark x (if the mark is not set, 0 is
---- returned)
---- v In Visual mode: the start of the Visual area (the
---- cursor is the end). When not in Visual mode
---- returns the cursor position. Differs from |'<| in
---- that it's updated right away.
+--- position given with {expr}.
+--- For accepted positions see |getpos()|.
+--- When {expr} is "$", it means the end of the cursor line, so
+--- the result is the number of bytes in the cursor line plus one.
--- Additionally {expr} can be [lnum, col]: a |List| with the line
--- and column number. Most useful when the column is "$", to get
--- the last column of a specific line. When "lnum" or "col" is
--- out of range then col() returns zero.
+---
--- With the optional {winid} argument the values are obtained for
--- that window instead of the current window.
+---
--- To get the line number use |line()|. To get both use
--- |getpos()|.
+---
--- For the screen column position use |virtcol()|. For the
--- character position use |charcol()|.
+---
--- Note that only marks in the current file can be used.
+---
--- Examples: >vim
--- echo col(".") " column of cursor
--- echo col("$") " length of cursor line plus one
--- echo col("'t") " column of mark t
--- echo col("'" .. markname) " column of mark markname
---- <The first column is 1. Returns 0 if {expr} is invalid or when
+--- <
+--- The first column is 1. Returns 0 if {expr} is invalid or when
--- the window with ID {winid} is not found.
--- For an uppercase mark the column may actually be in another
--- buffer.
@@ -2766,8 +2766,9 @@ function vim.fn.getchangelist(buf) end
--- endfunction
--- <
---
+--- @param expr? 0|1
--- @return integer
-function vim.fn.getchar() end
+function vim.fn.getchar(expr) end
--- The result is a Number which is the state of the modifiers for
--- the last obtained character with getchar() or in another way.
@@ -2837,8 +2838,9 @@ function vim.fn.getcharsearch() end
--- Otherwise this works like |getchar()|, except that a number
--- result is converted to a string.
---
+--- @param expr? 0|1
--- @return string
-function vim.fn.getcharstr() end
+function vim.fn.getcharstr(expr) end
--- Return the type of the current command-line completion.
--- Only works when the command line is being edited, thus
@@ -3249,8 +3251,8 @@ function vim.fn.getloclist(nr, what) end
--- Refer to |getpos()| for getting information about a specific
--- mark.
---
---- @param buf? any
---- @return any
+--- @param buf? integer?
+--- @return vim.fn.getmarklist.ret.item[]
function vim.fn.getmarklist(buf) end
--- Returns a |List| with all matches previously defined for the
@@ -3327,9 +3329,34 @@ function vim.fn.getmousepos() end
--- @return integer
function vim.fn.getpid() end
---- Get the position for String {expr}. For possible values of
---- {expr} see |line()|. For getting the cursor position see
---- |getcurpos()|.
+--- Get the position for String {expr}.
+--- The accepted values for {expr} are:
+--- . The cursor position.
+--- $ The last line in the current buffer.
+--- 'x Position of mark x (if the mark is not set, 0 is
+--- returned for all values).
+--- w0 First line visible in current window (one if the
+--- display isn't updated, e.g. in silent Ex mode).
+--- w$ Last line visible in current window (this is one
+--- less than "w0" if no lines are visible).
+--- v When not in Visual mode, returns the cursor
+--- position. In Visual mode, returns the other end
+--- of the Visual area. A good way to think about
+--- this is that in Visual mode "v" and "." complement
+--- each other. While "." refers to the cursor
+--- position, "v" refers to where |v_o| would move the
+--- cursor. As a result, you can use "v" and "."
+--- together to work on all of a selection in
+--- characterwise Visual mode. If the cursor is at
+--- the end of a characterwise Visual area, "v" refers
+--- to the start of the same Visual area. And if the
+--- cursor is at the start of a characterwise Visual
+--- area, "v" refers to the end of the same Visual
+--- area. "v" differs from |'<| and |'>| in that it's
+--- updated right away.
+--- Note that a mark in another file can be used. The line number
+--- then applies to another buffer.
+---
--- The result is a |List| with four numbers:
--- [bufnum, lnum, col, off]
--- "bufnum" is zero, unless a mark like '0 or 'A is used, then it
@@ -3340,20 +3367,25 @@ function vim.fn.getpid() end
--- it is the offset in screen columns from the start of the
--- character. E.g., a position within a <Tab> or after the last
--- character.
---- Note that for '< and '> Visual mode matters: when it is "V"
---- (visual line mode) the column of '< is zero and the column of
---- '> is a large number equal to |v:maxcol|.
+---
+--- For getting the cursor position see |getcurpos()|.
--- The column number in the returned List is the byte position
--- within the line. To get the character position in the line,
--- use |getcharpos()|.
+---
+--- Note that for '< and '> Visual mode matters: when it is "V"
+--- (visual line mode) the column of '< is zero and the column of
+--- '> is a large number equal to |v:maxcol|.
--- A very large column number equal to |v:maxcol| can be returned,
--- in which case it means "after the end of the line".
--- If {expr} is invalid, returns a list with all zeros.
+---
--- This can be used to save and restore the position of a mark: >vim
--- let save_a_mark = getpos("'a")
--- " ...
--- call setpos("'a", save_a_mark)
---- <Also see |getcharpos()|, |getcurpos()| and |setpos()|.
+--- <
+--- Also see |getcharpos()|, |getcurpos()| and |setpos()|.
---
--- @param expr string
--- @return integer[]
@@ -3569,8 +3601,8 @@ function vim.fn.getreginfo(regname) end
--- difference if the buffer is displayed in a window with
--- different 'virtualedit' or 'list' values.
---
---- Examples: >
---- :xnoremap <CR>
+--- Examples: >vim
+--- xnoremap <CR>
--- \ <Cmd>echom getregion(
--- \ getpos('v'), getpos('.'), #{ type: mode() })<CR>
--- <
@@ -4958,28 +4990,16 @@ function vim.fn.libcall(libname, funcname, argument) end
--- @return any
function vim.fn.libcallnr(libname, funcname, argument) end
---- The result is a Number, which is the line number of the file
---- position given with {expr}. The {expr} argument is a string.
---- The accepted positions are:
---- . the cursor position
---- $ the last line in the current buffer
---- 'x position of mark x (if the mark is not set, 0 is
---- returned)
---- w0 first line visible in current window (one if the
---- display isn't updated, e.g. in silent Ex mode)
---- w$ last line visible in current window (this is one
---- less than "w0" if no lines are visible)
---- v In Visual mode: the start of the Visual area (the
---- cursor is the end). When not in Visual mode
---- returns the cursor position. Differs from |'<| in
---- that it's updated right away.
---- Note that a mark in another file can be used. The line number
---- then applies to another buffer.
+--- See |getpos()| for accepted positions.
+---
--- To get the column number use |col()|. To get both use
--- |getpos()|.
+---
--- With the optional {winid} argument the values are obtained for
--- that window instead of the current window.
+---
--- Returns 0 for invalid values of {expr} and {winid}.
+---
--- Examples: >vim
--- echo line(".") " line number of the cursor
--- echo line(".", winid) " idem, in window "winid"
@@ -5297,8 +5317,9 @@ function vim.fn.mapcheck(name, mode, abbr) end
--- ounmap xyzzy
--- echo printf("Operator-pending mode bit: 0x%x", op_bit)
---
---- @return any
-function vim.fn.maplist() end
+--- @param abbr? 0|1
+--- @return table[]
+function vim.fn.maplist(abbr) end
--- Like |map()| but instead of replacing items in {expr1} a new
--- List or Dictionary is created and returned. {expr1} remains
@@ -5575,19 +5596,19 @@ function vim.fn.matcharg(nr) end
---
--- Examples: >vim
--- " Assuming line 3 in buffer 5 contains "a"
---- :echo matchbufline(5, '\<\k\+\>', 3, 3)
---- [{'lnum': 3, 'byteidx': 0, 'text': 'a'}]
+--- echo matchbufline(5, '\<\k\+\>', 3, 3)
+--- < `[{'lnum': 3, 'byteidx': 0, 'text': 'a'}]` >vim
--- " Assuming line 4 in buffer 10 contains "tik tok"
---- :echo matchbufline(10, '\<\k\+\>', 1, 4)
---- [{'lnum': 4, 'byteidx': 0, 'text': 'tik'}, {'lnum': 4, 'byteidx': 4, 'text': 'tok'}]
---- <
+--- echo matchbufline(10, '\<\k\+\>', 1, 4)
+--- < `[{'lnum': 4, 'byteidx': 0, 'text': 'tik'}, {'lnum': 4, 'byteidx': 4, 'text': 'tok'}]`
+---
--- If {submatch} is present and is v:true, then submatches like
--- "\1", "\2", etc. are also returned. Example: >vim
--- " Assuming line 2 in buffer 2 contains "acd"
---- :echo matchbufline(2, '\(a\)\?\(b\)\?\(c\)\?\(.*\)', 2, 2
+--- echo matchbufline(2, '\(a\)\?\(b\)\?\(c\)\?\(.*\)', 2, 2
--- \ {'submatches': v:true})
---- [{'lnum': 2, 'byteidx': 0, 'text': 'acd', 'submatches': ['a', '', 'c', 'd', '', '', '', '', '']}]
---- <The "submatches" List always contains 9 items. If a submatch
+--- < `[{'lnum': 2, 'byteidx': 0, 'text': 'acd', 'submatches': ['a', '', 'c', 'd', '', '', '', '', '']}]`
+--- The "submatches" List always contains 9 items. If a submatch
--- is not found, then an empty string is returned for that
--- submatch.
---
@@ -5786,17 +5807,17 @@ function vim.fn.matchstr(expr, pat, start, count) end
--- option settings on the pattern.
---
--- Example: >vim
---- :echo matchstrlist(['tik tok'], '\<\k\+\>')
---- [{'idx': 0, 'byteidx': 0, 'text': 'tik'}, {'idx': 0, 'byteidx': 4, 'text': 'tok'}]
---- :echo matchstrlist(['a', 'b'], '\<\k\+\>')
---- [{'idx': 0, 'byteidx': 0, 'text': 'a'}, {'idx': 1, 'byteidx': 0, 'text': 'b'}]
---- <
+--- echo matchstrlist(['tik tok'], '\<\k\+\>')
+--- < `[{'idx': 0, 'byteidx': 0, 'text': 'tik'}, {'idx': 0, 'byteidx': 4, 'text': 'tok'}]` >vim
+--- echo matchstrlist(['a', 'b'], '\<\k\+\>')
+--- < `[{'idx': 0, 'byteidx': 0, 'text': 'a'}, {'idx': 1, 'byteidx': 0, 'text': 'b'}]`
+---
--- If "submatches" is present and is v:true, then submatches like
--- "\1", "\2", etc. are also returned. Example: >vim
---- :echo matchstrlist(['acd'], '\(a\)\?\(b\)\?\(c\)\?\(.*\)',
+--- echo matchstrlist(['acd'], '\(a\)\?\(b\)\?\(c\)\?\(.*\)',
--- \ #{submatches: v:true})
---- [{'idx': 0, 'byteidx': 0, 'text': 'acd', 'submatches': ['a', '', 'c', 'd', '', '', '', '', '']}]
---- <The "submatches" List always contains 9 items. If a submatch
+--- < `[{'idx': 0, 'byteidx': 0, 'text': 'acd', 'submatches': ['a', '', 'c', 'd', '', '', '', '', '']}]`
+--- The "submatches" List always contains 9 items. If a submatch
--- is not found, then an empty string is returned for that
--- submatch.
---
@@ -5986,17 +6007,14 @@ function vim.fn.min(expr) end
--- When {flags} is present it must be a string. An empty string
--- has no effect.
---
---- If {flags} contains "p" then intermediate directories are
---- created as necessary.
+--- {flags} can contain these character flags:
+--- "p" intermediate directories will be created as necessary
+--- "D" {name} will be deleted at the end of the current
+--- function, but not recursively |:defer|
+--- "R" {name} will be deleted recursively at the end of the
+--- current function |:defer|
---
---- If {flags} contains "D" then {name} is deleted at the end of
---- the current function, as with: >vim
---- defer delete({name}, 'd')
---- <
---- If {flags} contains "R" then {name} is deleted recursively at
---- the end of the current function, as with: >vim
---- defer delete({name}, 'rf')
---- <Note that when {name} has more than one part and "p" is used
+--- Note that when {name} has more than one part and "p" is used
--- some directories may already exist. Only the first one that
--- is created and what it contains is scheduled to be deleted.
--- E.g. when using: >vim
@@ -7236,7 +7254,7 @@ function vim.fn.screenchars(row, col) end
--- the following mappings: >vim
--- nnoremap <expr> GG ":echom " .. screencol() .. "\n"
--- nnoremap <silent> GG :echom screencol()<CR>
---- noremap GG <Cmd>echom screencol()<Cr>
+--- noremap GG <Cmd>echom screencol()<CR>
--- <
---
--- @return any
@@ -7634,8 +7652,15 @@ function vim.fn.searchdecl(name, global, thisblock) end
--- \ 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string"')
--- <
---
---- @return any
-function vim.fn.searchpair() end
+--- @param start any
+--- @param middle any
+--- @param end_ any
+--- @param flags? string
+--- @param skip? any
+--- @param stopline? any
+--- @param timeout? integer
+--- @return integer
+function vim.fn.searchpair(start, middle, end_, flags, skip, stopline, timeout) end
--- Same as |searchpair()|, but returns a |List| with the line and
--- column position of the match. The first element of the |List|
@@ -7647,8 +7672,15 @@ function vim.fn.searchpair() end
--- <
--- See |match-parens| for a bigger and more useful example.
---
---- @return any
-function vim.fn.searchpairpos() end
+--- @param start any
+--- @param middle any
+--- @param end_ any
+--- @param flags? string
+--- @param skip? any
+--- @param stopline? any
+--- @param timeout? integer
+--- @return [integer, integer]
+function vim.fn.searchpairpos(start, middle, end_, flags, skip, stopline, timeout) end
--- Same as |search()|, but returns a |List| with the line and
--- column position of the match. The first element of the |List|
@@ -10382,7 +10414,9 @@ function vim.fn.values(dict) end
--- set to 8, it returns 8. |conceal| is ignored.
--- For the byte position use |col()|.
---
---- For the use of {expr} see |col()|.
+--- For the use of {expr} see |getpos()| and |col()|.
+--- When {expr} is "$", it means the end of the cursor line, so
+--- the result is the number of cells in the cursor line plus one.
---
--- When 'virtualedit' is used {expr} can be [lnum, col, off],
--- where "off" is the offset in screen columns from the start of
@@ -10392,18 +10426,6 @@ function vim.fn.values(dict) end
--- beyond the end of the line can be returned. Also see
--- |'virtualedit'|
---
---- The accepted positions are:
---- . the cursor position
---- $ the end of the cursor line (the result is the
---- number of displayed characters in the cursor line
---- plus one)
---- 'x position of mark x (if the mark is not set, 0 is
---- returned)
---- v In Visual mode: the start of the Visual area (the
---- cursor is the end). When not in Visual mode
---- returns the cursor position. Differs from |'<| in
---- that it's updated right away.
----
--- If {list} is present and non-zero then virtcol() returns a
--- List with the first and last screen position occupied by the
--- character.
@@ -10422,7 +10444,9 @@ function vim.fn.values(dict) end
--- " With text " there", with 't at 'h':
---
--- echo virtcol("'t") " returns 6
---- <The first column is 1. 0 or [0, 0] is returned for an error.
+--- <
+--- The first column is 1. 0 or [0, 0] is returned for an error.
+---
--- A more advanced example that echoes the maximum length of
--- all lines: >vim
--- echo max(map(range(1, line('$')), "virtcol([v:val, '$'])"))
diff --git a/runtime/lua/vim/_options.lua b/runtime/lua/vim/_options.lua
index 4a360c18e4..a61fa61256 100644
--- a/runtime/lua/vim/_options.lua
+++ b/runtime/lua/vim/_options.lua
@@ -174,6 +174,11 @@ local function new_buf_opt_accessor(bufnr)
end
local function new_win_opt_accessor(winid, bufnr)
+ -- TODO(lewis6991): allow passing both buf and win to nvim_get_option_value
+ if bufnr ~= nil and bufnr ~= 0 then
+ error('only bufnr=0 is supported')
+ end
+
return setmetatable({}, {
__index = function(_, k)
if bufnr == nil and type(k) == 'number' then
@@ -184,11 +189,6 @@ local function new_win_opt_accessor(winid, bufnr)
end
end
- if bufnr ~= nil and bufnr ~= 0 then
- error('only bufnr=0 is supported')
- end
-
- -- TODO(lewis6991): allow passing both buf and win to nvim_get_option_value
return api.nvim_get_option_value(k, {
scope = bufnr and 'local' or nil,
win = winid or 0,
@@ -196,7 +196,6 @@ local function new_win_opt_accessor(winid, bufnr)
end,
__newindex = function(_, k, v)
- -- TODO(lewis6991): allow passing both buf and win to nvim_set_option_value
return api.nvim_set_option_value(k, v, {
scope = bufnr and 'local' or nil,
win = winid or 0,
diff --git a/runtime/lua/vim/filetype.lua b/runtime/lua/vim/filetype.lua
index cc2fbe0cec..2bb50d8c0b 100644
--- a/runtime/lua/vim/filetype.lua
+++ b/runtime/lua/vim/filetype.lua
@@ -985,6 +985,7 @@ local extension = {
smt = 'smith',
smithy = 'smithy',
sml = 'sml',
+ smk = 'snakemake',
spt = 'snobol4',
sno = 'snobol4',
sln = 'solution',
@@ -1620,6 +1621,7 @@ local filename = {
['/etc/slp.spi'] = 'slpspi',
['.slrnrc'] = 'slrnrc',
['sendmail.cf'] = 'sm',
+ Snakefile = 'snakemake',
['.sqlite_history'] = 'sql',
['squid.conf'] = 'squid',
['ssh_config'] = 'sshconfig',
diff --git a/runtime/lua/vim/filetype/detect.lua b/runtime/lua/vim/filetype/detect.lua
index c56ece6289..fa90c83b81 100644
--- a/runtime/lua/vim/filetype/detect.lua
+++ b/runtime/lua/vim/filetype/detect.lua
@@ -1783,6 +1783,7 @@ local patterns_hashbang = {
['^janet\\>'] = { 'janet', { vim_regex = true } },
['^dart\\>'] = { 'dart', { vim_regex = true } },
['^execlineb\\>'] = { 'execline', { vim_regex = true } },
+ ['^vim\\>'] = { 'vim', { vim_regex = true } },
}
---@private
diff --git a/runtime/lua/vim/iter.lua b/runtime/lua/vim/iter.lua
index 1093759efe..6bddf0bc5e 100644
--- a/runtime/lua/vim/iter.lua
+++ b/runtime/lua/vim/iter.lua
@@ -276,7 +276,7 @@ end
--- -- { 6, 12 }
--- ```
---
----@param f fun(...):any Mapping function. Takes all values returned from
+---@param f fun(...):...:any Mapping function. Takes all values returned from
--- the previous stage in the pipeline as arguments
--- and returns one or more new values, which are used
--- in the next pipeline stage. Nil return values
diff --git a/runtime/lua/vim/lsp/_dynamic.lua b/runtime/lua/vim/lsp/_dynamic.lua
index 819b03a63a..27113c0e74 100644
--- a/runtime/lua/vim/lsp/_dynamic.lua
+++ b/runtime/lua/vim/lsp/_dynamic.lua
@@ -24,7 +24,6 @@ function M:supports_registration(method)
end
--- @param registrations lsp.Registration[]
---- @package
function M:register(registrations)
-- remove duplicates
self:unregister(registrations)
@@ -38,7 +37,6 @@ function M:register(registrations)
end
--- @param unregisterations lsp.Unregistration[]
---- @package
function M:unregister(unregisterations)
for _, unreg in ipairs(unregisterations) do
local method = unreg.method
@@ -58,7 +56,6 @@ end
--- @param method string
--- @param opts? {bufnr: integer?}
--- @return lsp.Registration? (table|nil) the registration if found
---- @package
function M:get(method, opts)
opts = opts or {}
opts.bufnr = opts.bufnr or vim.api.nvim_get_current_buf()
@@ -78,7 +75,6 @@ end
--- @param method string
--- @param opts? {bufnr: integer?}
---- @package
function M:supports(method, opts)
return self:get(method, opts) ~= nil
end
diff --git a/runtime/lua/vim/lsp/client.lua b/runtime/lua/vim/lsp/client.lua
index 327cd19125..8cdfdd4b90 100644
--- a/runtime/lua/vim/lsp/client.lua
+++ b/runtime/lua/vim/lsp/client.lua
@@ -436,7 +436,7 @@ local function ensure_list(x)
return { x }
end
---- @package
+--- @nodoc
--- @param config vim.lsp.ClientConfig
--- @return vim.lsp.Client?
function Client.create(config)
@@ -535,7 +535,7 @@ function Client:_run_callbacks(cbs, error_id, ...)
end
end
---- @package
+--- @nodoc
function Client:initialize()
local config = self.config
@@ -656,7 +656,7 @@ end
--- @param method string LSP method name.
--- @param params? table LSP request params.
--- @param handler? lsp.Handler Response |lsp-handler| for this method.
---- @param bufnr? integer Buffer handle (0 for current).
+--- @param bufnr integer Buffer handle (0 for current).
--- @return boolean status, integer? request_id {status} is a bool indicating
--- whether the request was successful. If it is `false`, then it will
--- always be `false` (the client has shutdown). If it was
@@ -861,7 +861,6 @@ function Client:_is_stopped()
return self.rpc.is_closing()
end
---- @package
--- Execute a lsp command, either via client command function (if available)
--- or via workspace/executeCommand (if supported by the server)
---
@@ -906,7 +905,6 @@ function Client:_exec_cmd(command, context, handler, on_unsupported)
self.request(ms.workspace_executeCommand, params, handler, context.bufnr)
end
---- @package
--- Default handler for the 'textDocument/didOpen' LSP notification.
---
--- @param bufnr integer Number of the buffer, or 0 for current
@@ -918,18 +916,16 @@ function Client:_text_document_did_open_handler(bufnr)
if not api.nvim_buf_is_loaded(bufnr) then
return
end
- local filetype = vim.bo[bufnr].filetype
- local params = {
+ local filetype = vim.bo[bufnr].filetype
+ self.notify(ms.textDocument_didOpen, {
textDocument = {
- version = 0,
+ version = lsp.util.buf_versions[bufnr],
uri = vim.uri_from_bufnr(bufnr),
languageId = self.get_language_id(bufnr, filetype),
text = lsp._buf_get_full_text(bufnr),
},
- }
- self.notify(ms.textDocument_didOpen, params)
- lsp.util.buf_versions[bufnr] = params.textDocument.version
+ })
-- Next chance we get, we should re-do the diagnostics
vim.schedule(function()
@@ -942,7 +938,6 @@ function Client:_text_document_did_open_handler(bufnr)
end)
end
---- @package
--- Runs the on_attach function from the client's config if it was defined.
--- @param bufnr integer Buffer number
function Client:_on_attach(bufnr)
@@ -1065,7 +1060,6 @@ function Client:_on_exit(code, signal)
)
end
---- @package
--- Add a directory to the workspace folders.
--- @param dir string?
function Client:_add_workspace_folder(dir)
@@ -1088,7 +1082,6 @@ function Client:_add_workspace_folder(dir)
vim.list_extend(self.workspace_folders, wf)
end
---- @package
--- Remove a directory to the workspace folders.
--- @param dir string?
function Client:_remove_workspace_folder(dir)
diff --git a/runtime/lua/vim/lsp/completion.lua b/runtime/lua/vim/lsp/completion.lua
index 4b7deabf41..2e6d82b367 100644
--- a/runtime/lua/vim/lsp/completion.lua
+++ b/runtime/lua/vim/lsp/completion.lua
@@ -145,8 +145,8 @@ local function get_completion_word(item)
-- label: insert
--
-- Typing `i` would remove the candidate because newText starts with `t`.
- local text = item.insertText or item.textEdit.newText
- return #text < #item.label and text or item.label
+ local text = parse_snippet(item.insertText or item.textEdit.newText)
+ return #text < #item.label and vim.fn.matchstr(text, '\\k*') or item.label
elseif item.insertText and item.insertText ~= '' then
return parse_snippet(item.insertText)
else
diff --git a/runtime/lua/vim/lsp/handlers.lua b/runtime/lua/vim/lsp/handlers.lua
index 38c43893eb..44548fec92 100644
--- a/runtime/lua/vim/lsp/handlers.lua
+++ b/runtime/lua/vim/lsp/handlers.lua
@@ -646,6 +646,7 @@ M[ms.window_showMessage] = function(_, result, ctx, _)
if message_type == protocol.MessageType.Error then
err_message('LSP[', client_name, '] ', message)
else
+ --- @type string
local message_type_name = protocol.MessageType[message_type]
api.nvim_out_write(string.format('LSP[%s][%s] %s\n', client_name, message_type_name, message))
end
diff --git a/runtime/lua/vim/lsp/inlay_hint.lua b/runtime/lua/vim/lsp/inlay_hint.lua
index 2d784816cb..aa84294cc4 100644
--- a/runtime/lua/vim/lsp/inlay_hint.lua
+++ b/runtime/lua/vim/lsp/inlay_hint.lua
@@ -370,7 +370,7 @@ api.nvim_set_decoration_provider(namespace, {
})
--- Query whether inlay hint is enabled in the {filter}ed scope
---- @param filter vim.lsp.inlay_hint.enable.Filter
+--- @param filter? vim.lsp.inlay_hint.enable.Filter
--- @return boolean
--- @since 12
function M.is_enabled(filter)
diff --git a/runtime/lua/vim/lsp/log.lua b/runtime/lua/vim/lsp/log.lua
index 9f2bd71158..0438ca84af 100644
--- a/runtime/lua/vim/lsp/log.lua
+++ b/runtime/lua/vim/lsp/log.lua
@@ -9,7 +9,7 @@ local log_levels = vim.log.levels
--- Can be used to lookup the number from the name or the name from the number.
--- Levels by name: "TRACE", "DEBUG", "INFO", "WARN", "ERROR", "OFF"
--- Level numbers begin with "TRACE" at 0
---- @type table<string|integer, string|integer>
+--- @type table<string,integer> | table<integer, string>
--- @nodoc
log.levels = vim.deepcopy(log_levels)
diff --git a/runtime/lua/vim/lsp/protocol.lua b/runtime/lua/vim/lsp/protocol.lua
index 8ac4cc794b..eb18043843 100644
--- a/runtime/lua/vim/lsp/protocol.lua
+++ b/runtime/lua/vim/lsp/protocol.lua
@@ -12,9 +12,6 @@ end
local sysname = vim.uv.os_uname().sysname
--- Protocol for the Microsoft Language Server Protocol (mslsp)
-local protocol = {}
-
local constants = {
--- @enum lsp.DiagnosticSeverity
DiagnosticSeverity = {
@@ -46,6 +43,8 @@ local constants = {
Info = 3,
-- A log message.
Log = 4,
+ -- A debug message.
+ Debug = 5,
},
-- The file event type.
@@ -308,326 +307,18 @@ local constants = {
},
}
-for k1, v1 in pairs(constants) do
- local tbl = vim.deepcopy(v1, true)
- for _, k2 in ipairs(vim.tbl_keys(tbl)) do
- local v2 = tbl[k2]
- tbl[v2] = k2
+-- Protocol for the Microsoft Language Server Protocol (mslsp)
+local protocol = {}
+
+--- @diagnostic disable:no-unknown
+for k1, v1 in pairs(vim.deepcopy(constants, true)) do
+ for _, k2 in ipairs(vim.tbl_keys(v1)) do
+ local v2 = v1[k2]
+ v1[v2] = k2
end
- protocol[k1] = tbl
+ protocol[k1] = v1
end
-
---[=[
---Text document specific client capabilities.
-export interface TextDocumentClientCapabilities {
- synchronization?: {
- --Whether text document synchronization supports dynamic registration.
- dynamicRegistration?: boolean;
- --The client supports sending will save notifications.
- willSave?: boolean;
- --The client supports sending a will save request and
- --waits for a response providing text edits which will
- --be applied to the document before it is saved.
- willSaveWaitUntil?: boolean;
- --The client supports did save notifications.
- didSave?: boolean;
- }
- --Capabilities specific to the `textDocument/completion`
- completion?: {
- --Whether completion supports dynamic registration.
- dynamicRegistration?: boolean;
- --The client supports the following `CompletionItem` specific
- --capabilities.
- completionItem?: {
- --The client supports snippets as insert text.
- --
- --A snippet can define tab stops and placeholders with `$1`, `$2`
- --and `${3:foo}`. `$0` defines the final tab stop, it defaults to
- --the end of the snippet. Placeholders with equal identifiers are linked,
- --that is typing in one will update others too.
- snippetSupport?: boolean;
- --The client supports commit characters on a completion item.
- commitCharactersSupport?: boolean
- --The client supports the following content formats for the documentation
- --property. The order describes the preferred format of the client.
- documentationFormat?: MarkupKind[];
- --The client supports the deprecated property on a completion item.
- deprecatedSupport?: boolean;
- --The client supports the preselect property on a completion item.
- preselectSupport?: boolean;
- }
- completionItemKind?: {
- --The completion item kind values the client supports. When this
- --property exists the client also guarantees that it will
- --handle values outside its set gracefully and falls back
- --to a default value when unknown.
- --
- --If this property is not present the client only supports
- --the completion items kinds from `Text` to `Reference` as defined in
- --the initial version of the protocol.
- valueSet?: CompletionItemKind[];
- },
- --The client supports to send additional context information for a
- --`textDocument/completion` request.
- contextSupport?: boolean;
- };
- --Capabilities specific to the `textDocument/hover`
- hover?: {
- --Whether hover supports dynamic registration.
- dynamicRegistration?: boolean;
- --The client supports the follow content formats for the content
- --property. The order describes the preferred format of the client.
- contentFormat?: MarkupKind[];
- };
- --Capabilities specific to the `textDocument/signatureHelp`
- signatureHelp?: {
- --Whether signature help supports dynamic registration.
- dynamicRegistration?: boolean;
- --The client supports the following `SignatureInformation`
- --specific properties.
- signatureInformation?: {
- --The client supports the follow content formats for the documentation
- --property. The order describes the preferred format of the client.
- documentationFormat?: MarkupKind[];
- --Client capabilities specific to parameter information.
- parameterInformation?: {
- --The client supports processing label offsets instead of a
- --simple label string.
- --
- --Since 3.14.0
- labelOffsetSupport?: boolean;
- }
- };
- };
- --Capabilities specific to the `textDocument/references`
- references?: {
- --Whether references supports dynamic registration.
- dynamicRegistration?: boolean;
- };
- --Capabilities specific to the `textDocument/documentHighlight`
- documentHighlight?: {
- --Whether document highlight supports dynamic registration.
- dynamicRegistration?: boolean;
- };
- --Capabilities specific to the `textDocument/documentSymbol`
- documentSymbol?: {
- --Whether document symbol supports dynamic registration.
- dynamicRegistration?: boolean;
- --Specific capabilities for the `SymbolKind`.
- symbolKind?: {
- --The symbol kind values the client supports. When this
- --property exists the client also guarantees that it will
- --handle values outside its set gracefully and falls back
- --to a default value when unknown.
- --
- --If this property is not present the client only supports
- --the symbol kinds from `File` to `Array` as defined in
- --the initial version of the protocol.
- valueSet?: SymbolKind[];
- }
- --The client supports hierarchical document symbols.
- hierarchicalDocumentSymbolSupport?: boolean;
- };
- --Capabilities specific to the `textDocument/formatting`
- formatting?: {
- --Whether formatting supports dynamic registration.
- dynamicRegistration?: boolean;
- };
- --Capabilities specific to the `textDocument/rangeFormatting`
- rangeFormatting?: {
- --Whether range formatting supports dynamic registration.
- dynamicRegistration?: boolean;
- };
- --Capabilities specific to the `textDocument/onTypeFormatting`
- onTypeFormatting?: {
- --Whether on type formatting supports dynamic registration.
- dynamicRegistration?: boolean;
- };
- --Capabilities specific to the `textDocument/declaration`
- declaration?: {
- --Whether declaration supports dynamic registration. If this is set to `true`
- --the client supports the new `(TextDocumentRegistrationOptions & StaticRegistrationOptions)`
- --return value for the corresponding server capability as well.
- dynamicRegistration?: boolean;
- --The client supports additional metadata in the form of declaration links.
- --
- --Since 3.14.0
- linkSupport?: boolean;
- };
- --Capabilities specific to the `textDocument/definition`.
- --
- --Since 3.14.0
- definition?: {
- --Whether definition supports dynamic registration.
- dynamicRegistration?: boolean;
- --The client supports additional metadata in the form of definition links.
- linkSupport?: boolean;
- };
- --Capabilities specific to the `textDocument/typeDefinition`
- --
- --Since 3.6.0
- typeDefinition?: {
- --Whether typeDefinition supports dynamic registration. If this is set to `true`
- --the client supports the new `(TextDocumentRegistrationOptions & StaticRegistrationOptions)`
- --return value for the corresponding server capability as well.
- dynamicRegistration?: boolean;
- --The client supports additional metadata in the form of definition links.
- --
- --Since 3.14.0
- linkSupport?: boolean;
- };
- --Capabilities specific to the `textDocument/implementation`.
- --
- --Since 3.6.0
- implementation?: {
- --Whether implementation supports dynamic registration. If this is set to `true`
- --the client supports the new `(TextDocumentRegistrationOptions & StaticRegistrationOptions)`
- --return value for the corresponding server capability as well.
- dynamicRegistration?: boolean;
- --The client supports additional metadata in the form of definition links.
- --
- --Since 3.14.0
- linkSupport?: boolean;
- };
- --Capabilities specific to the `textDocument/codeAction`
- codeAction?: {
- --Whether code action supports dynamic registration.
- dynamicRegistration?: boolean;
- --The client support code action literals as a valid
- --response of the `textDocument/codeAction` request.
- --
- --Since 3.8.0
- codeActionLiteralSupport?: {
- --The code action kind is support with the following value
- --set.
- codeActionKind: {
- --The code action kind values the client supports. When this
- --property exists the client also guarantees that it will
- --handle values outside its set gracefully and falls back
- --to a default value when unknown.
- valueSet: CodeActionKind[];
- };
- };
- };
- --Capabilities specific to the `textDocument/codeLens`
- codeLens?: {
- --Whether code lens supports dynamic registration.
- dynamicRegistration?: boolean;
- };
- --Capabilities specific to the `textDocument/documentLink`
- documentLink?: {
- --Whether document link supports dynamic registration.
- dynamicRegistration?: boolean;
- };
- --Capabilities specific to the `textDocument/documentColor` and the
- --`textDocument/colorPresentation` request.
- --
- --Since 3.6.0
- colorProvider?: {
- --Whether colorProvider supports dynamic registration. If this is set to `true`
- --the client supports the new `(ColorProviderOptions & TextDocumentRegistrationOptions & StaticRegistrationOptions)`
- --return value for the corresponding server capability as well.
- dynamicRegistration?: boolean;
- }
- --Capabilities specific to the `textDocument/rename`
- rename?: {
- --Whether rename supports dynamic registration.
- dynamicRegistration?: boolean;
- --The client supports testing for validity of rename operations
- --before execution.
- prepareSupport?: boolean;
- };
- --Capabilities specific to `textDocument/publishDiagnostics`.
- publishDiagnostics?: {
- --Whether the clients accepts diagnostics with related information.
- relatedInformation?: boolean;
- --Client supports the tag property to provide meta data about a diagnostic.
- --Clients supporting tags have to handle unknown tags gracefully.
- --Since 3.15.0
- tagSupport?: {
- --The tags supported by this client
- valueSet: DiagnosticTag[];
- };
- };
- --Capabilities specific to `textDocument/foldingRange` requests.
- --
- --Since 3.10.0
- foldingRange?: {
- --Whether implementation supports dynamic registration for folding range providers. If this is set to `true`
- --the client supports the new `(FoldingRangeProviderOptions & TextDocumentRegistrationOptions & StaticRegistrationOptions)`
- --return value for the corresponding server capability as well.
- dynamicRegistration?: boolean;
- --The maximum number of folding ranges that the client prefers to receive per document. The value serves as a
- --hint, servers are free to follow the limit.
- rangeLimit?: number;
- --If set, the client signals that it only supports folding complete lines. If set, client will
- --ignore specified `startCharacter` and `endCharacter` properties in a FoldingRange.
- lineFoldingOnly?: boolean;
- };
-}
---]=]
-
---[=[
---Workspace specific client capabilities.
-export interface WorkspaceClientCapabilities {
- --The client supports applying batch edits to the workspace by supporting
- --the request 'workspace/applyEdit'
- applyEdit?: boolean;
- --Capabilities specific to `WorkspaceEdit`s
- workspaceEdit?: {
- --The client supports versioned document changes in `WorkspaceEdit`s
- documentChanges?: boolean;
- --The resource operations the client supports. Clients should at least
- --support 'create', 'rename' and 'delete' files and folders.
- resourceOperations?: ResourceOperationKind[];
- --The failure handling strategy of a client if applying the workspace edit
- --fails.
- failureHandling?: FailureHandlingKind;
- };
- --Capabilities specific to the `workspace/didChangeConfiguration` notification.
- didChangeConfiguration?: {
- --Did change configuration notification supports dynamic registration.
- dynamicRegistration?: boolean;
- };
- --Capabilities specific to the `workspace/didChangeWatchedFiles` notification.
- didChangeWatchedFiles?: {
- --Did change watched files notification supports dynamic registration. Please note
- --that the current protocol doesn't support static configuration for file changes
- --from the server side.
- dynamicRegistration?: boolean;
- };
- --Capabilities specific to the `workspace/symbol` request.
- symbol?: {
- --Symbol request supports dynamic registration.
- dynamicRegistration?: boolean;
- --Specific capabilities for the `SymbolKind` in the `workspace/symbol` request.
- symbolKind?: {
- --The symbol kind values the client supports. When this
- --property exists the client also guarantees that it will
- --handle values outside its set gracefully and falls back
- --to a default value when unknown.
- --
- --If this property is not present the client only supports
- --the symbol kinds from `File` to `Array` as defined in
- --the initial version of the protocol.
- valueSet?: SymbolKind[];
- }
- };
- --Capabilities specific to the `workspace/executeCommand` request.
- executeCommand?: {
- --Execute command supports dynamic registration.
- dynamicRegistration?: boolean;
- };
- --The client has support for workspace folders.
- --
- --Since 3.6.0
- workspaceFolders?: boolean;
- --The client supports `workspace/configuration` requests.
- --
- --Since 3.6.0
- configuration?: boolean;
-}
---]=]
+--- @diagnostic enable:no-unknown
--- Gets a new ClientCapabilities object describing the LSP client
--- capabilities.
@@ -1250,14 +941,5 @@ protocol.Methods = {
--- The `workspace/workspaceFolders` is sent from the server to the client to fetch the open workspace folders.
workspace_workspaceFolders = 'workspace/workspaceFolders',
}
-local function freeze(t)
- return setmetatable({}, {
- __index = t,
- __newindex = function()
- error('cannot modify immutable table')
- end,
- })
-end
-protocol.Methods = freeze(protocol.Methods)
return protocol
diff --git a/runtime/lua/vim/lsp/rpc.lua b/runtime/lua/vim/lsp/rpc.lua
index 3c63a12da2..7acb67b25e 100644
--- a/runtime/lua/vim/lsp/rpc.lua
+++ b/runtime/lua/vim/lsp/rpc.lua
@@ -140,7 +140,7 @@ local client_errors = {
SERVER_RESULT_CALLBACK_ERROR = 7,
}
---- @type table<string|integer, string|integer>
+--- @type table<string,integer> | table<integer,string>
--- @nodoc
M.client_errors = vim.deepcopy(client_errors)
for k, v in pairs(client_errors) do
@@ -407,7 +407,9 @@ function Client:handle_body(body)
end
log.debug('rpc.receive', decoded)
- if type(decoded.method) == 'string' and decoded.id then
+ if type(decoded) ~= 'table' then
+ self:on_error(M.client_errors.INVALID_SERVER_MESSAGE, decoded)
+ elseif type(decoded.method) == 'string' and decoded.id then
local err --- @type lsp.ResponseError|nil
-- Schedule here so that the users functions don't trigger an error and
-- we can still use the result.
@@ -502,7 +504,7 @@ function Client:handle_body(body)
if decoded.error then
decoded.error = setmetatable(decoded.error, {
__tostring = M.format_rpc_error,
- }) --- @type table
+ })
end
self:try_call(
M.client_errors.SERVER_RESULT_CALLBACK_ERROR,
diff --git a/runtime/lua/vim/lsp/semantic_tokens.lua b/runtime/lua/vim/lsp/semantic_tokens.lua
index 279956658c..2ae86851d1 100644
--- a/runtime/lua/vim/lsp/semantic_tokens.lua
+++ b/runtime/lua/vim/lsp/semantic_tokens.lua
@@ -412,7 +412,7 @@ end
function STHighlighter:on_win(topline, botline)
for client_id, state in pairs(self.client_state) do
local current_result = state.current_result
- if current_result.version and current_result.version == util.buf_versions[self.bufnr] then
+ if current_result.version == util.buf_versions[self.bufnr] then
if not current_result.namespace_cleared then
api.nvim_buf_clear_namespace(self.bufnr, state.namespace, 0, -1)
current_result.namespace_cleared = true
@@ -773,7 +773,6 @@ function M.highlight_token(token, bufnr, client_id, hl_group, opts)
})
end
---- @package
--- |lsp-handler| for the method `workspace/semanticTokens/refresh`
---
--- Refresh requests are sent by the server to indicate a project-wide change
diff --git a/runtime/lua/vim/lsp/util.lua b/runtime/lua/vim/lsp/util.lua
index 088d57b6d6..a5cf13ed0f 100644
--- a/runtime/lua/vim/lsp/util.lua
+++ b/runtime/lua/vim/lsp/util.lua
@@ -238,6 +238,7 @@ end
---@param rows integer[] zero-indexed line numbers
---@return table<integer, string>|string a table mapping rows to lines
local function get_lines(bufnr, rows)
+ --- @type integer[]
rows = type(rows) == 'table' and rows or { rows }
-- This is needed for bufload and bufloaded
@@ -246,7 +247,7 @@ local function get_lines(bufnr, rows)
end
local function buf_lines()
- local lines = {}
+ local lines = {} --- @type table<integer,string>
for _, row in ipairs(rows) do
lines[row] = (api.nvim_buf_get_lines(bufnr, row, row + 1, false) or { '' })[1]
end
@@ -274,11 +275,11 @@ local function get_lines(bufnr, rows)
if not fd then
return ''
end
- local stat = uv.fs_fstat(fd)
- local data = uv.fs_read(fd, stat.size, 0)
+ local stat = assert(uv.fs_fstat(fd))
+ local data = assert(uv.fs_read(fd, stat.size, 0))
uv.fs_close(fd)
- local lines = {} -- rows we need to retrieve
+ local lines = {} --- @type table<integer,true|string> rows we need to retrieve
local need = 0 -- keep track of how many unique rows we need
for _, row in pairs(rows) do
if not lines[row] then
@@ -307,7 +308,7 @@ local function get_lines(bufnr, rows)
lines[i] = ''
end
end
- return lines
+ return lines --[[@as table<integer,string>]]
end
--- Gets the zero-indexed line from the given buffer.
@@ -322,7 +323,8 @@ local function get_line(bufnr, row)
end
--- Position is a https://microsoft.github.io/language-server-protocol/specifications/specification-current/#position
----@param offset_encoding string|nil utf-8|utf-16|utf-32
+---@param position lsp.Position
+---@param offset_encoding? string utf-8|utf-16|utf-32
---@return integer
local function get_line_byte_from_position(bufnr, position, offset_encoding)
-- LSP's line and characters are 0-indexed
@@ -366,6 +368,7 @@ function M.apply_text_edits(text_edits, bufnr, offset_encoding)
-- Fix reversed range and indexing each text_edits
local index = 0
+ --- @param text_edit lsp.TextEdit
text_edits = vim.tbl_map(function(text_edit)
index = index + 1
text_edit._index = index
@@ -383,6 +386,9 @@ function M.apply_text_edits(text_edits, bufnr, offset_encoding)
end, text_edits)
-- Sort text_edits
+ ---@param a lsp.TextEdit | { _index: integer }
+ ---@param b lsp.TextEdit | { _index: integer }
+ ---@return boolean
table.sort(text_edits, function(a, b)
if a.range.start.line ~= b.range.start.line then
return a.range.start.line > b.range.start.line
@@ -393,10 +399,11 @@ function M.apply_text_edits(text_edits, bufnr, offset_encoding)
if a._index ~= b._index then
return a._index < b._index
end
+ return false
end)
-- save and restore local marks since they get deleted by nvim_buf_set_lines
- local marks = {}
+ local marks = {} --- @type table<string,[integer,integer]>
for _, m in pairs(vim.fn.getmarklist(bufnr)) do
if m.mark:match("^'[a-z]$") then
marks[m.mark:sub(2, 2)] = { m.pos[2], m.pos[3] - 1 } -- api-indexed
@@ -509,7 +516,6 @@ function M.apply_text_document_edit(text_document_edit, index, offset_encoding)
and (
text_document.version
and text_document.version > 0
- and M.buf_versions[bufnr]
and M.buf_versions[bufnr] > text_document.version
)
then
@@ -2215,6 +2221,11 @@ end
M._get_line_byte_from_position = get_line_byte_from_position
---@nodoc
-M.buf_versions = {} ---@type table<integer,integer>
+---@type table<integer,integer>
+M.buf_versions = setmetatable({}, {
+ __index = function(t, bufnr)
+ return rawget(t, bufnr) or 0
+ end,
+})
return M
diff --git a/runtime/lua/vim/text.lua b/runtime/lua/vim/text.lua
index bc90d490aa..0be3396464 100644
--- a/runtime/lua/vim/text.lua
+++ b/runtime/lua/vim/text.lua
@@ -18,15 +18,19 @@ end
--- Hex decode a string.
---
--- @param enc string String to decode
---- @return string : Decoded string
+--- @return string? : Decoded string
+--- @return string? : Error message, if any
function M.hexdecode(enc)
- assert(#enc % 2 == 0, 'string must have an even number of hex characters')
+ if #enc % 2 ~= 0 then
+ return nil, 'string must have an even number of hex characters'
+ end
+
local str = {} ---@type string[]
for i = 1, #enc, 2 do
local n = assert(tonumber(enc:sub(i, i + 1), 16))
str[#str + 1] = string.char(n)
end
- return table.concat(str)
+ return table.concat(str), nil
end
return M
diff --git a/runtime/lua/vim/treesitter/_fold.lua b/runtime/lua/vim/treesitter/_fold.lua
index eecf1ad6b1..04a3c62cf1 100644
--- a/runtime/lua/vim/treesitter/_fold.lua
+++ b/runtime/lua/vim/treesitter/_fold.lua
@@ -383,7 +383,6 @@ local function on_bytes(bufnr, foldinfo, start_row, start_col, old_row, old_col,
end
end
----@package
---@param lnum integer|nil
---@return string
function M.foldexpr(lnum)
diff --git a/runtime/lua/vim/treesitter/_meta.lua b/runtime/lua/vim/treesitter/_meta.lua
index 177699a207..2aedf5754e 100644
--- a/runtime/lua/vim/treesitter/_meta.lua
+++ b/runtime/lua/vim/treesitter/_meta.lua
@@ -33,6 +33,7 @@ error('Cannot require a meta file')
---@field iter_children fun(self: TSNode): fun(): TSNode, string
---@field field fun(self: TSNode, name: string): TSNode[]
---@field byte_length fun(self: TSNode): integer
+---@field __has_ancestor fun(self: TSNode, node_types: string[]): boolean
local TSNode = {}
---@alias TSLoggerCallback fun(logtype: 'parse'|'lex', msg: string)
@@ -62,6 +63,7 @@ local TSNode = {}
---@field patterns table<integer, (integer|string)[][]>
--- @param lang string
+--- @return table
vim._ts_inspect_language = function(lang) end
---@return integer
diff --git a/runtime/lua/vim/treesitter/highlighter.lua b/runtime/lua/vim/treesitter/highlighter.lua
index d2f986b874..003f7e0169 100644
--- a/runtime/lua/vim/treesitter/highlighter.lua
+++ b/runtime/lua/vim/treesitter/highlighter.lua
@@ -47,7 +47,7 @@ function TSHighlighterQuery:get_hl_from_capture(capture)
return self.hl_cache[capture]
end
----@package
+---@nodoc
function TSHighlighterQuery:query()
return self._query
end
@@ -75,7 +75,7 @@ local TSHighlighter = {
TSHighlighter.__index = TSHighlighter
----@package
+---@nodoc
---
--- Creates a highlighter for `tree`.
---
@@ -232,7 +232,7 @@ function TSHighlighter:on_changedtree(changes)
end
--- Gets the query used for @param lang
----@package
+---@nodoc
---@param lang string Language used by the highlighter.
---@return vim.treesitter.highlighter.Query
function TSHighlighter:get_query(lang)
diff --git a/runtime/lua/vim/treesitter/languagetree.lua b/runtime/lua/vim/treesitter/languagetree.lua
index b0812123b9..3523ea95e0 100644
--- a/runtime/lua/vim/treesitter/languagetree.lua
+++ b/runtime/lua/vim/treesitter/languagetree.lua
@@ -98,9 +98,9 @@ local LanguageTree = {}
LanguageTree.__index = LanguageTree
---- @package
+--- @nodoc
---
---- |LanguageTree| contains a tree of parsers: the root treesitter parser for {lang} and any
+--- LanguageTree contains a tree of parsers: the root treesitter parser for {lang} and any
--- "injected" language parsers, which themselves may inject other languages, recursively.
---
---@param source (integer|string) Buffer or text string to parse
@@ -951,7 +951,7 @@ function LanguageTree:_edit(
end
end
----@package
+---@nodoc
---@param bufnr integer
---@param changed_tick integer
---@param start_row integer
@@ -1023,12 +1023,12 @@ function LanguageTree:_on_bytes(
)
end
----@package
+---@nodoc
function LanguageTree:_on_reload()
self:invalidate(true)
end
----@package
+---@nodoc
function LanguageTree:_on_detach(...)
self:invalidate(true)
self:_do_callback('detach', ...)