mirror of
https://github.com/neovim/neovim.git
synced 2026-04-28 10:14:06 +00:00
@@ -311,7 +311,7 @@ Nvim's filetype detection behavior matches Vim, but is implemented as part of
|
||||
|vim.filetype| (see `$VIMRUNTIME/lua/vim/filetype.lua`). The logic is encoded in
|
||||
three tables, listed in order of precedence (the first match is returned):
|
||||
1. `filename` for literal full path or basename lookup;
|
||||
2. `pattern` for matching filenames or paths against |lua-patterns|, optimized
|
||||
2. `pattern` for matching filenames or paths against |lua-pattern|s, optimized
|
||||
for fast lookup;
|
||||
3. `extension` for literal extension lookup.
|
||||
|
||||
|
||||
@@ -41,7 +41,8 @@ Follow these steps to get LSP features:
|
||||
-- current buffer that contains either a ".luarc.json" or a
|
||||
-- ".luarc.jsonc" file. Files that share a root directory will reuse
|
||||
-- the connection to the same LSP server.
|
||||
root_markers = { '.luarc.json', '.luarc.jsonc' },
|
||||
-- Nested lists indicate equal priority, see |vim.lsp.Config|.
|
||||
root_markers = { { '.luarc.json', '.luarc.jsonc' }, '.git' },
|
||||
|
||||
-- Specific settings to send to the server. The schema for this is
|
||||
-- defined by the server. For example the schema for lua-language-server
|
||||
@@ -705,27 +706,53 @@ Lua module: vim.lsp *lsp-core*
|
||||
• {cmd}? (`string[]|fun(dispatchers: vim.lsp.rpc.Dispatchers): vim.lsp.rpc.PublicClient`)
|
||||
See `cmd` in |vim.lsp.ClientConfig|.
|
||||
• {filetypes}? (`string[]`) Filetypes the client will attach to, if
|
||||
activated by `vim.lsp.enable()`. If not provided,
|
||||
then the client will attach to all filetypes.
|
||||
• {root_markers}? (`string[]`) Directory markers (.e.g. '.git/') where
|
||||
the LSP server will base its workspaceFolders,
|
||||
rootUri, and rootPath on initialization. Unused if
|
||||
`root_dir` is provided.
|
||||
activated by `vim.lsp.enable()`. If not provided, the
|
||||
client will attach to all filetypes.
|
||||
• {reuse_client}? (`fun(client: vim.lsp.Client, config: vim.lsp.ClientConfig): boolean`)
|
||||
Predicate which decides if a client should be
|
||||
re-used. Used on all running clients. The default
|
||||
implementation re-uses a client if name and root_dir
|
||||
matches.
|
||||
• {root_dir}? (`string|fun(bufnr: integer, on_dir:fun(root_dir?:string))`)
|
||||
*lsp-root_dir()* Directory where the LSP server will
|
||||
base its workspaceFolders, rootUri, and rootPath on
|
||||
initialization. The function form receives a buffer
|
||||
number and `on_dir` callback, which must be called to
|
||||
provide root_dir as a string. LSP will not be
|
||||
activated for the buffer unless `on_dir` is called;
|
||||
thus a `root_dir()` function can dynamically decide
|
||||
whether to activate (or skip) LSP per-buffer. See
|
||||
example at |vim.lsp.enable()|.
|
||||
• {reuse_client}? (`fun(client: vim.lsp.Client, config: vim.lsp.ClientConfig): boolean`)
|
||||
Predicate used to decide if a client should be
|
||||
re-used. Used on all running clients. The default
|
||||
implementation re-uses a client if name and root_dir
|
||||
matches.
|
||||
number and `on_dir` callback which it must call to
|
||||
provide root_dir, or LSP will not be activated for
|
||||
the buffer. Thus a `root_dir()` function can
|
||||
dynamically decide per-buffer whether to activate (or
|
||||
skip) LSP. See example at |vim.lsp.enable()|.
|
||||
• {root_markers}? (`(string|string[])[]`) Directory markers (.e.g.
|
||||
'.git/') where the LSP server will base its
|
||||
workspaceFolders, rootUri, and rootPath on
|
||||
initialization. Unused if `root_dir` is provided.
|
||||
|
||||
The list order decides the priority. To indicate
|
||||
"equal priority", specify names in a nested list
|
||||
(`{ { 'a', 'b' }, ... }`) Each entry in this list is
|
||||
a set of one or more markers. For each set, Nvim will
|
||||
search upwards for each marker contained in the set.
|
||||
If a marker is found, the directory which contains
|
||||
that marker is used as the root directory. If no
|
||||
markers from the set are found, the process is
|
||||
repeated with the next set in the list.
|
||||
|
||||
Example: >lua
|
||||
root_markers = { 'stylua.toml', '.git' }
|
||||
<
|
||||
|
||||
Find the first parent directory containing the file
|
||||
`stylua.toml`. If not found, find the first parent
|
||||
directory containing the file or directory `.git`.
|
||||
|
||||
Example: >lua
|
||||
root_markers = { { 'stylua.toml', '.luarc.json' }, '.git' }
|
||||
<
|
||||
|
||||
Find the first parent directory containing EITHER
|
||||
`stylua.toml` or `.luarc.json`. If not found, find
|
||||
the first parent directory containing the file or
|
||||
directory `.git`.
|
||||
|
||||
|
||||
buf_attach_client({bufnr}, {client_id}) *vim.lsp.buf_attach_client()*
|
||||
@@ -1148,65 +1175,17 @@ Lua module: vim.lsp.client *lsp-client*
|
||||
*vim.lsp.Client*
|
||||
|
||||
Fields: ~
|
||||
• {id} (`integer`) The id allocated to the client.
|
||||
• {name} (`string`) If a name is specified on creation,
|
||||
that will be used. Otherwise it is just the
|
||||
client id. This is used for logs and messages.
|
||||
• {rpc} (`vim.lsp.rpc.PublicClient`) RPC client
|
||||
object, for low level interaction with the
|
||||
client. See |vim.lsp.rpc.start()|.
|
||||
• {offset_encoding} (`string`) Called "position encoding" in LSP
|
||||
spec, the encoding used for communicating with
|
||||
the server. You can modify this in the
|
||||
`config`'s `on_init` method before text is
|
||||
sent to the server.
|
||||
• {handlers} (`table<string,lsp.Handler>`) The handlers
|
||||
used by the client as described in
|
||||
|lsp-handler|.
|
||||
• {requests} (`table<integer,{ type: string, bufnr: integer, method: string}?>`)
|
||||
The current pending requests in flight to the
|
||||
server. Entries are key-value pairs with the
|
||||
key being the request id while the value is a
|
||||
table with `type`, `bufnr`, and `method`
|
||||
key-value pairs. `type` is either "pending"
|
||||
for an active request, or "cancel" for a
|
||||
cancel request. It will be "complete"
|
||||
ephemerally while executing |LspRequest|
|
||||
autocmds when replies are received from the
|
||||
server.
|
||||
• {config} (`vim.lsp.ClientConfig`) copy of the table
|
||||
that was passed by the user to
|
||||
|vim.lsp.start()|. See |vim.lsp.ClientConfig|.
|
||||
• {server_capabilities} (`lsp.ServerCapabilities?`) Response from the
|
||||
server sent on `initialize` describing the
|
||||
server's capabilities.
|
||||
• {server_info} (`lsp.ServerInfo?`) Response from the server
|
||||
sent on `initialize` describing information
|
||||
about the server.
|
||||
• {progress} (`vim.lsp.Client.Progress`) A ring buffer
|
||||
(|vim.ringbuf()|) containing progress messages
|
||||
sent by the server. See
|
||||
|vim.lsp.Client.Progress|.
|
||||
• {initialized} (`true?`)
|
||||
• {workspace_folders} (`lsp.WorkspaceFolder[]?`) The workspace
|
||||
folders configured in the client when the
|
||||
server starts. This property is only available
|
||||
if the client supports workspace folders. It
|
||||
can be `null` if the client supports workspace
|
||||
folders but none are configured.
|
||||
• {root_dir} (`string?`)
|
||||
• {attached_buffers} (`table<integer,true>`)
|
||||
• {capabilities} (`lsp.ClientCapabilities`) Capabilities
|
||||
provided by the client (editor or tool), at
|
||||
startup.
|
||||
• {commands} (`table<string,fun(command: lsp.Command, ctx: table)>`)
|
||||
Table of command name to function which is
|
||||
called if any LSP action (code action, code
|
||||
lenses, ...) triggers the command. Client
|
||||
commands take precedence over the global
|
||||
command registry.
|
||||
• {settings} (`lsp.LSPObject`) Map with language server
|
||||
specific settings. These are returned to the
|
||||
language server if requested via
|
||||
`workspace/configuration`. Keys are
|
||||
case-sensitive.
|
||||
Client commands. See |vim.lsp.ClientConfig|.
|
||||
• {config} (`vim.lsp.ClientConfig`) Copy of the config
|
||||
passed to |vim.lsp.start()|. See
|
||||
|vim.lsp.ClientConfig|.
|
||||
• {dynamic_capabilities} (`lsp.DynamicCapabilities`) Capabilities
|
||||
provided at runtime (after startup).
|
||||
• {flags} (`table`) A table with flags for the client.
|
||||
The current (experimental) flags are:
|
||||
• {allow_incremental_sync}? (`boolean`,
|
||||
@@ -1223,9 +1202,41 @@ Lua module: vim.lsp.client *lsp-client*
|
||||
false, nvim exits immediately after sending
|
||||
the "shutdown" request to the server.
|
||||
• {get_language_id} (`fun(bufnr: integer, filetype: string): string`)
|
||||
• {capabilities} (`lsp.ClientCapabilities`) The capabilities
|
||||
provided by the client (editor or tool)
|
||||
• {dynamic_capabilities} (`lsp.DynamicCapabilities`)
|
||||
See |vim.lsp.ClientConfig|.
|
||||
• {handlers} (`table<string,lsp.Handler>`) See
|
||||
|vim.lsp.ClientConfig|.
|
||||
• {id} (`integer`) The id allocated to the client.
|
||||
• {initialized} (`true?`)
|
||||
• {name} (`string`) See |vim.lsp.ClientConfig|.
|
||||
• {offset_encoding} (`string`) See |vim.lsp.ClientConfig|.
|
||||
• {progress} (`vim.lsp.Client.Progress`) A ring buffer
|
||||
(|vim.ringbuf()|) containing progress messages
|
||||
sent by the server. See
|
||||
|vim.lsp.Client.Progress|.
|
||||
• {requests} (`table<integer,{ type: string, bufnr: integer, method: string}?>`)
|
||||
The current pending requests in flight to the
|
||||
server. Entries are key-value pairs with the
|
||||
key being the request id while the value is a
|
||||
table with `type`, `bufnr`, and `method`
|
||||
key-value pairs. `type` is either "pending"
|
||||
for an active request, or "cancel" for a
|
||||
cancel request. It will be "complete"
|
||||
ephemerally while executing |LspRequest|
|
||||
autocmds when replies are received from the
|
||||
server.
|
||||
• {root_dir} (`string?`) See |vim.lsp.ClientConfig|.
|
||||
• {rpc} (`vim.lsp.rpc.PublicClient`) RPC client
|
||||
object, for low level interaction with the
|
||||
client. See |vim.lsp.rpc.start()|.
|
||||
• {server_capabilities} (`lsp.ServerCapabilities?`) Response from the
|
||||
server sent on `initialize` describing the
|
||||
server's capabilities.
|
||||
• {server_info} (`lsp.ServerInfo?`) Response from the server
|
||||
sent on `initialize` describing server
|
||||
information (e.g. version).
|
||||
• {settings} (`lsp.LSPObject`) See |vim.lsp.ClientConfig|.
|
||||
• {workspace_folders} (`lsp.WorkspaceFolder[]?`) See
|
||||
|vim.lsp.ClientConfig|.
|
||||
• {request} (`fun(self: vim.lsp.Client, method: string, params: table?, handler: lsp.Handler?, bufnr: integer?): boolean, integer?`)
|
||||
See |Client:request()|.
|
||||
• {request_sync} (`fun(self: vim.lsp.Client, method: string, params: table, timeout_ms: integer?, bufnr: integer?): {err: lsp.ResponseError?, result:any}?, string?`)
|
||||
@@ -1255,6 +1266,23 @@ Lua module: vim.lsp.client *lsp-client*
|
||||
*vim.lsp.ClientConfig*
|
||||
|
||||
Fields: ~
|
||||
• {before_init}? (`fun(params: lsp.InitializeParams, config: vim.lsp.ClientConfig)`)
|
||||
Callback invoked before the LSP "initialize"
|
||||
phase, where `params` contains the parameters
|
||||
being sent to the server and `config` is the
|
||||
config that was passed to |vim.lsp.start()|.
|
||||
You can use this to modify parameters before
|
||||
they are sent.
|
||||
• {capabilities}? (`lsp.ClientCapabilities`) Map overriding the
|
||||
default capabilities defined by
|
||||
|vim.lsp.protocol.make_client_capabilities()|,
|
||||
passed to the language server on
|
||||
initialization. Hint: use
|
||||
make_client_capabilities() and modify its
|
||||
result.
|
||||
• Note: To send an empty dictionary use
|
||||
|vim.empty_dict()|, else it will be encoded
|
||||
as an array.
|
||||
• {cmd} (`string[]|fun(dispatchers: vim.lsp.rpc.Dispatchers): vim.lsp.rpc.PublicClient`)
|
||||
command string[] that launches the language
|
||||
server (treated as in |jobstart()|, must be
|
||||
@@ -1270,101 +1298,24 @@ Lua module: vim.lsp.client *lsp-client*
|
||||
|vim.lsp.rpc.connect()|
|
||||
• {cmd_cwd}? (`string`, default: cwd) Directory to launch
|
||||
the `cmd` process. Not related to `root_dir`.
|
||||
• {cmd_env}? (`table`) Environment flags to pass to the LSP
|
||||
on spawn. Must be specified using a table.
|
||||
Non-string values are coerced to string.
|
||||
Example: >lua
|
||||
{ PORT = 8080; HOST = "0.0.0.0"; }
|
||||
• {cmd_env}? (`table`) Environment variables passed to the
|
||||
LSP process on spawn. Non-string values are
|
||||
coerced to string. Example: >lua
|
||||
{ PORT = 8080; HOST = '0.0.0.0'; }
|
||||
<
|
||||
• {commands}? (`table<string,fun(command: lsp.Command, ctx: table)>`)
|
||||
Client commands. Map of command names to
|
||||
user-defined functions. Commands passed to
|
||||
`start()` take precedence over the global
|
||||
command registry. Each key must be a unique
|
||||
command name, and the value is a function which
|
||||
is called if any LSP action (code action, code
|
||||
lenses, …) triggers the command.
|
||||
• {detached}? (`boolean`, default: true) Daemonize the server
|
||||
process so that it runs in a separate process
|
||||
group from Nvim. Nvim will shutdown the process
|
||||
on exit, but if Nvim fails to exit cleanly this
|
||||
could leave behind orphaned server processes.
|
||||
• {workspace_folders}? (`lsp.WorkspaceFolder[]`) List of workspace
|
||||
folders passed to the language server. For
|
||||
backwards compatibility rootUri and rootPath
|
||||
will be derived from the first workspace folder
|
||||
in this list. See `workspaceFolders` in the LSP
|
||||
spec.
|
||||
• {workspace_required}? (`boolean`) (default false) Server requires a
|
||||
workspace (no "single file" support). Note:
|
||||
Without a workspace, cross-file features
|
||||
(navigation, hover) may or may not work
|
||||
depending on the language server, even if the
|
||||
server doesn't require a workspace.
|
||||
• {capabilities}? (`lsp.ClientCapabilities`) Map overriding the
|
||||
default capabilities defined by
|
||||
|vim.lsp.protocol.make_client_capabilities()|,
|
||||
passed to the language server on
|
||||
initialization. Hint: use
|
||||
make_client_capabilities() and modify its
|
||||
result.
|
||||
• Note: To send an empty dictionary use
|
||||
|vim.empty_dict()|, else it will be encoded
|
||||
as an array.
|
||||
• {handlers}? (`table<string,function>`) Map of language
|
||||
server method names to |lsp-handler|
|
||||
• {settings}? (`lsp.LSPObject`) Map with language server
|
||||
specific settings. See the {settings} in
|
||||
|vim.lsp.Client|.
|
||||
• {commands}? (`table<string,fun(command: lsp.Command, ctx: table)>`)
|
||||
Table that maps string of clientside commands
|
||||
to user-defined functions. Commands passed to
|
||||
`start()` take precedence over the global
|
||||
command registry. Each key must be a unique
|
||||
command name, and the value is a function which
|
||||
is called if any LSP action (code action, code
|
||||
lenses, ...) triggers the command.
|
||||
• {init_options}? (`lsp.LSPObject`) Values to pass in the
|
||||
initialization request as
|
||||
`initializationOptions`. See `initialize` in
|
||||
the LSP spec.
|
||||
• {name}? (`string`, default: client-id) Name in log
|
||||
messages.
|
||||
• {get_language_id}? (`fun(bufnr: integer, filetype: string): string`)
|
||||
Language ID as string. Defaults to the buffer
|
||||
filetype.
|
||||
• {offset_encoding}? (`'utf-8'|'utf-16'|'utf-32'`) Called "position
|
||||
encoding" in LSP spec, the encoding that the
|
||||
LSP server expects. Client does not verify this
|
||||
is correct.
|
||||
• {on_error}? (`fun(code: integer, err: string)`) Callback
|
||||
invoked when the client operation throws an
|
||||
error. `code` is a number describing the error.
|
||||
Other arguments may be passed depending on the
|
||||
error kind. See `vim.lsp.rpc.client_errors` for
|
||||
possible errors. Use
|
||||
`vim.lsp.rpc.client_errors[code]` to get
|
||||
human-friendly name.
|
||||
• {before_init}? (`fun(params: lsp.InitializeParams, config: vim.lsp.ClientConfig)`)
|
||||
Callback invoked before the LSP "initialize"
|
||||
phase, where `params` contains the parameters
|
||||
being sent to the server and `config` is the
|
||||
config that was passed to |vim.lsp.start()|.
|
||||
You can use this to modify parameters before
|
||||
they are sent.
|
||||
• {on_init}? (`elem_or_list<fun(client: vim.lsp.Client, init_result: lsp.InitializeResult)>`)
|
||||
Callback invoked after LSP "initialize", where
|
||||
`result` is a table of `capabilities` and
|
||||
anything else the server may send. For example,
|
||||
clangd sends `init_result.offsetEncoding` if
|
||||
`capabilities.offsetEncoding` was sent to it.
|
||||
You can only modify the
|
||||
`client.offset_encoding` here before any
|
||||
notifications are sent.
|
||||
• {on_exit}? (`elem_or_list<fun(code: integer, signal: integer, client_id: integer)>`)
|
||||
Callback invoked on client exit.
|
||||
• code: exit code of the process
|
||||
• signal: number describing the signal used to
|
||||
terminate (if any)
|
||||
• client_id: client handle
|
||||
• {on_attach}? (`elem_or_list<fun(client: vim.lsp.Client, bufnr: integer)>`)
|
||||
Callback invoked when client attaches to a
|
||||
buffer.
|
||||
• {trace}? (`'off'|'messages'|'verbose'`, default: "off")
|
||||
Passed directly to the language server in the
|
||||
initialize request. Invalid/empty values will
|
||||
• {flags}? (`table`) A table with flags for the client.
|
||||
The current (experimental) flags are:
|
||||
• {allow_incremental_sync}? (`boolean`,
|
||||
@@ -1380,9 +1331,72 @@ Lua module: vim.lsp.client *lsp-client*
|
||||
request before sending kill -15. If set to
|
||||
false, nvim exits immediately after sending
|
||||
the "shutdown" request to the server.
|
||||
• {get_language_id}? (`fun(bufnr: integer, filetype: string): string`)
|
||||
Language ID as string. Defaults to the buffer
|
||||
filetype.
|
||||
• {handlers}? (`table<string,function>`) Map of LSP method
|
||||
names to |lsp-handler|s.
|
||||
• {init_options}? (`lsp.LSPObject`) Values to pass in the
|
||||
initialization request as
|
||||
`initializationOptions`. See `initialize` in
|
||||
the LSP spec.
|
||||
• {name}? (`string`) (default: client-id) Name in logs
|
||||
and user messages.
|
||||
• {offset_encoding}? (`'utf-8'|'utf-16'|'utf-32'`) Called "position
|
||||
encoding" in LSP spec. The encoding that the
|
||||
LSP server expects, used for communication. Not
|
||||
validated. Can be modified in `on_init` before
|
||||
text is sent to the server.
|
||||
• {on_attach}? (`elem_or_list<fun(client: vim.lsp.Client, bufnr: integer)>`)
|
||||
Callback invoked when client attaches to a
|
||||
buffer.
|
||||
• {on_error}? (`fun(code: integer, err: string)`) Callback
|
||||
invoked when the client operation throws an
|
||||
error. `code` is a number describing the error.
|
||||
Other arguments may be passed depending on the
|
||||
error kind. See `vim.lsp.rpc.client_errors` for
|
||||
possible errors. Use
|
||||
`vim.lsp.rpc.client_errors[code]` to get
|
||||
human-friendly name.
|
||||
• {on_exit}? (`elem_or_list<fun(code: integer, signal: integer, client_id: integer)>`)
|
||||
Callback invoked on client exit.
|
||||
• code: exit code of the process
|
||||
• signal: number describing the signal used to
|
||||
terminate (if any)
|
||||
• client_id: client handle
|
||||
• {on_init}? (`elem_or_list<fun(client: vim.lsp.Client, init_result: lsp.InitializeResult)>`)
|
||||
Callback invoked after LSP "initialize", where
|
||||
`result` is a table of `capabilities` and
|
||||
anything else the server may send. For example,
|
||||
clangd sends `init_result.offsetEncoding` if
|
||||
`capabilities.offsetEncoding` was sent to it.
|
||||
You can only modify the
|
||||
`client.offset_encoding` here before any
|
||||
notifications are sent.
|
||||
• {root_dir}? (`string`) Directory where the LSP server will
|
||||
base its workspaceFolders, rootUri, and
|
||||
rootPath on initialization.
|
||||
• {settings}? (`lsp.LSPObject`) Map of language
|
||||
server-specific settings, decided by the
|
||||
client. Sent to the LS if requested via
|
||||
`workspace/configuration`. Keys are
|
||||
case-sensitive.
|
||||
• {trace}? (`'off'|'messages'|'verbose'`, default: "off")
|
||||
Passed directly to the language server in the
|
||||
initialize request. Invalid/empty values will
|
||||
• {workspace_folders}? (`lsp.WorkspaceFolder[]`) List of workspace
|
||||
folders passed to the language server. For
|
||||
backwards compatibility rootUri and rootPath
|
||||
are derived from the first workspace folder in
|
||||
this list. Can be `null` if the client supports
|
||||
workspace folders but none are configured. See
|
||||
`workspaceFolders` in LSP spec.
|
||||
• {workspace_required}? (`boolean`) (default false) Server requires a
|
||||
workspace (no "single file" support). Note:
|
||||
Without a workspace, cross-file features
|
||||
(navigation, hover) may or may not work
|
||||
depending on the language server, even if the
|
||||
server doesn't require a workspace.
|
||||
|
||||
|
||||
Client:cancel_request({id}) *Client:cancel_request()*
|
||||
|
||||
@@ -171,7 +171,7 @@ added. But visually, this small bit of sugar gets reasonably close to a
|
||||
|
||||
*lua-regex*
|
||||
Lua intentionally does not support regular expressions, instead it has limited
|
||||
|lua-patterns| which avoid the performance pitfalls of extended regex. Lua
|
||||
|lua-pattern|s which avoid the performance pitfalls of extended regex. Lua
|
||||
scripts can also use Vim regex via |vim.regex()|.
|
||||
|
||||
Examples: >lua
|
||||
@@ -2022,7 +2022,7 @@ vim.gsplit({s}, {sep}, {opts}) *vim.gsplit()*
|
||||
See also: ~
|
||||
• |string.gmatch()|
|
||||
• |vim.split()|
|
||||
• |lua-patterns|
|
||||
• |lua-pattern|s
|
||||
• https://www.lua.org/pil/20.2.html
|
||||
• http://lua-users.org/wiki/StringLibraryTutorial
|
||||
|
||||
@@ -2115,7 +2115,7 @@ vim.list_slice({list}, {start}, {finish}) *vim.list_slice()*
|
||||
(`any[]`) Copy of table sliced from start to finish (inclusive)
|
||||
|
||||
vim.pesc({s}) *vim.pesc()*
|
||||
Escapes magic chars in |lua-patterns|.
|
||||
Escapes magic chars in |lua-pattern|s.
|
||||
|
||||
Parameters: ~
|
||||
• {s} (`string`) String to escape
|
||||
@@ -2370,7 +2370,7 @@ vim.trim({s}) *vim.trim()*
|
||||
(`string`) String with whitespace removed from its beginning and end
|
||||
|
||||
See also: ~
|
||||
• |lua-patterns|
|
||||
• |lua-pattern|s
|
||||
• https://www.lua.org/pil/20.2.html
|
||||
|
||||
*vim.validate()*
|
||||
@@ -2670,7 +2670,7 @@ vim.filetype.add({filetypes}) *vim.filetype.add()*
|
||||
Filetype mappings can be added either by extension or by filename (either
|
||||
the "tail" or the full file path). The full file path is checked first,
|
||||
followed by the file name. If a match is not found using the filename,
|
||||
then the filename is matched against the list of |lua-patterns| (sorted by
|
||||
then the filename is matched against the list of |lua-pattern|s (sorted by
|
||||
priority) until a match is found. Lastly, if pattern matching does not
|
||||
find a filetype, then the file extension is used.
|
||||
|
||||
|
||||
@@ -4150,7 +4150,7 @@ string.upper({s}) *string.upper()*
|
||||
locale.
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
5.4.1 Patterns *lua-pattern* *lua-patterns*
|
||||
5.4.1 Patterns *lua-pattern*
|
||||
|
||||
A character class is used to represent a set of characters. The following
|
||||
combinations are allowed in describing a character class:
|
||||
|
||||
@@ -277,6 +277,7 @@ LSP
|
||||
• The `textDocument/completion` request now includes the completion context in
|
||||
its parameters.
|
||||
• |vim.lsp.Config| gained `workspace_required`.
|
||||
• `root_markers` in |vim.lsp.Config| can now be ordered by priority.
|
||||
|
||||
LUA
|
||||
|
||||
|
||||
@@ -120,7 +120,7 @@ The following predicates are built in:
|
||||
match.
|
||||
|
||||
`lua-match?` *treesitter-predicate-lua-match?*
|
||||
Match |lua-patterns| against the text corresponding to a node,
|
||||
Match |lua-pattern|s against the text corresponding to a node,
|
||||
similar to `match?`
|
||||
|
||||
`any-lua-match?` *treesitter-predicate-any-lua-match?*
|
||||
|
||||
@@ -2605,7 +2605,7 @@ end
|
||||
--- Filetype mappings can be added either by extension or by filename (either
|
||||
--- the "tail" or the full file path). The full file path is checked first,
|
||||
--- followed by the file name. If a match is not found using the filename, then
|
||||
--- the filename is matched against the list of |lua-patterns| (sorted by priority)
|
||||
--- the filename is matched against the list of |lua-pattern|s (sorted by priority)
|
||||
--- until a match is found. Lastly, if pattern matching does not find a
|
||||
--- filetype, then the file extension is used.
|
||||
---
|
||||
|
||||
@@ -277,25 +277,52 @@ end
|
||||
--- See `cmd` in [vim.lsp.ClientConfig].
|
||||
--- @field cmd? string[]|fun(dispatchers: vim.lsp.rpc.Dispatchers): vim.lsp.rpc.PublicClient
|
||||
---
|
||||
--- Filetypes the client will attach to, if activated by `vim.lsp.enable()`.
|
||||
--- If not provided, then the client will attach to all filetypes.
|
||||
--- Filetypes the client will attach to, if activated by `vim.lsp.enable()`. If not provided, the
|
||||
--- client will attach to all filetypes.
|
||||
--- @field filetypes? string[]
|
||||
---
|
||||
--- Directory markers (.e.g. '.git/') where the LSP server will base its workspaceFolders, rootUri,
|
||||
--- and rootPath on initialization. Unused if `root_dir` is provided.
|
||||
--- @field root_markers? string[]
|
||||
--- Predicate which decides if a client should be re-used. Used on all running clients. The default
|
||||
--- implementation re-uses a client if name and root_dir matches.
|
||||
--- @field reuse_client? fun(client: vim.lsp.Client, config: vim.lsp.ClientConfig): boolean
|
||||
---
|
||||
--- [lsp-root_dir()]() Directory where the LSP server will base its workspaceFolders, rootUri, and
|
||||
--- rootPath on initialization. The function form receives a buffer number and `on_dir` callback,
|
||||
--- which must be called to provide root_dir as a string. LSP will not be activated for the buffer
|
||||
--- unless `on_dir` is called; thus a `root_dir()` function can dynamically decide whether to
|
||||
--- activate (or skip) LSP per-buffer. See example at |vim.lsp.enable()|.
|
||||
--- rootPath on initialization. The function form receives a buffer number and `on_dir` callback
|
||||
--- which it must call to provide root_dir, or LSP will not be activated for the buffer. Thus
|
||||
--- a `root_dir()` function can dynamically decide per-buffer whether to activate (or skip) LSP. See
|
||||
--- example at |vim.lsp.enable()|.
|
||||
--- @field root_dir? string|fun(bufnr: integer, on_dir:fun(root_dir?:string))
|
||||
---
|
||||
--- Predicate used to decide if a client should be re-used. Used on all
|
||||
--- running clients. The default implementation re-uses a client if name and
|
||||
--- root_dir matches.
|
||||
--- @field reuse_client? fun(client: vim.lsp.Client, config: vim.lsp.ClientConfig): boolean
|
||||
--- Directory markers (.e.g. '.git/') where the LSP server will base its workspaceFolders,
|
||||
--- rootUri, and rootPath on initialization. Unused if `root_dir` is provided.
|
||||
---
|
||||
--- The list order decides the priority. To indicate "equal priority", specify names in a nested list (`{ { 'a', 'b' }, ... }`)
|
||||
--- Each entry in this list is a set of one or more markers. For each set, Nvim
|
||||
--- will search upwards for each marker contained in the set. If a marker is
|
||||
--- found, the directory which contains that marker is used as the root
|
||||
--- directory. If no markers from the set are found, the process is repeated
|
||||
--- with the next set in the list.
|
||||
---
|
||||
--- Example:
|
||||
---
|
||||
--- ```lua
|
||||
--- root_markers = { 'stylua.toml', '.git' }
|
||||
--- ```
|
||||
---
|
||||
--- Find the first parent directory containing the file `stylua.toml`. If not
|
||||
--- found, find the first parent directory containing the file or directory
|
||||
--- `.git`.
|
||||
---
|
||||
--- Example:
|
||||
---
|
||||
--- ```lua
|
||||
--- root_markers = { { 'stylua.toml', '.luarc.json' }, '.git' }
|
||||
--- ```
|
||||
---
|
||||
--- Find the first parent directory containing EITHER `stylua.toml` or
|
||||
--- `.luarc.json`. If not found, find the first parent directory containing the
|
||||
--- file or directory `.git`.
|
||||
---
|
||||
--- @field root_markers? (string|string[])[]
|
||||
|
||||
--- Update the configuration for an LSP client.
|
||||
---
|
||||
@@ -594,7 +621,7 @@ end
|
||||
--- Suppress error reporting if the LSP server fails to start (default false).
|
||||
--- @field silent? boolean
|
||||
---
|
||||
--- @field package _root_markers? string[]
|
||||
--- @field package _root_markers? (string|string[])[]
|
||||
|
||||
--- Create a new LSP client and start a language server or reuses an already
|
||||
--- running client if one is found matching `name` and `root_dir`.
|
||||
@@ -641,8 +668,16 @@ function lsp.start(config, opts)
|
||||
local bufnr = vim._resolve_bufnr(opts.bufnr)
|
||||
|
||||
if not config.root_dir and opts._root_markers then
|
||||
validate('root_markers', opts._root_markers, 'table')
|
||||
config = vim.deepcopy(config)
|
||||
config.root_dir = vim.fs.root(bufnr, opts._root_markers)
|
||||
|
||||
for _, marker in ipairs(opts._root_markers) do
|
||||
local root = vim.fs.root(bufnr, marker)
|
||||
if root ~= nil then
|
||||
config.root_dir = root
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if
|
||||
|
||||
@@ -30,6 +30,19 @@ local validate = vim.validate
|
||||
--- @field exit_timeout integer|false
|
||||
|
||||
--- @class vim.lsp.ClientConfig
|
||||
---
|
||||
--- Callback invoked before the LSP "initialize" phase, where `params` contains the parameters
|
||||
--- being sent to the server and `config` is the config that was passed to |vim.lsp.start()|.
|
||||
--- You can use this to modify parameters before they are sent.
|
||||
--- @field before_init? fun(params: lsp.InitializeParams, config: vim.lsp.ClientConfig)
|
||||
---
|
||||
--- Map overriding the default capabilities defined by |vim.lsp.protocol.make_client_capabilities()|,
|
||||
--- passed to the language server on initialization. Hint: use make_client_capabilities() and modify
|
||||
--- its result.
|
||||
--- - Note: To send an empty dictionary use |vim.empty_dict()|, else it will be encoded as an
|
||||
--- array.
|
||||
--- @field capabilities? lsp.ClientCapabilities
|
||||
---
|
||||
--- command string[] that launches the language
|
||||
--- server (treated as in |jobstart()|, must be absolute or on `$PATH`, shell constructs like
|
||||
--- "~" are not expanded), or function that creates an RPC client. Function receives
|
||||
@@ -43,125 +56,129 @@ local validate = vim.validate
|
||||
--- (default: cwd)
|
||||
--- @field cmd_cwd? string
|
||||
---
|
||||
--- Environment flags to pass to the LSP on spawn.
|
||||
--- Must be specified using a table.
|
||||
--- Non-string values are coerced to string.
|
||||
--- Environment variables passed to the LSP process on spawn. Non-string values are coerced to
|
||||
--- string.
|
||||
--- Example:
|
||||
--- ```lua
|
||||
--- { PORT = 8080; HOST = "0.0.0.0"; }
|
||||
--- { PORT = 8080; HOST = '0.0.0.0'; }
|
||||
--- ```
|
||||
--- @field cmd_env? table
|
||||
---
|
||||
--- Client commands. Map of command names to user-defined functions. Commands passed to `start()`
|
||||
--- take precedence over the global command registry. Each key must be a unique command name, and
|
||||
--- the value is a function which is called if any LSP action (code action, code lenses, …) triggers
|
||||
--- the command.
|
||||
--- @field commands? table<string,fun(command: lsp.Command, ctx: table)>
|
||||
---
|
||||
--- Daemonize the server process so that it runs in a separate process group from Nvim.
|
||||
--- Nvim will shutdown the process on exit, but if Nvim fails to exit cleanly this could leave
|
||||
--- behind orphaned server processes.
|
||||
--- (default: true)
|
||||
--- @field detached? boolean
|
||||
---
|
||||
--- List of workspace folders passed to the language server.
|
||||
--- For backwards compatibility rootUri and rootPath will be derived from the first workspace
|
||||
--- folder in this list. See `workspaceFolders` in the LSP spec.
|
||||
--- @field workspace_folders? lsp.WorkspaceFolder[]
|
||||
--- A table with flags for the client. The current (experimental) flags are:
|
||||
--- @field flags? vim.lsp.Client.Flags
|
||||
---
|
||||
--- (default false) Server requires a workspace (no "single file" support). Note: Without
|
||||
--- a workspace, cross-file features (navigation, hover) may or may not work depending on the
|
||||
--- language server, even if the server doesn't require a workspace.
|
||||
--- @field workspace_required? boolean
|
||||
--- Language ID as string. Defaults to the buffer filetype.
|
||||
--- @field get_language_id? fun(bufnr: integer, filetype: string): string
|
||||
---
|
||||
--- Map overriding the default capabilities defined by |vim.lsp.protocol.make_client_capabilities()|,
|
||||
--- passed to the language server on initialization. Hint: use make_client_capabilities() and modify
|
||||
--- its result.
|
||||
--- - Note: To send an empty dictionary use |vim.empty_dict()|, else it will be encoded as an
|
||||
--- array.
|
||||
--- @field capabilities? lsp.ClientCapabilities
|
||||
---
|
||||
--- Map of language server method names to |lsp-handler|
|
||||
--- Map of LSP method names to |lsp-handler|s.
|
||||
--- @field handlers? table<string,function>
|
||||
---
|
||||
--- Map with language server specific settings.
|
||||
--- See the {settings} in |vim.lsp.Client|.
|
||||
--- @field settings? lsp.LSPObject
|
||||
---
|
||||
--- Table that maps string of clientside commands to user-defined functions.
|
||||
--- Commands passed to `start()` take precedence over the global command registry. Each key
|
||||
--- must be a unique command name, and the value is a function which is called if any LSP action
|
||||
--- (code action, code lenses, ...) triggers the command.
|
||||
--- @field commands? table<string,fun(command: lsp.Command, ctx: table)>
|
||||
---
|
||||
--- Values to pass in the initialization request as `initializationOptions`. See `initialize` in
|
||||
--- the LSP spec.
|
||||
--- @field init_options? lsp.LSPObject
|
||||
---
|
||||
--- Name in log messages.
|
||||
--- (default: client-id)
|
||||
--- (default: client-id) Name in logs and user messages.
|
||||
--- @field name? string
|
||||
---
|
||||
--- Language ID as string. Defaults to the buffer filetype.
|
||||
--- @field get_language_id? fun(bufnr: integer, filetype: string): string
|
||||
---
|
||||
--- Called "position encoding" in LSP spec, the encoding that the LSP server expects.
|
||||
--- Client does not verify this is correct.
|
||||
--- Called "position encoding" in LSP spec. The encoding that the LSP server expects, used for
|
||||
--- communication. Not validated. Can be modified in `on_init` before text is sent to the server.
|
||||
--- @field offset_encoding? 'utf-8'|'utf-16'|'utf-32'
|
||||
---
|
||||
--- Callback invoked when client attaches to a buffer.
|
||||
--- @field on_attach? elem_or_list<fun(client: vim.lsp.Client, bufnr: integer)>
|
||||
---
|
||||
--- Callback invoked when the client operation throws an error. `code` is a number describing the error.
|
||||
--- Other arguments may be passed depending on the error kind. See `vim.lsp.rpc.client_errors`
|
||||
--- for possible errors. Use `vim.lsp.rpc.client_errors[code]` to get human-friendly name.
|
||||
--- @field on_error? fun(code: integer, err: string)
|
||||
---
|
||||
--- Callback invoked before the LSP "initialize" phase, where `params` contains the parameters
|
||||
--- being sent to the server and `config` is the config that was passed to |vim.lsp.start()|.
|
||||
--- You can use this to modify parameters before they are sent.
|
||||
--- @field before_init? fun(params: lsp.InitializeParams, config: vim.lsp.ClientConfig)
|
||||
---
|
||||
--- Callback invoked after LSP "initialize", where `result` is a table of `capabilities` and
|
||||
--- anything else the server may send. For example, clangd sends `init_result.offsetEncoding` if
|
||||
--- `capabilities.offsetEncoding` was sent to it. You can only modify the `client.offset_encoding`
|
||||
--- here before any notifications are sent.
|
||||
--- @field on_init? elem_or_list<fun(client: vim.lsp.Client, init_result: lsp.InitializeResult)>
|
||||
---
|
||||
--- Callback invoked on client exit.
|
||||
--- - code: exit code of the process
|
||||
--- - signal: number describing the signal used to terminate (if any)
|
||||
--- - client_id: client handle
|
||||
--- @field on_exit? elem_or_list<fun(code: integer, signal: integer, client_id: integer)>
|
||||
---
|
||||
--- Callback invoked when client attaches to a buffer.
|
||||
--- @field on_attach? elem_or_list<fun(client: vim.lsp.Client, bufnr: integer)>
|
||||
--- Callback invoked after LSP "initialize", where `result` is a table of `capabilities` and
|
||||
--- anything else the server may send. For example, clangd sends `init_result.offsetEncoding` if
|
||||
--- `capabilities.offsetEncoding` was sent to it. You can only modify the `client.offset_encoding`
|
||||
--- here before any notifications are sent.
|
||||
--- @field on_init? elem_or_list<fun(client: vim.lsp.Client, init_result: lsp.InitializeResult)>
|
||||
---
|
||||
--- Directory where the LSP server will base its workspaceFolders, rootUri, and rootPath on initialization.
|
||||
--- @field root_dir? string
|
||||
---
|
||||
--- Map of language server-specific settings, decided by the client. Sent to the LS if requested via
|
||||
--- `workspace/configuration`. Keys are case-sensitive.
|
||||
--- @field settings? lsp.LSPObject
|
||||
---
|
||||
--- Passed directly to the language server in the initialize request. Invalid/empty values will
|
||||
--- (default: "off")
|
||||
--- @field trace? 'off'|'messages'|'verbose'
|
||||
---
|
||||
--- A table with flags for the client. The current (experimental) flags are:
|
||||
--- @field flags? vim.lsp.Client.Flags
|
||||
--- List of workspace folders passed to the language server. For backwards compatibility rootUri and
|
||||
--- rootPath are derived from the first workspace folder in this list. Can be `null` if the client
|
||||
--- supports workspace folders but none are configured. See `workspaceFolders` in LSP spec.
|
||||
--- @field workspace_folders? lsp.WorkspaceFolder[]
|
||||
---
|
||||
--- Directory where the LSP server will base its workspaceFolders, rootUri, and rootPath on initialization.
|
||||
--- @field root_dir? string
|
||||
--- (default false) Server requires a workspace (no "single file" support). Note: Without
|
||||
--- a workspace, cross-file features (navigation, hover) may or may not work depending on the
|
||||
--- language server, even if the server doesn't require a workspace.
|
||||
--- @field workspace_required? boolean
|
||||
|
||||
--- @class vim.lsp.Client.Progress: vim.Ringbuf<{token: integer|string, value: any}>
|
||||
--- @field pending table<lsp.ProgressToken,lsp.LSPAny>
|
||||
|
||||
--- @class vim.lsp.Client
|
||||
---
|
||||
--- @field attached_buffers table<integer,true>
|
||||
---
|
||||
--- Capabilities provided by the client (editor or tool), at startup.
|
||||
--- @field capabilities lsp.ClientCapabilities
|
||||
---
|
||||
--- Client commands. See [vim.lsp.ClientConfig].
|
||||
--- @field commands table<string,fun(command: lsp.Command, ctx: table)>
|
||||
---
|
||||
--- Copy of the config passed to |vim.lsp.start()|.
|
||||
--- @field config vim.lsp.ClientConfig
|
||||
---
|
||||
--- Capabilities provided at runtime (after startup).
|
||||
--- @field dynamic_capabilities lsp.DynamicCapabilities
|
||||
---
|
||||
--- A table with flags for the client. The current (experimental) flags are:
|
||||
--- @field flags vim.lsp.Client.Flags
|
||||
---
|
||||
--- See [vim.lsp.ClientConfig].
|
||||
--- @field get_language_id fun(bufnr: integer, filetype: string): string
|
||||
---
|
||||
--- See [vim.lsp.ClientConfig].
|
||||
--- @field handlers table<string,lsp.Handler>
|
||||
---
|
||||
--- The id allocated to the client.
|
||||
--- @field id integer
|
||||
---
|
||||
--- If a name is specified on creation, that will be used. Otherwise it is just
|
||||
--- the client id. This is used for logs and messages.
|
||||
--- @field initialized true?
|
||||
---
|
||||
--- See [vim.lsp.ClientConfig].
|
||||
--- @field name string
|
||||
---
|
||||
--- RPC client object, for low level interaction with the client.
|
||||
--- See |vim.lsp.rpc.start()|.
|
||||
--- @field rpc vim.lsp.rpc.PublicClient
|
||||
---
|
||||
--- Called "position encoding" in LSP spec,
|
||||
--- the encoding used for communicating with the server.
|
||||
--- You can modify this in the `config`'s `on_init` method
|
||||
--- before text is sent to the server.
|
||||
--- See [vim.lsp.ClientConfig].
|
||||
--- @field offset_encoding string
|
||||
---
|
||||
--- The handlers used by the client as described in |lsp-handler|.
|
||||
--- @field handlers table<string,lsp.Handler>
|
||||
--- A ring buffer (|vim.ringbuf()|) containing progress messages
|
||||
--- sent by the server.
|
||||
--- @field progress vim.lsp.Client.Progress
|
||||
---
|
||||
--- The current pending requests in flight to the server. Entries are key-value
|
||||
--- pairs with the key being the request id while the value is a table with
|
||||
@@ -171,34 +188,25 @@ local validate = vim.validate
|
||||
--- are received from the server.
|
||||
--- @field requests table<integer,{ type: string, bufnr: integer, method: string}?>
|
||||
---
|
||||
--- copy of the table that was passed by the user
|
||||
--- to |vim.lsp.start()|.
|
||||
--- @field config vim.lsp.ClientConfig
|
||||
---
|
||||
--- Response from the server sent on `initialize` describing the server's
|
||||
--- capabilities.
|
||||
--- @field server_capabilities lsp.ServerCapabilities?
|
||||
---
|
||||
--- Response from the server sent on `initialize` describing information about
|
||||
--- the server.
|
||||
--- @field server_info lsp.ServerInfo?
|
||||
---
|
||||
--- A ring buffer (|vim.ringbuf()|) containing progress messages
|
||||
--- sent by the server.
|
||||
--- @field progress vim.lsp.Client.Progress
|
||||
---
|
||||
--- @field initialized true?
|
||||
---
|
||||
--- The workspace folders configured in the client when the server starts.
|
||||
--- This property is only available if the client supports workspace folders.
|
||||
--- It can be `null` if the client supports workspace folders but none are
|
||||
--- configured.
|
||||
--- @field workspace_folders lsp.WorkspaceFolder[]?
|
||||
--- See [vim.lsp.ClientConfig].
|
||||
--- @field root_dir string?
|
||||
---
|
||||
--- @field attached_buffers table<integer,true>
|
||||
--- RPC client object, for low level interaction with the client.
|
||||
--- See |vim.lsp.rpc.start()|.
|
||||
--- @field rpc vim.lsp.rpc.PublicClient
|
||||
---
|
||||
--- Response from the server sent on `initialize` describing the server's capabilities.
|
||||
--- @field server_capabilities lsp.ServerCapabilities?
|
||||
---
|
||||
--- Response from the server sent on `initialize` describing server information (e.g. version).
|
||||
--- @field server_info lsp.ServerInfo?
|
||||
---
|
||||
--- See [vim.lsp.ClientConfig].
|
||||
--- @field settings lsp.LSPObject
|
||||
---
|
||||
--- See [vim.lsp.ClientConfig].
|
||||
--- @field workspace_folders lsp.WorkspaceFolder[]?
|
||||
---
|
||||
--- @field private _log_prefix string
|
||||
---
|
||||
--- Track this so that we can escalate automatically if we've already tried a
|
||||
--- graceful shutdown
|
||||
@@ -208,26 +216,8 @@ local validate = vim.validate
|
||||
--- trace = "off" | "messages" | "verbose";
|
||||
--- @field private _trace 'off'|'messages'|'verbose'
|
||||
---
|
||||
--- Table of command name to function which is called if any LSP action
|
||||
--- (code action, code lenses, ...) triggers the command.
|
||||
--- Client commands take precedence over the global command registry.
|
||||
--- @field commands table<string,fun(command: lsp.Command, ctx: table)>
|
||||
---
|
||||
--- Map with language server specific settings. These are returned to the
|
||||
--- language server if requested via `workspace/configuration`. Keys are
|
||||
--- case-sensitive.
|
||||
--- @field settings lsp.LSPObject
|
||||
---
|
||||
--- A table with flags for the client. The current (experimental) flags are:
|
||||
--- @field flags vim.lsp.Client.Flags
|
||||
---
|
||||
--- @field get_language_id fun(bufnr: integer, filetype: string): string
|
||||
---
|
||||
--- The capabilities provided by the client (editor or tool)
|
||||
--- @field capabilities lsp.ClientCapabilities
|
||||
--- @field private registrations table<string,lsp.Registration[]>
|
||||
--- @field dynamic_capabilities lsp.DynamicCapabilities
|
||||
---
|
||||
--- @field private _log_prefix string
|
||||
--- @field private _before_init_cb? vim.lsp.client.before_init_cb
|
||||
--- @field private _on_attach_cbs vim.lsp.client.on_attach_cb[]
|
||||
--- @field private _on_init_cbs vim.lsp.client.on_init_cb[]
|
||||
|
||||
@@ -95,7 +95,7 @@ end
|
||||
---
|
||||
--- @see |string.gmatch()|
|
||||
--- @see |vim.split()|
|
||||
--- @see |lua-patterns|
|
||||
--- @see |lua-pattern|s
|
||||
--- @see https://www.lua.org/pil/20.2.html
|
||||
--- @see http://lua-users.org/wiki/StringLibraryTutorial
|
||||
---
|
||||
@@ -784,7 +784,7 @@ end
|
||||
|
||||
--- Trim whitespace (Lua pattern "%s") from both sides of a string.
|
||||
---
|
||||
---@see |lua-patterns|
|
||||
---@see |lua-pattern|s
|
||||
---@see https://www.lua.org/pil/20.2.html
|
||||
---@param s string String to trim
|
||||
---@return string String with whitespace removed from its beginning and end
|
||||
@@ -793,7 +793,7 @@ function vim.trim(s)
|
||||
return s:match('^%s*(.*%S)') or ''
|
||||
end
|
||||
|
||||
--- Escapes magic chars in |lua-patterns|.
|
||||
--- Escapes magic chars in |lua-pattern|s.
|
||||
---
|
||||
---@see https://github.com/rxi/lume
|
||||
---@param s string String to escape
|
||||
|
||||
@@ -5,7 +5,6 @@ local t_lsp = require('test.functional.plugin.lsp.testutil')
|
||||
|
||||
local assert_log = t.assert_log
|
||||
local buf_lines = n.buf_lines
|
||||
local clear = n.clear
|
||||
local command = n.command
|
||||
local dedent = t.dedent
|
||||
local exec_lua = n.exec_lua
|
||||
@@ -290,7 +289,6 @@ describe('LSP', function()
|
||||
it(
|
||||
"should set the client's offset_encoding when positionEncoding capability is supported",
|
||||
function()
|
||||
clear()
|
||||
exec_lua(create_server_definition)
|
||||
local result = exec_lua(function()
|
||||
local server = _G._create_server({
|
||||
@@ -573,7 +571,6 @@ describe('LSP', function()
|
||||
end)
|
||||
|
||||
it('should detach buffer on bufwipe', function()
|
||||
clear()
|
||||
exec_lua(create_server_definition)
|
||||
local result = exec_lua(function()
|
||||
local server = _G._create_server()
|
||||
@@ -606,7 +603,6 @@ describe('LSP', function()
|
||||
end)
|
||||
|
||||
it('should not re-attach buffer if it was deleted in on_init #28575', function()
|
||||
clear()
|
||||
exec_lua(create_server_definition)
|
||||
exec_lua(function()
|
||||
local server = _G._create_server({
|
||||
@@ -637,7 +633,6 @@ describe('LSP', function()
|
||||
end)
|
||||
|
||||
it('should allow on_lines + nvim_buf_delete during LSP initialization #28575', function()
|
||||
clear()
|
||||
exec_lua(create_server_definition)
|
||||
exec_lua(function()
|
||||
local initialized = false
|
||||
@@ -812,7 +807,6 @@ describe('LSP', function()
|
||||
end)
|
||||
|
||||
it('BufWritePre does not send notifications if server lacks willSave capabilities', function()
|
||||
clear()
|
||||
exec_lua(create_server_definition)
|
||||
local messages = exec_lua(function()
|
||||
local server = _G._create_server({
|
||||
@@ -837,7 +831,6 @@ describe('LSP', function()
|
||||
end)
|
||||
|
||||
it('BufWritePre sends willSave / willSaveWaitUntil, applies textEdits', function()
|
||||
clear()
|
||||
exec_lua(create_server_definition)
|
||||
local result = exec_lua(function()
|
||||
local server = _G._create_server({
|
||||
@@ -1253,8 +1246,6 @@ describe('LSP', function()
|
||||
end)
|
||||
|
||||
it('request should not be pending for sync responses (in-process LS)', function()
|
||||
clear()
|
||||
|
||||
--- @type boolean
|
||||
local pending_request = exec_lua(function()
|
||||
local function server(dispatchers)
|
||||
@@ -3871,7 +3862,6 @@ describe('LSP', function()
|
||||
end)
|
||||
|
||||
it('opens the quickfix list with the right subtypes', function()
|
||||
clear()
|
||||
exec_lua(create_server_definition)
|
||||
local qflist = exec_lua(function()
|
||||
local clangd_response = {
|
||||
@@ -4019,7 +4009,6 @@ describe('LSP', function()
|
||||
end)
|
||||
|
||||
it('opens the quickfix list with the right subtypes and details', function()
|
||||
clear()
|
||||
exec_lua(create_server_definition)
|
||||
local qflist = exec_lua(function()
|
||||
local jdtls_response = {
|
||||
@@ -4120,7 +4109,6 @@ describe('LSP', function()
|
||||
end)
|
||||
|
||||
it('opens the quickfix list with the right supertypes', function()
|
||||
clear()
|
||||
exec_lua(create_server_definition)
|
||||
local qflist = exec_lua(function()
|
||||
local clangd_response = {
|
||||
@@ -4269,7 +4257,6 @@ describe('LSP', function()
|
||||
end)
|
||||
|
||||
it('opens the quickfix list with the right supertypes and details', function()
|
||||
clear()
|
||||
exec_lua(create_server_definition)
|
||||
local qflist = exec_lua(function()
|
||||
local jdtls_response = {
|
||||
@@ -4623,7 +4610,6 @@ describe('LSP', function()
|
||||
end)
|
||||
|
||||
it('fallback to command execution on resolve error', function()
|
||||
clear()
|
||||
exec_lua(create_server_definition)
|
||||
local result = exec_lua(function()
|
||||
local server = _G._create_server({
|
||||
@@ -4668,7 +4654,6 @@ describe('LSP', function()
|
||||
end)
|
||||
|
||||
it('resolves command property', function()
|
||||
clear()
|
||||
exec_lua(create_server_definition)
|
||||
local result = exec_lua(function()
|
||||
local server = _G._create_server({
|
||||
@@ -4878,7 +4863,6 @@ describe('LSP', function()
|
||||
['file:///fake/uri1'] = 'Lens1',
|
||||
['file:///fake/uri2'] = 'Lens2',
|
||||
}
|
||||
clear()
|
||||
exec_lua(create_server_definition)
|
||||
|
||||
-- setup lsp
|
||||
@@ -5388,7 +5372,6 @@ describe('LSP', function()
|
||||
|
||||
describe('vim.lsp.tagfunc', function()
|
||||
before_each(function()
|
||||
clear()
|
||||
---@type lsp.Location[]
|
||||
local mock_locations = {
|
||||
{
|
||||
@@ -5729,7 +5712,7 @@ describe('LSP', function()
|
||||
local created, changed, deleted
|
||||
|
||||
setup(function()
|
||||
clear()
|
||||
n.clear()
|
||||
created = exec_lua([[return vim.lsp.protocol.FileChangeType.Created]])
|
||||
changed = exec_lua([[return vim.lsp.protocol.FileChangeType.Changed]])
|
||||
deleted = exec_lua([[return vim.lsp.protocol.FileChangeType.Deleted]])
|
||||
@@ -6552,5 +6535,116 @@ describe('LSP', function()
|
||||
end)
|
||||
)
|
||||
end)
|
||||
|
||||
it('does not allow wildcards in config name', function()
|
||||
local err =
|
||||
'.../lsp.lua:0: name: expected non%-wildcard string, got foo%*%. Info: LSP config name cannot contain wildcard %("%*"%)'
|
||||
|
||||
matches(
|
||||
err,
|
||||
pcall_err(exec_lua, function()
|
||||
local _ = vim.lsp.config['foo*']
|
||||
end)
|
||||
)
|
||||
|
||||
matches(
|
||||
err,
|
||||
pcall_err(exec_lua, function()
|
||||
vim.lsp.config['foo*'] = {}
|
||||
end)
|
||||
)
|
||||
|
||||
matches(
|
||||
err,
|
||||
pcall_err(exec_lua, function()
|
||||
vim.lsp.config('foo*', {})
|
||||
end)
|
||||
)
|
||||
|
||||
-- Exception for '*'
|
||||
pcall(exec_lua, function()
|
||||
vim.lsp.config('*', {})
|
||||
end)
|
||||
end)
|
||||
|
||||
it('correctly handles root_markers', function()
|
||||
--- Setup directories for testing
|
||||
-- root/
|
||||
-- ├── dir_a/
|
||||
-- │ ├── dir_b/
|
||||
-- │ │ ├── target
|
||||
-- │ │ └── marker_d
|
||||
-- │ ├── marker_b
|
||||
-- │ └── marker_c
|
||||
-- └── marker_a
|
||||
|
||||
---@param filepath string
|
||||
local function touch(filepath)
|
||||
local file = io.open(filepath, 'w')
|
||||
if file then
|
||||
file:close()
|
||||
end
|
||||
end
|
||||
|
||||
local tmp_root = tmpname(false)
|
||||
local marker_a = tmp_root .. '/marker_a'
|
||||
local dir_a = tmp_root .. '/dir_a'
|
||||
local marker_b = dir_a .. '/marker_b'
|
||||
local marker_c = dir_a .. '/marker_c'
|
||||
local dir_b = dir_a .. '/dir_b'
|
||||
local marker_d = dir_b .. '/marker_d'
|
||||
local target = dir_b .. '/target'
|
||||
|
||||
mkdir(tmp_root)
|
||||
touch(marker_a)
|
||||
mkdir(dir_a)
|
||||
touch(marker_b)
|
||||
touch(marker_c)
|
||||
mkdir(dir_b)
|
||||
touch(marker_d)
|
||||
touch(target)
|
||||
|
||||
exec_lua(create_server_definition)
|
||||
exec_lua(function()
|
||||
_G._custom_server = _G._create_server()
|
||||
end)
|
||||
|
||||
---@param root_markers (string|string[])[]
|
||||
---@param expected_root_dir string?
|
||||
local function markers_resolve_to(root_markers, expected_root_dir)
|
||||
exec_lua(function()
|
||||
vim.lsp.config['foo'] = {}
|
||||
vim.lsp.config('foo', {
|
||||
cmd = _G._custom_server.cmd,
|
||||
reuse_client = function()
|
||||
return false
|
||||
end,
|
||||
filetypes = { 'foo' },
|
||||
root_markers = root_markers,
|
||||
})
|
||||
vim.lsp.enable('foo')
|
||||
vim.cmd.edit(target)
|
||||
vim.bo.filetype = 'foo'
|
||||
end)
|
||||
retry(nil, 1000, function()
|
||||
eq(
|
||||
expected_root_dir,
|
||||
exec_lua(function()
|
||||
local clients = vim.lsp.get_clients()
|
||||
return clients[#clients].root_dir
|
||||
end)
|
||||
)
|
||||
end)
|
||||
end
|
||||
|
||||
markers_resolve_to({ 'marker_d' }, dir_b)
|
||||
markers_resolve_to({ 'marker_b' }, dir_a)
|
||||
markers_resolve_to({ 'marker_c' }, dir_a)
|
||||
markers_resolve_to({ 'marker_a' }, tmp_root)
|
||||
markers_resolve_to({ 'foo' }, nil)
|
||||
markers_resolve_to({ { 'marker_b', 'marker_a' }, 'marker_d' }, dir_a)
|
||||
markers_resolve_to({ 'marker_a', { 'marker_b', 'marker_d' } }, tmp_root)
|
||||
markers_resolve_to({ 'foo', { 'bar', 'baz' }, 'marker_d' }, dir_b)
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
|
||||
Reference in New Issue
Block a user