aboutsummaryrefslogtreecommitdiff
path: root/runtime
diff options
context:
space:
mode:
Diffstat (limited to 'runtime')
-rw-r--r--runtime/doc/api.txt140
-rw-r--r--runtime/doc/cmdline.txt7
-rw-r--r--runtime/doc/deprecated.txt4
-rw-r--r--runtime/doc/eval.txt3
-rw-r--r--runtime/doc/insert.txt12
-rw-r--r--runtime/doc/lsp.txt103
-rw-r--r--runtime/doc/map.txt2
-rw-r--r--runtime/doc/options.txt3
-rw-r--r--runtime/doc/syntax.txt3
-rw-r--r--runtime/doc/usr_05.txt8
-rw-r--r--runtime/doc/usr_06.txt24
-rw-r--r--runtime/doc/vim_diff.txt7
-rw-r--r--runtime/filetype.vim3
-rw-r--r--runtime/lua/vim/filetype.lua1
-rw-r--r--runtime/lua/vim/lsp.lua99
-rw-r--r--runtime/lua/vim/lsp/buf.lua173
-rw-r--r--runtime/lua/vim/lsp/handlers.lua16
-rw-r--r--runtime/lua/vim/lsp/protocol.lua47
-rw-r--r--runtime/lua/vim/lsp/rpc.lua2
-rw-r--r--runtime/lua/vim/lsp/util.lua4
-rw-r--r--runtime/lua/vim/shared.lua5
21 files changed, 513 insertions, 153 deletions
diff --git a/runtime/doc/api.txt b/runtime/doc/api.txt
index 8e33e7a67b..ed3a838b6d 100644
--- a/runtime/doc/api.txt
+++ b/runtime/doc/api.txt
@@ -148,9 +148,9 @@ indices, end-inclusive):
Most API functions are "deferred": they are queued on the main loop and
processed sequentially with normal input. So if the editor is waiting for
user input in a "modal" fashion (e.g. the |hit-enter-prompt|), the request
-will block. Non-deferred ({fast}) functions such as |nvim_get_mode()| and
+will block. Non-deferred (fast) functions such as |nvim_get_mode()| and
|nvim_input()| are served immediately (i.e. without waiting in the input
-queue). Lua code can use |vim.in_fast_event()| to detect a {fast} context.
+queue). Lua code can use |vim.in_fast_event()| to detect a fast context.
==============================================================================
API metadata *api-metadata*
@@ -535,7 +535,7 @@ nvim__get_runtime({pat}, {all}, {*opts}) *nvim__get_runtime()*
Find files in runtime directories
Attributes: ~
- {fast}
+ |api-fast|
Parameters: ~
{pat} pattern of files to search for
@@ -604,7 +604,7 @@ nvim__screenshot({path}) *nvim__screenshot()*
TODO: Documentation
Attributes: ~
- {fast}
+ |api-fast|
nvim__set_hl_ns({ns_id}) *nvim__set_hl_ns()*
Set active namespace for highlights.
@@ -616,7 +616,7 @@ nvim__set_hl_ns({ns_id}) *nvim__set_hl_ns()*
cycle.
Attributes: ~
- {fast}
+ |api-fast|
Parameters: ~
{ns_id} the namespace to activate
@@ -639,6 +639,9 @@ nvim_call_atomic({calls}) *nvim_call_atomic()*
2. To minimize RPC overhead (roundtrips) of a sequence of many
requests.
+ Attributes: ~
+ |RPC| only
+
Parameters: ~
{calls} an array of calls, where each call is described
by an array with two elements: the request name,
@@ -665,6 +668,10 @@ nvim_chan_send({chan}, {data}) *nvim_chan_send()*
RPC messages, use |vim.rpcnotify()| and |vim.rpcrequest()|
instead.
+ Attributes: ~
+ |RPC| only
+ |vim.api| only
+
Parameters: ~
{chan} id of the channel
{data} data to write. 8-bit clean: can contain NUL bytes.
@@ -816,7 +823,7 @@ nvim_eval_statusline({str}, {*opts}) *nvim_eval_statusline()*
Evaluates statusline string.
Attributes: ~
- {fast}
+ |api-fast|
Parameters: ~
{str} Statusline string (see 'statusline').
@@ -853,6 +860,9 @@ nvim_exec_lua({code}, {args}) *nvim_exec_lua()*
Only statements are executed. To evaluate an expression,
prefix it with `return`: return my_function(...)
+ Attributes: ~
+ |RPC| only
+
Parameters: ~
{code} Lua code to execute
{args} Arguments to the code
@@ -905,7 +915,8 @@ nvim_get_api_info() *nvim_get_api_info()*
2-tuple [{channel-id}, {api-metadata}]
Attributes: ~
- {fast}
+ |api-fast|
+ |RPC| only
nvim_get_chan_info({chan}) *nvim_get_chan_info()*
Gets information about a channel.
@@ -1081,7 +1092,7 @@ nvim_get_mode() *nvim_get_mode()*
Dictionary { "mode": String, "blocking": Boolean }
Attributes: ~
- {fast}
+ |api-fast|
nvim_get_option({name}) *nvim_get_option()*
Gets the global value of an option.
@@ -1157,7 +1168,7 @@ nvim_get_runtime_file({name}, {all}) *nvim_get_runtime_file()*
returned then.
Attributes: ~
- {fast}
+ |api-fast|
Parameters: ~
{name} pattern of files to search for
@@ -1201,7 +1212,7 @@ nvim_input({keys}) *nvim_input()*
|api-level| 6.
Attributes: ~
- {fast}
+ |api-fast|
Parameters: ~
{keys} to be typed
@@ -1226,7 +1237,7 @@ nvim_input_mouse({button}, {action}, {modifier}, {grid}, {row}, {col})
|nvim_input()| has the same limitation.
Attributes: ~
- {fast}
+ |api-fast|
Parameters: ~
{button} Mouse button: one of "left", "right",
@@ -1350,6 +1361,69 @@ nvim_out_write({str}) *nvim_out_write()*
Parameters: ~
{str} Message
+nvim_parse_cmd({str}, {opts}) *nvim_parse_cmd()*
+ Parse command line.
+
+ Doesn't check the validity of command arguments.
+
+ Attributes: ~
+ |api-fast|
+
+ Parameters: ~
+ {str} Command line string to parse. Cannot contain "\n".
+ {opts} Optional parameters. Reserved for future use.
+
+ Return: ~
+ Dictionary containing command information, with these
+ keys:
+ • cmd: (string) Command name.
+ • line1: (number) Starting line of command range. Only
+ applicable if command can take a range.
+ • line2: (number) Final line of command range. Only
+ applicable if command can take a range.
+ • bang: (boolean) Whether command contains a bang (!)
+ modifier.
+ • args: (array) Command arguments.
+ • addr: (string) Value of |:command-addr|. Uses short
+ name.
+ • nargs: (string) Value of |:command-nargs|.
+ • nextcmd: (string) Next command if there are multiple
+ commands separated by a |:bar|. Empty if there isn't a
+ next command.
+ • magic: (dictionary) Which characters have special
+ meaning in the command arguments.
+ • file: (boolean) The command expands filenames. Which
+ means characters such as "%", "#" and wildcards are
+ expanded.
+ • bar: (boolean) The "|" character is treated as a
+ command separator and the double quote character (")
+ is treated as the start of a comment.
+
+ • mods: (dictionary) |:command-modifiers|.
+ • silent: (boolean) |:silent|.
+ • emsg_silent: (boolean) |:silent!|.
+ • sandbox: (boolean) |:sandbox|.
+ • noautocmd: (boolean) |:noautocmd|.
+ • browse: (boolean) |:browse|.
+ • confirm: (boolean) |:confirm|.
+ • hide: (boolean) |:hide|.
+ • keepalt: (boolean) |:keepalt|.
+ • keepjumps: (boolean) |:keepjumps|.
+ • keepmarks: (boolean) |:keepmarks|.
+ • keeppatterns: (boolean) |:keeppatterns|.
+ • lockmarks: (boolean) |:lockmarks|.
+ • noswapfile: (boolean) |:noswapfile|.
+ • tab: (integer) |:tab|.
+ • verbose: (integer) |:verbose|.
+ • vertical: (boolean) |:vertical|.
+ • split: (string) Split modifier string, is an empty
+ string when there's no split modifier. If there is a
+ split modifier it can be one of:
+ • "aboveleft": |:aboveleft|.
+ • "belowright": |:belowright|.
+ • "topleft": |:topleft|.
+ • "botright": |:botright|.
+
nvim_paste({data}, {crlf}, {phase}) *nvim_paste()*
Pastes at cursor, in any mode.
@@ -1455,6 +1529,9 @@ nvim_set_client_info({name}, {version}, {type}, {methods}, {attributes})
"Something is better than nothing". You don't need to
include all the fields.
+ Attributes: ~
+ |RPC| only
+
Parameters: ~
{name} Short name for the connected client
{version} Dictionary describing the version, with
@@ -1649,12 +1726,18 @@ nvim_strwidth({text}) *nvim_strwidth()*
nvim_subscribe({event}) *nvim_subscribe()*
Subscribes to event broadcasts.
+ Attributes: ~
+ |RPC| only
+
Parameters: ~
{event} Event type string
nvim_unsubscribe({event}) *nvim_unsubscribe()*
Unsubscribes to event broadcasts.
+ Attributes: ~
+ |RPC| only
+
Parameters: ~
{event} Event type string
@@ -1744,7 +1827,7 @@ nvim_parse_expression({expr}, {flags}, {highlight})
Parse a VimL expression.
Attributes: ~
- {fast}
+ |api-fast|
Parameters: ~
{expr} Expression to parse. Always treated as a
@@ -1964,6 +2047,9 @@ nvim_buf_call({buffer}, {fun}) *nvim_buf_call()*
This is useful e.g. to call vimL functions that only work with
the current buffer/window currently, like |termopen()|.
+ Attributes: ~
+ |vim.api| only
+
Parameters: ~
{buffer} Buffer handle, or 0 for current buffer
{fun} Function to call inside the buffer (currently
@@ -2046,6 +2132,9 @@ nvim_buf_delete({buffer}, {opts}) *nvim_buf_delete()*
nvim_buf_detach({buffer}) *nvim_buf_detach()*
Deactivates buffer-update events on the channel.
+ Attributes: ~
+ |RPC| only
+
Parameters: ~
{buffer} Buffer handle, or 0 for current buffer
@@ -2674,6 +2763,9 @@ nvim_set_decoration_provider({ns_id}, {opts})
`vim.rpcnotify` should be OK, but `vim.rpcrequest` is quite
dubious for the moment.
+ Attributes: ~
+ |vim.api| only
+
Parameters: ~
{ns_id} Namespace id from |nvim_create_namespace()|
{opts} Callbacks invoked during redraw:
@@ -2697,6 +2789,9 @@ Window Functions *api-window*
nvim_win_call({window}, {fun}) *nvim_win_call()*
Calls a function with window as temporary current window.
+ Attributes: ~
+ |vim.api| only
+
Parameters: ~
{window} Window handle, or 0 for current window
{fun} Function to call inside the window (currently
@@ -3429,6 +3524,9 @@ nvim_ui_attach({width}, {height}, {options}) *nvim_ui_attach()*
A requests 80x40 but client B requests 200x100, the global
screen has size 80x40.
+ Attributes: ~
+ |RPC| only
+
Parameters: ~
{width} Requested screen columns
{height} Requested screen rows
@@ -3439,6 +3537,9 @@ nvim_ui_detach() *nvim_ui_detach()*
Removes the client from the list of UIs. |nvim_list_uis()|
+ Attributes: ~
+ |RPC| only
+
*nvim_ui_pum_set_bounds()*
nvim_ui_pum_set_bounds({width}, {height}, {row}, {col})
Tells Nvim the geometry of the popumenu, to align floating
@@ -3452,6 +3553,9 @@ nvim_ui_pum_set_bounds({width}, {height}, {row}, {col})
nor be anchored to exact grid corners, so one can set
floating-point numbers to the popup menu geometry.
+ Attributes: ~
+ |RPC| only
+
Parameters: ~
{width} Popupmenu width.
{height} Popupmenu height.
@@ -3462,15 +3566,24 @@ nvim_ui_pum_set_height({height}) *nvim_ui_pum_set_height()*
Tells Nvim the number of elements displaying in the popumenu,
to decide <PageUp> and <PageDown> movement.
+ Attributes: ~
+ |RPC| only
+
Parameters: ~
{height} Popupmenu height, must be greater than zero.
nvim_ui_set_option({name}, {value}) *nvim_ui_set_option()*
TODO: Documentation
+ Attributes: ~
+ |RPC| only
+
nvim_ui_try_resize({width}, {height}) *nvim_ui_try_resize()*
TODO: Documentation
+ Attributes: ~
+ |RPC| only
+
*nvim_ui_try_resize_grid()*
nvim_ui_try_resize_grid({grid}, {width}, {height})
Tell Nvim to resize a grid. Triggers a grid_resize event with
@@ -3479,6 +3592,9 @@ nvim_ui_try_resize_grid({grid}, {width}, {height})
On invalid grid handle, fails with error.
+ Attributes: ~
+ |RPC| only
+
Parameters: ~
{grid} The handle of the grid to be changed.
{width} The new requested width.
diff --git a/runtime/doc/cmdline.txt b/runtime/doc/cmdline.txt
index 9fa2034718..6228c9238f 100644
--- a/runtime/doc/cmdline.txt
+++ b/runtime/doc/cmdline.txt
@@ -67,12 +67,19 @@ CTRL-V Insert next non-digit literally. Up to three digits form the
decimal value of a single byte. The non-digit and the three
digits are not considered for mapping. This works the same
way as in Insert mode (see above, |i_CTRL-V|).
+ For special keys, the CTRL modifier may be included into the
+ key to produce a control character. If there is no control
+ character for the key then its |key-notation| is inserted.
Note: Under Windows CTRL-V is often mapped to paste text.
Use CTRL-Q instead then.
*c_CTRL-Q*
CTRL-Q Same as CTRL-V. But with some terminals it is used for
control flow, it doesn't work then.
+CTRL-SHIFT-V *c_CTRL-SHIFT-V* *c_CTRL-SHIFT-Q*
+CTRL-SHIFT-Q Works just like CTRL-V, but do not try to include the CTRL
+ modifier into the key.
+
*c_<Left>* *c_Left*
<Left> cursor left
*c_<Right>* *c_Right*
diff --git a/runtime/doc/deprecated.txt b/runtime/doc/deprecated.txt
index 21a34178b3..f24bf06feb 100644
--- a/runtime/doc/deprecated.txt
+++ b/runtime/doc/deprecated.txt
@@ -55,6 +55,10 @@ Functions ~
without stopping the job. Use chanclose(id) to close
any socket.
+Highlights ~
+
+*hl-VertSplit* Use |hl-WinSeparator| instead.
+
LSP Diagnostics ~
For each of the functions below, use the corresponding function in
diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt
index 2f3602caa1..c6319c717a 100644
--- a/runtime/doc/eval.txt
+++ b/runtime/doc/eval.txt
@@ -1325,6 +1325,9 @@ A string constant accepts these special characters:
To use the double quote character it must be escaped: "<M-\">".
Don't use <Char-xxxx> to get a UTF-8 character, use \uxxxx as
mentioned above.
+\<*xxx> Like \<xxx> but prepends a modifier instead of including it in the
+ character. E.g. "\<C-w>" is one character 0x17 while "\<*C-w>" is four
+ bytes: 3 for the CTRL modifier and then character "W".
Note that "\xff" is stored as the byte 255, which may be invalid in some
encodings. Use "\u00ff" to store character 255 correctly as UTF-8.
diff --git a/runtime/doc/insert.txt b/runtime/doc/insert.txt
index 9db44eaaa0..7f6662089d 100644
--- a/runtime/doc/insert.txt
+++ b/runtime/doc/insert.txt
@@ -192,12 +192,14 @@ CTRL-D Delete one shiftwidth of indent at the start of the current
label.
*i_CTRL-V*
-CTRL-V Insert next non-digit literally. For special keys, the
- terminal code is inserted. It's also possible to enter the
- decimal, octal or hexadecimal value of a character
+CTRL-V Insert next non-digit literally. It's also possible to enter
+ the decimal, octal or hexadecimal value of a character
|i_CTRL-V_digit|.
The characters typed right after CTRL-V are not considered for
mapping.
+ For special keys, the CTRL modifier may be included into the
+ key to produce a control character. If there is no control
+ character for the key then its |key-notation| is inserted.
Note: When CTRL-V is mapped (e.g., to paste text) you can
often use CTRL-Q instead |i_CTRL-Q|.
@@ -206,6 +208,10 @@ CTRL-Q Same as CTRL-V.
Note: Some terminal connections may eat CTRL-Q, it doesn't
work then. It does work in the GUI.
+CTRL-SHIFT-V *i_CTRL-SHIFT-V* *i_CTRL-SHIFT-Q*
+CTRL-SHIFT-Q Works just like CTRL-V, but do not try to include the CTRL
+ modifier into the key.
+
CTRL-X Enter CTRL-X mode. This is a sub-mode where commands can
be given to complete words or scroll the window. See
|i_CTRL-X| and |ins-completion|.
diff --git a/runtime/doc/lsp.txt b/runtime/doc/lsp.txt
index b704d2d6e8..f55c959a03 100644
--- a/runtime/doc/lsp.txt
+++ b/runtime/doc/lsp.txt
@@ -653,9 +653,6 @@ client() *vim.lsp.client*
user to |vim.lsp.start_client()|.
• {server_capabilities} (table): Response from the server
sent on `initialize` describing the server's capabilities.
- • {resolved_capabilities} (table): Normalized table of
- capabilities that we have detected based on the initialize
- response from the server in `server_capabilities`.
client_is_stopped({client_id}) *vim.lsp.client_is_stopped()*
Checks whether a client is stopped.
@@ -969,18 +966,28 @@ add_workspace_folder({workspace_folder})
clear_references() *vim.lsp.buf.clear_references()*
Removes document highlights from current buffer.
-code_action({context}) *vim.lsp.buf.code_action()*
+code_action({options}) *vim.lsp.buf.code_action()*
Selects a code action available at the current cursor
position.
Parameters: ~
- {context} table|nil `CodeActionContext` of the LSP specification:
- • diagnostics: (table|nil) LSP`Diagnostic[]` . Inferred from the current position if not
- provided.
- • only: (string|nil) LSP `CodeActionKind` used
- to filter the code actions. Most language
- servers support values like `refactor` or
- `quickfix`.
+ {options} table|nil Optional table which holds the
+ following optional fields:
+ • context (table|nil): Corresponds to `CodeActionContext` of the LSP specification:
+ • diagnostics (table|nil): LSP`Diagnostic[]` . Inferred from the current position if not
+ provided.
+ • only (string|nil): LSP `CodeActionKind`
+ used to filter the code actions. Most
+ language servers support values like
+ `refactor` or `quickfix`.
+
+ • filter (function|nil): Predicate function
+ taking an `CodeAction` and returning a
+ boolean.
+ • apply (boolean|nil): When set to `true`, and
+ there is just one remaining action (after
+ filtering), the action is applied without
+ user query.
See also: ~
https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_codeAction
@@ -1038,11 +1045,54 @@ execute_command({command_params}) *vim.lsp.buf.execute_command()*
See also: ~
https://microsoft.github.io/language-server-protocol/specifications/specification-current/#workspace_executeCommand
+format({options}) *vim.lsp.buf.format()*
+ Formats a buffer using the attached (and optionally filtered)
+ language server clients.
+
+ Parameters: ~
+ {options} table|nil Optional table which holds the
+ following optional fields:
+ • formatting_options (table|nil): Can be used
+ to specify FormattingOptions. Some
+ unspecified options will be automatically
+ derived from the current Neovim options.
+
+ See also: ~
+ https://microsoft.github.io/language-server-protocol/specification#textDocument_formatting
+ • timeout_ms (integer|nil, default 1000): Time in
+ milliseconds to block for formatting requests. No effect
+ if async=true
+ • bufnr (number|nil): Restrict formatting to the clients
+ attached to the given buffer, defaults to the current
+ buffer (0).
+ • filter (function|nil): Predicate to filter clients used
+ for formatting. Receives the list of clients attached to
+ bufnr as the argument and must return the list of
+ clients on which to request formatting. Example: • >
+
+ -- Never request typescript-language-server for formatting
+ vim.lsp.buf.format {
+ filter = function(clients)
+ return vim.tbl_filter(
+ function(client) return client.name ~= "tsserver" end,
+ clients
+ )
+ end
+ }
+<
+ • async boolean|nil If true the method won't block.
+ Defaults to false. Editing the buffer while formatting
+ asynchronous can lead to unexpected changes.
+ • id (number|nil): Restrict formatting to the client with
+ ID (client.id) matching this field.
+ • name (string|nil): Restrict formatting to the client
+ with name (client.name) matching this field.
+
formatting({options}) *vim.lsp.buf.formatting()*
Formats the current buffer.
Parameters: ~
- {options} (optional, table) Can be used to specify
+ {options} (table|nil) Can be used to specify
FormattingOptions. Some unspecified options
will be automatically derived from the current
Neovim options.
@@ -1066,15 +1116,13 @@ formatting_seq_sync({options}, {timeout_ms}, {order})
<
Parameters: ~
- {options} (optional, table) `FormattingOptions`
- entries
- {timeout_ms} (optional, number) Request timeout
- {order} (optional, table) List of client names.
- Formatting is requested from clients in the
- following order: first all clients that are
- not in the `order` list, then the remaining
- clients in the order as they occur in the
- `order` list.
+ {options} (table|nil) `FormattingOptions` entries
+ {timeout_ms} (number|nil) Request timeout
+ {order} (table|nil) List of client names. Formatting
+ is requested from clients in the following
+ order: first all clients that are not in the
+ `order` list, then the remaining clients in
+ the order as they occur in the `order` list.
*vim.lsp.buf.formatting_sync()*
formatting_sync({options}, {timeout_ms})
@@ -1089,7 +1137,8 @@ formatting_sync({options}, {timeout_ms})
<
Parameters: ~
- {options} Table with valid `FormattingOptions` entries
+ {options} table|nil with valid `FormattingOptions`
+ entries
{timeout_ms} (number) Request timeout
See also: ~
@@ -1464,8 +1513,7 @@ get_effective_tabstop({bufnr}) *vim.lsp.util.get_effective_tabstop()*
Returns indentation size.
Parameters: ~
- {bufnr} (optional, number): Buffer handle, defaults to
- current
+ {bufnr} (number|nil): Buffer handle, defaults to current
Return: ~
(number) indentation size
@@ -1541,7 +1589,8 @@ make_formatting_params({options})
buffer and cursor position.
Parameters: ~
- {options} Table with valid `FormattingOptions` entries
+ {options} table|nil with valid `FormattingOptions`
+ entries
Return: ~
`DocumentFormattingParams` object
@@ -1865,8 +1914,8 @@ request({method}, {params}, {callback}, {notify_reply_callback})
{params} (table) Parameters for the
invoked LSP method
{callback} (function) Callback to invoke
- {notify_reply_callback} (function) Callback to invoke as
- soon as a request is no longer
+ {notify_reply_callback} (function|nil) Callback to invoke
+ as soon as a request is no longer
pending
Return: ~
diff --git a/runtime/doc/map.txt b/runtime/doc/map.txt
index b874d6dc61..6e100e5854 100644
--- a/runtime/doc/map.txt
+++ b/runtime/doc/map.txt
@@ -1421,7 +1421,7 @@ which by default correspond to the current line, last line and the whole
buffer, relate to arguments, (loaded) buffers, windows or tab pages.
Possible values are (second column is the short name used in listing):
- -addr=lines Range of lines (this is the default)
+ -addr=lines line Range of lines (this is the default)
-addr=arguments arg Range for arguments
-addr=buffers buf Range for buffers (also not loaded buffers)
-addr=loaded_buffers load Range for loaded buffers
diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt
index b6f9c007ef..1109056d47 100644
--- a/runtime/doc/options.txt
+++ b/runtime/doc/options.txt
@@ -4483,8 +4483,7 @@ A jump table for the options with a short description can be found at |Q_op|.
Note that typing <F10> in paste mode inserts "<F10>", since in paste
mode everything is inserted literally, except the 'pastetoggle' key
sequence.
- No timeout is used, this means that a multi-key 'pastetoggle' can not
- be triggered manually.
+ When the value has several bytes 'ttimeoutlen' applies.
*'pex'* *'patchexpr'*
'patchexpr' 'pex' string (default "")
diff --git a/runtime/doc/syntax.txt b/runtime/doc/syntax.txt
index b97f158c31..2a78d975ee 100644
--- a/runtime/doc/syntax.txt
+++ b/runtime/doc/syntax.txt
@@ -26,7 +26,8 @@ In the User Manual:
1. Quick start *:syn-qstart*
*:syn-enable* *:syntax-enable* *:syn-on* *:syntax-on*
-This command switches on syntax highlighting: >
+Syntax highlighting is enabled by default. If you need to enable it again
+after it was disabled (see below), use: >
:syntax enable
diff --git a/runtime/doc/usr_05.txt b/runtime/doc/usr_05.txt
index b1ef563e43..1cf383dce3 100644
--- a/runtime/doc/usr_05.txt
+++ b/runtime/doc/usr_05.txt
@@ -139,13 +139,11 @@ quite complicated things. Still, it is just a sequence of commands that are
executed like you typed them.
>
- syntax on
set hlsearch
-This switches on syntax highlighting. And the 'hlsearch' option tells Vim to
-highlight matches with the last used search pattern. The "if" command is very
-useful to set options only when some condition is met. More about that in
-|usr_41.txt|.
+This option tells Vim to highlight matches with the last used search pattern.
+The "if" command is very useful to set options only when some condition is
+met. More about that in |usr_41.txt|.
*vimrc-filetype* >
filetype plugin indent on
diff --git a/runtime/doc/usr_06.txt b/runtime/doc/usr_06.txt
index 360f72ec63..b99e0fb482 100644
--- a/runtime/doc/usr_06.txt
+++ b/runtime/doc/usr_06.txt
@@ -24,28 +24,8 @@ Table of contents: |usr_toc.txt|
==============================================================================
*06.1* Switching it on
-It all starts with one simple command: >
-
- :syntax enable
-
-That should work in most situations to get color in your files. Vim will
-automagically detect the type of file and load the right syntax highlighting.
-Suddenly comments are blue, keywords brown and strings red. This makes it
-easy to overview the file. After a while you will find that black&white text
-slows you down!
-
-If you always want to use syntax highlighting, put the ":syntax enable"
-command in your |init.vim| file.
-
-If you want syntax highlighting only when the terminal supports colors, you
-can put this in your |init.vim| file: >
-
- if &t_Co > 1
- syntax enable
- endif
-
-If you want syntax highlighting only in the GUI version, put the ":syntax
-enable" command in your |ginit.vim| file.
+Syntax highlighting is enabled by default. Nvim will automagically detect the
+type of file and load the right syntax highlighting.
==============================================================================
*06.2* No or wrong colors?
diff --git a/runtime/doc/vim_diff.txt b/runtime/doc/vim_diff.txt
index 540043f52d..e24dd46f49 100644
--- a/runtime/doc/vim_diff.txt
+++ b/runtime/doc/vim_diff.txt
@@ -354,7 +354,7 @@ Highlight groups:
|hl-CurSearch| highlights match under cursor instead of last match found
using |n| or |N|
|hl-CursorLine| is low-priority unless foreground color is set
- *hl-VertSplit* superseded by |hl-WinSeparator|
+ |hl-VertSplit| superseded by |hl-WinSeparator|
Macro/|recording| behavior
Replay of a macro recorded during :lmap produces the same actions as when it
@@ -365,6 +365,11 @@ Macro/|recording| behavior
macros and 'keymap' at the same time. This also means you can use |:imap| on
the results of keys from 'keymap'.
+Mappings:
+- Creating a mapping for a simplifiable key (e.g. <C-I>) doesn't replace an
+ existing mapping for its simplified form (e.g. <Tab>).
+- The rhs of a mapping is not simplified when it is defined.
+
Motion:
The |jumplist| avoids useless/phantom jumps.
diff --git a/runtime/filetype.vim b/runtime/filetype.vim
index 28ca09e57d..7337647b03 100644
--- a/runtime/filetype.vim
+++ b/runtime/filetype.vim
@@ -715,6 +715,9 @@ au BufNewFile,BufRead *.git/*
" Gkrellmrc
au BufNewFile,BufRead gkrellmrc,gkrellmrc_? setf gkrellmrc
+" Gleam
+au BufNewFile,BufRead *.gleam setf gleam
+
" GLSL
au BufNewFile,BufRead *.glsl setf glsl
diff --git a/runtime/lua/vim/filetype.lua b/runtime/lua/vim/filetype.lua
index 1297ef6241..2a34fec7f2 100644
--- a/runtime/lua/vim/filetype.lua
+++ b/runtime/lua/vim/filetype.lua
@@ -241,6 +241,7 @@ local extension = {
gmi = "gemtext",
gemini = "gemtext",
gift = "gift",
+ gleam = "gleam",
glsl = "glsl",
gpi = "gnuplot",
gnuplot = "gnuplot",
diff --git a/runtime/lua/vim/lsp.lua b/runtime/lua/vim/lsp.lua
index 7bbe3637db..19ee75a1b6 100644
--- a/runtime/lua/vim/lsp.lua
+++ b/runtime/lua/vim/lsp.lua
@@ -31,28 +31,28 @@ local lsp = {
rpc_response_error = lsp_rpc.rpc_response_error;
}
--- maps request name to the required resolved_capability in the client.
+-- maps request name to the required server_capability in the client.
lsp._request_name_to_capability = {
- ['textDocument/hover'] = 'hover';
- ['textDocument/signatureHelp'] = 'signature_help';
- ['textDocument/definition'] = 'goto_definition';
- ['textDocument/implementation'] = 'implementation';
- ['textDocument/declaration'] = 'declaration';
- ['textDocument/typeDefinition'] = 'type_definition';
- ['textDocument/documentSymbol'] = 'document_symbol';
- ['textDocument/prepareCallHierarchy'] = 'call_hierarchy';
- ['textDocument/rename'] = 'rename';
- ['textDocument/prepareRename'] = 'rename';
- ['textDocument/codeAction'] = 'code_action';
- ['textDocument/codeLens'] = 'code_lens';
- ['codeLens/resolve'] = 'code_lens_resolve';
- ['workspace/executeCommand'] = 'execute_command';
- ['workspace/symbol'] = 'workspace_symbol';
- ['textDocument/references'] = 'find_references';
- ['textDocument/rangeFormatting'] = 'document_range_formatting';
- ['textDocument/formatting'] = 'document_formatting';
- ['textDocument/completion'] = 'completion';
- ['textDocument/documentHighlight'] = 'document_highlight';
+ ['textDocument/hover'] = { 'hoverProvider' };
+ ['textDocument/signatureHelp'] = { 'signatureHelpProvider' };
+ ['textDocument/definition'] = { 'definitionProvider' };
+ ['textDocument/implementation'] = { 'implementationProvider' };
+ ['textDocument/declaration'] = { 'declarationProvider' };
+ ['textDocument/typeDefinition'] = { 'typeDefinitionProvider' };
+ ['textDocument/documentSymbol'] = { 'documentSymbolProvider' };
+ ['textDocument/prepareCallHierarchy'] = { 'callHierarchyProvider' };
+ ['textDocument/rename'] = { 'renameProvider' };
+ ['textDocument/prepareRename'] = { 'renameProvider', 'prepareProvider'} ;
+ ['textDocument/codeAction'] = { 'codeActionProvider' };
+ ['textDocument/codeLens'] = { 'codeLensProvider' };
+ ['codeLens/resolve'] = { 'codeLensProvider', 'resolveProvider' };
+ ['workspace/executeCommand'] = { 'executeCommandProvider' };
+ ['workspace/symbol'] = { 'workspaceSymbolProvider' };
+ ['textDocument/references'] = { 'referencesProvider' };
+ ['textDocument/rangeFormatting'] = { 'documentRangeFormattingProvider' };
+ ['textDocument/formatting'] = { 'documentFormattingProvider' };
+ ['textDocument/completion'] = { 'completionProvider' };
+ ['textDocument/documentHighlight'] = { 'documentHighlightProvider' };
}
-- TODO improve handling of scratch buffers with LSP attached.
@@ -328,7 +328,7 @@ do
function changetracking.init(client, bufnr)
local use_incremental_sync = (
if_nil(client.config.flags.allow_incremental_sync, true)
- and client.resolved_capabilities.text_document_did_change == protocol.TextDocumentSyncKind.Incremental
+ and vim.tbl_get(client.server_capabilities, "textDocumentSync", "change") == protocol.TextDocumentSyncKind.Incremental
)
local state = state_by_client[client.id]
if not state then
@@ -447,7 +447,7 @@ do
end)
local uri = vim.uri_from_bufnr(bufnr)
return function(client)
- if client.resolved_capabilities.text_document_did_change == protocol.TextDocumentSyncKind.None then
+ if vim.tbl_get(client.server_capabilities, "textDocumentSync", "change") == protocol.TextDocumentSyncKind.None then
return
end
local state = state_by_client[client.id]
@@ -526,7 +526,7 @@ end
---@param client Client object
local function text_document_did_open_handler(bufnr, client)
changetracking.init(client, bufnr)
- if not client.resolved_capabilities.text_document_open_close then
+ if not vim.tbl_get(client.server_capabilities, "textDocumentSync", "openClose") then
return
end
if not vim.api.nvim_buf_is_loaded(bufnr) then
@@ -632,10 +632,6 @@ end
---
--- - {server_capabilities} (table): Response from the server sent on
--- `initialize` describing the server's capabilities.
----
---- - {resolved_capabilities} (table): Normalized table of
---- capabilities that we have detected based on the initialize
---- response from the server in `server_capabilities`.
function lsp.client()
error()
end
@@ -884,6 +880,7 @@ function lsp.start_client(config)
messages = { name = name, messages = {}, progress = {}, status = {} };
}
+
-- Store the uninitialized_clients for cleanup in case we exit before initialize finishes.
uninitialized_clients[client_id] = client;
@@ -960,27 +957,48 @@ function lsp.start_client(config)
client.workspace_folders = workspace_folders
-- TODO(mjlbach): Backwards compatibility, to be removed in 0.7
client.workspaceFolders = client.workspace_folders
- client.server_capabilities = assert(result.capabilities, "initialize result doesn't contain capabilities")
+
-- These are the cleaned up capabilities we use for dynamically deciding
-- when to send certain events to clients.
- client.resolved_capabilities = protocol.resolve_capabilities(client.server_capabilities)
+ client.server_capabilities = assert(result.capabilities, "initialize result doesn't contain capabilities")
+ client.server_capabilities = protocol.resolve_capabilities(client.server_capabilities)
+
+ -- Deprecation wrapper: this will be removed in 0.8
+ local mt = {}
+ mt.__index = function(table, key)
+ if key == 'resolved_capabilities' then
+ vim.notify_once("[LSP] Accessing client.resolved_capabilities is deprecated, " ..
+ "update your plugins or configuration to access client.server_capabilities instead." ..
+ "The new key/value pairs in server_capabilities directly match those " ..
+ "defined in the language server protocol", vim.log.levels.WARN)
+ rawset(table, key, protocol._resolve_capabilities_compat(client.server_capabilities))
+ return rawget(table, key)
+ else
+ return rawget(table, key)
+ end
+ end
+ setmetatable(client, mt)
+
client.supports_method = function(method)
local required_capability = lsp._request_name_to_capability[method]
-- if we don't know about the method, assume that the client supports it.
if not required_capability then
return true
end
-
- return client.resolved_capabilities[required_capability]
+ if vim.tbl_get(client.server_capabilities, unpack(required_capability)) then
+ return true
+ else
+ return false
+ end
end
+
if config.on_init then
local status, err = pcall(config.on_init, client, result)
if not status then
pcall(handlers.on_error, lsp.client_errors.ON_INIT_CALLBACK_ERROR, err)
end
end
- local _ = log.debug() and log.debug(log_prefix, "server_capabilities", client.server_capabilities)
- local _ = log.info() and log.info(log_prefix, "initialized", { resolved_capabilities = client.resolved_capabilities })
+ local _ = log.info() and log.info(log_prefix, "server_capabilities", { server_capabilities = client.server_capabilities })
-- Only assign after initialized.
active_clients[client_id] = client
@@ -1190,10 +1208,11 @@ function lsp._text_document_did_save_handler(bufnr)
bufnr = resolve_bufnr(bufnr)
local uri = vim.uri_from_bufnr(bufnr)
local text = once(buf_get_full_text)
- for_each_buffer_client(bufnr, function(client, _client_id)
- if client.resolved_capabilities.text_document_save then
+ for_each_buffer_client(bufnr, function(client)
+ local save_capability = vim.tbl_get(client.server_capabilities, "textDocumentSync", "save")
+ if save_capability then
local included_text
- if client.resolved_capabilities.text_document_save_include_text then
+ if type(save_capability) == "table" and save_capability.includeText then
included_text = text(bufnr)
end
client.notify('textDocument/didSave', {
@@ -1246,7 +1265,7 @@ function lsp.buf_attach_client(bufnr, client_id)
local params = { textDocument = { uri = uri; } }
for_each_buffer_client(bufnr, function(client, _)
changetracking.reset_buf(client, bufnr)
- if client.resolved_capabilities.text_document_open_close then
+ if vim.tbl_get(client.server_capabilities, "textDocumentSync", "openClose") then
client.notify('textDocument/didClose', params)
end
text_document_did_open_handler(bufnr, client)
@@ -1256,7 +1275,7 @@ function lsp.buf_attach_client(bufnr, client_id)
local params = { textDocument = { uri = uri; } }
for_each_buffer_client(bufnr, function(client, _)
changetracking.reset_buf(client, bufnr)
- if client.resolved_capabilities.text_document_open_close then
+ if vim.tbl_get(client.server_capabilities, "textDocumentSync", "openClose") then
client.notify('textDocument/didClose', params)
end
end)
@@ -1306,7 +1325,7 @@ function lsp.buf_detach_client(bufnr, client_id)
changetracking.reset_buf(client, bufnr)
- if client.resolved_capabilities.text_document_open_close then
+ if vim.tbl_get(client.server_capabilities, "textDocumentSync", "openClose") then
local uri = vim.uri_from_bufnr(bufnr)
local params = { textDocument = { uri = uri; } }
client.notify('textDocument/didClose', params)
diff --git a/runtime/lua/vim/lsp/buf.lua b/runtime/lua/vim/lsp/buf.lua
index eb7ec579f1..aabafc422f 100644
--- a/runtime/lua/vim/lsp/buf.lua
+++ b/runtime/lua/vim/lsp/buf.lua
@@ -143,14 +143,114 @@ local function select_client(method, on_choice)
end
end
+--- Formats a buffer using the attached (and optionally filtered) language
+--- server clients.
+---
+--- @param options table|nil Optional table which holds the following optional fields:
+--- - formatting_options (table|nil):
+--- Can be used to specify FormattingOptions. Some unspecified options will be
+--- automatically derived from the current Neovim options.
+--- @see https://microsoft.github.io/language-server-protocol/specification#textDocument_formatting
+--- - timeout_ms (integer|nil, default 1000):
+--- Time in milliseconds to block for formatting requests. No effect if async=true
+--- - bufnr (number|nil):
+--- Restrict formatting to the clients attached to the given buffer, defaults to the current
+--- buffer (0).
+--- - filter (function|nil):
+--- Predicate to filter clients used for formatting. Receives the list of clients attached
+--- to bufnr as the argument and must return the list of clients on which to request
+--- formatting. Example:
+---
+--- <pre>
+--- -- Never request typescript-language-server for formatting
+--- vim.lsp.buf.format {
+--- filter = function(clients)
+--- return vim.tbl_filter(
+--- function(client) return client.name ~= "tsserver" end,
+--- clients
+--- )
+--- end
+--- }
+--- </pre>
+---
+--- - async boolean|nil
+--- If true the method won't block. Defaults to false.
+--- Editing the buffer while formatting asynchronous can lead to unexpected
+--- changes.
+---
+--- - id (number|nil):
+--- Restrict formatting to the client with ID (client.id) matching this field.
+--- - name (string|nil):
+--- Restrict formatting to the client with name (client.name) matching this field.
+
+function M.format(options)
+ options = options or {}
+ local bufnr = options.bufnr or vim.api.nvim_get_current_buf()
+ local clients = vim.lsp.buf_get_clients(bufnr)
+
+ if options.filter then
+ clients = options.filter(clients)
+ elseif options.id then
+ clients = vim.tbl_filter(
+ function(client) return client.id == options.id end,
+ clients
+ )
+ elseif options.name then
+ clients = vim.tbl_filter(
+ function(client) return client.name == options.name end,
+ clients
+ )
+ end
+
+ clients = vim.tbl_filter(
+ function(client) return client.supports_method("textDocument/formatting") end,
+ clients
+ )
+
+ if #clients == 0 then
+ vim.notify("[LSP] Format request failed, no matching language servers.")
+ end
+
+ if options.async then
+ local do_format
+ do_format = function(idx, client)
+ if not client then
+ return
+ end
+ local params = util.make_formatting_params(options.formatting_options)
+ client.request("textDocument/formatting", params, function(...)
+ local handler = client.handlers['textDocument/formatting'] or vim.lsp.handlers['textDocument/formatting']
+ handler(...)
+ do_format(next(clients, idx))
+ end, bufnr)
+ end
+ do_format(next(clients))
+ else
+ local timeout_ms = options.timeout_ms or 1000
+ for _, client in pairs(clients) do
+ local params = util.make_formatting_params(options.formatting_options)
+ local result, err = client.request_sync("textDocument/formatting", params, timeout_ms, bufnr)
+ if result and result.result then
+ util.apply_text_edits(result.result, bufnr, client.offset_encoding)
+ elseif err then
+ vim.notify(string.format("[LSP][%s] %s", client.name, err), vim.log.levels.WARN)
+ end
+ end
+ end
+end
+
--- Formats the current buffer.
---
----@param options (optional, table) Can be used to specify FormattingOptions.
+---@param options (table|nil) Can be used to specify FormattingOptions.
--- Some unspecified options will be automatically derived from the current
--- Neovim options.
--
---@see https://microsoft.github.io/language-server-protocol/specification#textDocument_formatting
function M.formatting(options)
+ vim.notify_once(
+ 'vim.lsp.buf.formatting is deprecated. Use vim.lsp.buf.format { async = true } instead',
+ vim.log.levels.WARN
+ )
local params = util.make_formatting_params(options)
local bufnr = vim.api.nvim_get_current_buf()
select_client('textDocument/formatting', function(client)
@@ -171,10 +271,11 @@ end
--- autocmd BufWritePre <buffer> lua vim.lsp.buf.formatting_sync()
--- </pre>
---
----@param options Table with valid `FormattingOptions` entries
+---@param options table|nil with valid `FormattingOptions` entries
---@param timeout_ms (number) Request timeout
---@see |vim.lsp.buf.formatting_seq_sync|
function M.formatting_sync(options, timeout_ms)
+ vim.notify_once('vim.lsp.buf.formatting_sync is deprecated. Use vim.lsp.buf.format instead', vim.log.levels.WARN)
local params = util.make_formatting_params(options)
local bufnr = vim.api.nvim_get_current_buf()
select_client('textDocument/formatting', function(client)
@@ -202,12 +303,13 @@ end
--- vim.api.nvim_command[[autocmd BufWritePre <buffer> lua vim.lsp.buf.formatting_seq_sync()]]
--- </pre>
---
----@param options (optional, table) `FormattingOptions` entries
----@param timeout_ms (optional, number) Request timeout
----@param order (optional, table) List of client names. Formatting is requested from clients
+---@param options (table|nil) `FormattingOptions` entries
+---@param timeout_ms (number|nil) Request timeout
+---@param order (table|nil) List of client names. Formatting is requested from clients
---in the following order: first all clients that are not in the `order` list, then
---the remaining clients in the order as they occur in the `order` list.
function M.formatting_seq_sync(options, timeout_ms, order)
+ vim.notify_once('vim.lsp.buf.formatting_seq_sync is deprecated. Use vim.lsp.buf.format instead', vim.log.levels.WARN)
local clients = vim.tbl_values(vim.lsp.buf_get_clients());
local bufnr = vim.api.nvim_get_current_buf()
@@ -224,7 +326,7 @@ function M.formatting_seq_sync(options, timeout_ms, order)
-- loop through the clients and make synchronous formatting requests
for _, client in pairs(clients) do
- if client.resolved_capabilities.document_formatting then
+ if vim.tbl_get(client.server_capabilities, "documentFormattingProvider") then
local params = util.make_formatting_params(options)
local result, err = client.request_sync("textDocument/formatting", params, timeout_ms, vim.api.nvim_get_current_buf())
if result and result.result then
@@ -491,11 +593,14 @@ end
--- from multiple clients to have 1 single UI prompt for the user, yet we still
--- need to be able to link a `CodeAction|Command` to the right client for
--- `codeAction/resolve`
-local function on_code_action_results(results, ctx)
+local function on_code_action_results(results, ctx, options)
local action_tuples = {}
+ local filter = options and options.filter
for client_id, result in pairs(results) do
for _, action in pairs(result.result or {}) do
- table.insert(action_tuples, { client_id, action })
+ if not filter or filter(action) then
+ table.insert(action_tuples, { client_id, action })
+ end
end
end
if #action_tuples == 0 then
@@ -542,8 +647,7 @@ local function on_code_action_results(results, ctx)
local action = action_tuple[2]
if not action.edit
and client
- and type(client.resolved_capabilities.code_action) == 'table'
- and client.resolved_capabilities.code_action.resolveProvider then
+ and vim.tbl_get(client.server_capabilities, "codeActionProvider", "resolveProvider") then
client.request('codeAction/resolve', action, function(err, resolved_action)
if err then
@@ -557,6 +661,13 @@ local function on_code_action_results(results, ctx)
end
end
+ -- If options.apply is given, and there are just one remaining code action,
+ -- apply it directly without querying the user.
+ if options and options.apply and #action_tuples == 1 then
+ on_user_choice(action_tuples[1])
+ return
+ end
+
vim.ui.select(action_tuples, {
prompt = 'Code actions:',
kind = 'codeaction',
@@ -571,35 +682,49 @@ end
--- Requests code actions from all clients and calls the handler exactly once
--- with all aggregated results
---@private
-local function code_action_request(params)
+local function code_action_request(params, options)
local bufnr = vim.api.nvim_get_current_buf()
local method = 'textDocument/codeAction'
vim.lsp.buf_request_all(bufnr, method, params, function(results)
- on_code_action_results(results, { bufnr = bufnr, method = method, params = params })
+ local ctx = { bufnr = bufnr, method = method, params = params}
+ on_code_action_results(results, ctx, options)
end)
end
--- Selects a code action available at the current
--- cursor position.
---
----@param context table|nil `CodeActionContext` of the LSP specification:
---- - diagnostics: (table|nil)
---- LSP `Diagnostic[]`. Inferred from the current
---- position if not provided.
---- - only: (string|nil)
---- LSP `CodeActionKind` used to filter the code actions.
---- Most language servers support values like `refactor`
---- or `quickfix`.
+---@param options table|nil Optional table which holds the following optional fields:
+--- - context (table|nil):
+--- Corresponds to `CodeActionContext` of the LSP specification:
+--- - diagnostics (table|nil):
+--- LSP `Diagnostic[]`. Inferred from the current
+--- position if not provided.
+--- - only (string|nil):
+--- LSP `CodeActionKind` used to filter the code actions.
+--- Most language servers support values like `refactor`
+--- or `quickfix`.
+--- - filter (function|nil):
+--- Predicate function taking an `CodeAction` and returning a boolean.
+--- - apply (boolean|nil):
+--- When set to `true`, and there is just one remaining action
+--- (after filtering), the action is applied without user query.
---@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_codeAction
-function M.code_action(context)
- validate { context = { context, 't', true } }
- context = context or {}
+function M.code_action(options)
+ validate { options = { options, 't', true } }
+ options = options or {}
+ -- Detect old API call code_action(context) which should now be
+ -- code_action({ context = context} )
+ if options.diagnostics or options.only then
+ options = { options = options }
+ end
+ local context = options.context or {}
if not context.diagnostics then
context.diagnostics = vim.lsp.diagnostic.get_line_diagnostics()
end
local params = util.make_range_params()
params.context = context
- code_action_request(params)
+ code_action_request(params, options)
end
--- Performs |vim.lsp.buf.code_action()| for a given range.
diff --git a/runtime/lua/vim/lsp/handlers.lua b/runtime/lua/vim/lsp/handlers.lua
index 71b4d33ec0..5c80ed0d10 100644
--- a/runtime/lua/vim/lsp/handlers.lua
+++ b/runtime/lua/vim/lsp/handlers.lua
@@ -27,7 +27,7 @@ local function progress_handler(_, result, ctx, _)
local client = vim.lsp.get_client_by_id(client_id)
local client_name = client and client.name or string.format("id=%d", client_id)
if not client then
- err_message("LSP[", client_name, "] client has shut down after sending the message")
+ err_message("LSP[", client_name, "] client has shut down during progress update")
return vim.NIL
end
local val = result.value -- unspecified yet
@@ -70,7 +70,7 @@ M['window/workDoneProgress/create'] = function(_, result, ctx)
local token = result.token -- string or number
local client_name = client and client.name or string.format("id=%d", client_id)
if not client then
- err_message("LSP[", client_name, "] client has shut down after sending the message")
+ err_message("LSP[", client_name, "] client has shut down while creating progress report")
return vim.NIL
end
client.messages.progress[token] = {}
@@ -132,7 +132,7 @@ M['workspace/configuration'] = function(_, result, ctx)
local client_id = ctx.client_id
local client = vim.lsp.get_client_by_id(client_id)
if not client then
- err_message("LSP[id=", client_id, "] client has shut down after sending the message")
+ err_message("LSP[", client_id, "] client has shut down after sending a workspace/configuration request")
return
end
if not result.items then
@@ -298,13 +298,13 @@ function M.hover(_, result, ctx, config)
config = config or {}
config.focus_id = ctx.method
if not (result and result.contents) then
- -- return { 'No information available' }
+ vim.notify('No information available')
return
end
local markdown_lines = util.convert_input_to_markdown_lines(result.contents)
markdown_lines = util.trim_empty_lines(markdown_lines)
if vim.tbl_isempty(markdown_lines) then
- -- return { 'No information available' }
+ vim.notify('No information available')
return
end
return util.open_floating_preview(markdown_lines, "markdown", config)
@@ -379,7 +379,7 @@ function M.signature_help(_, result, ctx, config)
return
end
local client = vim.lsp.get_client_by_id(ctx.client_id)
- local triggers = client.resolved_capabilities.signature_help_trigger_characters
+ local triggers = vim.tbl_get(client.server_capabilities, "signatureHelpProvider", "triggerCharacters")
local ft = api.nvim_buf_get_option(ctx.bufnr, 'filetype')
local lines, hl = util.convert_signature_help_to_markdown_lines(result, ft, triggers)
lines = util.trim_empty_lines(lines)
@@ -449,7 +449,7 @@ M['window/logMessage'] = function(_, result, ctx, _)
local client = vim.lsp.get_client_by_id(client_id)
local client_name = client and client.name or string.format("id=%d", client_id)
if not client then
- err_message("LSP[", client_name, "] client has shut down after sending the message")
+ err_message("LSP[", client_name, "] client has shut down after sending ", message)
end
if message_type == protocol.MessageType.Error then
log.error(message)
@@ -471,7 +471,7 @@ M['window/showMessage'] = function(_, result, ctx, _)
local client = vim.lsp.get_client_by_id(client_id)
local client_name = client and client.name or string.format("id=%d", client_id)
if not client then
- err_message("LSP[", client_name, "] client has shut down after sending the message")
+ err_message("LSP[", client_name, "] client has shut down after sending ", message)
end
if message_type == protocol.MessageType.Error then
err_message("LSP[", client_name, "] ", message)
diff --git a/runtime/lua/vim/lsp/protocol.lua b/runtime/lua/vim/lsp/protocol.lua
index 86c9e2fd58..8f50863360 100644
--- a/runtime/lua/vim/lsp/protocol.lua
+++ b/runtime/lua/vim/lsp/protocol.lua
@@ -1,7 +1,5 @@
-- Protocol for the Microsoft Language Server Protocol (mslsp)
-local if_nil = vim.F.if_nil
-
local protocol = {}
--[=[
@@ -645,6 +643,7 @@ function protocol.make_client_capabilities()
end)();
};
};
+ isPreferredSupport = true;
dataSupport = true;
resolveSupport = {
properties = { 'edit', }
@@ -776,10 +775,50 @@ function protocol.make_client_capabilities()
}
end
+local if_nil = vim.F.if_nil
--- Creates a normalized object describing LSP server capabilities.
---@param server_capabilities table Table of capabilities supported by the server
---@return table Normalized table of capabilities
function protocol.resolve_capabilities(server_capabilities)
+ local TextDocumentSyncKind = protocol.TextDocumentSyncKind
+ local textDocumentSync = server_capabilities.textDocumentSync
+ if textDocumentSync == nil then
+ -- Defaults if omitted.
+ server_capabilities.textDocumentSync = {
+ openClose = false,
+ change = TextDocumentSyncKind.None,
+ willSave = false,
+ willSaveWaitUntil = false,
+ save = {
+ includeText = false,
+ }
+ }
+ elseif type(textDocumentSync) == 'number' then
+ -- Backwards compatibility
+ if not TextDocumentSyncKind[textDocumentSync] then
+ return nil, "Invalid server TextDocumentSyncKind for textDocumentSync"
+ end
+ server_capabilities.textDocumentSync = {
+ openClose = true,
+ change = textDocumentSync,
+ willSave = false,
+ willSaveWaitUntil = false,
+ save = {
+ includeText = false,
+ }
+ }
+ elseif type(textDocumentSync) ~= 'table' then
+ return nil, string.format("Invalid type for textDocumentSync: %q", type(textDocumentSync))
+ end
+ return server_capabilities
+end
+
+---@private
+--- Creates a normalized object describing LSP server capabilities.
+-- @deprecated access resolved_capabilities instead
+---@param server_capabilities table Table of capabilities supported by the server
+---@return table Normalized table of capabilities
+function protocol._resolve_capabilities_compat(server_capabilities)
local general_properties = {}
local text_document_sync_properties
do
@@ -930,12 +969,14 @@ function protocol.resolve_capabilities(server_capabilities)
error("The server sent invalid signatureHelpProvider")
end
- return vim.tbl_extend("error"
+ local capabilities = vim.tbl_extend("error"
, text_document_sync_properties
, signature_help_properties
, workspace_properties
, general_properties
)
+
+ return capabilities
end
return protocol
diff --git a/runtime/lua/vim/lsp/rpc.lua b/runtime/lua/vim/lsp/rpc.lua
index 1ecac50df4..6d0a78fba8 100644
--- a/runtime/lua/vim/lsp/rpc.lua
+++ b/runtime/lua/vim/lsp/rpc.lua
@@ -385,7 +385,7 @@ local function start(cmd, cmd_args, dispatchers, extra_spawn_params)
---@param method (string) The invoked LSP method
---@param params (table) Parameters for the invoked LSP method
---@param callback (function) Callback to invoke
- ---@param notify_reply_callback (function) Callback to invoke as soon as a request is no longer pending
+ ---@param notify_reply_callback (function|nil) Callback to invoke as soon as a request is no longer pending
---@returns (bool, number) `(true, message_id)` if request could be sent, `false` if not
local function request(method, params, callback, notify_reply_callback)
validate {
diff --git a/runtime/lua/vim/lsp/util.lua b/runtime/lua/vim/lsp/util.lua
index 1f1a34b04a..77ab1d4224 100644
--- a/runtime/lua/vim/lsp/util.lua
+++ b/runtime/lua/vim/lsp/util.lua
@@ -1873,7 +1873,7 @@ end
--- Returns indentation size.
---
---@see |shiftwidth|
----@param bufnr (optional, number): Buffer handle, defaults to current
+---@param bufnr (number|nil): Buffer handle, defaults to current
---@returns (number) indentation size
function M.get_effective_tabstop(bufnr)
validate { bufnr = {bufnr, 'n', true} }
@@ -1884,7 +1884,7 @@ end
--- Creates a `DocumentFormattingParams` object for the current buffer and cursor position.
---
----@param options Table with valid `FormattingOptions` entries
+---@param options table|nil with valid `FormattingOptions` entries
---@returns `DocumentFormattingParams` object
---@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_formatting
function M.make_formatting_params(options)
diff --git a/runtime/lua/vim/shared.lua b/runtime/lua/vim/shared.lua
index f0dc34608c..172fac3a88 100644
--- a/runtime/lua/vim/shared.lua
+++ b/runtime/lua/vim/shared.lua
@@ -365,7 +365,10 @@ function vim.tbl_get(o, ...)
if #keys == 0 then
return
end
- for _, k in ipairs(keys) do
+ for i, k in ipairs(keys) do
+ if type(o[k]) ~= 'table' and next(keys, i) then
+ return nil
+ end
o = o[k]
if o == nil then
return