2023-03-11 06:50:14 -07:00
|
|
|
---@diagnostic disable: invisible
|
2022-07-15 09:26:47 -07:00
|
|
|
local api = vim.api
|
2022-12-19 09:37:45 -07:00
|
|
|
local nvim_err_writeln, nvim_buf_get_lines, nvim_command, nvim_exec_autocmds =
|
|
|
|
api.nvim_err_writeln, api.nvim_buf_get_lines, api.nvim_command, api.nvim_exec_autocmds
|
2023-06-03 03:06:00 -07:00
|
|
|
local uv = vim.uv
|
2019-11-13 13:55:26 -07:00
|
|
|
local tbl_isempty, tbl_extend = vim.tbl_isempty, vim.tbl_extend
|
|
|
|
local validate = vim.validate
|
2022-05-09 11:00:27 -07:00
|
|
|
local if_nil = vim.F.if_nil
|
2019-11-13 13:55:26 -07:00
|
|
|
|
2024-01-22 10:23:28 -07:00
|
|
|
local lsp = vim._defer_require('vim.lsp', {
|
|
|
|
_changetracking = ..., --- @module 'vim.lsp._changetracking'
|
|
|
|
_completion = ..., --- @module 'vim.lsp._completion'
|
|
|
|
_dynamic = ..., --- @module 'vim.lsp._dynamic'
|
|
|
|
_snippet_grammar = ..., --- @module 'vim.lsp._snippet_grammar'
|
2024-02-03 15:47:56 -07:00
|
|
|
_tagfunc = ..., --- @module 'vim.lsp._tagfunc'
|
2024-01-22 10:23:28 -07:00
|
|
|
_watchfiles = ..., --- @module 'vim.lsp._watchfiles'
|
|
|
|
buf = ..., --- @module 'vim.lsp.buf'
|
|
|
|
codelens = ..., --- @module 'vim.lsp.codelens'
|
|
|
|
diagnostic = ..., --- @module 'vim.lsp.diagnostic'
|
|
|
|
handlers = ..., --- @module 'vim.lsp.handlers'
|
|
|
|
inlay_hint = ..., --- @module 'vim.lsp.inlay_hint'
|
|
|
|
log = ..., --- @module 'vim.lsp.log'
|
|
|
|
protocol = ..., --- @module 'vim.lsp.protocol'
|
|
|
|
rpc = ..., --- @module 'vim.lsp.rpc'
|
|
|
|
semantic_tokens = ..., --- @module 'vim.lsp.semantic_tokens'
|
|
|
|
util = ..., --- @module 'vim.lsp.util'
|
|
|
|
})
|
lsp: vim.lsp.diagnostic (#12655)
Breaking Changes:
- Deprecated all `vim.lsp.util.{*diagnostics*}()` functions.
- Instead, all functions must be found in vim.lsp.diagnostic
- For now, they issue a warning ONCE per neovim session. In a
"little while" we will remove them completely.
- `vim.lsp.callbacks` has moved to `vim.lsp.handlers`.
- For a "little while" we will just redirect `vim.lsp.callbacks` to
`vim.lsp.handlers`. However, we will remove this at some point, so
it is recommended that you change all of your references to
`callbacks` into `handlers`.
- This also means that for functions like |vim.lsp.start_client()|
and similar, keyword style arguments have moved from "callbacks"
to "handlers". Once again, these are currently being forward, but
will cease to be forwarded in a "little while".
- Changed the highlight groups for LspDiagnostic highlight as they were
inconsistently named.
- For more information, see |lsp-highlight-diagnostics|
- Changed the sign group names as well, to be consistent with
|lsp-highlight-diagnostics|
General Enhancements:
- Rewrote much of the getting started help document for lsp. It also
provides a much nicer configuration strategy, so as to not recommend
globally overwriting builtin neovim mappings.
LSP Enhancements:
- Introduced the concept of |lsp-handlers| which will allow much better
customization for users without having to copy & paste entire files /
functions / etc.
Diagnostic Enhancements:
- "goto next diagnostic" |vim.lsp.diagnostic.goto_next()|
- "goto prev diagnostic" |vim.lsp.diagnostic.goto_prev()|
- For each of the gotos, auto open diagnostics is available as a
configuration option
- Configurable diagnostic handling:
- See |vim.lsp.diagnostic.on_publish_diagnostics()|
- Delay display until after insert mode
- Configure signs
- Configure virtual text
- Configure underline
- Set the location list with the buffers diagnostics.
- See |vim.lsp.diagnostic.set_loclist()|
- Better performance for getting counts and line diagnostics
- They are now cached on save, to enhance lookups.
- Particularly useful for checking in statusline, etc.
- Actual testing :)
- See ./test/functional/plugin/lsp/diagnostic_spec.lua
- Added `guisp` for underline highlighting
NOTE: "a little while" means enough time to feel like most plugins and
plugin authors have had a chance to refactor their code to use the
updated calls. Then we will remove them completely. There is no need to
keep them, because we don't have any released version of neovim that
exposes these APIs. I'm trying to be nice to people following HEAD :)
Co-authored: [Twitch Chat 2020](https://twitch.tv/teej_dv)
2020-11-12 20:21:34 -07:00
|
|
|
|
2024-01-22 10:23:28 -07:00
|
|
|
local log = lsp.log
|
|
|
|
local protocol = lsp.protocol
|
|
|
|
local ms = protocol.Methods
|
|
|
|
local util = lsp.util
|
|
|
|
local changetracking = lsp._changetracking
|
lsp: vim.lsp.diagnostic (#12655)
Breaking Changes:
- Deprecated all `vim.lsp.util.{*diagnostics*}()` functions.
- Instead, all functions must be found in vim.lsp.diagnostic
- For now, they issue a warning ONCE per neovim session. In a
"little while" we will remove them completely.
- `vim.lsp.callbacks` has moved to `vim.lsp.handlers`.
- For a "little while" we will just redirect `vim.lsp.callbacks` to
`vim.lsp.handlers`. However, we will remove this at some point, so
it is recommended that you change all of your references to
`callbacks` into `handlers`.
- This also means that for functions like |vim.lsp.start_client()|
and similar, keyword style arguments have moved from "callbacks"
to "handlers". Once again, these are currently being forward, but
will cease to be forwarded in a "little while".
- Changed the highlight groups for LspDiagnostic highlight as they were
inconsistently named.
- For more information, see |lsp-highlight-diagnostics|
- Changed the sign group names as well, to be consistent with
|lsp-highlight-diagnostics|
General Enhancements:
- Rewrote much of the getting started help document for lsp. It also
provides a much nicer configuration strategy, so as to not recommend
globally overwriting builtin neovim mappings.
LSP Enhancements:
- Introduced the concept of |lsp-handlers| which will allow much better
customization for users without having to copy & paste entire files /
functions / etc.
Diagnostic Enhancements:
- "goto next diagnostic" |vim.lsp.diagnostic.goto_next()|
- "goto prev diagnostic" |vim.lsp.diagnostic.goto_prev()|
- For each of the gotos, auto open diagnostics is available as a
configuration option
- Configurable diagnostic handling:
- See |vim.lsp.diagnostic.on_publish_diagnostics()|
- Delay display until after insert mode
- Configure signs
- Configure virtual text
- Configure underline
- Set the location list with the buffers diagnostics.
- See |vim.lsp.diagnostic.set_loclist()|
- Better performance for getting counts and line diagnostics
- They are now cached on save, to enhance lookups.
- Particularly useful for checking in statusline, etc.
- Actual testing :)
- See ./test/functional/plugin/lsp/diagnostic_spec.lua
- Added `guisp` for underline highlighting
NOTE: "a little while" means enough time to feel like most plugins and
plugin authors have had a chance to refactor their code to use the
updated calls. Then we will remove them completely. There is no need to
keep them, because we don't have any released version of neovim that
exposes these APIs. I'm trying to be nice to people following HEAD :)
Co-authored: [Twitch Chat 2020](https://twitch.tv/teej_dv)
2020-11-12 20:21:34 -07:00
|
|
|
|
2024-01-22 10:23:28 -07:00
|
|
|
-- Export these directly from rpc.
|
|
|
|
---@nodoc
|
|
|
|
lsp.rpc_response_error = lsp.rpc.rpc_response_error
|
2019-11-13 13:55:26 -07:00
|
|
|
|
2022-04-30 02:22:30 -07:00
|
|
|
-- maps request name to the required server_capability in the client.
|
2020-10-24 21:28:15 -07:00
|
|
|
lsp._request_name_to_capability = {
|
2023-08-03 04:03:48 -07:00
|
|
|
[ms.textDocument_hover] = { 'hoverProvider' },
|
|
|
|
[ms.textDocument_signatureHelp] = { 'signatureHelpProvider' },
|
|
|
|
[ms.textDocument_definition] = { 'definitionProvider' },
|
|
|
|
[ms.textDocument_implementation] = { 'implementationProvider' },
|
|
|
|
[ms.textDocument_declaration] = { 'declarationProvider' },
|
|
|
|
[ms.textDocument_typeDefinition] = { 'typeDefinitionProvider' },
|
|
|
|
[ms.textDocument_documentSymbol] = { 'documentSymbolProvider' },
|
|
|
|
[ms.textDocument_prepareCallHierarchy] = { 'callHierarchyProvider' },
|
|
|
|
[ms.callHierarchy_incomingCalls] = { 'callHierarchyProvider' },
|
|
|
|
[ms.callHierarchy_outgoingCalls] = { 'callHierarchyProvider' },
|
|
|
|
[ms.textDocument_rename] = { 'renameProvider' },
|
|
|
|
[ms.textDocument_prepareRename] = { 'renameProvider', 'prepareProvider' },
|
|
|
|
[ms.textDocument_codeAction] = { 'codeActionProvider' },
|
|
|
|
[ms.textDocument_codeLens] = { 'codeLensProvider' },
|
|
|
|
[ms.codeLens_resolve] = { 'codeLensProvider', 'resolveProvider' },
|
|
|
|
[ms.codeAction_resolve] = { 'codeActionProvider', 'resolveProvider' },
|
|
|
|
[ms.workspace_executeCommand] = { 'executeCommandProvider' },
|
|
|
|
[ms.workspace_symbol] = { 'workspaceSymbolProvider' },
|
|
|
|
[ms.textDocument_references] = { 'referencesProvider' },
|
|
|
|
[ms.textDocument_rangeFormatting] = { 'documentRangeFormattingProvider' },
|
|
|
|
[ms.textDocument_formatting] = { 'documentFormattingProvider' },
|
|
|
|
[ms.textDocument_completion] = { 'completionProvider' },
|
|
|
|
[ms.textDocument_documentHighlight] = { 'documentHighlightProvider' },
|
|
|
|
[ms.textDocument_semanticTokens_full] = { 'semanticTokensProvider' },
|
|
|
|
[ms.textDocument_semanticTokens_full_delta] = { 'semanticTokensProvider' },
|
|
|
|
[ms.textDocument_inlayHint] = { 'inlayHintProvider' },
|
|
|
|
[ms.textDocument_diagnostic] = { 'diagnosticProvider' },
|
|
|
|
[ms.inlayHint_resolve] = { 'inlayHintProvider', 'resolveProvider' },
|
2020-10-24 21:28:15 -07:00
|
|
|
}
|
|
|
|
|
2019-11-13 13:55:26 -07:00
|
|
|
-- TODO improve handling of scratch buffers with LSP attached.
|
|
|
|
|
2020-08-19 09:17:08 -07:00
|
|
|
--- Concatenates and writes a list of strings to the Vim error buffer.
|
|
|
|
---
|
2023-02-25 10:47:05 -07:00
|
|
|
---@param ... string List to write to the buffer
|
2019-11-20 17:16:13 -07:00
|
|
|
local function err_message(...)
|
|
|
|
nvim_err_writeln(table.concat(vim.tbl_flatten({ ... })))
|
|
|
|
nvim_command('redraw')
|
|
|
|
end
|
|
|
|
|
2020-08-19 09:17:08 -07:00
|
|
|
--- Returns the buffer number for the given {bufnr}.
|
|
|
|
---
|
2023-02-25 10:47:05 -07:00
|
|
|
---@param bufnr (integer|nil) Buffer number to resolve. Defaults to current buffer
|
|
|
|
---@return integer bufnr
|
2019-11-13 13:55:26 -07:00
|
|
|
local function resolve_bufnr(bufnr)
|
|
|
|
validate({ bufnr = { bufnr, 'n', true } })
|
|
|
|
if bufnr == nil or bufnr == 0 then
|
2022-07-15 09:26:47 -07:00
|
|
|
return api.nvim_get_current_buf()
|
2019-11-13 13:55:26 -07:00
|
|
|
end
|
|
|
|
return bufnr
|
|
|
|
end
|
|
|
|
|
2021-08-22 13:55:28 -07:00
|
|
|
---@private
|
lsp: vim.lsp.diagnostic (#12655)
Breaking Changes:
- Deprecated all `vim.lsp.util.{*diagnostics*}()` functions.
- Instead, all functions must be found in vim.lsp.diagnostic
- For now, they issue a warning ONCE per neovim session. In a
"little while" we will remove them completely.
- `vim.lsp.callbacks` has moved to `vim.lsp.handlers`.
- For a "little while" we will just redirect `vim.lsp.callbacks` to
`vim.lsp.handlers`. However, we will remove this at some point, so
it is recommended that you change all of your references to
`callbacks` into `handlers`.
- This also means that for functions like |vim.lsp.start_client()|
and similar, keyword style arguments have moved from "callbacks"
to "handlers". Once again, these are currently being forward, but
will cease to be forwarded in a "little while".
- Changed the highlight groups for LspDiagnostic highlight as they were
inconsistently named.
- For more information, see |lsp-highlight-diagnostics|
- Changed the sign group names as well, to be consistent with
|lsp-highlight-diagnostics|
General Enhancements:
- Rewrote much of the getting started help document for lsp. It also
provides a much nicer configuration strategy, so as to not recommend
globally overwriting builtin neovim mappings.
LSP Enhancements:
- Introduced the concept of |lsp-handlers| which will allow much better
customization for users without having to copy & paste entire files /
functions / etc.
Diagnostic Enhancements:
- "goto next diagnostic" |vim.lsp.diagnostic.goto_next()|
- "goto prev diagnostic" |vim.lsp.diagnostic.goto_prev()|
- For each of the gotos, auto open diagnostics is available as a
configuration option
- Configurable diagnostic handling:
- See |vim.lsp.diagnostic.on_publish_diagnostics()|
- Delay display until after insert mode
- Configure signs
- Configure virtual text
- Configure underline
- Set the location list with the buffers diagnostics.
- See |vim.lsp.diagnostic.set_loclist()|
- Better performance for getting counts and line diagnostics
- They are now cached on save, to enhance lookups.
- Particularly useful for checking in statusline, etc.
- Actual testing :)
- See ./test/functional/plugin/lsp/diagnostic_spec.lua
- Added `guisp` for underline highlighting
NOTE: "a little while" means enough time to feel like most plugins and
plugin authors have had a chance to refactor their code to use the
updated calls. Then we will remove them completely. There is no need to
keep them, because we don't have any released version of neovim that
exposes these APIs. I'm trying to be nice to people following HEAD :)
Co-authored: [Twitch Chat 2020](https://twitch.tv/teej_dv)
2020-11-12 20:21:34 -07:00
|
|
|
--- Called by the client when trying to call a method that's not
|
2020-10-24 21:28:15 -07:00
|
|
|
--- supported in any of the servers registered for the current buffer.
|
2021-08-22 13:55:28 -07:00
|
|
|
---@param method (string) name of the method
|
2020-10-24 21:28:15 -07:00
|
|
|
function lsp._unsupported_method(method)
|
|
|
|
local msg = string.format(
|
|
|
|
'method %s is not supported by any of the servers registered for the current buffer',
|
|
|
|
method
|
|
|
|
)
|
|
|
|
log.warn(msg)
|
2021-10-10 22:32:50 -07:00
|
|
|
return msg
|
2020-10-24 21:28:15 -07:00
|
|
|
end
|
|
|
|
|
2020-08-19 09:17:08 -07:00
|
|
|
--- Checks whether a given path is a directory.
|
|
|
|
---
|
2021-08-22 13:55:28 -07:00
|
|
|
---@param filename (string) path to check
|
2023-02-25 10:47:05 -07:00
|
|
|
---@return boolean # true if {filename} exists and is a directory, false otherwise
|
2019-11-13 13:55:26 -07:00
|
|
|
local function is_dir(filename)
|
|
|
|
validate({ filename = { filename, 's' } })
|
|
|
|
local stat = uv.fs_stat(filename)
|
|
|
|
return stat and stat.type == 'directory' or false
|
|
|
|
end
|
|
|
|
|
|
|
|
local wait_result_reason = { [-1] = 'timeout', [-2] = 'interrupted', [-3] = 'error' }
|
|
|
|
|
|
|
|
local valid_encodings = {
|
|
|
|
['utf-8'] = 'utf-8',
|
|
|
|
['utf-16'] = 'utf-16',
|
|
|
|
['utf-32'] = 'utf-32',
|
|
|
|
['utf8'] = 'utf-8',
|
|
|
|
['utf16'] = 'utf-16',
|
|
|
|
['utf32'] = 'utf-32',
|
|
|
|
UTF8 = 'utf-8',
|
|
|
|
UTF16 = 'utf-16',
|
|
|
|
UTF32 = 'utf-32',
|
|
|
|
}
|
|
|
|
|
2021-11-09 15:37:48 -07:00
|
|
|
local format_line_ending = {
|
|
|
|
['unix'] = '\n',
|
|
|
|
['dos'] = '\r\n',
|
|
|
|
['mac'] = '\r',
|
|
|
|
}
|
|
|
|
|
2023-12-17 02:54:38 -07:00
|
|
|
---@private
|
2021-11-21 10:03:45 -07:00
|
|
|
---@param bufnr (number)
|
2023-02-25 10:47:05 -07:00
|
|
|
---@return string
|
2023-12-17 02:54:38 -07:00
|
|
|
function lsp._buf_get_line_ending(bufnr)
|
2022-12-19 09:37:45 -07:00
|
|
|
return format_line_ending[vim.bo[bufnr].fileformat] or '\n'
|
2021-11-21 10:03:45 -07:00
|
|
|
end
|
|
|
|
|
2019-11-13 13:55:26 -07:00
|
|
|
local client_index = 0
|
2020-08-19 09:17:08 -07:00
|
|
|
--- Returns a new, unused client id.
|
|
|
|
---
|
2023-02-25 10:47:05 -07:00
|
|
|
---@return integer client_id
|
2019-11-13 13:55:26 -07:00
|
|
|
local function next_client_id()
|
|
|
|
client_index = client_index + 1
|
|
|
|
return client_index
|
|
|
|
end
|
|
|
|
-- Tracks all clients created via lsp.start_client
|
2023-06-07 05:39:41 -07:00
|
|
|
local active_clients = {} --- @type table<integer,lsp.Client>
|
|
|
|
local all_buffer_active_clients = {} --- @type table<integer,table<integer,true>>
|
|
|
|
local uninitialized_clients = {} --- @type table<integer,lsp.Client>
|
2019-11-13 13:55:26 -07:00
|
|
|
|
2023-03-09 14:17:08 -07:00
|
|
|
---@param bufnr? integer
|
|
|
|
---@param fn fun(client: lsp.Client, client_id: integer, bufnr: integer)
|
2021-10-10 22:32:50 -07:00
|
|
|
local function for_each_buffer_client(bufnr, fn, restrict_client_ids)
|
2019-11-13 13:55:26 -07:00
|
|
|
validate({
|
lsp: vim.lsp.diagnostic (#12655)
Breaking Changes:
- Deprecated all `vim.lsp.util.{*diagnostics*}()` functions.
- Instead, all functions must be found in vim.lsp.diagnostic
- For now, they issue a warning ONCE per neovim session. In a
"little while" we will remove them completely.
- `vim.lsp.callbacks` has moved to `vim.lsp.handlers`.
- For a "little while" we will just redirect `vim.lsp.callbacks` to
`vim.lsp.handlers`. However, we will remove this at some point, so
it is recommended that you change all of your references to
`callbacks` into `handlers`.
- This also means that for functions like |vim.lsp.start_client()|
and similar, keyword style arguments have moved from "callbacks"
to "handlers". Once again, these are currently being forward, but
will cease to be forwarded in a "little while".
- Changed the highlight groups for LspDiagnostic highlight as they were
inconsistently named.
- For more information, see |lsp-highlight-diagnostics|
- Changed the sign group names as well, to be consistent with
|lsp-highlight-diagnostics|
General Enhancements:
- Rewrote much of the getting started help document for lsp. It also
provides a much nicer configuration strategy, so as to not recommend
globally overwriting builtin neovim mappings.
LSP Enhancements:
- Introduced the concept of |lsp-handlers| which will allow much better
customization for users without having to copy & paste entire files /
functions / etc.
Diagnostic Enhancements:
- "goto next diagnostic" |vim.lsp.diagnostic.goto_next()|
- "goto prev diagnostic" |vim.lsp.diagnostic.goto_prev()|
- For each of the gotos, auto open diagnostics is available as a
configuration option
- Configurable diagnostic handling:
- See |vim.lsp.diagnostic.on_publish_diagnostics()|
- Delay display until after insert mode
- Configure signs
- Configure virtual text
- Configure underline
- Set the location list with the buffers diagnostics.
- See |vim.lsp.diagnostic.set_loclist()|
- Better performance for getting counts and line diagnostics
- They are now cached on save, to enhance lookups.
- Particularly useful for checking in statusline, etc.
- Actual testing :)
- See ./test/functional/plugin/lsp/diagnostic_spec.lua
- Added `guisp` for underline highlighting
NOTE: "a little while" means enough time to feel like most plugins and
plugin authors have had a chance to refactor their code to use the
updated calls. Then we will remove them completely. There is no need to
keep them, because we don't have any released version of neovim that
exposes these APIs. I'm trying to be nice to people following HEAD :)
Co-authored: [Twitch Chat 2020](https://twitch.tv/teej_dv)
2020-11-12 20:21:34 -07:00
|
|
|
fn = { fn, 'f' },
|
2021-10-10 22:32:50 -07:00
|
|
|
restrict_client_ids = { restrict_client_ids, 't', true },
|
2019-11-13 13:55:26 -07:00
|
|
|
})
|
|
|
|
bufnr = resolve_bufnr(bufnr)
|
|
|
|
local client_ids = all_buffer_active_clients[bufnr]
|
|
|
|
if not client_ids or tbl_isempty(client_ids) then
|
|
|
|
return
|
|
|
|
end
|
2021-10-10 22:32:50 -07:00
|
|
|
|
|
|
|
if restrict_client_ids and #restrict_client_ids > 0 then
|
2023-06-07 05:39:41 -07:00
|
|
|
local filtered_client_ids = {} --- @type table<integer,true>
|
2021-10-11 08:52:11 -07:00
|
|
|
for client_id in pairs(client_ids) do
|
2023-04-14 01:39:57 -07:00
|
|
|
if vim.list_contains(restrict_client_ids, client_id) then
|
2021-10-11 08:52:11 -07:00
|
|
|
filtered_client_ids[client_id] = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
client_ids = filtered_client_ids
|
2021-10-10 22:32:50 -07:00
|
|
|
end
|
|
|
|
|
2019-11-13 13:55:26 -07:00
|
|
|
for client_id in pairs(client_ids) do
|
|
|
|
local client = active_clients[client_id]
|
|
|
|
if client then
|
lsp: vim.lsp.diagnostic (#12655)
Breaking Changes:
- Deprecated all `vim.lsp.util.{*diagnostics*}()` functions.
- Instead, all functions must be found in vim.lsp.diagnostic
- For now, they issue a warning ONCE per neovim session. In a
"little while" we will remove them completely.
- `vim.lsp.callbacks` has moved to `vim.lsp.handlers`.
- For a "little while" we will just redirect `vim.lsp.callbacks` to
`vim.lsp.handlers`. However, we will remove this at some point, so
it is recommended that you change all of your references to
`callbacks` into `handlers`.
- This also means that for functions like |vim.lsp.start_client()|
and similar, keyword style arguments have moved from "callbacks"
to "handlers". Once again, these are currently being forward, but
will cease to be forwarded in a "little while".
- Changed the highlight groups for LspDiagnostic highlight as they were
inconsistently named.
- For more information, see |lsp-highlight-diagnostics|
- Changed the sign group names as well, to be consistent with
|lsp-highlight-diagnostics|
General Enhancements:
- Rewrote much of the getting started help document for lsp. It also
provides a much nicer configuration strategy, so as to not recommend
globally overwriting builtin neovim mappings.
LSP Enhancements:
- Introduced the concept of |lsp-handlers| which will allow much better
customization for users without having to copy & paste entire files /
functions / etc.
Diagnostic Enhancements:
- "goto next diagnostic" |vim.lsp.diagnostic.goto_next()|
- "goto prev diagnostic" |vim.lsp.diagnostic.goto_prev()|
- For each of the gotos, auto open diagnostics is available as a
configuration option
- Configurable diagnostic handling:
- See |vim.lsp.diagnostic.on_publish_diagnostics()|
- Delay display until after insert mode
- Configure signs
- Configure virtual text
- Configure underline
- Set the location list with the buffers diagnostics.
- See |vim.lsp.diagnostic.set_loclist()|
- Better performance for getting counts and line diagnostics
- They are now cached on save, to enhance lookups.
- Particularly useful for checking in statusline, etc.
- Actual testing :)
- See ./test/functional/plugin/lsp/diagnostic_spec.lua
- Added `guisp` for underline highlighting
NOTE: "a little while" means enough time to feel like most plugins and
plugin authors have had a chance to refactor their code to use the
updated calls. Then we will remove them completely. There is no need to
keep them, because we don't have any released version of neovim that
exposes these APIs. I'm trying to be nice to people following HEAD :)
Co-authored: [Twitch Chat 2020](https://twitch.tv/teej_dv)
2020-11-12 20:21:34 -07:00
|
|
|
fn(client, client_id, bufnr)
|
2019-11-13 13:55:26 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-07-18 07:42:30 -07:00
|
|
|
--- Error codes to be used with `on_error` from |vim.lsp.start_client|.
|
|
|
|
--- Can be used to look up the string from a the number or the number
|
|
|
|
--- from the string.
|
|
|
|
--- @nodoc
|
2019-11-13 13:55:26 -07:00
|
|
|
lsp.client_errors = tbl_extend(
|
|
|
|
'error',
|
2024-01-22 10:23:28 -07:00
|
|
|
lsp.rpc.client_errors,
|
2019-11-13 13:55:26 -07:00
|
|
|
vim.tbl_add_reverse_lookup({
|
2024-01-22 10:23:28 -07:00
|
|
|
BEFORE_INIT_CALLBACK_ERROR = table.maxn(lsp.rpc.client_errors) + 1,
|
|
|
|
ON_INIT_CALLBACK_ERROR = table.maxn(lsp.rpc.client_errors) + 2,
|
|
|
|
ON_ATTACH_ERROR = table.maxn(lsp.rpc.client_errors) + 3,
|
2019-11-13 13:55:26 -07:00
|
|
|
})
|
2022-05-09 02:23:51 -07:00
|
|
|
)
|
2019-11-13 13:55:26 -07:00
|
|
|
|
2020-08-19 09:17:08 -07:00
|
|
|
--- Normalizes {encoding} to valid LSP encoding names.
|
|
|
|
---
|
2021-08-22 13:55:28 -07:00
|
|
|
---@param encoding (string) Encoding to normalize
|
2023-02-25 10:47:05 -07:00
|
|
|
---@return string # normalized encoding name
|
2019-11-13 13:55:26 -07:00
|
|
|
local function validate_encoding(encoding)
|
|
|
|
validate({
|
|
|
|
encoding = { encoding, 's' },
|
|
|
|
})
|
|
|
|
return valid_encodings[encoding:lower()]
|
|
|
|
or error(
|
|
|
|
string.format(
|
|
|
|
"Invalid offset encoding %q. Must be one of: 'utf-8', 'utf-16', 'utf-32'",
|
|
|
|
encoding
|
|
|
|
)
|
2022-07-07 09:27:18 -07:00
|
|
|
)
|
2019-11-13 13:55:26 -07:00
|
|
|
end
|
|
|
|
|
2021-08-22 13:55:28 -07:00
|
|
|
---@internal
|
2020-08-19 09:17:08 -07:00
|
|
|
--- Parses a command invocation into the command itself and its args. If there
|
|
|
|
--- are no arguments, an empty table is returned as the second argument.
|
|
|
|
---
|
2023-02-25 10:47:05 -07:00
|
|
|
---@param input string[]
|
|
|
|
---@return string command, string[] args #the command and arguments
|
2020-02-11 22:48:25 -07:00
|
|
|
function lsp._cmd_parts(input)
|
2022-07-09 16:57:35 -07:00
|
|
|
validate({
|
2020-05-26 05:55:45 -07:00
|
|
|
cmd = {
|
|
|
|
input,
|
|
|
|
function()
|
|
|
|
return vim.tbl_islist(input)
|
|
|
|
end,
|
|
|
|
'list',
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
local cmd = input[1]
|
|
|
|
local cmd_args = {}
|
|
|
|
-- Don't mutate our input.
|
|
|
|
for i, v in ipairs(input) do
|
2022-07-09 16:57:35 -07:00
|
|
|
validate({ ['cmd argument'] = { v, 's' } })
|
2020-05-26 05:55:45 -07:00
|
|
|
if i > 1 then
|
|
|
|
table.insert(cmd_args, v)
|
2019-11-13 13:55:26 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
return cmd, cmd_args
|
|
|
|
end
|
|
|
|
|
2020-08-19 09:17:08 -07:00
|
|
|
--- Augments a validator function with support for optional (nil) values.
|
|
|
|
---
|
2023-02-25 10:47:05 -07:00
|
|
|
---@param fn (fun(v): boolean) The original validator function; should return a
|
2020-08-19 09:17:08 -07:00
|
|
|
---bool.
|
2023-02-25 10:47:05 -07:00
|
|
|
---@return fun(v): boolean # The augmented function. Also returns true if {v} is
|
2020-08-19 09:17:08 -07:00
|
|
|
---`nil`.
|
2019-11-13 13:55:26 -07:00
|
|
|
local function optional_validator(fn)
|
|
|
|
return function(v)
|
|
|
|
return v == nil or fn(v)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-08-19 09:17:08 -07:00
|
|
|
--- Validates a client configuration as given to |vim.lsp.start_client()|.
|
|
|
|
---
|
2023-06-07 05:39:41 -07:00
|
|
|
---@param config (lsp.ClientConfig)
|
2024-01-09 16:04:27 -07:00
|
|
|
---@return (string|fun(dispatchers:vim.rpc.Dispatchers):vim.lsp.rpc.PublicClient?) Command
|
2023-06-07 05:39:41 -07:00
|
|
|
---@return string[] Arguments
|
|
|
|
---@return string Encoding.
|
2019-11-13 13:55:26 -07:00
|
|
|
local function validate_client_config(config)
|
|
|
|
validate({
|
|
|
|
config = { config, 't' },
|
|
|
|
})
|
|
|
|
validate({
|
lsp: vim.lsp.diagnostic (#12655)
Breaking Changes:
- Deprecated all `vim.lsp.util.{*diagnostics*}()` functions.
- Instead, all functions must be found in vim.lsp.diagnostic
- For now, they issue a warning ONCE per neovim session. In a
"little while" we will remove them completely.
- `vim.lsp.callbacks` has moved to `vim.lsp.handlers`.
- For a "little while" we will just redirect `vim.lsp.callbacks` to
`vim.lsp.handlers`. However, we will remove this at some point, so
it is recommended that you change all of your references to
`callbacks` into `handlers`.
- This also means that for functions like |vim.lsp.start_client()|
and similar, keyword style arguments have moved from "callbacks"
to "handlers". Once again, these are currently being forward, but
will cease to be forwarded in a "little while".
- Changed the highlight groups for LspDiagnostic highlight as they were
inconsistently named.
- For more information, see |lsp-highlight-diagnostics|
- Changed the sign group names as well, to be consistent with
|lsp-highlight-diagnostics|
General Enhancements:
- Rewrote much of the getting started help document for lsp. It also
provides a much nicer configuration strategy, so as to not recommend
globally overwriting builtin neovim mappings.
LSP Enhancements:
- Introduced the concept of |lsp-handlers| which will allow much better
customization for users without having to copy & paste entire files /
functions / etc.
Diagnostic Enhancements:
- "goto next diagnostic" |vim.lsp.diagnostic.goto_next()|
- "goto prev diagnostic" |vim.lsp.diagnostic.goto_prev()|
- For each of the gotos, auto open diagnostics is available as a
configuration option
- Configurable diagnostic handling:
- See |vim.lsp.diagnostic.on_publish_diagnostics()|
- Delay display until after insert mode
- Configure signs
- Configure virtual text
- Configure underline
- Set the location list with the buffers diagnostics.
- See |vim.lsp.diagnostic.set_loclist()|
- Better performance for getting counts and line diagnostics
- They are now cached on save, to enhance lookups.
- Particularly useful for checking in statusline, etc.
- Actual testing :)
- See ./test/functional/plugin/lsp/diagnostic_spec.lua
- Added `guisp` for underline highlighting
NOTE: "a little while" means enough time to feel like most plugins and
plugin authors have had a chance to refactor their code to use the
updated calls. Then we will remove them completely. There is no need to
keep them, because we don't have any released version of neovim that
exposes these APIs. I'm trying to be nice to people following HEAD :)
Co-authored: [Twitch Chat 2020](https://twitch.tv/teej_dv)
2020-11-12 20:21:34 -07:00
|
|
|
handlers = { config.handlers, 't', true },
|
2019-11-13 13:55:26 -07:00
|
|
|
capabilities = { config.capabilities, 't', true },
|
|
|
|
cmd_cwd = { config.cmd_cwd, optional_validator(is_dir), 'directory' },
|
2020-02-08 18:25:53 -07:00
|
|
|
cmd_env = { config.cmd_env, 't', true },
|
2022-05-08 12:00:30 -07:00
|
|
|
detached = { config.detached, 'b', true },
|
2019-11-13 13:55:26 -07:00
|
|
|
name = { config.name, 's', true },
|
|
|
|
on_error = { config.on_error, 'f', true },
|
|
|
|
on_exit = { config.on_exit, 'f', true },
|
|
|
|
on_init = { config.on_init, 'f', true },
|
2021-01-18 12:11:37 -07:00
|
|
|
settings = { config.settings, 't', true },
|
2021-11-01 03:14:59 -07:00
|
|
|
commands = { config.commands, 't', true },
|
2019-11-21 16:19:06 -07:00
|
|
|
before_init = { config.before_init, 'f', true },
|
2019-11-13 13:55:26 -07:00
|
|
|
offset_encoding = { config.offset_encoding, 's', true },
|
2020-12-08 19:09:33 -07:00
|
|
|
flags = { config.flags, 't', true },
|
2021-03-10 14:53:23 -07:00
|
|
|
get_language_id = { config.get_language_id, 'f', true },
|
2019-11-13 13:55:26 -07:00
|
|
|
})
|
2021-03-12 07:01:41 -07:00
|
|
|
assert(
|
|
|
|
(
|
|
|
|
not config.flags
|
|
|
|
or not config.flags.debounce_text_changes
|
|
|
|
or type(config.flags.debounce_text_changes) == 'number'
|
|
|
|
),
|
2022-01-05 09:36:35 -07:00
|
|
|
'flags.debounce_text_changes must be a number with the debounce time in milliseconds'
|
2021-03-12 07:01:41 -07:00
|
|
|
)
|
lsp: vim.lsp.diagnostic (#12655)
Breaking Changes:
- Deprecated all `vim.lsp.util.{*diagnostics*}()` functions.
- Instead, all functions must be found in vim.lsp.diagnostic
- For now, they issue a warning ONCE per neovim session. In a
"little while" we will remove them completely.
- `vim.lsp.callbacks` has moved to `vim.lsp.handlers`.
- For a "little while" we will just redirect `vim.lsp.callbacks` to
`vim.lsp.handlers`. However, we will remove this at some point, so
it is recommended that you change all of your references to
`callbacks` into `handlers`.
- This also means that for functions like |vim.lsp.start_client()|
and similar, keyword style arguments have moved from "callbacks"
to "handlers". Once again, these are currently being forward, but
will cease to be forwarded in a "little while".
- Changed the highlight groups for LspDiagnostic highlight as they were
inconsistently named.
- For more information, see |lsp-highlight-diagnostics|
- Changed the sign group names as well, to be consistent with
|lsp-highlight-diagnostics|
General Enhancements:
- Rewrote much of the getting started help document for lsp. It also
provides a much nicer configuration strategy, so as to not recommend
globally overwriting builtin neovim mappings.
LSP Enhancements:
- Introduced the concept of |lsp-handlers| which will allow much better
customization for users without having to copy & paste entire files /
functions / etc.
Diagnostic Enhancements:
- "goto next diagnostic" |vim.lsp.diagnostic.goto_next()|
- "goto prev diagnostic" |vim.lsp.diagnostic.goto_prev()|
- For each of the gotos, auto open diagnostics is available as a
configuration option
- Configurable diagnostic handling:
- See |vim.lsp.diagnostic.on_publish_diagnostics()|
- Delay display until after insert mode
- Configure signs
- Configure virtual text
- Configure underline
- Set the location list with the buffers diagnostics.
- See |vim.lsp.diagnostic.set_loclist()|
- Better performance for getting counts and line diagnostics
- They are now cached on save, to enhance lookups.
- Particularly useful for checking in statusline, etc.
- Actual testing :)
- See ./test/functional/plugin/lsp/diagnostic_spec.lua
- Added `guisp` for underline highlighting
NOTE: "a little while" means enough time to feel like most plugins and
plugin authors have had a chance to refactor their code to use the
updated calls. Then we will remove them completely. There is no need to
keep them, because we don't have any released version of neovim that
exposes these APIs. I'm trying to be nice to people following HEAD :)
Co-authored: [Twitch Chat 2020](https://twitch.tv/teej_dv)
2020-11-12 20:21:34 -07:00
|
|
|
|
2024-01-09 16:04:27 -07:00
|
|
|
local cmd, cmd_args --- @type (string|fun(dispatchers:vim.rpc.Dispatchers):vim.lsp.rpc.PublicClient), string[]
|
2023-06-07 05:39:41 -07:00
|
|
|
local config_cmd = config.cmd
|
|
|
|
if type(config_cmd) == 'function' then
|
|
|
|
cmd = config_cmd
|
2022-08-24 11:25:34 -07:00
|
|
|
else
|
2023-06-07 05:39:41 -07:00
|
|
|
cmd, cmd_args = lsp._cmd_parts(config_cmd)
|
2022-08-24 11:25:34 -07:00
|
|
|
end
|
2019-11-13 13:55:26 -07:00
|
|
|
local offset_encoding = valid_encodings.UTF16
|
|
|
|
if config.offset_encoding then
|
|
|
|
offset_encoding = validate_encoding(config.offset_encoding)
|
|
|
|
end
|
lsp: vim.lsp.diagnostic (#12655)
Breaking Changes:
- Deprecated all `vim.lsp.util.{*diagnostics*}()` functions.
- Instead, all functions must be found in vim.lsp.diagnostic
- For now, they issue a warning ONCE per neovim session. In a
"little while" we will remove them completely.
- `vim.lsp.callbacks` has moved to `vim.lsp.handlers`.
- For a "little while" we will just redirect `vim.lsp.callbacks` to
`vim.lsp.handlers`. However, we will remove this at some point, so
it is recommended that you change all of your references to
`callbacks` into `handlers`.
- This also means that for functions like |vim.lsp.start_client()|
and similar, keyword style arguments have moved from "callbacks"
to "handlers". Once again, these are currently being forward, but
will cease to be forwarded in a "little while".
- Changed the highlight groups for LspDiagnostic highlight as they were
inconsistently named.
- For more information, see |lsp-highlight-diagnostics|
- Changed the sign group names as well, to be consistent with
|lsp-highlight-diagnostics|
General Enhancements:
- Rewrote much of the getting started help document for lsp. It also
provides a much nicer configuration strategy, so as to not recommend
globally overwriting builtin neovim mappings.
LSP Enhancements:
- Introduced the concept of |lsp-handlers| which will allow much better
customization for users without having to copy & paste entire files /
functions / etc.
Diagnostic Enhancements:
- "goto next diagnostic" |vim.lsp.diagnostic.goto_next()|
- "goto prev diagnostic" |vim.lsp.diagnostic.goto_prev()|
- For each of the gotos, auto open diagnostics is available as a
configuration option
- Configurable diagnostic handling:
- See |vim.lsp.diagnostic.on_publish_diagnostics()|
- Delay display until after insert mode
- Configure signs
- Configure virtual text
- Configure underline
- Set the location list with the buffers diagnostics.
- See |vim.lsp.diagnostic.set_loclist()|
- Better performance for getting counts and line diagnostics
- They are now cached on save, to enhance lookups.
- Particularly useful for checking in statusline, etc.
- Actual testing :)
- See ./test/functional/plugin/lsp/diagnostic_spec.lua
- Added `guisp` for underline highlighting
NOTE: "a little while" means enough time to feel like most plugins and
plugin authors have had a chance to refactor their code to use the
updated calls. Then we will remove them completely. There is no need to
keep them, because we don't have any released version of neovim that
exposes these APIs. I'm trying to be nice to people following HEAD :)
Co-authored: [Twitch Chat 2020](https://twitch.tv/teej_dv)
2020-11-12 20:21:34 -07:00
|
|
|
|
2023-06-07 05:39:41 -07:00
|
|
|
return cmd, cmd_args, offset_encoding
|
2019-11-13 13:55:26 -07:00
|
|
|
end
|
|
|
|
|
2023-12-17 02:54:38 -07:00
|
|
|
---@private
|
2020-08-19 09:17:08 -07:00
|
|
|
--- Returns full text of buffer {bufnr} as a string.
|
|
|
|
---
|
2021-08-22 13:55:28 -07:00
|
|
|
---@param bufnr (number) Buffer handle, or 0 for current.
|
2023-02-25 10:47:05 -07:00
|
|
|
---@return string # Buffer text as string.
|
2023-12-17 02:54:38 -07:00
|
|
|
function lsp._buf_get_full_text(bufnr)
|
|
|
|
local line_ending = lsp._buf_get_line_ending(bufnr)
|
2021-11-21 10:03:45 -07:00
|
|
|
local text = table.concat(nvim_buf_get_lines(bufnr, 0, -1, true), line_ending)
|
2022-12-19 09:37:45 -07:00
|
|
|
if vim.bo[bufnr].eol then
|
2021-11-21 10:03:45 -07:00
|
|
|
text = text .. line_ending
|
2019-11-21 02:29:54 -07:00
|
|
|
end
|
|
|
|
return text
|
|
|
|
end
|
|
|
|
|
2021-03-12 07:01:41 -07:00
|
|
|
--- Memoizes a function. On first run, the function return value is saved and
|
2021-04-15 04:42:25 -07:00
|
|
|
--- immediately returned on subsequent runs. If the function returns a multival,
|
|
|
|
--- only the first returned value will be memoized and returned. The function will only be run once,
|
|
|
|
--- even if it has side effects.
|
2021-03-12 07:01:41 -07:00
|
|
|
---
|
2023-06-07 05:39:41 -07:00
|
|
|
---@generic T: function
|
|
|
|
---@param fn (T) Function to run
|
|
|
|
---@return T
|
2021-03-12 07:01:41 -07:00
|
|
|
local function once(fn)
|
2023-12-13 06:04:24 -07:00
|
|
|
local value --- @type function
|
2021-04-15 04:42:25 -07:00
|
|
|
local ran = false
|
2021-03-12 07:01:41 -07:00
|
|
|
return function(...)
|
2021-04-15 04:42:25 -07:00
|
|
|
if not ran then
|
2023-12-13 06:04:24 -07:00
|
|
|
value = fn(...) --- @type function
|
2021-04-15 04:42:25 -07:00
|
|
|
ran = true
|
|
|
|
end
|
2021-03-12 07:01:41 -07:00
|
|
|
return value
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-08-19 09:17:08 -07:00
|
|
|
--- Default handler for the 'textDocument/didOpen' LSP notification.
|
|
|
|
---
|
2023-03-06 23:17:52 -07:00
|
|
|
---@param bufnr integer Number of the buffer, or 0 for current
|
2023-12-13 05:00:11 -07:00
|
|
|
---@param client lsp.Client Client object
|
2019-11-13 13:55:26 -07:00
|
|
|
local function text_document_did_open_handler(bufnr, client)
|
2021-03-12 07:01:41 -07:00
|
|
|
changetracking.init(client, bufnr)
|
2022-04-30 02:22:30 -07:00
|
|
|
if not vim.tbl_get(client.server_capabilities, 'textDocumentSync', 'openClose') then
|
2019-11-13 13:55:26 -07:00
|
|
|
return
|
|
|
|
end
|
2022-07-15 09:26:47 -07:00
|
|
|
if not api.nvim_buf_is_loaded(bufnr) then
|
2019-11-13 13:55:26 -07:00
|
|
|
return
|
|
|
|
end
|
2022-12-19 09:37:45 -07:00
|
|
|
local filetype = vim.bo[bufnr].filetype
|
2023-03-10 23:35:23 -07:00
|
|
|
|
2019-11-13 13:55:26 -07:00
|
|
|
local params = {
|
|
|
|
textDocument = {
|
|
|
|
version = 0,
|
2023-03-10 23:35:23 -07:00
|
|
|
uri = vim.uri_from_bufnr(bufnr),
|
2021-03-10 14:53:23 -07:00
|
|
|
languageId = client.config.get_language_id(bufnr, filetype),
|
2023-12-17 02:54:38 -07:00
|
|
|
text = lsp._buf_get_full_text(bufnr),
|
2019-11-13 13:55:26 -07:00
|
|
|
},
|
|
|
|
}
|
2023-08-03 04:03:48 -07:00
|
|
|
client.notify(ms.textDocument_didOpen, params)
|
2020-04-25 05:58:35 -07:00
|
|
|
util.buf_versions[bufnr] = params.textDocument.version
|
2021-03-22 07:21:56 -07:00
|
|
|
|
|
|
|
-- Next chance we get, we should re-do the diagnostics
|
|
|
|
vim.schedule(function()
|
2021-11-14 04:55:16 -07:00
|
|
|
-- Protect against a race where the buffer disappears
|
|
|
|
-- between `did_open_handler` and the scheduled function firing.
|
2022-07-15 09:26:47 -07:00
|
|
|
if api.nvim_buf_is_valid(bufnr) then
|
2021-12-07 10:25:21 -07:00
|
|
|
local namespace = vim.lsp.diagnostic.get_namespace(client.id)
|
|
|
|
vim.diagnostic.show(namespace, bufnr)
|
2021-11-14 04:55:16 -07:00
|
|
|
end
|
2021-03-22 07:21:56 -07:00
|
|
|
end)
|
2019-11-13 13:55:26 -07:00
|
|
|
end
|
|
|
|
|
2020-08-23 04:28:56 -07:00
|
|
|
-- FIXME: DOC: Shouldn't need to use a dummy function
|
|
|
|
--
|
2020-08-19 09:17:08 -07:00
|
|
|
--- LSP client object. You can get an active client object via
|
2023-07-17 09:27:16 -07:00
|
|
|
--- |vim.lsp.get_client_by_id()| or |vim.lsp.get_clients()|.
|
2019-12-31 07:52:14 -07:00
|
|
|
---
|
|
|
|
--- - Methods:
|
|
|
|
---
|
lsp: vim.lsp.diagnostic (#12655)
Breaking Changes:
- Deprecated all `vim.lsp.util.{*diagnostics*}()` functions.
- Instead, all functions must be found in vim.lsp.diagnostic
- For now, they issue a warning ONCE per neovim session. In a
"little while" we will remove them completely.
- `vim.lsp.callbacks` has moved to `vim.lsp.handlers`.
- For a "little while" we will just redirect `vim.lsp.callbacks` to
`vim.lsp.handlers`. However, we will remove this at some point, so
it is recommended that you change all of your references to
`callbacks` into `handlers`.
- This also means that for functions like |vim.lsp.start_client()|
and similar, keyword style arguments have moved from "callbacks"
to "handlers". Once again, these are currently being forward, but
will cease to be forwarded in a "little while".
- Changed the highlight groups for LspDiagnostic highlight as they were
inconsistently named.
- For more information, see |lsp-highlight-diagnostics|
- Changed the sign group names as well, to be consistent with
|lsp-highlight-diagnostics|
General Enhancements:
- Rewrote much of the getting started help document for lsp. It also
provides a much nicer configuration strategy, so as to not recommend
globally overwriting builtin neovim mappings.
LSP Enhancements:
- Introduced the concept of |lsp-handlers| which will allow much better
customization for users without having to copy & paste entire files /
functions / etc.
Diagnostic Enhancements:
- "goto next diagnostic" |vim.lsp.diagnostic.goto_next()|
- "goto prev diagnostic" |vim.lsp.diagnostic.goto_prev()|
- For each of the gotos, auto open diagnostics is available as a
configuration option
- Configurable diagnostic handling:
- See |vim.lsp.diagnostic.on_publish_diagnostics()|
- Delay display until after insert mode
- Configure signs
- Configure virtual text
- Configure underline
- Set the location list with the buffers diagnostics.
- See |vim.lsp.diagnostic.set_loclist()|
- Better performance for getting counts and line diagnostics
- They are now cached on save, to enhance lookups.
- Particularly useful for checking in statusline, etc.
- Actual testing :)
- See ./test/functional/plugin/lsp/diagnostic_spec.lua
- Added `guisp` for underline highlighting
NOTE: "a little while" means enough time to feel like most plugins and
plugin authors have had a chance to refactor their code to use the
updated calls. Then we will remove them completely. There is no need to
keep them, because we don't have any released version of neovim that
exposes these APIs. I'm trying to be nice to people following HEAD :)
Co-authored: [Twitch Chat 2020](https://twitch.tv/teej_dv)
2020-11-12 20:21:34 -07:00
|
|
|
--- - request(method, params, [handler], bufnr)
|
2020-08-19 09:17:08 -07:00
|
|
|
--- Sends a request to the server.
|
2019-12-31 07:52:14 -07:00
|
|
|
--- This is a thin wrapper around {client.rpc.request} with some additional
|
|
|
|
--- checking.
|
lsp: vim.lsp.diagnostic (#12655)
Breaking Changes:
- Deprecated all `vim.lsp.util.{*diagnostics*}()` functions.
- Instead, all functions must be found in vim.lsp.diagnostic
- For now, they issue a warning ONCE per neovim session. In a
"little while" we will remove them completely.
- `vim.lsp.callbacks` has moved to `vim.lsp.handlers`.
- For a "little while" we will just redirect `vim.lsp.callbacks` to
`vim.lsp.handlers`. However, we will remove this at some point, so
it is recommended that you change all of your references to
`callbacks` into `handlers`.
- This also means that for functions like |vim.lsp.start_client()|
and similar, keyword style arguments have moved from "callbacks"
to "handlers". Once again, these are currently being forward, but
will cease to be forwarded in a "little while".
- Changed the highlight groups for LspDiagnostic highlight as they were
inconsistently named.
- For more information, see |lsp-highlight-diagnostics|
- Changed the sign group names as well, to be consistent with
|lsp-highlight-diagnostics|
General Enhancements:
- Rewrote much of the getting started help document for lsp. It also
provides a much nicer configuration strategy, so as to not recommend
globally overwriting builtin neovim mappings.
LSP Enhancements:
- Introduced the concept of |lsp-handlers| which will allow much better
customization for users without having to copy & paste entire files /
functions / etc.
Diagnostic Enhancements:
- "goto next diagnostic" |vim.lsp.diagnostic.goto_next()|
- "goto prev diagnostic" |vim.lsp.diagnostic.goto_prev()|
- For each of the gotos, auto open diagnostics is available as a
configuration option
- Configurable diagnostic handling:
- See |vim.lsp.diagnostic.on_publish_diagnostics()|
- Delay display until after insert mode
- Configure signs
- Configure virtual text
- Configure underline
- Set the location list with the buffers diagnostics.
- See |vim.lsp.diagnostic.set_loclist()|
- Better performance for getting counts and line diagnostics
- They are now cached on save, to enhance lookups.
- Particularly useful for checking in statusline, etc.
- Actual testing :)
- See ./test/functional/plugin/lsp/diagnostic_spec.lua
- Added `guisp` for underline highlighting
NOTE: "a little while" means enough time to feel like most plugins and
plugin authors have had a chance to refactor their code to use the
updated calls. Then we will remove them completely. There is no need to
keep them, because we don't have any released version of neovim that
exposes these APIs. I'm trying to be nice to people following HEAD :)
Co-authored: [Twitch Chat 2020](https://twitch.tv/teej_dv)
2020-11-12 20:21:34 -07:00
|
|
|
--- If {handler} is not specified, If one is not found there, then an error will occur.
|
2020-08-19 09:17:08 -07:00
|
|
|
--- Returns: {status}, {[client_id]}. {status} is a boolean indicating if
|
|
|
|
--- the notification was successful. If it is `false`, then it will always
|
|
|
|
--- be `false` (the client has shutdown).
|
|
|
|
--- If {status} is `true`, the function returns {request_id} as the second
|
|
|
|
--- result. You can use this with `client.cancel_request(request_id)`
|
|
|
|
--- to cancel the request.
|
2019-12-31 07:52:14 -07:00
|
|
|
---
|
2021-05-02 07:24:58 -07:00
|
|
|
--- - request_sync(method, params, timeout_ms, bufnr)
|
|
|
|
--- Sends a request to the server and synchronously waits for the response.
|
|
|
|
--- This is a wrapper around {client.request}
|
|
|
|
--- Returns: { err=err, result=result }, a dictionary, where `err` and `result` come from
|
|
|
|
--- the |lsp-handler|. On timeout, cancel or error, returns `(nil, err)` where `err` is a
|
|
|
|
--- string describing the failure reason. If the request was unsuccessful returns `nil`.
|
|
|
|
---
|
2019-12-31 07:52:14 -07:00
|
|
|
--- - notify(method, params)
|
2020-08-19 09:17:08 -07:00
|
|
|
--- Sends a notification to an LSP server.
|
|
|
|
--- Returns: a boolean to indicate if the notification was successful. If
|
|
|
|
--- it is false, then it will always be false (the client has shutdown).
|
2019-12-31 07:52:14 -07:00
|
|
|
---
|
|
|
|
--- - cancel_request(id)
|
2020-08-19 09:17:08 -07:00
|
|
|
--- Cancels a request with a given request id.
|
|
|
|
--- Returns: same as `notify()`.
|
2019-12-31 07:52:14 -07:00
|
|
|
---
|
|
|
|
--- - stop([force])
|
2020-08-19 09:17:08 -07:00
|
|
|
--- Stops a client, optionally with force.
|
2019-12-31 07:52:14 -07:00
|
|
|
--- By default, it will just ask the server to shutdown without force.
|
|
|
|
--- If you request to stop a client which has previously been requested to
|
|
|
|
--- shutdown, it will automatically escalate and force shutdown.
|
|
|
|
---
|
|
|
|
--- - is_stopped()
|
2020-08-19 09:17:08 -07:00
|
|
|
--- Checks whether a client is stopped.
|
|
|
|
--- Returns: true if the client is fully stopped.
|
|
|
|
---
|
2021-01-12 14:47:34 -07:00
|
|
|
--- - on_attach(client, bufnr)
|
2020-08-19 09:17:08 -07:00
|
|
|
--- Runs the on_attach function from the client's config if it was defined.
|
2021-01-12 14:47:34 -07:00
|
|
|
--- Useful for buffer-local setup.
|
2019-12-31 07:52:14 -07:00
|
|
|
---
|
2024-01-02 10:52:29 -07:00
|
|
|
--- - supports_method(method, [opts]): boolean
|
|
|
|
--- Checks if a client supports a given method.
|
|
|
|
--- Always returns true for unknown off-spec methods.
|
|
|
|
--- [opts] is a optional `{bufnr?: integer}` table.
|
|
|
|
--- Some language server capabilities can be file specific.
|
|
|
|
---
|
2019-12-31 07:52:14 -07:00
|
|
|
--- - Members
|
2020-08-19 09:17:08 -07:00
|
|
|
--- - {id} (number): The id allocated to the client.
|
2019-12-31 07:52:14 -07:00
|
|
|
---
|
2020-08-19 09:17:08 -07:00
|
|
|
--- - {name} (string): If a name is specified on creation, that will be
|
2019-12-31 07:52:14 -07:00
|
|
|
--- used. Otherwise it is just the client id. This is used for
|
|
|
|
--- logs and messages.
|
|
|
|
---
|
2020-08-19 09:17:08 -07:00
|
|
|
--- - {rpc} (table): RPC client object, for low level interaction with the
|
|
|
|
--- client. See |vim.lsp.rpc.start()|.
|
|
|
|
---
|
|
|
|
--- - {offset_encoding} (string): The encoding used for communicating
|
|
|
|
--- with the server. You can modify this in the `config`'s `on_init` method
|
2019-12-31 07:52:14 -07:00
|
|
|
--- before text is sent to the server.
|
|
|
|
---
|
lsp: vim.lsp.diagnostic (#12655)
Breaking Changes:
- Deprecated all `vim.lsp.util.{*diagnostics*}()` functions.
- Instead, all functions must be found in vim.lsp.diagnostic
- For now, they issue a warning ONCE per neovim session. In a
"little while" we will remove them completely.
- `vim.lsp.callbacks` has moved to `vim.lsp.handlers`.
- For a "little while" we will just redirect `vim.lsp.callbacks` to
`vim.lsp.handlers`. However, we will remove this at some point, so
it is recommended that you change all of your references to
`callbacks` into `handlers`.
- This also means that for functions like |vim.lsp.start_client()|
and similar, keyword style arguments have moved from "callbacks"
to "handlers". Once again, these are currently being forward, but
will cease to be forwarded in a "little while".
- Changed the highlight groups for LspDiagnostic highlight as they were
inconsistently named.
- For more information, see |lsp-highlight-diagnostics|
- Changed the sign group names as well, to be consistent with
|lsp-highlight-diagnostics|
General Enhancements:
- Rewrote much of the getting started help document for lsp. It also
provides a much nicer configuration strategy, so as to not recommend
globally overwriting builtin neovim mappings.
LSP Enhancements:
- Introduced the concept of |lsp-handlers| which will allow much better
customization for users without having to copy & paste entire files /
functions / etc.
Diagnostic Enhancements:
- "goto next diagnostic" |vim.lsp.diagnostic.goto_next()|
- "goto prev diagnostic" |vim.lsp.diagnostic.goto_prev()|
- For each of the gotos, auto open diagnostics is available as a
configuration option
- Configurable diagnostic handling:
- See |vim.lsp.diagnostic.on_publish_diagnostics()|
- Delay display until after insert mode
- Configure signs
- Configure virtual text
- Configure underline
- Set the location list with the buffers diagnostics.
- See |vim.lsp.diagnostic.set_loclist()|
- Better performance for getting counts and line diagnostics
- They are now cached on save, to enhance lookups.
- Particularly useful for checking in statusline, etc.
- Actual testing :)
- See ./test/functional/plugin/lsp/diagnostic_spec.lua
- Added `guisp` for underline highlighting
NOTE: "a little while" means enough time to feel like most plugins and
plugin authors have had a chance to refactor their code to use the
updated calls. Then we will remove them completely. There is no need to
keep them, because we don't have any released version of neovim that
exposes these APIs. I'm trying to be nice to people following HEAD :)
Co-authored: [Twitch Chat 2020](https://twitch.tv/teej_dv)
2020-11-12 20:21:34 -07:00
|
|
|
--- - {handlers} (table): The handlers used by the client as described in |lsp-handler|.
|
2019-12-31 07:52:14 -07:00
|
|
|
---
|
2021-12-05 06:04:53 -07:00
|
|
|
--- - {requests} (table): 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"
|
2023-05-30 11:56:29 -07:00
|
|
|
--- 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.
|
2021-12-05 06:04:53 -07:00
|
|
|
---
|
2020-08-19 09:17:08 -07:00
|
|
|
--- - {config} (table): copy of the table that was passed by the user
|
2019-12-31 07:52:14 -07:00
|
|
|
--- to |vim.lsp.start_client()|.
|
|
|
|
---
|
2020-08-19 09:17:08 -07:00
|
|
|
--- - {server_capabilities} (table): Response from the server sent on
|
2019-12-31 07:52:14 -07:00
|
|
|
--- `initialize` describing the server's capabilities.
|
2023-06-09 02:32:43 -07:00
|
|
|
---
|
|
|
|
--- - {progress} A ring buffer (|vim.ringbuf()|) containing progress messages
|
|
|
|
--- sent by the server.
|
2019-12-31 07:52:14 -07:00
|
|
|
function lsp.client()
|
|
|
|
error()
|
|
|
|
end
|
2019-11-13 13:55:26 -07:00
|
|
|
|
2023-06-07 05:39:41 -07:00
|
|
|
--- @class lsp.StartOpts
|
|
|
|
--- @field reuse_client fun(client: lsp.Client, config: table): boolean
|
|
|
|
--- @field bufnr integer
|
|
|
|
|
2022-06-03 05:59:19 -07:00
|
|
|
--- 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`.
|
|
|
|
--- Attaches the current buffer to the client.
|
|
|
|
---
|
|
|
|
--- Example:
|
2023-09-14 06:23:01 -07:00
|
|
|
---
|
|
|
|
--- ```lua
|
2022-06-03 05:59:19 -07:00
|
|
|
--- vim.lsp.start({
|
|
|
|
--- name = 'my-server-name',
|
|
|
|
--- cmd = {'name-of-language-server-executable'},
|
|
|
|
--- root_dir = vim.fs.dirname(vim.fs.find({'pyproject.toml', 'setup.py'}, { upward = true })[1]),
|
|
|
|
--- })
|
2023-09-14 06:23:01 -07:00
|
|
|
--- ```
|
2022-06-03 05:59:19 -07:00
|
|
|
---
|
2022-09-25 16:58:27 -07:00
|
|
|
--- See |vim.lsp.start_client()| for all available options. The most important are:
|
2022-06-03 05:59:19 -07:00
|
|
|
---
|
2022-10-14 08:01:13 -07:00
|
|
|
--- - `name` arbitrary name for the LSP client. Should be unique per language server.
|
2024-01-18 01:14:48 -07:00
|
|
|
--- - `cmd` command string[] or function, described at |vim.lsp.start_client()|.
|
2022-10-14 08:01:13 -07:00
|
|
|
--- - `root_dir` path to the project root. By default this is used to decide if an existing client
|
|
|
|
--- should be re-used. The example above uses |vim.fs.find()| and |vim.fs.dirname()| to detect the
|
|
|
|
--- root by traversing the file system upwards starting from the current directory until either
|
|
|
|
--- a `pyproject.toml` or `setup.py` file is found.
|
|
|
|
--- - `workspace_folders` list of `{ uri:string, name: string }` tables specifying the project root
|
|
|
|
--- folders used by the language server. If `nil` the property is derived from `root_dir` for
|
|
|
|
--- convenience.
|
2022-06-03 05:59:19 -07:00
|
|
|
---
|
|
|
|
--- Language servers use this information to discover metadata like the
|
|
|
|
--- dependencies of your project and they tend to index the contents within the
|
|
|
|
--- project folder.
|
|
|
|
---
|
|
|
|
---
|
|
|
|
--- To ensure a language server is only started for languages it can handle,
|
2022-09-25 16:58:27 -07:00
|
|
|
--- make sure to call |vim.lsp.start()| within a |FileType| autocmd.
|
2022-06-03 05:59:19 -07:00
|
|
|
--- Either use |:au|, |nvim_create_autocmd()| or put the call in a
|
|
|
|
--- `ftplugin/<filetype_name>.lua` (See |ftplugin-name|)
|
|
|
|
---
|
2022-09-25 16:58:27 -07:00
|
|
|
---@param config table Same configuration as documented in |vim.lsp.start_client()|
|
2023-06-07 05:39:41 -07:00
|
|
|
---@param opts (nil|lsp.StartOpts) Optional keyword arguments:
|
2022-06-03 05:59:19 -07:00
|
|
|
--- - reuse_client (fun(client: client, config: table): 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.
|
2022-10-04 11:44:19 -07:00
|
|
|
--- - bufnr (number)
|
|
|
|
--- Buffer handle to attach to if starting or re-using a
|
|
|
|
--- client (0 for current).
|
2023-06-07 05:39:41 -07:00
|
|
|
---@return integer|nil client_id
|
2022-06-03 05:59:19 -07:00
|
|
|
function lsp.start(config, opts)
|
|
|
|
opts = opts or {}
|
|
|
|
local reuse_client = opts.reuse_client
|
|
|
|
or function(client, conf)
|
|
|
|
return client.config.root_dir == conf.root_dir and client.name == conf.name
|
|
|
|
end
|
2022-08-24 11:25:34 -07:00
|
|
|
if not config.name and type(config.cmd) == 'table' then
|
|
|
|
config.name = config.cmd[1] and vim.fs.basename(config.cmd[1]) or nil
|
|
|
|
end
|
2022-10-04 11:44:19 -07:00
|
|
|
local bufnr = opts.bufnr
|
|
|
|
if bufnr == nil or bufnr == 0 then
|
|
|
|
bufnr = api.nvim_get_current_buf()
|
|
|
|
end
|
2023-07-17 09:27:16 -07:00
|
|
|
for _, clients in ipairs({ uninitialized_clients, lsp.get_clients() }) do
|
2022-07-12 00:44:11 -07:00
|
|
|
for _, client in pairs(clients) do
|
|
|
|
if reuse_client(client, config) then
|
|
|
|
lsp.buf_attach_client(bufnr, client.id)
|
|
|
|
return client.id
|
|
|
|
end
|
2022-06-03 05:59:19 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
local client_id = lsp.start_client(config)
|
2022-07-11 18:37:01 -07:00
|
|
|
if client_id == nil then
|
|
|
|
return nil -- lsp.start_client will have printed an error
|
|
|
|
end
|
2022-06-03 05:59:19 -07:00
|
|
|
lsp.buf_attach_client(bufnr, client_id)
|
|
|
|
return client_id
|
|
|
|
end
|
|
|
|
|
2023-06-09 02:32:43 -07:00
|
|
|
--- Consumes the latest progress messages from all clients and formats them as a string.
|
|
|
|
--- Empty if there are no clients or if no new messages
|
|
|
|
---
|
|
|
|
---@return string
|
|
|
|
function lsp.status()
|
|
|
|
local percentage = nil
|
2023-12-13 05:00:11 -07:00
|
|
|
local messages = {} --- @type string[]
|
2023-07-17 09:27:16 -07:00
|
|
|
for _, client in ipairs(vim.lsp.get_clients()) do
|
2023-06-09 02:32:43 -07:00
|
|
|
for progress in client.progress do
|
|
|
|
local value = progress.value
|
|
|
|
if type(value) == 'table' and value.kind then
|
2023-06-22 01:18:49 -07:00
|
|
|
local message = value.message and (value.title .. ': ' .. value.message) or value.title
|
|
|
|
messages[#messages + 1] = message
|
2023-06-09 02:32:43 -07:00
|
|
|
if value.percentage then
|
|
|
|
percentage = math.max(percentage or 0, value.percentage)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
-- else: Doesn't look like work done progress and can be in any format
|
|
|
|
-- Just ignore it as there is no sensible way to display it
|
|
|
|
end
|
|
|
|
end
|
|
|
|
local message = table.concat(messages, ', ')
|
|
|
|
if percentage then
|
2023-06-10 11:32:41 -07:00
|
|
|
return string.format('%3d%%: %s', percentage, message)
|
2023-06-09 02:32:43 -07:00
|
|
|
end
|
|
|
|
return message
|
|
|
|
end
|
|
|
|
|
2023-05-27 22:51:28 -07:00
|
|
|
-- Determines whether the given option can be set by `set_defaults`.
|
2023-12-13 05:00:11 -07:00
|
|
|
---@param bufnr integer
|
|
|
|
---@param option string
|
|
|
|
---@return boolean
|
2023-05-27 22:51:28 -07:00
|
|
|
local function is_empty_or_default(bufnr, option)
|
|
|
|
if vim.bo[bufnr][option] == '' then
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2023-12-13 05:00:11 -07:00
|
|
|
local info = api.nvim_get_option_info2(option, { buf = bufnr })
|
2023-05-27 22:51:28 -07:00
|
|
|
local scriptinfo = vim.tbl_filter(function(e)
|
|
|
|
return e.sid == info.last_set_sid
|
|
|
|
end, vim.fn.getscriptinfo())
|
|
|
|
|
|
|
|
if #scriptinfo ~= 1 then
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
|
|
|
return vim.startswith(scriptinfo[1].name, vim.fn.expand('$VIMRUNTIME'))
|
|
|
|
end
|
|
|
|
|
|
|
|
---@private
|
|
|
|
---@param client lsp.Client
|
2023-12-13 05:00:11 -07:00
|
|
|
---@param bufnr integer
|
2023-05-27 22:51:28 -07:00
|
|
|
function lsp._set_defaults(client, bufnr)
|
|
|
|
if
|
2023-08-03 04:03:48 -07:00
|
|
|
client.supports_method(ms.textDocument_definition) and is_empty_or_default(bufnr, 'tagfunc')
|
2023-05-27 22:51:28 -07:00
|
|
|
then
|
|
|
|
vim.bo[bufnr].tagfunc = 'v:lua.vim.lsp.tagfunc'
|
|
|
|
end
|
|
|
|
if
|
2023-08-03 04:03:48 -07:00
|
|
|
client.supports_method(ms.textDocument_completion) and is_empty_or_default(bufnr, 'omnifunc')
|
2023-05-27 22:51:28 -07:00
|
|
|
then
|
|
|
|
vim.bo[bufnr].omnifunc = 'v:lua.vim.lsp.omnifunc'
|
|
|
|
end
|
|
|
|
if
|
2023-08-03 04:03:48 -07:00
|
|
|
client.supports_method(ms.textDocument_rangeFormatting)
|
2023-05-27 22:51:28 -07:00
|
|
|
and is_empty_or_default(bufnr, 'formatprg')
|
|
|
|
and is_empty_or_default(bufnr, 'formatexpr')
|
|
|
|
then
|
|
|
|
vim.bo[bufnr].formatexpr = 'v:lua.vim.lsp.formatexpr()'
|
|
|
|
end
|
2023-07-14 09:47:18 -07:00
|
|
|
api.nvim_buf_call(bufnr, function()
|
|
|
|
if
|
2023-08-03 04:03:48 -07:00
|
|
|
client.supports_method(ms.textDocument_hover)
|
2023-07-14 09:47:18 -07:00
|
|
|
and is_empty_or_default(bufnr, 'keywordprg')
|
|
|
|
and vim.fn.maparg('K', 'n', false, false) == ''
|
|
|
|
then
|
|
|
|
vim.keymap.set('n', 'K', vim.lsp.buf.hover, { buffer = bufnr })
|
|
|
|
end
|
|
|
|
end)
|
2023-08-03 04:03:48 -07:00
|
|
|
if client.supports_method(ms.textDocument_diagnostic) then
|
2023-07-20 00:03:48 -07:00
|
|
|
lsp.diagnostic._enable(bufnr)
|
|
|
|
end
|
2023-05-27 22:51:28 -07:00
|
|
|
end
|
|
|
|
|
2023-06-07 05:39:41 -07:00
|
|
|
--- @class lsp.ClientConfig
|
|
|
|
--- @field cmd (string[]|fun(dispatchers: table):table)
|
|
|
|
--- @field cmd_cwd string
|
|
|
|
--- @field cmd_env (table)
|
|
|
|
--- @field detached boolean
|
|
|
|
--- @field workspace_folders (table)
|
|
|
|
--- @field capabilities lsp.ClientCapabilities
|
|
|
|
--- @field handlers table<string,function>
|
|
|
|
--- @field settings table
|
|
|
|
--- @field commands table
|
|
|
|
--- @field init_options table
|
|
|
|
--- @field name string
|
|
|
|
--- @field get_language_id fun(bufnr: integer, filetype: string): string
|
|
|
|
--- @field offset_encoding string
|
|
|
|
--- @field on_error fun(code: integer)
|
|
|
|
--- @field before_init function
|
|
|
|
--- @field on_init function
|
|
|
|
--- @field on_exit fun(code: integer, signal: integer, client_id: integer)
|
|
|
|
--- @field on_attach fun(client: lsp.Client, bufnr: integer)
|
|
|
|
--- @field trace 'off'|'messages'|'verbose'|nil
|
|
|
|
--- @field flags table
|
|
|
|
--- @field root_dir string
|
|
|
|
|
2020-08-23 04:28:56 -07:00
|
|
|
-- FIXME: DOC: Currently all methods on the `vim.lsp.client` object are
|
|
|
|
-- documented twice: Here, and on the methods themselves (e.g.
|
|
|
|
-- `client.request()`). This is a workaround for the vimdoc generator script
|
|
|
|
-- not handling method names correctly. If you change the documentation on
|
|
|
|
-- either, please make sure to update the other as well.
|
|
|
|
--
|
2019-12-31 08:51:54 -07:00
|
|
|
--- Starts and initializes a client with the given configuration.
|
2019-12-31 07:52:14 -07:00
|
|
|
---
|
2023-01-24 11:04:15 -07:00
|
|
|
--- Field `cmd` in {config} is required.
|
|
|
|
---
|
2023-06-07 05:39:41 -07:00
|
|
|
---@param config (lsp.ClientConfig) Configuration for the server:
|
2024-01-18 01:14:48 -07:00
|
|
|
--- - cmd: (string[]|fun(dispatchers: table):table) 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
|
|
|
|
--- a `dispatchers` table and returns a table with member functions `request`, `notify`,
|
|
|
|
--- `is_closing` and `terminate`.
|
|
|
|
--- See |vim.lsp.rpc.request()|, |vim.lsp.rpc.notify()|.
|
|
|
|
--- For TCP there is a builtin RPC client factory: |vim.lsp.rpc.connect()|
|
2023-01-24 11:04:15 -07:00
|
|
|
---
|
|
|
|
--- - cmd_cwd: (string, default=|getcwd()|) Directory to launch
|
|
|
|
--- the `cmd` process. Not related to `root_dir`.
|
|
|
|
---
|
|
|
|
--- - cmd_env: (table) Environment flags to pass to the LSP on
|
2023-05-13 12:33:22 -07:00
|
|
|
--- spawn. Must be specified using a table.
|
2023-02-27 13:19:41 -07:00
|
|
|
--- Non-string values are coerced to string.
|
2023-01-24 11:04:15 -07:00
|
|
|
--- Example:
|
|
|
|
--- <pre>
|
2023-02-27 13:19:41 -07:00
|
|
|
--- { PORT = 8080; HOST = "0.0.0.0"; }
|
2023-01-24 11:04:15 -07:00
|
|
|
--- </pre>
|
|
|
|
---
|
|
|
|
--- - 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: (table) 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.
|
|
|
|
---
|
|
|
|
--- - capabilities: Map overriding the default capabilities defined by
|
2023-06-07 05:39:41 -07:00
|
|
|
--- \|vim.lsp.protocol.make_client_capabilities()|, passed to the language
|
2023-01-24 11:04:15 -07:00
|
|
|
--- server on initialization. Hint: use make_client_capabilities() and modify
|
|
|
|
--- its result.
|
2023-08-03 23:10:54 -07:00
|
|
|
--- - Note: To send an empty dictionary use |vim.empty_dict()|, else it will be encoded as an
|
2023-01-24 11:04:15 -07:00
|
|
|
--- array.
|
|
|
|
---
|
|
|
|
--- - handlers: Map of language server method names to |lsp-handler|
|
|
|
|
---
|
|
|
|
--- - settings: Map with language server specific settings. These are
|
|
|
|
--- returned to the language server if requested via `workspace/configuration`.
|
|
|
|
--- Keys are case-sensitive.
|
|
|
|
---
|
|
|
|
--- - commands: table Table that maps string of clientside commands to user-defined functions.
|
|
|
|
--- Commands passed to start_client 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 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: function(bufnr, filetype) -> language ID as string.
|
|
|
|
--- Defaults to the filetype.
|
|
|
|
---
|
|
|
|
--- - offset_encoding: (default="utf-16") One of "utf-8", "utf-16",
|
|
|
|
--- or "utf-32" which is the encoding that the LSP server expects. Client does
|
|
|
|
--- not verify this is correct.
|
|
|
|
---
|
|
|
|
--- - on_error: Callback with parameters (code, ...), 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: Callback with parameters (initialize_params, config)
|
|
|
|
--- 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_client()|. You can use this to modify parameters before
|
|
|
|
--- they are sent.
|
|
|
|
---
|
|
|
|
--- - on_init: Callback (client, initialize_result) invoked after LSP
|
|
|
|
--- "initialize", where `result` is a table of `capabilities` and anything else
|
|
|
|
--- the server may send. For example, clangd sends
|
|
|
|
--- `initialize_result.offsetEncoding` if `capabilities.offsetEncoding` was
|
|
|
|
--- sent to it. You can only modify the `client.offset_encoding` here before
|
|
|
|
--- any notifications are sent. Most language servers expect to be sent client specified settings after
|
2023-06-22 03:44:51 -07:00
|
|
|
--- initialization. Nvim does not make this assumption. A
|
2023-01-24 11:04:15 -07:00
|
|
|
--- `workspace/didChangeConfiguration` notification should be sent
|
|
|
|
--- to the server during on_init.
|
|
|
|
---
|
|
|
|
--- - on_exit Callback (code, signal, client_id) invoked on client
|
2019-12-31 07:52:14 -07:00
|
|
|
--- exit.
|
2023-01-24 11:04:15 -07:00
|
|
|
--- - code: exit code of the process
|
|
|
|
--- - signal: number describing the signal used to terminate (if any)
|
|
|
|
--- - client_id: client handle
|
|
|
|
---
|
|
|
|
--- - on_attach: Callback (client, bufnr) invoked when client
|
|
|
|
--- attaches to a buffer.
|
|
|
|
---
|
|
|
|
--- - trace: ("off" | "messages" | "verbose" | nil) passed directly to the language
|
|
|
|
--- server in the initialize request. Invalid/empty values will default to "off"
|
|
|
|
---
|
|
|
|
--- - flags: A table with flags for the client. The current (experimental) flags are:
|
|
|
|
--- - allow_incremental_sync (bool, default true): Allow using incremental sync for buffer edits
|
|
|
|
--- - debounce_text_changes (number, default 150): Debounce didChange
|
|
|
|
--- notifications to the server by the given number in milliseconds. No debounce
|
|
|
|
--- occurs if nil
|
|
|
|
--- - exit_timeout (number|boolean, default false): Milliseconds to wait for server to
|
|
|
|
--- exit cleanly after sending the "shutdown" request before sending kill -15.
|
|
|
|
--- If set to false, nvim exits immediately after sending the "shutdown" request to the server.
|
|
|
|
---
|
|
|
|
--- - root_dir: (string) Directory where the LSP
|
|
|
|
--- server will base its workspaceFolders, rootUri, and rootPath
|
|
|
|
--- on initialization.
|
2021-11-21 09:39:30 -07:00
|
|
|
---
|
2023-02-25 10:47:05 -07:00
|
|
|
---@return integer|nil client_id. |vim.lsp.get_client_by_id()| Note: client may not be
|
2020-10-22 11:59:17 -07:00
|
|
|
--- fully initialized. Use `on_init` to do any actions once
|
2019-12-31 07:52:14 -07:00
|
|
|
--- the client has been initialized.
|
2019-11-13 13:55:26 -07:00
|
|
|
function lsp.start_client(config)
|
2023-06-07 05:39:41 -07:00
|
|
|
local cmd, cmd_args, offset_encoding = validate_client_config(config)
|
2019-11-13 13:55:26 -07:00
|
|
|
|
2020-12-08 19:09:33 -07:00
|
|
|
config.flags = config.flags or {}
|
2021-01-18 11:33:10 -07:00
|
|
|
config.settings = config.settings or {}
|
2020-12-08 19:09:33 -07:00
|
|
|
|
2021-03-10 14:53:23 -07:00
|
|
|
-- By default, get_language_id just returns the exact filetype it is passed.
|
|
|
|
-- It is possible to pass in something that will calculate a different filetype,
|
|
|
|
-- to be sent by the client.
|
|
|
|
config.get_language_id = config.get_language_id or function(_, filetype)
|
|
|
|
return filetype
|
|
|
|
end
|
|
|
|
|
2019-11-13 13:55:26 -07:00
|
|
|
local client_id = next_client_id()
|
|
|
|
|
2021-02-22 16:02:51 -07:00
|
|
|
local handlers = config.handlers or {}
|
2019-11-13 13:55:26 -07:00
|
|
|
local name = config.name or tostring(client_id)
|
|
|
|
local log_prefix = string.format('LSP[%s]', name)
|
|
|
|
|
lsp: vim.lsp.diagnostic (#12655)
Breaking Changes:
- Deprecated all `vim.lsp.util.{*diagnostics*}()` functions.
- Instead, all functions must be found in vim.lsp.diagnostic
- For now, they issue a warning ONCE per neovim session. In a
"little while" we will remove them completely.
- `vim.lsp.callbacks` has moved to `vim.lsp.handlers`.
- For a "little while" we will just redirect `vim.lsp.callbacks` to
`vim.lsp.handlers`. However, we will remove this at some point, so
it is recommended that you change all of your references to
`callbacks` into `handlers`.
- This also means that for functions like |vim.lsp.start_client()|
and similar, keyword style arguments have moved from "callbacks"
to "handlers". Once again, these are currently being forward, but
will cease to be forwarded in a "little while".
- Changed the highlight groups for LspDiagnostic highlight as they were
inconsistently named.
- For more information, see |lsp-highlight-diagnostics|
- Changed the sign group names as well, to be consistent with
|lsp-highlight-diagnostics|
General Enhancements:
- Rewrote much of the getting started help document for lsp. It also
provides a much nicer configuration strategy, so as to not recommend
globally overwriting builtin neovim mappings.
LSP Enhancements:
- Introduced the concept of |lsp-handlers| which will allow much better
customization for users without having to copy & paste entire files /
functions / etc.
Diagnostic Enhancements:
- "goto next diagnostic" |vim.lsp.diagnostic.goto_next()|
- "goto prev diagnostic" |vim.lsp.diagnostic.goto_prev()|
- For each of the gotos, auto open diagnostics is available as a
configuration option
- Configurable diagnostic handling:
- See |vim.lsp.diagnostic.on_publish_diagnostics()|
- Delay display until after insert mode
- Configure signs
- Configure virtual text
- Configure underline
- Set the location list with the buffers diagnostics.
- See |vim.lsp.diagnostic.set_loclist()|
- Better performance for getting counts and line diagnostics
- They are now cached on save, to enhance lookups.
- Particularly useful for checking in statusline, etc.
- Actual testing :)
- See ./test/functional/plugin/lsp/diagnostic_spec.lua
- Added `guisp` for underline highlighting
NOTE: "a little while" means enough time to feel like most plugins and
plugin authors have had a chance to refactor their code to use the
updated calls. Then we will remove them completely. There is no need to
keep them, because we don't have any released version of neovim that
exposes these APIs. I'm trying to be nice to people following HEAD :)
Co-authored: [Twitch Chat 2020](https://twitch.tv/teej_dv)
2020-11-12 20:21:34 -07:00
|
|
|
local dispatch = {}
|
2019-11-13 13:55:26 -07:00
|
|
|
|
lsp: vim.lsp.diagnostic (#12655)
Breaking Changes:
- Deprecated all `vim.lsp.util.{*diagnostics*}()` functions.
- Instead, all functions must be found in vim.lsp.diagnostic
- For now, they issue a warning ONCE per neovim session. In a
"little while" we will remove them completely.
- `vim.lsp.callbacks` has moved to `vim.lsp.handlers`.
- For a "little while" we will just redirect `vim.lsp.callbacks` to
`vim.lsp.handlers`. However, we will remove this at some point, so
it is recommended that you change all of your references to
`callbacks` into `handlers`.
- This also means that for functions like |vim.lsp.start_client()|
and similar, keyword style arguments have moved from "callbacks"
to "handlers". Once again, these are currently being forward, but
will cease to be forwarded in a "little while".
- Changed the highlight groups for LspDiagnostic highlight as they were
inconsistently named.
- For more information, see |lsp-highlight-diagnostics|
- Changed the sign group names as well, to be consistent with
|lsp-highlight-diagnostics|
General Enhancements:
- Rewrote much of the getting started help document for lsp. It also
provides a much nicer configuration strategy, so as to not recommend
globally overwriting builtin neovim mappings.
LSP Enhancements:
- Introduced the concept of |lsp-handlers| which will allow much better
customization for users without having to copy & paste entire files /
functions / etc.
Diagnostic Enhancements:
- "goto next diagnostic" |vim.lsp.diagnostic.goto_next()|
- "goto prev diagnostic" |vim.lsp.diagnostic.goto_prev()|
- For each of the gotos, auto open diagnostics is available as a
configuration option
- Configurable diagnostic handling:
- See |vim.lsp.diagnostic.on_publish_diagnostics()|
- Delay display until after insert mode
- Configure signs
- Configure virtual text
- Configure underline
- Set the location list with the buffers diagnostics.
- See |vim.lsp.diagnostic.set_loclist()|
- Better performance for getting counts and line diagnostics
- They are now cached on save, to enhance lookups.
- Particularly useful for checking in statusline, etc.
- Actual testing :)
- See ./test/functional/plugin/lsp/diagnostic_spec.lua
- Added `guisp` for underline highlighting
NOTE: "a little while" means enough time to feel like most plugins and
plugin authors have had a chance to refactor their code to use the
updated calls. Then we will remove them completely. There is no need to
keep them, because we don't have any released version of neovim that
exposes these APIs. I'm trying to be nice to people following HEAD :)
Co-authored: [Twitch Chat 2020](https://twitch.tv/teej_dv)
2020-11-12 20:21:34 -07:00
|
|
|
--- Returns the handler associated with an LSP method.
|
|
|
|
--- Returns the default handler if the user hasn't set a custom one.
|
2020-08-19 09:17:08 -07:00
|
|
|
---
|
2021-08-22 13:55:28 -07:00
|
|
|
---@param method (string) LSP method name
|
2023-12-13 05:00:11 -07:00
|
|
|
---@return lsp.Handler|nil handler for the given method, if defined, or the default from |vim.lsp.handlers|
|
lsp: vim.lsp.diagnostic (#12655)
Breaking Changes:
- Deprecated all `vim.lsp.util.{*diagnostics*}()` functions.
- Instead, all functions must be found in vim.lsp.diagnostic
- For now, they issue a warning ONCE per neovim session. In a
"little while" we will remove them completely.
- `vim.lsp.callbacks` has moved to `vim.lsp.handlers`.
- For a "little while" we will just redirect `vim.lsp.callbacks` to
`vim.lsp.handlers`. However, we will remove this at some point, so
it is recommended that you change all of your references to
`callbacks` into `handlers`.
- This also means that for functions like |vim.lsp.start_client()|
and similar, keyword style arguments have moved from "callbacks"
to "handlers". Once again, these are currently being forward, but
will cease to be forwarded in a "little while".
- Changed the highlight groups for LspDiagnostic highlight as they were
inconsistently named.
- For more information, see |lsp-highlight-diagnostics|
- Changed the sign group names as well, to be consistent with
|lsp-highlight-diagnostics|
General Enhancements:
- Rewrote much of the getting started help document for lsp. It also
provides a much nicer configuration strategy, so as to not recommend
globally overwriting builtin neovim mappings.
LSP Enhancements:
- Introduced the concept of |lsp-handlers| which will allow much better
customization for users without having to copy & paste entire files /
functions / etc.
Diagnostic Enhancements:
- "goto next diagnostic" |vim.lsp.diagnostic.goto_next()|
- "goto prev diagnostic" |vim.lsp.diagnostic.goto_prev()|
- For each of the gotos, auto open diagnostics is available as a
configuration option
- Configurable diagnostic handling:
- See |vim.lsp.diagnostic.on_publish_diagnostics()|
- Delay display until after insert mode
- Configure signs
- Configure virtual text
- Configure underline
- Set the location list with the buffers diagnostics.
- See |vim.lsp.diagnostic.set_loclist()|
- Better performance for getting counts and line diagnostics
- They are now cached on save, to enhance lookups.
- Particularly useful for checking in statusline, etc.
- Actual testing :)
- See ./test/functional/plugin/lsp/diagnostic_spec.lua
- Added `guisp` for underline highlighting
NOTE: "a little while" means enough time to feel like most plugins and
plugin authors have had a chance to refactor their code to use the
updated calls. Then we will remove them completely. There is no need to
keep them, because we don't have any released version of neovim that
exposes these APIs. I'm trying to be nice to people following HEAD :)
Co-authored: [Twitch Chat 2020](https://twitch.tv/teej_dv)
2020-11-12 20:21:34 -07:00
|
|
|
local function resolve_handler(method)
|
2024-01-22 10:23:28 -07:00
|
|
|
return handlers[method] or lsp.handlers[method]
|
2019-11-20 17:09:03 -07:00
|
|
|
end
|
|
|
|
|
2021-08-22 13:55:28 -07:00
|
|
|
---@private
|
2020-08-19 09:17:08 -07:00
|
|
|
--- Handles a notification sent by an LSP server by invoking the
|
lsp: vim.lsp.diagnostic (#12655)
Breaking Changes:
- Deprecated all `vim.lsp.util.{*diagnostics*}()` functions.
- Instead, all functions must be found in vim.lsp.diagnostic
- For now, they issue a warning ONCE per neovim session. In a
"little while" we will remove them completely.
- `vim.lsp.callbacks` has moved to `vim.lsp.handlers`.
- For a "little while" we will just redirect `vim.lsp.callbacks` to
`vim.lsp.handlers`. However, we will remove this at some point, so
it is recommended that you change all of your references to
`callbacks` into `handlers`.
- This also means that for functions like |vim.lsp.start_client()|
and similar, keyword style arguments have moved from "callbacks"
to "handlers". Once again, these are currently being forward, but
will cease to be forwarded in a "little while".
- Changed the highlight groups for LspDiagnostic highlight as they were
inconsistently named.
- For more information, see |lsp-highlight-diagnostics|
- Changed the sign group names as well, to be consistent with
|lsp-highlight-diagnostics|
General Enhancements:
- Rewrote much of the getting started help document for lsp. It also
provides a much nicer configuration strategy, so as to not recommend
globally overwriting builtin neovim mappings.
LSP Enhancements:
- Introduced the concept of |lsp-handlers| which will allow much better
customization for users without having to copy & paste entire files /
functions / etc.
Diagnostic Enhancements:
- "goto next diagnostic" |vim.lsp.diagnostic.goto_next()|
- "goto prev diagnostic" |vim.lsp.diagnostic.goto_prev()|
- For each of the gotos, auto open diagnostics is available as a
configuration option
- Configurable diagnostic handling:
- See |vim.lsp.diagnostic.on_publish_diagnostics()|
- Delay display until after insert mode
- Configure signs
- Configure virtual text
- Configure underline
- Set the location list with the buffers diagnostics.
- See |vim.lsp.diagnostic.set_loclist()|
- Better performance for getting counts and line diagnostics
- They are now cached on save, to enhance lookups.
- Particularly useful for checking in statusline, etc.
- Actual testing :)
- See ./test/functional/plugin/lsp/diagnostic_spec.lua
- Added `guisp` for underline highlighting
NOTE: "a little while" means enough time to feel like most plugins and
plugin authors have had a chance to refactor their code to use the
updated calls. Then we will remove them completely. There is no need to
keep them, because we don't have any released version of neovim that
exposes these APIs. I'm trying to be nice to people following HEAD :)
Co-authored: [Twitch Chat 2020](https://twitch.tv/teej_dv)
2020-11-12 20:21:34 -07:00
|
|
|
--- corresponding handler.
|
2020-08-19 09:17:08 -07:00
|
|
|
---
|
2021-08-22 13:55:28 -07:00
|
|
|
---@param method (string) LSP method name
|
|
|
|
---@param params (table) The parameters for that method.
|
lsp: vim.lsp.diagnostic (#12655)
Breaking Changes:
- Deprecated all `vim.lsp.util.{*diagnostics*}()` functions.
- Instead, all functions must be found in vim.lsp.diagnostic
- For now, they issue a warning ONCE per neovim session. In a
"little while" we will remove them completely.
- `vim.lsp.callbacks` has moved to `vim.lsp.handlers`.
- For a "little while" we will just redirect `vim.lsp.callbacks` to
`vim.lsp.handlers`. However, we will remove this at some point, so
it is recommended that you change all of your references to
`callbacks` into `handlers`.
- This also means that for functions like |vim.lsp.start_client()|
and similar, keyword style arguments have moved from "callbacks"
to "handlers". Once again, these are currently being forward, but
will cease to be forwarded in a "little while".
- Changed the highlight groups for LspDiagnostic highlight as they were
inconsistently named.
- For more information, see |lsp-highlight-diagnostics|
- Changed the sign group names as well, to be consistent with
|lsp-highlight-diagnostics|
General Enhancements:
- Rewrote much of the getting started help document for lsp. It also
provides a much nicer configuration strategy, so as to not recommend
globally overwriting builtin neovim mappings.
LSP Enhancements:
- Introduced the concept of |lsp-handlers| which will allow much better
customization for users without having to copy & paste entire files /
functions / etc.
Diagnostic Enhancements:
- "goto next diagnostic" |vim.lsp.diagnostic.goto_next()|
- "goto prev diagnostic" |vim.lsp.diagnostic.goto_prev()|
- For each of the gotos, auto open diagnostics is available as a
configuration option
- Configurable diagnostic handling:
- See |vim.lsp.diagnostic.on_publish_diagnostics()|
- Delay display until after insert mode
- Configure signs
- Configure virtual text
- Configure underline
- Set the location list with the buffers diagnostics.
- See |vim.lsp.diagnostic.set_loclist()|
- Better performance for getting counts and line diagnostics
- They are now cached on save, to enhance lookups.
- Particularly useful for checking in statusline, etc.
- Actual testing :)
- See ./test/functional/plugin/lsp/diagnostic_spec.lua
- Added `guisp` for underline highlighting
NOTE: "a little while" means enough time to feel like most plugins and
plugin authors have had a chance to refactor their code to use the
updated calls. Then we will remove them completely. There is no need to
keep them, because we don't have any released version of neovim that
exposes these APIs. I'm trying to be nice to people following HEAD :)
Co-authored: [Twitch Chat 2020](https://twitch.tv/teej_dv)
2020-11-12 20:21:34 -07:00
|
|
|
function dispatch.notification(method, params)
|
2023-06-07 05:39:41 -07:00
|
|
|
if log.trace() then
|
|
|
|
log.trace('notification', method, params)
|
|
|
|
end
|
lsp: vim.lsp.diagnostic (#12655)
Breaking Changes:
- Deprecated all `vim.lsp.util.{*diagnostics*}()` functions.
- Instead, all functions must be found in vim.lsp.diagnostic
- For now, they issue a warning ONCE per neovim session. In a
"little while" we will remove them completely.
- `vim.lsp.callbacks` has moved to `vim.lsp.handlers`.
- For a "little while" we will just redirect `vim.lsp.callbacks` to
`vim.lsp.handlers`. However, we will remove this at some point, so
it is recommended that you change all of your references to
`callbacks` into `handlers`.
- This also means that for functions like |vim.lsp.start_client()|
and similar, keyword style arguments have moved from "callbacks"
to "handlers". Once again, these are currently being forward, but
will cease to be forwarded in a "little while".
- Changed the highlight groups for LspDiagnostic highlight as they were
inconsistently named.
- For more information, see |lsp-highlight-diagnostics|
- Changed the sign group names as well, to be consistent with
|lsp-highlight-diagnostics|
General Enhancements:
- Rewrote much of the getting started help document for lsp. It also
provides a much nicer configuration strategy, so as to not recommend
globally overwriting builtin neovim mappings.
LSP Enhancements:
- Introduced the concept of |lsp-handlers| which will allow much better
customization for users without having to copy & paste entire files /
functions / etc.
Diagnostic Enhancements:
- "goto next diagnostic" |vim.lsp.diagnostic.goto_next()|
- "goto prev diagnostic" |vim.lsp.diagnostic.goto_prev()|
- For each of the gotos, auto open diagnostics is available as a
configuration option
- Configurable diagnostic handling:
- See |vim.lsp.diagnostic.on_publish_diagnostics()|
- Delay display until after insert mode
- Configure signs
- Configure virtual text
- Configure underline
- Set the location list with the buffers diagnostics.
- See |vim.lsp.diagnostic.set_loclist()|
- Better performance for getting counts and line diagnostics
- They are now cached on save, to enhance lookups.
- Particularly useful for checking in statusline, etc.
- Actual testing :)
- See ./test/functional/plugin/lsp/diagnostic_spec.lua
- Added `guisp` for underline highlighting
NOTE: "a little while" means enough time to feel like most plugins and
plugin authors have had a chance to refactor their code to use the
updated calls. Then we will remove them completely. There is no need to
keep them, because we don't have any released version of neovim that
exposes these APIs. I'm trying to be nice to people following HEAD :)
Co-authored: [Twitch Chat 2020](https://twitch.tv/teej_dv)
2020-11-12 20:21:34 -07:00
|
|
|
local handler = resolve_handler(method)
|
|
|
|
if handler then
|
2019-11-13 13:55:26 -07:00
|
|
|
-- Method name is provided here for convenience.
|
feat(lsp)!: change handler signature
Previously, the handler signature was:
function(err, method, params, client_id, bufnr, config)
In order to better support external plugins that wish to extend the
protocol, there is other information which would be advantageous to
forward to the client, such as the original params of the request that
generated the callback.
In order to do this, we would need to break symmetry of the handlers, to
add an additional "params" as the 7th argument.
Instead, this PR changes the signature of the handlers to:
function(err, result, ctx, config)
where ctx (the context) includes params, client_id, and bufnr. This also leaves
flexibility for future use-cases.
BREAKING_CHANGE: changes the signature of the built-in client handlers, requiring
updating handler calls
2021-08-27 21:12:30 -07:00
|
|
|
handler(nil, params, { method = method, client_id = client_id })
|
2019-11-13 13:55:26 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-08-22 13:55:28 -07:00
|
|
|
---@private
|
lsp: vim.lsp.diagnostic (#12655)
Breaking Changes:
- Deprecated all `vim.lsp.util.{*diagnostics*}()` functions.
- Instead, all functions must be found in vim.lsp.diagnostic
- For now, they issue a warning ONCE per neovim session. In a
"little while" we will remove them completely.
- `vim.lsp.callbacks` has moved to `vim.lsp.handlers`.
- For a "little while" we will just redirect `vim.lsp.callbacks` to
`vim.lsp.handlers`. However, we will remove this at some point, so
it is recommended that you change all of your references to
`callbacks` into `handlers`.
- This also means that for functions like |vim.lsp.start_client()|
and similar, keyword style arguments have moved from "callbacks"
to "handlers". Once again, these are currently being forward, but
will cease to be forwarded in a "little while".
- Changed the highlight groups for LspDiagnostic highlight as they were
inconsistently named.
- For more information, see |lsp-highlight-diagnostics|
- Changed the sign group names as well, to be consistent with
|lsp-highlight-diagnostics|
General Enhancements:
- Rewrote much of the getting started help document for lsp. It also
provides a much nicer configuration strategy, so as to not recommend
globally overwriting builtin neovim mappings.
LSP Enhancements:
- Introduced the concept of |lsp-handlers| which will allow much better
customization for users without having to copy & paste entire files /
functions / etc.
Diagnostic Enhancements:
- "goto next diagnostic" |vim.lsp.diagnostic.goto_next()|
- "goto prev diagnostic" |vim.lsp.diagnostic.goto_prev()|
- For each of the gotos, auto open diagnostics is available as a
configuration option
- Configurable diagnostic handling:
- See |vim.lsp.diagnostic.on_publish_diagnostics()|
- Delay display until after insert mode
- Configure signs
- Configure virtual text
- Configure underline
- Set the location list with the buffers diagnostics.
- See |vim.lsp.diagnostic.set_loclist()|
- Better performance for getting counts and line diagnostics
- They are now cached on save, to enhance lookups.
- Particularly useful for checking in statusline, etc.
- Actual testing :)
- See ./test/functional/plugin/lsp/diagnostic_spec.lua
- Added `guisp` for underline highlighting
NOTE: "a little while" means enough time to feel like most plugins and
plugin authors have had a chance to refactor their code to use the
updated calls. Then we will remove them completely. There is no need to
keep them, because we don't have any released version of neovim that
exposes these APIs. I'm trying to be nice to people following HEAD :)
Co-authored: [Twitch Chat 2020](https://twitch.tv/teej_dv)
2020-11-12 20:21:34 -07:00
|
|
|
--- Handles a request from an LSP server by invoking the corresponding handler.
|
2020-08-19 09:17:08 -07:00
|
|
|
---
|
2021-08-22 13:55:28 -07:00
|
|
|
---@param method (string) LSP method name
|
|
|
|
---@param params (table) The parameters for that method
|
2024-01-09 16:04:27 -07:00
|
|
|
---@return any result
|
|
|
|
---@return lsp.ResponseError error code and message set in case an exception happens during the request.
|
lsp: vim.lsp.diagnostic (#12655)
Breaking Changes:
- Deprecated all `vim.lsp.util.{*diagnostics*}()` functions.
- Instead, all functions must be found in vim.lsp.diagnostic
- For now, they issue a warning ONCE per neovim session. In a
"little while" we will remove them completely.
- `vim.lsp.callbacks` has moved to `vim.lsp.handlers`.
- For a "little while" we will just redirect `vim.lsp.callbacks` to
`vim.lsp.handlers`. However, we will remove this at some point, so
it is recommended that you change all of your references to
`callbacks` into `handlers`.
- This also means that for functions like |vim.lsp.start_client()|
and similar, keyword style arguments have moved from "callbacks"
to "handlers". Once again, these are currently being forward, but
will cease to be forwarded in a "little while".
- Changed the highlight groups for LspDiagnostic highlight as they were
inconsistently named.
- For more information, see |lsp-highlight-diagnostics|
- Changed the sign group names as well, to be consistent with
|lsp-highlight-diagnostics|
General Enhancements:
- Rewrote much of the getting started help document for lsp. It also
provides a much nicer configuration strategy, so as to not recommend
globally overwriting builtin neovim mappings.
LSP Enhancements:
- Introduced the concept of |lsp-handlers| which will allow much better
customization for users without having to copy & paste entire files /
functions / etc.
Diagnostic Enhancements:
- "goto next diagnostic" |vim.lsp.diagnostic.goto_next()|
- "goto prev diagnostic" |vim.lsp.diagnostic.goto_prev()|
- For each of the gotos, auto open diagnostics is available as a
configuration option
- Configurable diagnostic handling:
- See |vim.lsp.diagnostic.on_publish_diagnostics()|
- Delay display until after insert mode
- Configure signs
- Configure virtual text
- Configure underline
- Set the location list with the buffers diagnostics.
- See |vim.lsp.diagnostic.set_loclist()|
- Better performance for getting counts and line diagnostics
- They are now cached on save, to enhance lookups.
- Particularly useful for checking in statusline, etc.
- Actual testing :)
- See ./test/functional/plugin/lsp/diagnostic_spec.lua
- Added `guisp` for underline highlighting
NOTE: "a little while" means enough time to feel like most plugins and
plugin authors have had a chance to refactor their code to use the
updated calls. Then we will remove them completely. There is no need to
keep them, because we don't have any released version of neovim that
exposes these APIs. I'm trying to be nice to people following HEAD :)
Co-authored: [Twitch Chat 2020](https://twitch.tv/teej_dv)
2020-11-12 20:21:34 -07:00
|
|
|
function dispatch.server_request(method, params)
|
2023-06-07 05:39:41 -07:00
|
|
|
if log.trace() then
|
|
|
|
log.trace('server_request', method, params)
|
|
|
|
end
|
lsp: vim.lsp.diagnostic (#12655)
Breaking Changes:
- Deprecated all `vim.lsp.util.{*diagnostics*}()` functions.
- Instead, all functions must be found in vim.lsp.diagnostic
- For now, they issue a warning ONCE per neovim session. In a
"little while" we will remove them completely.
- `vim.lsp.callbacks` has moved to `vim.lsp.handlers`.
- For a "little while" we will just redirect `vim.lsp.callbacks` to
`vim.lsp.handlers`. However, we will remove this at some point, so
it is recommended that you change all of your references to
`callbacks` into `handlers`.
- This also means that for functions like |vim.lsp.start_client()|
and similar, keyword style arguments have moved from "callbacks"
to "handlers". Once again, these are currently being forward, but
will cease to be forwarded in a "little while".
- Changed the highlight groups for LspDiagnostic highlight as they were
inconsistently named.
- For more information, see |lsp-highlight-diagnostics|
- Changed the sign group names as well, to be consistent with
|lsp-highlight-diagnostics|
General Enhancements:
- Rewrote much of the getting started help document for lsp. It also
provides a much nicer configuration strategy, so as to not recommend
globally overwriting builtin neovim mappings.
LSP Enhancements:
- Introduced the concept of |lsp-handlers| which will allow much better
customization for users without having to copy & paste entire files /
functions / etc.
Diagnostic Enhancements:
- "goto next diagnostic" |vim.lsp.diagnostic.goto_next()|
- "goto prev diagnostic" |vim.lsp.diagnostic.goto_prev()|
- For each of the gotos, auto open diagnostics is available as a
configuration option
- Configurable diagnostic handling:
- See |vim.lsp.diagnostic.on_publish_diagnostics()|
- Delay display until after insert mode
- Configure signs
- Configure virtual text
- Configure underline
- Set the location list with the buffers diagnostics.
- See |vim.lsp.diagnostic.set_loclist()|
- Better performance for getting counts and line diagnostics
- They are now cached on save, to enhance lookups.
- Particularly useful for checking in statusline, etc.
- Actual testing :)
- See ./test/functional/plugin/lsp/diagnostic_spec.lua
- Added `guisp` for underline highlighting
NOTE: "a little while" means enough time to feel like most plugins and
plugin authors have had a chance to refactor their code to use the
updated calls. Then we will remove them completely. There is no need to
keep them, because we don't have any released version of neovim that
exposes these APIs. I'm trying to be nice to people following HEAD :)
Co-authored: [Twitch Chat 2020](https://twitch.tv/teej_dv)
2020-11-12 20:21:34 -07:00
|
|
|
local handler = resolve_handler(method)
|
|
|
|
if handler then
|
2023-06-07 05:39:41 -07:00
|
|
|
if log.trace() then
|
|
|
|
log.trace('server_request: found handler for', method)
|
|
|
|
end
|
feat(lsp)!: change handler signature
Previously, the handler signature was:
function(err, method, params, client_id, bufnr, config)
In order to better support external plugins that wish to extend the
protocol, there is other information which would be advantageous to
forward to the client, such as the original params of the request that
generated the callback.
In order to do this, we would need to break symmetry of the handlers, to
add an additional "params" as the 7th argument.
Instead, this PR changes the signature of the handlers to:
function(err, result, ctx, config)
where ctx (the context) includes params, client_id, and bufnr. This also leaves
flexibility for future use-cases.
BREAKING_CHANGE: changes the signature of the built-in client handlers, requiring
updating handler calls
2021-08-27 21:12:30 -07:00
|
|
|
return handler(nil, params, { method = method, client_id = client_id })
|
2019-11-13 13:55:26 -07:00
|
|
|
end
|
2023-06-07 05:39:41 -07:00
|
|
|
if log.warn() then
|
|
|
|
log.warn('server_request: no handler found for', method)
|
|
|
|
end
|
2019-11-13 13:55:26 -07:00
|
|
|
return nil, lsp.rpc_response_error(protocol.ErrorCodes.MethodNotFound)
|
|
|
|
end
|
|
|
|
|
2023-10-11 13:38:58 -07:00
|
|
|
--- Logs the given error to the LSP log and to the error buffer.
|
|
|
|
--- @param code integer Error code
|
|
|
|
--- @param err any Error arguments
|
|
|
|
local function write_error(code, err)
|
|
|
|
if log.error() then
|
|
|
|
log.error(log_prefix, 'on_error', { code = lsp.client_errors[code], err = err })
|
|
|
|
end
|
|
|
|
err_message(log_prefix, ': Error ', lsp.client_errors[code], ': ', vim.inspect(err))
|
|
|
|
end
|
|
|
|
|
2021-08-22 13:55:28 -07:00
|
|
|
---@private
|
2020-08-19 09:17:08 -07:00
|
|
|
--- Invoked when the client operation throws an error.
|
|
|
|
---
|
2023-03-06 23:17:52 -07:00
|
|
|
---@param code (integer) Error code
|
2023-12-13 05:00:11 -07:00
|
|
|
---@param err any Other arguments may be passed depending on the error kind
|
2023-06-23 04:54:47 -07:00
|
|
|
---@see vim.lsp.rpc.client_errors for possible errors. Use
|
2020-08-19 09:17:08 -07:00
|
|
|
---`vim.lsp.rpc.client_errors[code]` to get a human-friendly name.
|
lsp: vim.lsp.diagnostic (#12655)
Breaking Changes:
- Deprecated all `vim.lsp.util.{*diagnostics*}()` functions.
- Instead, all functions must be found in vim.lsp.diagnostic
- For now, they issue a warning ONCE per neovim session. In a
"little while" we will remove them completely.
- `vim.lsp.callbacks` has moved to `vim.lsp.handlers`.
- For a "little while" we will just redirect `vim.lsp.callbacks` to
`vim.lsp.handlers`. However, we will remove this at some point, so
it is recommended that you change all of your references to
`callbacks` into `handlers`.
- This also means that for functions like |vim.lsp.start_client()|
and similar, keyword style arguments have moved from "callbacks"
to "handlers". Once again, these are currently being forward, but
will cease to be forwarded in a "little while".
- Changed the highlight groups for LspDiagnostic highlight as they were
inconsistently named.
- For more information, see |lsp-highlight-diagnostics|
- Changed the sign group names as well, to be consistent with
|lsp-highlight-diagnostics|
General Enhancements:
- Rewrote much of the getting started help document for lsp. It also
provides a much nicer configuration strategy, so as to not recommend
globally overwriting builtin neovim mappings.
LSP Enhancements:
- Introduced the concept of |lsp-handlers| which will allow much better
customization for users without having to copy & paste entire files /
functions / etc.
Diagnostic Enhancements:
- "goto next diagnostic" |vim.lsp.diagnostic.goto_next()|
- "goto prev diagnostic" |vim.lsp.diagnostic.goto_prev()|
- For each of the gotos, auto open diagnostics is available as a
configuration option
- Configurable diagnostic handling:
- See |vim.lsp.diagnostic.on_publish_diagnostics()|
- Delay display until after insert mode
- Configure signs
- Configure virtual text
- Configure underline
- Set the location list with the buffers diagnostics.
- See |vim.lsp.diagnostic.set_loclist()|
- Better performance for getting counts and line diagnostics
- They are now cached on save, to enhance lookups.
- Particularly useful for checking in statusline, etc.
- Actual testing :)
- See ./test/functional/plugin/lsp/diagnostic_spec.lua
- Added `guisp` for underline highlighting
NOTE: "a little while" means enough time to feel like most plugins and
plugin authors have had a chance to refactor their code to use the
updated calls. Then we will remove them completely. There is no need to
keep them, because we don't have any released version of neovim that
exposes these APIs. I'm trying to be nice to people following HEAD :)
Co-authored: [Twitch Chat 2020](https://twitch.tv/teej_dv)
2020-11-12 20:21:34 -07:00
|
|
|
function dispatch.on_error(code, err)
|
2023-10-11 13:38:58 -07:00
|
|
|
write_error(code, err)
|
2019-11-13 13:55:26 -07:00
|
|
|
if config.on_error then
|
|
|
|
local status, usererr = pcall(config.on_error, code, err)
|
|
|
|
if not status then
|
2023-12-13 05:00:11 -07:00
|
|
|
if log.error() then
|
|
|
|
log.error(log_prefix, 'user on_error failed', { err = usererr })
|
|
|
|
end
|
2019-11-20 17:16:13 -07:00
|
|
|
err_message(log_prefix, ' user on_error failed: ', tostring(usererr))
|
2019-11-13 13:55:26 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-07-10 08:26:43 -07:00
|
|
|
--- Reset defaults set by `set_defaults`.
|
|
|
|
--- Must only be called if the last client attached to a buffer exits.
|
2023-07-14 09:47:18 -07:00
|
|
|
local function reset_defaults(bufnr)
|
2022-07-10 08:26:43 -07:00
|
|
|
if vim.bo[bufnr].tagfunc == 'v:lua.vim.lsp.tagfunc' then
|
|
|
|
vim.bo[bufnr].tagfunc = nil
|
|
|
|
end
|
|
|
|
if vim.bo[bufnr].omnifunc == 'v:lua.vim.lsp.omnifunc' then
|
|
|
|
vim.bo[bufnr].omnifunc = nil
|
|
|
|
end
|
2022-08-08 09:30:17 -07:00
|
|
|
if vim.bo[bufnr].formatexpr == 'v:lua.vim.lsp.formatexpr()' then
|
|
|
|
vim.bo[bufnr].formatexpr = nil
|
|
|
|
end
|
2023-07-14 09:47:18 -07:00
|
|
|
api.nvim_buf_call(bufnr, function()
|
|
|
|
local keymap = vim.fn.maparg('K', 'n', false, true)
|
|
|
|
if keymap and keymap.callback == vim.lsp.buf.hover then
|
|
|
|
vim.keymap.del('n', 'K', { buffer = bufnr })
|
|
|
|
end
|
|
|
|
end)
|
2022-07-10 08:26:43 -07:00
|
|
|
end
|
|
|
|
|
2021-08-22 13:55:28 -07:00
|
|
|
---@private
|
2020-08-19 09:17:08 -07:00
|
|
|
--- Invoked on client exit.
|
|
|
|
---
|
2023-03-06 23:17:52 -07:00
|
|
|
---@param code (integer) exit code of the process
|
|
|
|
---@param signal (integer) the signal used to terminate (if any)
|
lsp: vim.lsp.diagnostic (#12655)
Breaking Changes:
- Deprecated all `vim.lsp.util.{*diagnostics*}()` functions.
- Instead, all functions must be found in vim.lsp.diagnostic
- For now, they issue a warning ONCE per neovim session. In a
"little while" we will remove them completely.
- `vim.lsp.callbacks` has moved to `vim.lsp.handlers`.
- For a "little while" we will just redirect `vim.lsp.callbacks` to
`vim.lsp.handlers`. However, we will remove this at some point, so
it is recommended that you change all of your references to
`callbacks` into `handlers`.
- This also means that for functions like |vim.lsp.start_client()|
and similar, keyword style arguments have moved from "callbacks"
to "handlers". Once again, these are currently being forward, but
will cease to be forwarded in a "little while".
- Changed the highlight groups for LspDiagnostic highlight as they were
inconsistently named.
- For more information, see |lsp-highlight-diagnostics|
- Changed the sign group names as well, to be consistent with
|lsp-highlight-diagnostics|
General Enhancements:
- Rewrote much of the getting started help document for lsp. It also
provides a much nicer configuration strategy, so as to not recommend
globally overwriting builtin neovim mappings.
LSP Enhancements:
- Introduced the concept of |lsp-handlers| which will allow much better
customization for users without having to copy & paste entire files /
functions / etc.
Diagnostic Enhancements:
- "goto next diagnostic" |vim.lsp.diagnostic.goto_next()|
- "goto prev diagnostic" |vim.lsp.diagnostic.goto_prev()|
- For each of the gotos, auto open diagnostics is available as a
configuration option
- Configurable diagnostic handling:
- See |vim.lsp.diagnostic.on_publish_diagnostics()|
- Delay display until after insert mode
- Configure signs
- Configure virtual text
- Configure underline
- Set the location list with the buffers diagnostics.
- See |vim.lsp.diagnostic.set_loclist()|
- Better performance for getting counts and line diagnostics
- They are now cached on save, to enhance lookups.
- Particularly useful for checking in statusline, etc.
- Actual testing :)
- See ./test/functional/plugin/lsp/diagnostic_spec.lua
- Added `guisp` for underline highlighting
NOTE: "a little while" means enough time to feel like most plugins and
plugin authors have had a chance to refactor their code to use the
updated calls. Then we will remove them completely. There is no need to
keep them, because we don't have any released version of neovim that
exposes these APIs. I'm trying to be nice to people following HEAD :)
Co-authored: [Twitch Chat 2020](https://twitch.tv/teej_dv)
2020-11-12 20:21:34 -07:00
|
|
|
function dispatch.on_exit(code, signal)
|
2021-12-17 13:06:44 -07:00
|
|
|
if config.on_exit then
|
|
|
|
pcall(config.on_exit, code, signal, client_id)
|
|
|
|
end
|
|
|
|
|
2023-03-01 09:47:56 -07:00
|
|
|
local client = active_clients[client_id] and active_clients[client_id]
|
|
|
|
or uninitialized_clients[client_id]
|
|
|
|
|
2022-05-09 11:00:27 -07:00
|
|
|
for bufnr, client_ids in pairs(all_buffer_active_clients) do
|
|
|
|
if client_ids[client_id] then
|
|
|
|
vim.schedule(function()
|
2023-03-01 09:47:56 -07:00
|
|
|
if client and client.attached_buffers[bufnr] then
|
|
|
|
nvim_exec_autocmds('LspDetach', {
|
|
|
|
buffer = bufnr,
|
|
|
|
modeline = false,
|
|
|
|
data = { client_id = client_id },
|
|
|
|
})
|
|
|
|
end
|
2022-05-09 11:00:27 -07:00
|
|
|
|
|
|
|
local namespace = vim.lsp.diagnostic.get_namespace(client_id)
|
|
|
|
vim.diagnostic.reset(namespace, bufnr)
|
|
|
|
|
2022-09-10 17:56:29 -07:00
|
|
|
client_ids[client_id] = nil
|
|
|
|
if vim.tbl_isempty(client_ids) then
|
2023-07-14 09:47:18 -07:00
|
|
|
reset_defaults(bufnr)
|
2022-09-10 17:56:29 -07:00
|
|
|
end
|
2022-07-10 08:26:43 -07:00
|
|
|
end)
|
|
|
|
end
|
2022-05-09 11:00:27 -07:00
|
|
|
end
|
2021-02-19 20:05:49 -07:00
|
|
|
|
2022-09-10 17:56:29 -07:00
|
|
|
-- Schedule the deletion of the client object so that it exists in the execution of LspDetach
|
|
|
|
-- autocommands
|
|
|
|
vim.schedule(function()
|
|
|
|
active_clients[client_id] = nil
|
|
|
|
uninitialized_clients[client_id] = nil
|
|
|
|
|
|
|
|
-- Client can be absent if executable starts, but initialize fails
|
|
|
|
-- init/attach won't have happened
|
|
|
|
if client then
|
|
|
|
changetracking.reset(client)
|
|
|
|
end
|
|
|
|
if code ~= 0 or (signal ~= 0 and signal ~= 15) then
|
2023-07-29 07:10:40 -07:00
|
|
|
local msg = string.format(
|
|
|
|
'Client %s quit with exit code %s and signal %s. Check log for errors: %s',
|
|
|
|
name,
|
|
|
|
code,
|
|
|
|
signal,
|
|
|
|
lsp.get_log_path()
|
|
|
|
)
|
2021-03-02 13:36:35 -07:00
|
|
|
vim.notify(msg, vim.log.levels.WARN)
|
2022-09-10 17:56:29 -07:00
|
|
|
end
|
|
|
|
end)
|
2019-11-13 13:55:26 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
-- Start the RPC client.
|
2024-01-09 16:04:27 -07:00
|
|
|
local rpc --- @type vim.lsp.rpc.PublicClient?
|
2022-08-24 11:25:34 -07:00
|
|
|
if type(cmd) == 'function' then
|
|
|
|
rpc = cmd(dispatch)
|
|
|
|
else
|
2024-01-22 10:23:28 -07:00
|
|
|
rpc = lsp.rpc.start(cmd, cmd_args, dispatch, {
|
2022-08-24 11:25:34 -07:00
|
|
|
cwd = config.cmd_cwd,
|
|
|
|
env = config.cmd_env,
|
|
|
|
detached = config.detached,
|
|
|
|
})
|
|
|
|
end
|
2019-11-13 13:55:26 -07:00
|
|
|
|
2021-11-25 05:54:45 -07:00
|
|
|
-- Return nil if client fails to start
|
|
|
|
if not rpc then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2023-03-09 14:17:08 -07:00
|
|
|
---@class lsp.Client
|
2019-11-13 13:55:26 -07:00
|
|
|
local client = {
|
|
|
|
id = client_id,
|
|
|
|
name = name,
|
|
|
|
rpc = rpc,
|
|
|
|
offset_encoding = offset_encoding,
|
|
|
|
config = config,
|
2023-12-13 05:00:11 -07:00
|
|
|
attached_buffers = {}, --- @type table<integer,true>
|
lsp: vim.lsp.diagnostic (#12655)
Breaking Changes:
- Deprecated all `vim.lsp.util.{*diagnostics*}()` functions.
- Instead, all functions must be found in vim.lsp.diagnostic
- For now, they issue a warning ONCE per neovim session. In a
"little while" we will remove them completely.
- `vim.lsp.callbacks` has moved to `vim.lsp.handlers`.
- For a "little while" we will just redirect `vim.lsp.callbacks` to
`vim.lsp.handlers`. However, we will remove this at some point, so
it is recommended that you change all of your references to
`callbacks` into `handlers`.
- This also means that for functions like |vim.lsp.start_client()|
and similar, keyword style arguments have moved from "callbacks"
to "handlers". Once again, these are currently being forward, but
will cease to be forwarded in a "little while".
- Changed the highlight groups for LspDiagnostic highlight as they were
inconsistently named.
- For more information, see |lsp-highlight-diagnostics|
- Changed the sign group names as well, to be consistent with
|lsp-highlight-diagnostics|
General Enhancements:
- Rewrote much of the getting started help document for lsp. It also
provides a much nicer configuration strategy, so as to not recommend
globally overwriting builtin neovim mappings.
LSP Enhancements:
- Introduced the concept of |lsp-handlers| which will allow much better
customization for users without having to copy & paste entire files /
functions / etc.
Diagnostic Enhancements:
- "goto next diagnostic" |vim.lsp.diagnostic.goto_next()|
- "goto prev diagnostic" |vim.lsp.diagnostic.goto_prev()|
- For each of the gotos, auto open diagnostics is available as a
configuration option
- Configurable diagnostic handling:
- See |vim.lsp.diagnostic.on_publish_diagnostics()|
- Delay display until after insert mode
- Configure signs
- Configure virtual text
- Configure underline
- Set the location list with the buffers diagnostics.
- See |vim.lsp.diagnostic.set_loclist()|
- Better performance for getting counts and line diagnostics
- They are now cached on save, to enhance lookups.
- Particularly useful for checking in statusline, etc.
- Actual testing :)
- See ./test/functional/plugin/lsp/diagnostic_spec.lua
- Added `guisp` for underline highlighting
NOTE: "a little while" means enough time to feel like most plugins and
plugin authors have had a chance to refactor their code to use the
updated calls. Then we will remove them completely. There is no need to
keep them, because we don't have any released version of neovim that
exposes these APIs. I'm trying to be nice to people following HEAD :)
Co-authored: [Twitch Chat 2020](https://twitch.tv/teej_dv)
2020-11-12 20:21:34 -07:00
|
|
|
|
|
|
|
handlers = handlers,
|
2023-12-13 05:00:11 -07:00
|
|
|
--- @type table<string,function>
|
2021-11-01 03:14:59 -07:00
|
|
|
commands = config.commands or {},
|
2021-10-29 05:45:01 -07:00
|
|
|
|
2023-06-07 05:39:41 -07:00
|
|
|
--- @type table<integer,{ type: string, bufnr: integer, method: string}>
|
2021-11-01 03:14:59 -07:00
|
|
|
requests = {},
|
2023-06-09 02:32:43 -07:00
|
|
|
|
|
|
|
--- Contains $/progress report messages.
|
|
|
|
--- They have the format {token: integer|string, value: any}
|
|
|
|
--- For "work done progress", value will be one of:
|
|
|
|
--- - lsp.WorkDoneProgressBegin,
|
|
|
|
--- - lsp.WorkDoneProgressReport (extended with title from Begin)
|
|
|
|
--- - lsp.WorkDoneProgressEnd (extended with title from Begin)
|
|
|
|
progress = vim.ringbuf(50),
|
|
|
|
|
2023-08-31 01:14:20 -07:00
|
|
|
--- @type lsp.ServerCapabilities
|
|
|
|
server_capabilities = {},
|
|
|
|
|
2023-06-09 02:32:43 -07:00
|
|
|
---@deprecated use client.progress instead
|
2021-10-29 05:45:01 -07:00
|
|
|
messages = { name = name, messages = {}, progress = {}, status = {} },
|
2024-01-22 10:23:28 -07:00
|
|
|
dynamic_capabilities = vim.lsp._dynamic.new(client_id),
|
2019-11-13 13:55:26 -07:00
|
|
|
}
|
2023-06-09 02:32:43 -07:00
|
|
|
|
|
|
|
---@type table<string|integer, string> title of unfinished progress sequences by token
|
|
|
|
client.progress.pending = {}
|
|
|
|
|
2023-06-07 05:39:41 -07:00
|
|
|
--- @type lsp.ClientCapabilities
|
2023-05-27 22:51:28 -07:00
|
|
|
client.config.capabilities = config.capabilities or protocol.make_client_capabilities()
|
2019-11-13 13:55:26 -07:00
|
|
|
|
lsp: vim.lsp.diagnostic (#12655)
Breaking Changes:
- Deprecated all `vim.lsp.util.{*diagnostics*}()` functions.
- Instead, all functions must be found in vim.lsp.diagnostic
- For now, they issue a warning ONCE per neovim session. In a
"little while" we will remove them completely.
- `vim.lsp.callbacks` has moved to `vim.lsp.handlers`.
- For a "little while" we will just redirect `vim.lsp.callbacks` to
`vim.lsp.handlers`. However, we will remove this at some point, so
it is recommended that you change all of your references to
`callbacks` into `handlers`.
- This also means that for functions like |vim.lsp.start_client()|
and similar, keyword style arguments have moved from "callbacks"
to "handlers". Once again, these are currently being forward, but
will cease to be forwarded in a "little while".
- Changed the highlight groups for LspDiagnostic highlight as they were
inconsistently named.
- For more information, see |lsp-highlight-diagnostics|
- Changed the sign group names as well, to be consistent with
|lsp-highlight-diagnostics|
General Enhancements:
- Rewrote much of the getting started help document for lsp. It also
provides a much nicer configuration strategy, so as to not recommend
globally overwriting builtin neovim mappings.
LSP Enhancements:
- Introduced the concept of |lsp-handlers| which will allow much better
customization for users without having to copy & paste entire files /
functions / etc.
Diagnostic Enhancements:
- "goto next diagnostic" |vim.lsp.diagnostic.goto_next()|
- "goto prev diagnostic" |vim.lsp.diagnostic.goto_prev()|
- For each of the gotos, auto open diagnostics is available as a
configuration option
- Configurable diagnostic handling:
- See |vim.lsp.diagnostic.on_publish_diagnostics()|
- Delay display until after insert mode
- Configure signs
- Configure virtual text
- Configure underline
- Set the location list with the buffers diagnostics.
- See |vim.lsp.diagnostic.set_loclist()|
- Better performance for getting counts and line diagnostics
- They are now cached on save, to enhance lookups.
- Particularly useful for checking in statusline, etc.
- Actual testing :)
- See ./test/functional/plugin/lsp/diagnostic_spec.lua
- Added `guisp` for underline highlighting
NOTE: "a little while" means enough time to feel like most plugins and
plugin authors have had a chance to refactor their code to use the
updated calls. Then we will remove them completely. There is no need to
keep them, because we don't have any released version of neovim that
exposes these APIs. I'm trying to be nice to people following HEAD :)
Co-authored: [Twitch Chat 2020](https://twitch.tv/teej_dv)
2020-11-12 20:21:34 -07:00
|
|
|
-- Store the uninitialized_clients for cleanup in case we exit before initialize finishes.
|
2019-11-13 13:55:26 -07:00
|
|
|
uninitialized_clients[client_id] = client
|
|
|
|
|
|
|
|
local function initialize()
|
|
|
|
local valid_traces = {
|
|
|
|
off = 'off',
|
|
|
|
messages = 'messages',
|
|
|
|
verbose = 'verbose',
|
|
|
|
}
|
2021-07-20 13:00:38 -07:00
|
|
|
|
2023-12-13 05:00:11 -07:00
|
|
|
local workspace_folders --- @type lsp.WorkspaceFolder[]?
|
2023-06-07 05:39:41 -07:00
|
|
|
local root_uri --- @type string?
|
|
|
|
local root_path --- @type string?
|
2021-11-21 09:39:30 -07:00
|
|
|
if config.workspace_folders or config.root_dir then
|
|
|
|
if config.root_dir and not config.workspace_folders then
|
|
|
|
workspace_folders = {
|
2022-05-09 02:23:51 -07:00
|
|
|
{
|
2021-11-21 09:39:30 -07:00
|
|
|
uri = vim.uri_from_fname(config.root_dir),
|
|
|
|
name = string.format('%s', config.root_dir),
|
|
|
|
},
|
2022-05-09 02:23:51 -07:00
|
|
|
}
|
2021-11-21 09:39:30 -07:00
|
|
|
else
|
|
|
|
workspace_folders = config.workspace_folders
|
|
|
|
end
|
|
|
|
root_uri = workspace_folders[1].uri
|
|
|
|
root_path = vim.uri_to_fname(root_uri)
|
|
|
|
else
|
2021-11-22 07:52:24 -07:00
|
|
|
workspace_folders = nil
|
|
|
|
root_uri = nil
|
|
|
|
root_path = nil
|
2021-07-20 13:00:38 -07:00
|
|
|
end
|
|
|
|
|
2019-11-13 13:55:26 -07:00
|
|
|
local initialize_params = {
|
|
|
|
-- The process Id of the parent process that started the server. Is null if
|
|
|
|
-- the process has not been started by another process. If the parent
|
|
|
|
-- process is not alive then the server should exit (see exit notification)
|
|
|
|
-- its process.
|
2023-06-07 05:39:41 -07:00
|
|
|
processId = uv.os_getpid(),
|
2021-01-18 02:13:26 -07:00
|
|
|
-- Information about the client
|
|
|
|
-- since 3.15.0
|
|
|
|
clientInfo = {
|
|
|
|
name = 'Neovim',
|
2023-06-21 02:34:49 -07:00
|
|
|
version = tostring(vim.version()),
|
2021-01-18 02:13:26 -07:00
|
|
|
},
|
2019-11-13 13:55:26 -07:00
|
|
|
-- The rootPath of the workspace. Is null if no folder is open.
|
|
|
|
--
|
|
|
|
-- @deprecated in favour of rootUri.
|
2021-11-22 07:52:24 -07:00
|
|
|
rootPath = root_path or vim.NIL,
|
2019-11-13 13:55:26 -07:00
|
|
|
-- The rootUri of the workspace. Is null if no folder is open. If both
|
|
|
|
-- `rootPath` and `rootUri` are set `rootUri` wins.
|
2021-11-22 07:52:24 -07:00
|
|
|
rootUri = root_uri or vim.NIL,
|
2021-11-21 09:39:30 -07:00
|
|
|
-- 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.
|
2021-11-22 07:52:24 -07:00
|
|
|
workspaceFolders = workspace_folders or vim.NIL,
|
2019-11-13 13:55:26 -07:00
|
|
|
-- User provided initialization options.
|
|
|
|
initializationOptions = config.init_options,
|
|
|
|
-- The capabilities provided by the client (editor or tool)
|
2023-05-27 22:51:28 -07:00
|
|
|
capabilities = config.capabilities,
|
2019-12-31 07:52:14 -07:00
|
|
|
-- The initial trace setting. If omitted trace is disabled ("off").
|
|
|
|
-- trace = "off" | "messages" | "verbose";
|
2019-11-13 13:55:26 -07:00
|
|
|
trace = valid_traces[config.trace] or 'off',
|
|
|
|
}
|
2019-11-21 16:19:06 -07:00
|
|
|
if config.before_init then
|
2023-10-11 13:38:58 -07:00
|
|
|
local status, err = pcall(config.before_init, initialize_params, config)
|
|
|
|
if not status then
|
|
|
|
write_error(lsp.client_errors.BEFORE_INIT_CALLBACK_ERROR, err)
|
|
|
|
end
|
2019-11-21 16:19:06 -07:00
|
|
|
end
|
2023-05-27 22:51:28 -07:00
|
|
|
|
|
|
|
--- @param method string
|
2023-12-22 07:03:13 -07:00
|
|
|
--- @param opts? {bufnr: integer?}
|
2023-05-27 22:51:28 -07:00
|
|
|
client.supports_method = function(method, opts)
|
|
|
|
opts = opts or {}
|
|
|
|
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
|
2023-08-31 01:14:20 -07:00
|
|
|
if vim.tbl_get(client.server_capabilities, unpack(required_capability)) then
|
2023-05-27 22:51:28 -07:00
|
|
|
return true
|
|
|
|
else
|
|
|
|
if client.dynamic_capabilities:supports_registration(method) then
|
|
|
|
return client.dynamic_capabilities:supports(method, opts)
|
|
|
|
end
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-12-13 05:00:11 -07:00
|
|
|
if log.trace() then
|
|
|
|
log.trace(log_prefix, 'initialize_params', initialize_params)
|
|
|
|
end
|
2019-11-13 13:55:26 -07:00
|
|
|
rpc.request('initialize', initialize_params, function(init_err, result)
|
|
|
|
assert(not init_err, tostring(init_err))
|
|
|
|
assert(result, 'server sent empty result')
|
2021-09-26 13:53:04 -07:00
|
|
|
rpc.notify('initialized', vim.empty_dict())
|
2019-11-13 13:55:26 -07:00
|
|
|
client.initialized = true
|
|
|
|
uninitialized_clients[client_id] = nil
|
2021-11-22 07:52:24 -07:00
|
|
|
client.workspace_folders = workspace_folders
|
2022-04-30 02:22:30 -07:00
|
|
|
|
2019-11-13 13:55:26 -07:00
|
|
|
-- These are the cleaned up capabilities we use for dynamically deciding
|
|
|
|
-- when to send certain events to clients.
|
2022-04-30 02:22:30 -07:00
|
|
|
client.server_capabilities =
|
|
|
|
assert(result.capabilities, "initialize result doesn't contain capabilities")
|
2023-12-13 05:00:11 -07:00
|
|
|
client.server_capabilities = assert(protocol.resolve_capabilities(client.server_capabilities))
|
2022-06-03 09:16:11 -07:00
|
|
|
|
2023-06-01 09:15:33 -07:00
|
|
|
if client.server_capabilities.positionEncoding then
|
|
|
|
client.offset_encoding = client.server_capabilities.positionEncoding
|
|
|
|
end
|
|
|
|
|
2022-06-03 09:16:11 -07:00
|
|
|
if next(config.settings) then
|
2023-08-03 04:03:48 -07:00
|
|
|
client.notify(ms.workspace_didChangeConfiguration, { settings = config.settings })
|
2022-06-03 09:16:11 -07:00
|
|
|
end
|
2022-04-30 02:22:30 -07:00
|
|
|
|
2019-11-13 13:55:26 -07:00
|
|
|
if config.on_init then
|
|
|
|
local status, err = pcall(config.on_init, client, result)
|
|
|
|
if not status then
|
2023-10-11 13:38:58 -07:00
|
|
|
write_error(lsp.client_errors.ON_INIT_CALLBACK_ERROR, err)
|
2019-11-13 13:55:26 -07:00
|
|
|
end
|
|
|
|
end
|
2023-12-13 05:00:11 -07:00
|
|
|
if log.info() then
|
|
|
|
log.info(
|
2022-04-30 02:22:30 -07:00
|
|
|
log_prefix,
|
|
|
|
'server_capabilities',
|
|
|
|
{ server_capabilities = client.server_capabilities }
|
|
|
|
)
|
2023-12-13 05:00:11 -07:00
|
|
|
end
|
2019-11-13 13:55:26 -07:00
|
|
|
|
|
|
|
-- Only assign after initialized.
|
|
|
|
active_clients[client_id] = client
|
|
|
|
-- If we had been registered before we start, then send didOpen This can
|
|
|
|
-- happen if we attach to buffers before initialize finishes or if
|
|
|
|
-- someone restarts a client.
|
|
|
|
for bufnr, client_ids in pairs(all_buffer_active_clients) do
|
|
|
|
if client_ids[client_id] then
|
|
|
|
client._on_attach(bufnr)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
|
2023-07-24 11:21:35 -07:00
|
|
|
---@nodoc
|
2020-08-19 09:17:08 -07:00
|
|
|
--- Sends a request to the server.
|
|
|
|
---
|
|
|
|
--- This is a thin wrapper around {client.rpc.request} with some additional
|
lsp: vim.lsp.diagnostic (#12655)
Breaking Changes:
- Deprecated all `vim.lsp.util.{*diagnostics*}()` functions.
- Instead, all functions must be found in vim.lsp.diagnostic
- For now, they issue a warning ONCE per neovim session. In a
"little while" we will remove them completely.
- `vim.lsp.callbacks` has moved to `vim.lsp.handlers`.
- For a "little while" we will just redirect `vim.lsp.callbacks` to
`vim.lsp.handlers`. However, we will remove this at some point, so
it is recommended that you change all of your references to
`callbacks` into `handlers`.
- This also means that for functions like |vim.lsp.start_client()|
and similar, keyword style arguments have moved from "callbacks"
to "handlers". Once again, these are currently being forward, but
will cease to be forwarded in a "little while".
- Changed the highlight groups for LspDiagnostic highlight as they were
inconsistently named.
- For more information, see |lsp-highlight-diagnostics|
- Changed the sign group names as well, to be consistent with
|lsp-highlight-diagnostics|
General Enhancements:
- Rewrote much of the getting started help document for lsp. It also
provides a much nicer configuration strategy, so as to not recommend
globally overwriting builtin neovim mappings.
LSP Enhancements:
- Introduced the concept of |lsp-handlers| which will allow much better
customization for users without having to copy & paste entire files /
functions / etc.
Diagnostic Enhancements:
- "goto next diagnostic" |vim.lsp.diagnostic.goto_next()|
- "goto prev diagnostic" |vim.lsp.diagnostic.goto_prev()|
- For each of the gotos, auto open diagnostics is available as a
configuration option
- Configurable diagnostic handling:
- See |vim.lsp.diagnostic.on_publish_diagnostics()|
- Delay display until after insert mode
- Configure signs
- Configure virtual text
- Configure underline
- Set the location list with the buffers diagnostics.
- See |vim.lsp.diagnostic.set_loclist()|
- Better performance for getting counts and line diagnostics
- They are now cached on save, to enhance lookups.
- Particularly useful for checking in statusline, etc.
- Actual testing :)
- See ./test/functional/plugin/lsp/diagnostic_spec.lua
- Added `guisp` for underline highlighting
NOTE: "a little while" means enough time to feel like most plugins and
plugin authors have had a chance to refactor their code to use the
updated calls. Then we will remove them completely. There is no need to
keep them, because we don't have any released version of neovim that
exposes these APIs. I'm trying to be nice to people following HEAD :)
Co-authored: [Twitch Chat 2020](https://twitch.tv/teej_dv)
2020-11-12 20:21:34 -07:00
|
|
|
--- checks for capabilities and handler availability.
|
2020-08-19 09:17:08 -07:00
|
|
|
---
|
2023-02-25 10:47:05 -07:00
|
|
|
---@param method string LSP method name.
|
2023-03-09 14:17:08 -07:00
|
|
|
---@param params table|nil LSP request params.
|
2023-12-13 05:00:11 -07:00
|
|
|
---@param handler lsp.Handler|nil Response |lsp-handler| for this method.
|
2023-02-25 10:47:05 -07:00
|
|
|
---@param bufnr integer Buffer handle (0 for current).
|
|
|
|
---@return boolean status, integer|nil request_id {status} is a bool indicating
|
2020-08-19 09:17:08 -07:00
|
|
|
---whether the request was successful. If it is `false`, then it will
|
|
|
|
---always be `false` (the client has shutdown). If it was
|
|
|
|
---successful, then it will return {request_id} as the
|
|
|
|
---second result. You can use this with `client.cancel_request(request_id)`
|
|
|
|
---to cancel the-request.
|
2023-06-19 08:40:33 -07:00
|
|
|
---@see |vim.lsp.buf_request_all()|
|
lsp: vim.lsp.diagnostic (#12655)
Breaking Changes:
- Deprecated all `vim.lsp.util.{*diagnostics*}()` functions.
- Instead, all functions must be found in vim.lsp.diagnostic
- For now, they issue a warning ONCE per neovim session. In a
"little while" we will remove them completely.
- `vim.lsp.callbacks` has moved to `vim.lsp.handlers`.
- For a "little while" we will just redirect `vim.lsp.callbacks` to
`vim.lsp.handlers`. However, we will remove this at some point, so
it is recommended that you change all of your references to
`callbacks` into `handlers`.
- This also means that for functions like |vim.lsp.start_client()|
and similar, keyword style arguments have moved from "callbacks"
to "handlers". Once again, these are currently being forward, but
will cease to be forwarded in a "little while".
- Changed the highlight groups for LspDiagnostic highlight as they were
inconsistently named.
- For more information, see |lsp-highlight-diagnostics|
- Changed the sign group names as well, to be consistent with
|lsp-highlight-diagnostics|
General Enhancements:
- Rewrote much of the getting started help document for lsp. It also
provides a much nicer configuration strategy, so as to not recommend
globally overwriting builtin neovim mappings.
LSP Enhancements:
- Introduced the concept of |lsp-handlers| which will allow much better
customization for users without having to copy & paste entire files /
functions / etc.
Diagnostic Enhancements:
- "goto next diagnostic" |vim.lsp.diagnostic.goto_next()|
- "goto prev diagnostic" |vim.lsp.diagnostic.goto_prev()|
- For each of the gotos, auto open diagnostics is available as a
configuration option
- Configurable diagnostic handling:
- See |vim.lsp.diagnostic.on_publish_diagnostics()|
- Delay display until after insert mode
- Configure signs
- Configure virtual text
- Configure underline
- Set the location list with the buffers diagnostics.
- See |vim.lsp.diagnostic.set_loclist()|
- Better performance for getting counts and line diagnostics
- They are now cached on save, to enhance lookups.
- Particularly useful for checking in statusline, etc.
- Actual testing :)
- See ./test/functional/plugin/lsp/diagnostic_spec.lua
- Added `guisp` for underline highlighting
NOTE: "a little while" means enough time to feel like most plugins and
plugin authors have had a chance to refactor their code to use the
updated calls. Then we will remove them completely. There is no need to
keep them, because we don't have any released version of neovim that
exposes these APIs. I'm trying to be nice to people following HEAD :)
Co-authored: [Twitch Chat 2020](https://twitch.tv/teej_dv)
2020-11-12 20:21:34 -07:00
|
|
|
function client.request(method, params, handler, bufnr)
|
|
|
|
if not handler then
|
2022-12-09 11:18:31 -07:00
|
|
|
handler = assert(
|
|
|
|
resolve_handler(method),
|
|
|
|
string.format('not found: %q request handler for client %q.', method, client.name)
|
|
|
|
)
|
2019-11-13 13:55:26 -07:00
|
|
|
end
|
2021-03-12 07:01:41 -07:00
|
|
|
-- Ensure pending didChange notifications are sent so that the server doesn't operate on a stale state
|
2022-01-11 10:10:29 -07:00
|
|
|
changetracking.flush(client, bufnr)
|
2023-06-11 02:53:37 -07:00
|
|
|
local version = util.buf_versions[bufnr]
|
2021-10-29 05:45:01 -07:00
|
|
|
bufnr = resolve_bufnr(bufnr)
|
2023-06-07 05:39:41 -07:00
|
|
|
if log.debug() then
|
|
|
|
log.debug(log_prefix, 'client.request', client_id, method, params, handler, bufnr)
|
|
|
|
end
|
2021-10-29 05:45:01 -07:00
|
|
|
local success, request_id = rpc.request(method, params, function(err, result)
|
2023-06-11 02:53:37 -07:00
|
|
|
local context = {
|
|
|
|
method = method,
|
|
|
|
client_id = client_id,
|
|
|
|
bufnr = bufnr,
|
|
|
|
params = params,
|
|
|
|
version = version,
|
|
|
|
}
|
|
|
|
handler(err, result, context)
|
2021-10-29 05:45:01 -07:00
|
|
|
end, function(request_id)
|
2023-05-30 11:56:29 -07:00
|
|
|
local request = client.requests[request_id]
|
|
|
|
request.type = 'complete'
|
|
|
|
nvim_exec_autocmds('LspRequest', {
|
2023-06-13 07:53:13 -07:00
|
|
|
buffer = api.nvim_buf_is_valid(bufnr) and bufnr or nil,
|
2023-05-30 11:56:29 -07:00
|
|
|
modeline = false,
|
|
|
|
data = { client_id = client_id, request_id = request_id, request = request },
|
|
|
|
})
|
2021-10-29 05:45:01 -07:00
|
|
|
client.requests[request_id] = nil
|
2019-11-13 13:55:26 -07:00
|
|
|
end)
|
2021-10-29 05:45:01 -07:00
|
|
|
|
2022-12-09 11:18:31 -07:00
|
|
|
if success and request_id then
|
2023-05-30 11:56:29 -07:00
|
|
|
local request = { type = 'pending', bufnr = bufnr, method = method }
|
|
|
|
client.requests[request_id] = request
|
|
|
|
nvim_exec_autocmds('LspRequest', {
|
|
|
|
buffer = bufnr,
|
|
|
|
modeline = false,
|
|
|
|
data = { client_id = client_id, request_id = request_id, request = request },
|
|
|
|
})
|
2021-10-29 05:45:01 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
return success, request_id
|
2019-11-13 13:55:26 -07:00
|
|
|
end
|
|
|
|
|
2021-08-22 13:55:28 -07:00
|
|
|
---@private
|
2021-04-30 04:40:20 -07:00
|
|
|
--- Sends a request to the server and synchronously waits for the response.
|
|
|
|
---
|
|
|
|
--- This is a wrapper around {client.request}
|
|
|
|
---
|
2021-08-22 13:55:28 -07:00
|
|
|
---@param method (string) LSP method name.
|
|
|
|
---@param params (table) LSP request params.
|
2023-03-06 23:17:52 -07:00
|
|
|
---@param timeout_ms (integer|nil) Maximum time in milliseconds to wait for
|
2022-12-09 11:18:31 -07:00
|
|
|
--- a result. Defaults to 1000
|
2023-03-06 23:17:52 -07:00
|
|
|
---@param bufnr (integer) Buffer handle (0 for current).
|
2023-02-25 10:47:05 -07:00
|
|
|
---@return {err: lsp.ResponseError|nil, result:any}|nil, string|nil err # a dictionary, where
|
|
|
|
--- `err` and `result` come from the |lsp-handler|.
|
|
|
|
--- On timeout, cancel or error, returns `(nil, err)` where `err` is a
|
|
|
|
--- string describing the failure reason. If the request was unsuccessful
|
|
|
|
--- returns `nil`.
|
2021-08-22 13:55:28 -07:00
|
|
|
---@see |vim.lsp.buf_request_sync()|
|
2021-04-30 04:40:20 -07:00
|
|
|
function client.request_sync(method, params, timeout_ms, bufnr)
|
|
|
|
local request_result = nil
|
feat(lsp)!: change handler signature
Previously, the handler signature was:
function(err, method, params, client_id, bufnr, config)
In order to better support external plugins that wish to extend the
protocol, there is other information which would be advantageous to
forward to the client, such as the original params of the request that
generated the callback.
In order to do this, we would need to break symmetry of the handlers, to
add an additional "params" as the 7th argument.
Instead, this PR changes the signature of the handlers to:
function(err, result, ctx, config)
where ctx (the context) includes params, client_id, and bufnr. This also leaves
flexibility for future use-cases.
BREAKING_CHANGE: changes the signature of the built-in client handlers, requiring
updating handler calls
2021-08-27 21:12:30 -07:00
|
|
|
local function _sync_handler(err, result)
|
2021-05-02 06:23:13 -07:00
|
|
|
request_result = { err = err, result = result }
|
2021-04-30 04:40:20 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
local success, request_id = client.request(method, params, _sync_handler, bufnr)
|
|
|
|
if not success then
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
|
2021-05-02 08:08:57 -07:00
|
|
|
local wait_result, reason = vim.wait(timeout_ms or 1000, function()
|
2021-04-30 04:40:20 -07:00
|
|
|
return request_result ~= nil
|
|
|
|
end, 10)
|
|
|
|
|
|
|
|
if not wait_result then
|
2022-12-09 11:18:31 -07:00
|
|
|
if request_id then
|
|
|
|
client.cancel_request(request_id)
|
|
|
|
end
|
2021-04-30 04:40:20 -07:00
|
|
|
return nil, wait_result_reason[reason]
|
|
|
|
end
|
|
|
|
return request_result
|
|
|
|
end
|
|
|
|
|
2023-07-24 11:21:35 -07:00
|
|
|
---@nodoc
|
2020-08-19 09:17:08 -07:00
|
|
|
--- Sends a notification to an LSP server.
|
|
|
|
---
|
2022-01-11 10:10:29 -07:00
|
|
|
---@param method string LSP method name.
|
|
|
|
---@param params table|nil LSP request params.
|
2023-02-25 10:47:05 -07:00
|
|
|
---@return boolean status true if the notification was successful.
|
2020-08-19 09:17:08 -07:00
|
|
|
---If it is false, then it will always be false
|
|
|
|
---(the client has shutdown).
|
2022-01-11 10:10:29 -07:00
|
|
|
function client.notify(method, params)
|
2023-08-03 04:03:48 -07:00
|
|
|
if method ~= ms.textDocument_didChange then
|
2022-01-11 10:10:29 -07:00
|
|
|
changetracking.flush(client)
|
|
|
|
end
|
2023-07-20 00:03:48 -07:00
|
|
|
|
2023-07-22 02:00:17 -07:00
|
|
|
local client_active = rpc.notify(method, params)
|
2023-07-20 00:03:48 -07:00
|
|
|
|
2023-07-22 02:00:17 -07:00
|
|
|
if client_active then
|
2023-07-20 00:03:48 -07:00
|
|
|
vim.schedule(function()
|
|
|
|
nvim_exec_autocmds('LspNotify', {
|
|
|
|
modeline = false,
|
|
|
|
data = {
|
|
|
|
client_id = client.id,
|
|
|
|
method = method,
|
|
|
|
params = params,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
|
2023-07-22 02:00:17 -07:00
|
|
|
return client_active
|
2019-11-13 13:55:26 -07:00
|
|
|
end
|
|
|
|
|
2023-07-24 11:21:35 -07:00
|
|
|
---@nodoc
|
2020-08-19 09:17:08 -07:00
|
|
|
--- Cancels a request with a given request id.
|
|
|
|
---
|
2023-03-06 23:17:52 -07:00
|
|
|
---@param id (integer) id of request to cancel
|
2023-02-25 10:47:05 -07:00
|
|
|
---@return boolean status true if notification was successful. false otherwise
|
2021-08-22 13:55:28 -07:00
|
|
|
---@see |vim.lsp.client.notify()|
|
2019-11-13 13:55:26 -07:00
|
|
|
function client.cancel_request(id)
|
|
|
|
validate({ id = { id, 'n' } })
|
2021-10-29 05:45:01 -07:00
|
|
|
local request = client.requests[id]
|
|
|
|
if request and request.type == 'pending' then
|
|
|
|
request.type = 'cancel'
|
2023-05-30 11:56:29 -07:00
|
|
|
nvim_exec_autocmds('LspRequest', {
|
|
|
|
buffer = request.bufnr,
|
|
|
|
modeline = false,
|
|
|
|
data = { client_id = client_id, request_id = id, request = request },
|
|
|
|
})
|
2021-10-29 05:45:01 -07:00
|
|
|
end
|
2023-08-05 02:03:57 -07:00
|
|
|
return rpc.notify(ms.dollar_cancelRequest, { id = id })
|
2019-11-13 13:55:26 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
-- Track this so that we can escalate automatically if we've already tried a
|
|
|
|
-- graceful shutdown
|
2021-04-23 05:26:33 -07:00
|
|
|
local graceful_shutdown_failed = false
|
2023-07-24 11:21:35 -07:00
|
|
|
|
|
|
|
---@nodoc
|
2020-08-19 09:17:08 -07:00
|
|
|
--- Stops a client, optionally with force.
|
|
|
|
---
|
|
|
|
---By default, it will just ask the - server to shutdown without force. If
|
|
|
|
--- you request to stop a client which has previously been requested to
|
|
|
|
--- shutdown, it will automatically escalate and force shutdown.
|
|
|
|
---
|
2022-08-23 13:39:34 -07:00
|
|
|
---@param force boolean|nil
|
2019-11-13 13:55:26 -07:00
|
|
|
function client.stop(force)
|
2022-08-23 13:39:34 -07:00
|
|
|
if rpc.is_closing() then
|
2019-11-13 13:55:26 -07:00
|
|
|
return
|
|
|
|
end
|
2021-04-23 05:26:33 -07:00
|
|
|
if force or not client.initialized or graceful_shutdown_failed then
|
2022-08-23 13:39:34 -07:00
|
|
|
rpc.terminate()
|
2019-11-13 13:55:26 -07:00
|
|
|
return
|
|
|
|
end
|
|
|
|
-- Sending a signal after a process has exited is acceptable.
|
2023-08-05 02:03:57 -07:00
|
|
|
rpc.request(ms.shutdown, nil, function(err, _)
|
2019-11-13 13:55:26 -07:00
|
|
|
if err == nil then
|
2023-08-05 02:03:57 -07:00
|
|
|
rpc.notify(ms.exit)
|
2019-11-13 13:55:26 -07:00
|
|
|
else
|
|
|
|
-- If there was an error in the shutdown request, then term to be safe.
|
2022-08-23 13:39:34 -07:00
|
|
|
rpc.terminate()
|
2021-04-23 05:26:33 -07:00
|
|
|
graceful_shutdown_failed = true
|
2019-11-13 13:55:26 -07:00
|
|
|
end
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
|
2021-08-22 13:55:28 -07:00
|
|
|
---@private
|
2020-08-19 09:17:08 -07:00
|
|
|
--- Checks whether a client is stopped.
|
|
|
|
---
|
2023-02-25 10:47:05 -07:00
|
|
|
---@return boolean # true if client is stopped or in the process of being
|
2020-08-19 09:17:08 -07:00
|
|
|
---stopped; false otherwise
|
2019-11-13 13:55:26 -07:00
|
|
|
function client.is_stopped()
|
2022-08-23 13:39:34 -07:00
|
|
|
return rpc.is_closing()
|
2019-11-13 13:55:26 -07:00
|
|
|
end
|
|
|
|
|
2023-06-20 09:36:18 -07:00
|
|
|
---@private
|
|
|
|
--- Execute a lsp command, either via client command function (if available)
|
|
|
|
--- or via workspace/executeCommand (if supported by the server)
|
|
|
|
---
|
|
|
|
---@param command lsp.Command
|
|
|
|
---@param context? {bufnr: integer}
|
2023-12-13 05:00:11 -07:00
|
|
|
---@param handler? lsp.Handler only called if a server command
|
2023-06-20 09:36:18 -07:00
|
|
|
function client._exec_cmd(command, context, handler)
|
2024-01-02 08:47:55 -07:00
|
|
|
context = vim.deepcopy(context or {}, true) --[[@as lsp.HandlerContext]]
|
2023-06-20 09:36:18 -07:00
|
|
|
context.bufnr = context.bufnr or api.nvim_get_current_buf()
|
|
|
|
context.client_id = client.id
|
|
|
|
local cmdname = command.command
|
|
|
|
local fn = client.commands[cmdname] or lsp.commands[cmdname]
|
|
|
|
if fn then
|
|
|
|
fn(command, context)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local command_provider = client.server_capabilities.executeCommandProvider
|
|
|
|
local commands = type(command_provider) == 'table' and command_provider.commands or {}
|
|
|
|
if not vim.list_contains(commands, cmdname) then
|
|
|
|
vim.notify_once(
|
|
|
|
string.format(
|
|
|
|
'Language server `%s` does not support command `%s`. This command may require a client extension.',
|
|
|
|
client.name,
|
|
|
|
cmdname
|
|
|
|
),
|
|
|
|
vim.log.levels.WARN
|
|
|
|
)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
-- Not using command directly to exclude extra properties,
|
|
|
|
-- see https://github.com/python-lsp/python-lsp-server/issues/146
|
|
|
|
local params = {
|
|
|
|
command = command.command,
|
|
|
|
arguments = command.arguments,
|
|
|
|
}
|
2023-08-03 04:03:48 -07:00
|
|
|
client.request(ms.workspace_executeCommand, params, handler, context.bufnr)
|
2023-06-20 09:36:18 -07:00
|
|
|
end
|
|
|
|
|
2021-08-22 13:55:28 -07:00
|
|
|
---@private
|
2020-08-19 09:17:08 -07:00
|
|
|
--- Runs the on_attach function from the client's config if it was defined.
|
2023-02-25 10:47:05 -07:00
|
|
|
---@param bufnr integer Buffer number
|
2019-11-13 13:55:26 -07:00
|
|
|
function client._on_attach(bufnr)
|
|
|
|
text_document_did_open_handler(bufnr, client)
|
2022-05-09 11:00:27 -07:00
|
|
|
|
2023-05-27 22:51:28 -07:00
|
|
|
lsp._set_defaults(client, bufnr)
|
2022-07-10 08:26:43 -07:00
|
|
|
|
2022-05-09 11:00:27 -07:00
|
|
|
nvim_exec_autocmds('LspAttach', {
|
|
|
|
buffer = bufnr,
|
|
|
|
modeline = false,
|
|
|
|
data = { client_id = client.id },
|
|
|
|
})
|
|
|
|
|
2019-11-13 13:55:26 -07:00
|
|
|
if config.on_attach then
|
2023-10-11 13:38:58 -07:00
|
|
|
local status, err = pcall(config.on_attach, client, bufnr)
|
|
|
|
if not status then
|
|
|
|
write_error(lsp.client_errors.ON_ATTACH_ERROR, err)
|
|
|
|
end
|
2019-11-13 13:55:26 -07:00
|
|
|
end
|
2022-11-23 09:06:36 -07:00
|
|
|
|
2022-12-09 03:54:09 -07:00
|
|
|
-- schedule the initialization of semantic tokens to give the above
|
|
|
|
-- on_attach and LspAttach callbacks the ability to schedule wrap the
|
|
|
|
-- opt-out (deleting the semanticTokensProvider from capabilities)
|
|
|
|
vim.schedule(function()
|
|
|
|
if vim.tbl_get(client.server_capabilities, 'semanticTokensProvider', 'full') then
|
2024-01-22 10:23:28 -07:00
|
|
|
lsp.semantic_tokens.start(bufnr, client.id)
|
2022-12-09 03:54:09 -07:00
|
|
|
end
|
|
|
|
end)
|
2022-11-23 09:06:36 -07:00
|
|
|
|
2021-10-20 09:33:09 -07:00
|
|
|
client.attached_buffers[bufnr] = true
|
2019-11-13 13:55:26 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
initialize()
|
|
|
|
|
|
|
|
return client_id
|
|
|
|
end
|
|
|
|
|
2020-08-19 09:17:08 -07:00
|
|
|
--- Notify all attached clients that a buffer has changed.
|
2023-12-13 05:00:11 -07:00
|
|
|
---@param _ integer
|
|
|
|
---@param bufnr integer
|
|
|
|
---@param changedtick integer
|
|
|
|
---@param firstline integer
|
|
|
|
---@param lastline integer
|
|
|
|
---@param new_lastline integer
|
|
|
|
---@return true?
|
|
|
|
local function text_document_did_change_handler(
|
|
|
|
_,
|
|
|
|
bufnr,
|
|
|
|
changedtick,
|
|
|
|
firstline,
|
|
|
|
lastline,
|
|
|
|
new_lastline
|
|
|
|
)
|
|
|
|
-- Detach (nvim_buf_attach) via returning True to on_lines if no clients are attached
|
|
|
|
if tbl_isempty(all_buffer_active_clients[bufnr] or {}) then
|
|
|
|
return true
|
2023-01-15 08:00:23 -07:00
|
|
|
end
|
2023-12-13 05:00:11 -07:00
|
|
|
util.buf_versions[bufnr] = changedtick
|
|
|
|
changetracking.send_changes(bufnr, firstline, lastline, new_lastline)
|
2019-11-13 13:55:26 -07:00
|
|
|
end
|
|
|
|
|
2022-07-17 10:13:33 -07:00
|
|
|
---Buffer lifecycle handler for textDocument/didSave
|
2023-12-13 05:00:11 -07:00
|
|
|
--- @param bufnr integer
|
2022-07-17 10:13:33 -07:00
|
|
|
local function text_document_did_save_handler(bufnr)
|
2019-11-13 13:55:26 -07:00
|
|
|
bufnr = resolve_bufnr(bufnr)
|
|
|
|
local uri = vim.uri_from_bufnr(bufnr)
|
2023-12-17 02:54:38 -07:00
|
|
|
local text = once(lsp._buf_get_full_text)
|
2023-07-17 09:27:16 -07:00
|
|
|
for _, client in ipairs(lsp.get_clients({ bufnr = bufnr })) do
|
2022-08-01 13:32:53 -07:00
|
|
|
local name = api.nvim_buf_get_name(bufnr)
|
2023-03-10 23:35:23 -07:00
|
|
|
local old_name = changetracking._get_and_set_name(client, bufnr, name)
|
|
|
|
if old_name and name ~= old_name then
|
2023-08-03 04:03:48 -07:00
|
|
|
client.notify(ms.textDocument_didClose, {
|
2023-03-11 06:50:14 -07:00
|
|
|
textDocument = {
|
|
|
|
uri = vim.uri_from_fname(old_name),
|
|
|
|
},
|
|
|
|
})
|
2023-08-03 04:03:48 -07:00
|
|
|
client.notify(ms.textDocument_didOpen, {
|
2022-08-01 13:32:53 -07:00
|
|
|
textDocument = {
|
|
|
|
version = 0,
|
|
|
|
uri = uri,
|
|
|
|
languageId = client.config.get_language_id(bufnr, vim.bo[bufnr].filetype),
|
2023-12-17 02:54:38 -07:00
|
|
|
text = lsp._buf_get_full_text(bufnr),
|
2022-08-01 13:32:53 -07:00
|
|
|
},
|
|
|
|
})
|
|
|
|
util.buf_versions[bufnr] = 0
|
|
|
|
end
|
2022-04-30 13:13:26 -07:00
|
|
|
local save_capability = vim.tbl_get(client.server_capabilities, 'textDocumentSync', 'save')
|
|
|
|
if save_capability then
|
2023-12-13 05:00:11 -07:00
|
|
|
local included_text --- @type string?
|
2022-04-30 13:13:26 -07:00
|
|
|
if type(save_capability) == 'table' and save_capability.includeText then
|
2022-01-03 19:03:16 -07:00
|
|
|
included_text = text(bufnr)
|
2019-11-13 13:55:26 -07:00
|
|
|
end
|
2023-08-03 04:03:48 -07:00
|
|
|
client.notify(ms.textDocument_didSave, {
|
2019-11-13 13:55:26 -07:00
|
|
|
textDocument = {
|
|
|
|
uri = uri,
|
2020-12-20 10:12:39 -07:00
|
|
|
},
|
|
|
|
text = included_text,
|
2019-11-13 13:55:26 -07:00
|
|
|
})
|
|
|
|
end
|
2023-06-22 04:54:35 -07:00
|
|
|
end
|
2019-11-13 13:55:26 -07:00
|
|
|
end
|
|
|
|
|
2019-12-31 07:52:14 -07:00
|
|
|
--- Implements the `textDocument/did…` notifications required to track a buffer
|
|
|
|
--- for any language server.
|
|
|
|
---
|
|
|
|
--- Without calling this, the server won't be notified of changes to a buffer.
|
|
|
|
---
|
2023-03-06 23:17:52 -07:00
|
|
|
---@param bufnr (integer) Buffer handle, or 0 for current
|
|
|
|
---@param client_id (integer) Client id
|
2023-06-20 12:17:13 -07:00
|
|
|
---@return boolean success `true` if client was attached successfully; `false` otherwise
|
2019-11-13 13:55:26 -07:00
|
|
|
function lsp.buf_attach_client(bufnr, client_id)
|
|
|
|
validate({
|
|
|
|
bufnr = { bufnr, 'n', true },
|
|
|
|
client_id = { client_id, 'n' },
|
|
|
|
})
|
|
|
|
bufnr = resolve_bufnr(bufnr)
|
2022-07-15 09:26:47 -07:00
|
|
|
if not api.nvim_buf_is_loaded(bufnr) then
|
2023-12-13 05:00:11 -07:00
|
|
|
if log.warn() then
|
|
|
|
log.warn(string.format('buf_attach_client called on unloaded buffer (id: %d): ', bufnr))
|
|
|
|
end
|
2021-12-19 13:49:56 -07:00
|
|
|
return false
|
|
|
|
end
|
2019-11-13 13:55:26 -07:00
|
|
|
local buffer_client_ids = all_buffer_active_clients[bufnr]
|
|
|
|
-- This is our first time attaching to this buffer.
|
|
|
|
if not buffer_client_ids then
|
|
|
|
buffer_client_ids = {}
|
|
|
|
all_buffer_active_clients[bufnr] = buffer_client_ids
|
|
|
|
|
|
|
|
local uri = vim.uri_from_bufnr(bufnr)
|
2022-12-08 02:55:01 -07:00
|
|
|
local augroup = ('lsp_c_%d_b_%d_save'):format(client_id, bufnr)
|
|
|
|
local group = api.nvim_create_augroup(augroup, { clear = true })
|
|
|
|
api.nvim_create_autocmd('BufWritePre', {
|
|
|
|
group = group,
|
|
|
|
buffer = bufnr,
|
|
|
|
desc = 'vim.lsp: textDocument/willSave',
|
|
|
|
callback = function(ctx)
|
2023-07-17 09:27:16 -07:00
|
|
|
for _, client in ipairs(lsp.get_clients({ bufnr = ctx.buf })) do
|
2022-12-08 02:55:01 -07:00
|
|
|
local params = {
|
|
|
|
textDocument = {
|
|
|
|
uri = uri,
|
|
|
|
},
|
|
|
|
reason = protocol.TextDocumentSaveReason.Manual,
|
|
|
|
}
|
|
|
|
if vim.tbl_get(client.server_capabilities, 'textDocumentSync', 'willSave') then
|
2023-08-03 04:03:48 -07:00
|
|
|
client.notify(ms.textDocument_willSave, params)
|
2022-12-08 02:55:01 -07:00
|
|
|
end
|
|
|
|
if vim.tbl_get(client.server_capabilities, 'textDocumentSync', 'willSaveWaitUntil') then
|
|
|
|
local result, err =
|
2023-08-03 04:03:48 -07:00
|
|
|
client.request_sync(ms.textDocument_willSaveWaitUntil, params, 1000, ctx.buf)
|
2022-12-08 02:55:01 -07:00
|
|
|
if result and result.result then
|
|
|
|
util.apply_text_edits(result.result, ctx.buf, client.offset_encoding)
|
|
|
|
elseif err then
|
|
|
|
log.error(vim.inspect(err))
|
|
|
|
end
|
|
|
|
end
|
2023-06-22 04:54:35 -07:00
|
|
|
end
|
2022-12-08 02:55:01 -07:00
|
|
|
end,
|
|
|
|
})
|
2022-07-17 10:13:33 -07:00
|
|
|
api.nvim_create_autocmd('BufWritePost', {
|
2022-12-08 02:55:01 -07:00
|
|
|
group = group,
|
2022-07-17 10:13:33 -07:00
|
|
|
buffer = bufnr,
|
|
|
|
desc = 'vim.lsp: textDocument/didSave handler',
|
|
|
|
callback = function(ctx)
|
|
|
|
text_document_did_save_handler(ctx.buf)
|
|
|
|
end,
|
|
|
|
})
|
2019-11-13 13:55:26 -07:00
|
|
|
-- First time, so attach and set up stuff.
|
2022-07-15 09:26:47 -07:00
|
|
|
api.nvim_buf_attach(bufnr, false, {
|
2019-11-13 13:55:26 -07:00
|
|
|
on_lines = text_document_did_change_handler,
|
2021-03-31 22:41:00 -07:00
|
|
|
on_reload = function()
|
|
|
|
local params = { textDocument = { uri = uri } }
|
2023-07-17 09:27:16 -07:00
|
|
|
for _, client in ipairs(lsp.get_clients({ bufnr = bufnr })) do
|
2021-11-26 02:54:58 -07:00
|
|
|
changetracking.reset_buf(client, bufnr)
|
2022-04-30 02:22:30 -07:00
|
|
|
if vim.tbl_get(client.server_capabilities, 'textDocumentSync', 'openClose') then
|
2023-08-03 04:03:48 -07:00
|
|
|
client.notify(ms.textDocument_didClose, params)
|
2021-03-31 22:41:00 -07:00
|
|
|
end
|
|
|
|
text_document_did_open_handler(bufnr, client)
|
2023-06-22 04:54:35 -07:00
|
|
|
end
|
2021-03-31 22:41:00 -07:00
|
|
|
end,
|
2019-11-13 13:55:26 -07:00
|
|
|
on_detach = function()
|
2023-03-10 23:35:23 -07:00
|
|
|
local params = { textDocument = { uri = uri } }
|
2023-07-17 09:27:16 -07:00
|
|
|
for _, client in ipairs(lsp.get_clients({ bufnr = bufnr })) do
|
2021-11-26 02:54:58 -07:00
|
|
|
changetracking.reset_buf(client, bufnr)
|
2022-04-30 02:22:30 -07:00
|
|
|
if vim.tbl_get(client.server_capabilities, 'textDocumentSync', 'openClose') then
|
2023-08-03 04:03:48 -07:00
|
|
|
client.notify(ms.textDocument_didClose, params)
|
2019-11-13 13:55:26 -07:00
|
|
|
end
|
2022-09-08 08:09:32 -07:00
|
|
|
client.attached_buffers[bufnr] = nil
|
2023-06-22 04:54:35 -07:00
|
|
|
end
|
2020-04-25 05:58:35 -07:00
|
|
|
util.buf_versions[bufnr] = nil
|
2019-11-13 13:55:26 -07:00
|
|
|
all_buffer_active_clients[bufnr] = nil
|
|
|
|
end,
|
|
|
|
-- TODO if we know all of the potential clients ahead of time, then we
|
|
|
|
-- could conditionally set this.
|
|
|
|
-- utf_sizes = size_index > 1;
|
|
|
|
utf_sizes = true,
|
|
|
|
})
|
|
|
|
end
|
2021-01-23 09:43:06 -07:00
|
|
|
|
2019-11-13 13:55:26 -07:00
|
|
|
if buffer_client_ids[client_id] then
|
2023-06-20 12:17:13 -07:00
|
|
|
return true
|
2019-11-13 13:55:26 -07:00
|
|
|
end
|
|
|
|
-- This is our first time attaching this client to this buffer.
|
|
|
|
buffer_client_ids[client_id] = true
|
|
|
|
|
|
|
|
local client = active_clients[client_id]
|
|
|
|
-- Send didOpen for the client if it is initialized. If it isn't initialized
|
|
|
|
-- then it will send didOpen on initialize.
|
|
|
|
if client then
|
|
|
|
client._on_attach(bufnr)
|
|
|
|
end
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2021-12-21 11:53:34 -07:00
|
|
|
--- Detaches client from the specified buffer.
|
|
|
|
--- Note: While the server is notified that the text document (buffer)
|
|
|
|
--- was closed, it is still able to send notifications should it ignore this notification.
|
|
|
|
---
|
2023-03-06 23:17:52 -07:00
|
|
|
---@param bufnr integer Buffer handle, or 0 for current
|
|
|
|
---@param client_id integer Client id
|
2021-12-21 11:53:34 -07:00
|
|
|
function lsp.buf_detach_client(bufnr, client_id)
|
|
|
|
validate({
|
|
|
|
bufnr = { bufnr, 'n', true },
|
|
|
|
client_id = { client_id, 'n' },
|
|
|
|
})
|
|
|
|
bufnr = resolve_bufnr(bufnr)
|
|
|
|
|
|
|
|
local client = lsp.get_client_by_id(client_id)
|
|
|
|
if not client or not client.attached_buffers[bufnr] then
|
|
|
|
vim.notify(
|
|
|
|
string.format(
|
|
|
|
'Buffer (id: %d) is not attached to client (id: %d). Cannot detach.',
|
2023-02-20 23:24:47 -07:00
|
|
|
bufnr,
|
|
|
|
client_id
|
2021-12-21 11:53:34 -07:00
|
|
|
)
|
2022-07-07 09:27:18 -07:00
|
|
|
)
|
2021-12-21 11:53:34 -07:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2022-05-09 11:00:27 -07:00
|
|
|
nvim_exec_autocmds('LspDetach', {
|
|
|
|
buffer = bufnr,
|
|
|
|
modeline = false,
|
|
|
|
data = { client_id = client_id },
|
|
|
|
})
|
|
|
|
|
2021-12-21 11:53:34 -07:00
|
|
|
changetracking.reset_buf(client, bufnr)
|
|
|
|
|
2022-04-30 02:22:30 -07:00
|
|
|
if vim.tbl_get(client.server_capabilities, 'textDocumentSync', 'openClose') then
|
2021-12-21 11:53:34 -07:00
|
|
|
local uri = vim.uri_from_bufnr(bufnr)
|
|
|
|
local params = { textDocument = { uri = uri } }
|
2023-08-03 04:03:48 -07:00
|
|
|
client.notify(ms.textDocument_didClose, params)
|
2021-12-21 11:53:34 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
client.attached_buffers[bufnr] = nil
|
|
|
|
util.buf_versions[bufnr] = nil
|
|
|
|
|
|
|
|
all_buffer_active_clients[bufnr][client_id] = nil
|
|
|
|
if #vim.tbl_keys(all_buffer_active_clients[bufnr]) == 0 then
|
|
|
|
all_buffer_active_clients[bufnr] = nil
|
|
|
|
end
|
|
|
|
|
2023-06-22 04:54:35 -07:00
|
|
|
local namespace = lsp.diagnostic.get_namespace(client_id)
|
2021-12-21 11:53:34 -07:00
|
|
|
vim.diagnostic.reset(namespace, bufnr)
|
|
|
|
end
|
|
|
|
|
2019-12-31 07:52:14 -07:00
|
|
|
--- Checks if a buffer is attached for a particular client.
|
|
|
|
---
|
2023-03-06 23:17:52 -07:00
|
|
|
---@param bufnr (integer) Buffer handle, or 0 for current
|
|
|
|
---@param client_id (integer) the client id
|
2019-11-13 13:55:26 -07:00
|
|
|
function lsp.buf_is_attached(bufnr, client_id)
|
2021-08-30 04:46:00 -07:00
|
|
|
return (all_buffer_active_clients[resolve_bufnr(bufnr)] or {})[client_id] == true
|
2019-11-13 13:55:26 -07:00
|
|
|
end
|
|
|
|
|
2020-10-22 11:59:17 -07:00
|
|
|
--- Gets a client by id, or nil if the id is invalid.
|
|
|
|
--- The returned client may not yet be fully initialized.
|
|
|
|
---
|
2023-03-06 23:17:52 -07:00
|
|
|
---@param client_id integer client id
|
2019-12-31 07:52:14 -07:00
|
|
|
---
|
2023-07-10 04:38:15 -07:00
|
|
|
---@return (nil|lsp.Client) client rpc object
|
2019-11-13 13:55:26 -07:00
|
|
|
function lsp.get_client_by_id(client_id)
|
2020-10-22 11:59:17 -07:00
|
|
|
return active_clients[client_id] or uninitialized_clients[client_id]
|
2019-11-13 13:55:26 -07:00
|
|
|
end
|
|
|
|
|
2021-01-23 09:43:06 -07:00
|
|
|
--- Returns list of buffers attached to client_id.
|
|
|
|
---
|
2023-02-25 10:47:05 -07:00
|
|
|
---@param client_id integer client id
|
|
|
|
---@return integer[] buffers list of buffer ids
|
2021-01-23 09:43:06 -07:00
|
|
|
function lsp.get_buffers_by_client_id(client_id)
|
2021-10-20 09:33:09 -07:00
|
|
|
local client = lsp.get_client_by_id(client_id)
|
|
|
|
return client and vim.tbl_keys(client.attached_buffers) or {}
|
2021-01-23 09:43:06 -07:00
|
|
|
end
|
|
|
|
|
2019-12-31 08:51:54 -07:00
|
|
|
--- Stops a client(s).
|
2019-12-31 07:52:14 -07:00
|
|
|
---
|
|
|
|
--- You can also use the `stop()` function on a |vim.lsp.client| object.
|
2019-12-31 08:51:54 -07:00
|
|
|
--- To stop all clients:
|
2023-09-14 06:23:01 -07:00
|
|
|
---
|
|
|
|
--- ```lua
|
2023-07-17 09:27:16 -07:00
|
|
|
--- vim.lsp.stop_client(vim.lsp.get_clients())
|
2023-09-14 06:23:01 -07:00
|
|
|
--- ```
|
2019-12-31 07:52:14 -07:00
|
|
|
---
|
|
|
|
--- By default asks the server to shutdown, unless stop was requested
|
|
|
|
--- already for this client, then force-shutdown is attempted.
|
|
|
|
---
|
2023-03-06 23:17:52 -07:00
|
|
|
---@param client_id integer|table id or |vim.lsp.client| object, or list thereof
|
2023-01-04 04:48:41 -07:00
|
|
|
---@param force boolean|nil shutdown forcefully
|
2019-11-13 13:55:26 -07:00
|
|
|
function lsp.stop_client(client_id, force)
|
2019-12-31 08:51:54 -07:00
|
|
|
local ids = type(client_id) == 'table' and client_id or { client_id }
|
|
|
|
for _, id in ipairs(ids) do
|
|
|
|
if type(id) == 'table' and id.stop ~= nil then
|
|
|
|
id.stop(force)
|
|
|
|
elseif active_clients[id] then
|
|
|
|
active_clients[id].stop(force)
|
|
|
|
elseif uninitialized_clients[id] then
|
|
|
|
uninitialized_clients[id].stop(true)
|
|
|
|
end
|
2019-11-13 13:55:26 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-07-17 09:27:16 -07:00
|
|
|
---@class vim.lsp.get_clients.filter
|
2023-03-06 23:17:52 -07:00
|
|
|
---@field id integer|nil Match clients by id
|
|
|
|
---@field bufnr integer|nil match clients attached to the given buffer
|
2023-01-03 05:44:44 -07:00
|
|
|
---@field name string|nil match clients by name
|
2023-07-12 05:48:21 -07:00
|
|
|
---@field method string|nil match client by supported method name
|
2022-12-09 11:18:31 -07:00
|
|
|
|
2022-05-16 15:44:55 -07:00
|
|
|
--- Get active clients.
|
2019-12-31 07:52:14 -07:00
|
|
|
---
|
2023-07-17 09:27:16 -07:00
|
|
|
---@param filter vim.lsp.get_clients.filter|nil (table|nil) A table with
|
2022-12-09 11:18:31 -07:00
|
|
|
--- key-value pairs used to filter the returned clients.
|
|
|
|
--- The available keys are:
|
2022-05-16 15:44:55 -07:00
|
|
|
--- - id (number): Only return clients with the given id
|
|
|
|
--- - bufnr (number): Only return clients attached to this buffer
|
|
|
|
--- - name (string): Only return clients with the given name
|
2023-07-12 05:48:21 -07:00
|
|
|
--- - method (string): Only return clients supporting the given method
|
2023-06-07 05:39:41 -07:00
|
|
|
---@return lsp.Client[]: List of |vim.lsp.client| objects
|
2023-07-17 09:27:16 -07:00
|
|
|
function lsp.get_clients(filter)
|
2022-05-16 15:44:55 -07:00
|
|
|
validate({ filter = { filter, 't', true } })
|
|
|
|
|
|
|
|
filter = filter or {}
|
|
|
|
|
2023-06-07 05:39:41 -07:00
|
|
|
local clients = {} --- @type lsp.Client[]
|
2022-05-16 15:44:55 -07:00
|
|
|
|
|
|
|
local t = filter.bufnr and (all_buffer_active_clients[resolve_bufnr(filter.bufnr)] or {})
|
|
|
|
or active_clients
|
|
|
|
for client_id in pairs(t) do
|
|
|
|
local client = active_clients[client_id]
|
|
|
|
if
|
2022-12-30 08:42:18 -07:00
|
|
|
client
|
|
|
|
and (filter.id == nil or client.id == filter.id)
|
2022-05-16 15:44:55 -07:00
|
|
|
and (filter.name == nil or client.name == filter.name)
|
2023-07-12 05:48:21 -07:00
|
|
|
and (filter.method == nil or client.supports_method(filter.method, { bufnr = filter.bufnr }))
|
2022-05-16 15:44:55 -07:00
|
|
|
then
|
|
|
|
clients[#clients + 1] = client
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return clients
|
2019-11-13 13:55:26 -07:00
|
|
|
end
|
|
|
|
|
2023-07-17 09:27:16 -07:00
|
|
|
---@private
|
|
|
|
---@deprecated
|
|
|
|
function lsp.get_active_clients(filter)
|
2023-12-25 13:28:28 -07:00
|
|
|
vim.deprecate('vim.lsp.get_active_clients()', 'vim.lsp.get_clients()', '0.12')
|
2023-07-17 09:27:16 -07:00
|
|
|
return lsp.get_clients(filter)
|
|
|
|
end
|
|
|
|
|
2022-07-17 10:13:33 -07:00
|
|
|
api.nvim_create_autocmd('VimLeavePre', {
|
|
|
|
desc = 'vim.lsp: exit handler',
|
|
|
|
callback = function()
|
|
|
|
log.info('exit_handler', active_clients)
|
|
|
|
for _, client in pairs(uninitialized_clients) do
|
|
|
|
client.stop(true)
|
|
|
|
end
|
|
|
|
-- TODO handle v:dying differently?
|
|
|
|
if tbl_isempty(active_clients) then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
for _, client in pairs(active_clients) do
|
|
|
|
client.stop()
|
|
|
|
end
|
2020-05-20 08:08:19 -07:00
|
|
|
|
2023-12-13 05:00:11 -07:00
|
|
|
local timeouts = {} --- @type table<integer,integer>
|
2022-07-17 10:13:33 -07:00
|
|
|
local max_timeout = 0
|
|
|
|
local send_kill = false
|
2021-10-21 09:36:01 -07:00
|
|
|
|
2022-07-17 10:13:33 -07:00
|
|
|
for client_id, client in pairs(active_clients) do
|
2022-08-08 03:34:37 -07:00
|
|
|
local timeout = if_nil(client.config.flags.exit_timeout, false)
|
2022-07-17 10:13:33 -07:00
|
|
|
if timeout then
|
|
|
|
send_kill = true
|
|
|
|
timeouts[client_id] = timeout
|
|
|
|
max_timeout = math.max(timeout, max_timeout)
|
|
|
|
end
|
2021-10-21 09:36:01 -07:00
|
|
|
end
|
|
|
|
|
2022-07-17 10:13:33 -07:00
|
|
|
local poll_time = 50
|
2021-10-21 09:36:01 -07:00
|
|
|
|
2022-07-17 10:13:33 -07:00
|
|
|
local function check_clients_closed()
|
|
|
|
for client_id, timeout in pairs(timeouts) do
|
|
|
|
timeouts[client_id] = timeout - poll_time
|
|
|
|
end
|
2021-10-31 12:05:57 -07:00
|
|
|
|
2022-07-17 10:13:33 -07:00
|
|
|
for client_id, _ in pairs(active_clients) do
|
|
|
|
if timeouts[client_id] ~= nil and timeouts[client_id] > 0 then
|
|
|
|
return false
|
|
|
|
end
|
2021-10-21 09:36:01 -07:00
|
|
|
end
|
2022-07-17 10:13:33 -07:00
|
|
|
return true
|
2021-10-21 09:36:01 -07:00
|
|
|
end
|
|
|
|
|
2022-07-17 10:13:33 -07:00
|
|
|
if send_kill then
|
|
|
|
if not vim.wait(max_timeout, check_clients_closed, poll_time) then
|
|
|
|
for client_id, client in pairs(active_clients) do
|
|
|
|
if timeouts[client_id] ~= nil then
|
|
|
|
client.stop(true)
|
|
|
|
end
|
2021-10-31 12:05:57 -07:00
|
|
|
end
|
2021-10-21 09:36:01 -07:00
|
|
|
end
|
2019-11-13 13:55:26 -07:00
|
|
|
end
|
2022-07-17 10:13:33 -07:00
|
|
|
end,
|
|
|
|
})
|
2019-11-13 13:55:26 -07:00
|
|
|
|
2022-08-18 01:57:17 -07:00
|
|
|
---@private
|
2019-12-31 07:52:14 -07:00
|
|
|
--- Sends an async request for all active clients attached to the
|
|
|
|
--- buffer.
|
|
|
|
---
|
2023-03-06 23:17:52 -07:00
|
|
|
---@param bufnr (integer) Buffer handle, or 0 for current.
|
2021-08-22 13:55:28 -07:00
|
|
|
---@param method (string) LSP method name
|
2022-08-18 01:57:17 -07:00
|
|
|
---@param params table|nil Parameters to send to the server
|
2023-12-13 05:00:11 -07:00
|
|
|
---@param handler? lsp.Handler See |lsp-handler|
|
lsp: vim.lsp.diagnostic (#12655)
Breaking Changes:
- Deprecated all `vim.lsp.util.{*diagnostics*}()` functions.
- Instead, all functions must be found in vim.lsp.diagnostic
- For now, they issue a warning ONCE per neovim session. In a
"little while" we will remove them completely.
- `vim.lsp.callbacks` has moved to `vim.lsp.handlers`.
- For a "little while" we will just redirect `vim.lsp.callbacks` to
`vim.lsp.handlers`. However, we will remove this at some point, so
it is recommended that you change all of your references to
`callbacks` into `handlers`.
- This also means that for functions like |vim.lsp.start_client()|
and similar, keyword style arguments have moved from "callbacks"
to "handlers". Once again, these are currently being forward, but
will cease to be forwarded in a "little while".
- Changed the highlight groups for LspDiagnostic highlight as they were
inconsistently named.
- For more information, see |lsp-highlight-diagnostics|
- Changed the sign group names as well, to be consistent with
|lsp-highlight-diagnostics|
General Enhancements:
- Rewrote much of the getting started help document for lsp. It also
provides a much nicer configuration strategy, so as to not recommend
globally overwriting builtin neovim mappings.
LSP Enhancements:
- Introduced the concept of |lsp-handlers| which will allow much better
customization for users without having to copy & paste entire files /
functions / etc.
Diagnostic Enhancements:
- "goto next diagnostic" |vim.lsp.diagnostic.goto_next()|
- "goto prev diagnostic" |vim.lsp.diagnostic.goto_prev()|
- For each of the gotos, auto open diagnostics is available as a
configuration option
- Configurable diagnostic handling:
- See |vim.lsp.diagnostic.on_publish_diagnostics()|
- Delay display until after insert mode
- Configure signs
- Configure virtual text
- Configure underline
- Set the location list with the buffers diagnostics.
- See |vim.lsp.diagnostic.set_loclist()|
- Better performance for getting counts and line diagnostics
- They are now cached on save, to enhance lookups.
- Particularly useful for checking in statusline, etc.
- Actual testing :)
- See ./test/functional/plugin/lsp/diagnostic_spec.lua
- Added `guisp` for underline highlighting
NOTE: "a little while" means enough time to feel like most plugins and
plugin authors have had a chance to refactor their code to use the
updated calls. Then we will remove them completely. There is no need to
keep them, because we don't have any released version of neovim that
exposes these APIs. I'm trying to be nice to people following HEAD :)
Co-authored: [Twitch Chat 2020](https://twitch.tv/teej_dv)
2020-11-12 20:21:34 -07:00
|
|
|
--- If nil, follows resolution strategy defined in |lsp-handler-configuration|
|
2019-11-13 13:55:26 -07:00
|
|
|
---
|
2023-07-10 04:38:15 -07:00
|
|
|
---@return table<integer, integer> client_request_ids Map of client-id:request-id pairs
|
|
|
|
---for all successful requests.
|
|
|
|
---@return function _cancel_all_requests Function which can be used to
|
|
|
|
---cancel all the requests. You could instead
|
|
|
|
---iterate all clients and call their `cancel_request()` methods.
|
lsp: vim.lsp.diagnostic (#12655)
Breaking Changes:
- Deprecated all `vim.lsp.util.{*diagnostics*}()` functions.
- Instead, all functions must be found in vim.lsp.diagnostic
- For now, they issue a warning ONCE per neovim session. In a
"little while" we will remove them completely.
- `vim.lsp.callbacks` has moved to `vim.lsp.handlers`.
- For a "little while" we will just redirect `vim.lsp.callbacks` to
`vim.lsp.handlers`. However, we will remove this at some point, so
it is recommended that you change all of your references to
`callbacks` into `handlers`.
- This also means that for functions like |vim.lsp.start_client()|
and similar, keyword style arguments have moved from "callbacks"
to "handlers". Once again, these are currently being forward, but
will cease to be forwarded in a "little while".
- Changed the highlight groups for LspDiagnostic highlight as they were
inconsistently named.
- For more information, see |lsp-highlight-diagnostics|
- Changed the sign group names as well, to be consistent with
|lsp-highlight-diagnostics|
General Enhancements:
- Rewrote much of the getting started help document for lsp. It also
provides a much nicer configuration strategy, so as to not recommend
globally overwriting builtin neovim mappings.
LSP Enhancements:
- Introduced the concept of |lsp-handlers| which will allow much better
customization for users without having to copy & paste entire files /
functions / etc.
Diagnostic Enhancements:
- "goto next diagnostic" |vim.lsp.diagnostic.goto_next()|
- "goto prev diagnostic" |vim.lsp.diagnostic.goto_prev()|
- For each of the gotos, auto open diagnostics is available as a
configuration option
- Configurable diagnostic handling:
- See |vim.lsp.diagnostic.on_publish_diagnostics()|
- Delay display until after insert mode
- Configure signs
- Configure virtual text
- Configure underline
- Set the location list with the buffers diagnostics.
- See |vim.lsp.diagnostic.set_loclist()|
- Better performance for getting counts and line diagnostics
- They are now cached on save, to enhance lookups.
- Particularly useful for checking in statusline, etc.
- Actual testing :)
- See ./test/functional/plugin/lsp/diagnostic_spec.lua
- Added `guisp` for underline highlighting
NOTE: "a little while" means enough time to feel like most plugins and
plugin authors have had a chance to refactor their code to use the
updated calls. Then we will remove them completely. There is no need to
keep them, because we don't have any released version of neovim that
exposes these APIs. I'm trying to be nice to people following HEAD :)
Co-authored: [Twitch Chat 2020](https://twitch.tv/teej_dv)
2020-11-12 20:21:34 -07:00
|
|
|
function lsp.buf_request(bufnr, method, params, handler)
|
2019-11-13 13:55:26 -07:00
|
|
|
validate({
|
|
|
|
bufnr = { bufnr, 'n', true },
|
|
|
|
method = { method, 's' },
|
lsp: vim.lsp.diagnostic (#12655)
Breaking Changes:
- Deprecated all `vim.lsp.util.{*diagnostics*}()` functions.
- Instead, all functions must be found in vim.lsp.diagnostic
- For now, they issue a warning ONCE per neovim session. In a
"little while" we will remove them completely.
- `vim.lsp.callbacks` has moved to `vim.lsp.handlers`.
- For a "little while" we will just redirect `vim.lsp.callbacks` to
`vim.lsp.handlers`. However, we will remove this at some point, so
it is recommended that you change all of your references to
`callbacks` into `handlers`.
- This also means that for functions like |vim.lsp.start_client()|
and similar, keyword style arguments have moved from "callbacks"
to "handlers". Once again, these are currently being forward, but
will cease to be forwarded in a "little while".
- Changed the highlight groups for LspDiagnostic highlight as they were
inconsistently named.
- For more information, see |lsp-highlight-diagnostics|
- Changed the sign group names as well, to be consistent with
|lsp-highlight-diagnostics|
General Enhancements:
- Rewrote much of the getting started help document for lsp. It also
provides a much nicer configuration strategy, so as to not recommend
globally overwriting builtin neovim mappings.
LSP Enhancements:
- Introduced the concept of |lsp-handlers| which will allow much better
customization for users without having to copy & paste entire files /
functions / etc.
Diagnostic Enhancements:
- "goto next diagnostic" |vim.lsp.diagnostic.goto_next()|
- "goto prev diagnostic" |vim.lsp.diagnostic.goto_prev()|
- For each of the gotos, auto open diagnostics is available as a
configuration option
- Configurable diagnostic handling:
- See |vim.lsp.diagnostic.on_publish_diagnostics()|
- Delay display until after insert mode
- Configure signs
- Configure virtual text
- Configure underline
- Set the location list with the buffers diagnostics.
- See |vim.lsp.diagnostic.set_loclist()|
- Better performance for getting counts and line diagnostics
- They are now cached on save, to enhance lookups.
- Particularly useful for checking in statusline, etc.
- Actual testing :)
- See ./test/functional/plugin/lsp/diagnostic_spec.lua
- Added `guisp` for underline highlighting
NOTE: "a little while" means enough time to feel like most plugins and
plugin authors have had a chance to refactor their code to use the
updated calls. Then we will remove them completely. There is no need to
keep them, because we don't have any released version of neovim that
exposes these APIs. I'm trying to be nice to people following HEAD :)
Co-authored: [Twitch Chat 2020](https://twitch.tv/teej_dv)
2020-11-12 20:21:34 -07:00
|
|
|
handler = { handler, 'f', true },
|
2019-11-13 13:55:26 -07:00
|
|
|
})
|
|
|
|
|
2023-06-22 04:54:35 -07:00
|
|
|
bufnr = resolve_bufnr(bufnr)
|
2020-10-24 21:28:15 -07:00
|
|
|
local method_supported = false
|
2023-07-17 09:27:16 -07:00
|
|
|
local clients = lsp.get_clients({ bufnr = bufnr })
|
2023-12-13 05:00:11 -07:00
|
|
|
local client_request_ids = {} --- @type table<integer,integer>
|
2023-06-22 04:54:35 -07:00
|
|
|
for _, client in ipairs(clients) do
|
2023-05-27 22:51:28 -07:00
|
|
|
if client.supports_method(method, { bufnr = bufnr }) then
|
2020-10-24 21:28:15 -07:00
|
|
|
method_supported = true
|
2023-06-22 04:54:35 -07:00
|
|
|
|
|
|
|
local request_success, request_id = client.request(method, params, handler, bufnr)
|
|
|
|
-- This could only fail if the client shut down in the time since we looked
|
|
|
|
-- it up and we did the request, which should be rare.
|
|
|
|
if request_success then
|
|
|
|
client_request_ids[client.id] = request_id
|
|
|
|
end
|
2019-11-13 13:55:26 -07:00
|
|
|
end
|
2023-06-22 04:54:35 -07:00
|
|
|
end
|
2019-11-13 13:55:26 -07:00
|
|
|
|
2021-10-10 22:32:50 -07:00
|
|
|
-- if has client but no clients support the given method, notify the user
|
2023-06-22 04:54:35 -07:00
|
|
|
if next(clients) and not method_supported then
|
2021-10-10 22:32:50 -07:00
|
|
|
vim.notify(lsp._unsupported_method(method), vim.log.levels.ERROR)
|
2022-07-09 16:57:35 -07:00
|
|
|
nvim_command('redraw')
|
2021-10-31 04:44:45 -07:00
|
|
|
return {}, function() end
|
2020-10-24 21:28:15 -07:00
|
|
|
end
|
|
|
|
|
2019-12-31 07:52:14 -07:00
|
|
|
local function _cancel_all_requests()
|
2019-11-13 13:55:26 -07:00
|
|
|
for client_id, request_id in pairs(client_request_ids) do
|
|
|
|
local client = active_clients[client_id]
|
|
|
|
client.cancel_request(request_id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-12-31 07:52:14 -07:00
|
|
|
return client_request_ids, _cancel_all_requests
|
2019-11-13 13:55:26 -07:00
|
|
|
end
|
|
|
|
|
2023-06-19 08:40:33 -07:00
|
|
|
--- Sends an async request for all active clients attached to the buffer and executes the `handler`
|
|
|
|
--- callback with the combined result.
|
2021-04-15 04:42:25 -07:00
|
|
|
---
|
2023-03-06 23:17:52 -07:00
|
|
|
---@param bufnr (integer) Buffer handle, or 0 for current.
|
2021-08-22 13:55:28 -07:00
|
|
|
---@param method (string) LSP method name
|
2022-12-09 11:18:31 -07:00
|
|
|
---@param params (table|nil) Parameters to send to the server
|
2023-06-19 08:40:33 -07:00
|
|
|
---@param handler fun(results: table<integer, {error: lsp.ResponseError, result: any}>) (function)
|
|
|
|
--- Handler called after all requests are completed. Server results are passed as
|
|
|
|
--- a `client_id:result` map.
|
2023-07-10 04:38:15 -07:00
|
|
|
---@return function cancel Function that cancels all requests.
|
2023-06-19 08:40:33 -07:00
|
|
|
function lsp.buf_request_all(bufnr, method, params, handler)
|
2023-12-13 05:00:11 -07:00
|
|
|
local results = {} --- @type table<integer,{error:string, result:any}>
|
2021-04-15 04:42:25 -07:00
|
|
|
local result_count = 0
|
|
|
|
local expected_result_count = 0
|
|
|
|
|
2021-10-10 22:32:50 -07:00
|
|
|
local set_expected_result_count = once(function()
|
2023-07-17 09:27:16 -07:00
|
|
|
for _, client in ipairs(lsp.get_clients({ bufnr = bufnr })) do
|
2023-05-27 22:51:28 -07:00
|
|
|
if client.supports_method(method, { bufnr = bufnr }) then
|
2021-10-10 22:32:50 -07:00
|
|
|
expected_result_count = expected_result_count + 1
|
|
|
|
end
|
2023-06-22 04:54:35 -07:00
|
|
|
end
|
2021-04-15 04:42:25 -07:00
|
|
|
end)
|
|
|
|
|
feat(lsp)!: change handler signature
Previously, the handler signature was:
function(err, method, params, client_id, bufnr, config)
In order to better support external plugins that wish to extend the
protocol, there is other information which would be advantageous to
forward to the client, such as the original params of the request that
generated the callback.
In order to do this, we would need to break symmetry of the handlers, to
add an additional "params" as the 7th argument.
Instead, this PR changes the signature of the handlers to:
function(err, result, ctx, config)
where ctx (the context) includes params, client_id, and bufnr. This also leaves
flexibility for future use-cases.
BREAKING_CHANGE: changes the signature of the built-in client handlers, requiring
updating handler calls
2021-08-27 21:12:30 -07:00
|
|
|
local function _sync_handler(err, result, ctx)
|
2023-06-19 08:40:33 -07:00
|
|
|
results[ctx.client_id] = { error = err, result = result }
|
2021-04-15 04:42:25 -07:00
|
|
|
result_count = result_count + 1
|
|
|
|
set_expected_result_count()
|
|
|
|
|
|
|
|
if result_count >= expected_result_count then
|
2023-06-19 08:40:33 -07:00
|
|
|
handler(results)
|
2021-04-15 04:42:25 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-10-10 22:32:50 -07:00
|
|
|
local _, cancel = lsp.buf_request(bufnr, method, params, _sync_handler)
|
2021-04-15 04:42:25 -07:00
|
|
|
|
|
|
|
return cancel
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Sends a request to all server and waits for the response of all of them.
|
2019-12-31 07:52:14 -07:00
|
|
|
---
|
2021-04-15 04:42:25 -07:00
|
|
|
--- Calls |vim.lsp.buf_request_all()| but blocks Nvim while awaiting the result.
|
2023-06-19 08:40:33 -07:00
|
|
|
--- Parameters are the same as |vim.lsp.buf_request_all()| but the result is
|
|
|
|
--- different. Waits a maximum of {timeout_ms} (default 1000) ms.
|
2019-12-31 07:52:14 -07:00
|
|
|
---
|
2023-03-06 23:17:52 -07:00
|
|
|
---@param bufnr (integer) Buffer handle, or 0 for current.
|
2021-08-22 13:55:28 -07:00
|
|
|
---@param method (string) LSP method name
|
2022-12-09 11:18:31 -07:00
|
|
|
---@param params (table|nil) Parameters to send to the server
|
2023-03-06 23:17:52 -07:00
|
|
|
---@param timeout_ms (integer|nil) Maximum time in milliseconds to wait for a
|
2022-12-09 11:18:31 -07:00
|
|
|
--- result. Defaults to 1000
|
2019-12-31 07:52:14 -07:00
|
|
|
---
|
2023-03-11 06:50:53 -07:00
|
|
|
---@return table<integer, {err: lsp.ResponseError, result: any}>|nil (table) result Map of client_id:request_result.
|
|
|
|
---@return string|nil err On timeout, cancel, or error, `err` is a string describing the failure reason, and `result` is nil.
|
2019-11-13 13:55:26 -07:00
|
|
|
function lsp.buf_request_sync(bufnr, method, params, timeout_ms)
|
2021-04-15 04:42:25 -07:00
|
|
|
local request_results
|
|
|
|
|
|
|
|
local cancel = lsp.buf_request_all(bufnr, method, params, function(it)
|
|
|
|
request_results = it
|
|
|
|
end)
|
2020-05-20 08:08:19 -07:00
|
|
|
|
2021-05-02 08:08:57 -07:00
|
|
|
local wait_result, reason = vim.wait(timeout_ms or 1000, function()
|
2021-04-15 04:42:25 -07:00
|
|
|
return request_results ~= nil
|
2019-11-13 13:55:26 -07:00
|
|
|
end, 10)
|
2020-05-20 08:08:19 -07:00
|
|
|
|
|
|
|
if not wait_result then
|
2019-11-13 13:55:26 -07:00
|
|
|
cancel()
|
2020-05-20 08:08:19 -07:00
|
|
|
return nil, wait_result_reason[reason]
|
2019-11-13 13:55:26 -07:00
|
|
|
end
|
2021-04-15 04:42:25 -07:00
|
|
|
|
2019-11-13 13:55:26 -07:00
|
|
|
return request_results
|
|
|
|
end
|
|
|
|
|
2020-02-26 12:22:14 -07:00
|
|
|
--- Send a notification to a server
|
2023-03-09 14:17:08 -07:00
|
|
|
---@param bufnr (integer|nil) The number of the buffer
|
2022-12-09 11:18:31 -07:00
|
|
|
---@param method (string) Name of the request method
|
2023-01-11 12:17:10 -07:00
|
|
|
---@param params (any) Arguments to send to the server
|
2020-07-02 04:09:17 -07:00
|
|
|
---
|
2023-02-25 10:47:05 -07:00
|
|
|
---@return boolean success true if any client returns true; false otherwise
|
2019-11-13 13:55:26 -07:00
|
|
|
function lsp.buf_notify(bufnr, method, params)
|
|
|
|
validate({
|
|
|
|
bufnr = { bufnr, 'n', true },
|
|
|
|
method = { method, 's' },
|
|
|
|
})
|
2020-02-26 12:22:14 -07:00
|
|
|
local resp = false
|
2023-07-17 09:27:16 -07:00
|
|
|
for _, client in ipairs(lsp.get_clients({ bufnr = bufnr })) do
|
2020-02-26 12:22:14 -07:00
|
|
|
if client.rpc.notify(method, params) then
|
|
|
|
resp = true
|
|
|
|
end
|
2023-06-22 04:54:35 -07:00
|
|
|
end
|
2020-02-26 12:22:14 -07:00
|
|
|
return resp
|
2019-11-13 13:55:26 -07:00
|
|
|
end
|
|
|
|
|
2020-01-13 00:41:55 -07:00
|
|
|
--- Implements 'omnifunc' compatible LSP completion.
|
|
|
|
---
|
2021-08-22 13:55:28 -07:00
|
|
|
---@see |complete-functions|
|
|
|
|
---@see |complete-items|
|
|
|
|
---@see |CompleteDone|
|
2020-01-13 00:41:55 -07:00
|
|
|
---
|
2023-03-06 23:17:52 -07:00
|
|
|
---@param findstart integer 0 or 1, decides behavior
|
|
|
|
---@param base integer findstart=0, text to match against
|
2020-01-13 00:41:55 -07:00
|
|
|
---
|
2023-07-10 04:38:15 -07:00
|
|
|
---@return integer|table Decided by {findstart}:
|
2020-01-13 00:41:55 -07:00
|
|
|
--- - findstart=0: column where the completion starts, or -2 or -3
|
|
|
|
--- - findstart=1: list of matches (actually just calls |complete()|)
|
2019-11-13 13:55:26 -07:00
|
|
|
function lsp.omnifunc(findstart, base)
|
2023-06-07 05:39:41 -07:00
|
|
|
if log.debug() then
|
|
|
|
log.debug('omnifunc.findstart', { findstart = findstart, base = base })
|
|
|
|
end
|
2024-01-22 10:23:28 -07:00
|
|
|
return vim.lsp._completion.omnifunc(findstart, base)
|
2019-11-13 13:55:26 -07:00
|
|
|
end
|
|
|
|
|
2021-10-31 05:40:26 -07:00
|
|
|
--- Provides an interface between the built-in client and a `formatexpr` function.
|
|
|
|
---
|
|
|
|
--- Currently only supports a single client. This can be set via
|
|
|
|
--- `setlocal formatexpr=v:lua.vim.lsp.formatexpr()` but will typically or in `on_attach`
|
2022-12-19 09:37:45 -07:00
|
|
|
--- via ``vim.bo[bufnr].formatexpr = 'v:lua.vim.lsp.formatexpr(#{timeout_ms:250})'``.
|
2021-10-31 05:40:26 -07:00
|
|
|
---
|
|
|
|
---@param opts table options for customizing the formatting expression which takes the
|
2021-11-02 17:02:04 -07:00
|
|
|
--- following optional keys:
|
2021-10-31 05:40:26 -07:00
|
|
|
--- * timeout_ms (default 500ms). The timeout period for the formatting request.
|
|
|
|
function lsp.formatexpr(opts)
|
|
|
|
opts = opts or {}
|
|
|
|
local timeout_ms = opts.timeout_ms or 500
|
|
|
|
|
2023-04-14 01:39:57 -07:00
|
|
|
if vim.list_contains({ 'i', 'R', 'ic', 'ix' }, vim.fn.mode()) then
|
2021-10-31 05:40:26 -07:00
|
|
|
-- `formatexpr` is also called when exceeding `textwidth` in insert mode
|
|
|
|
-- fall back to internal formatting
|
|
|
|
return 1
|
|
|
|
end
|
|
|
|
|
2022-08-08 04:02:15 -07:00
|
|
|
local start_lnum = vim.v.lnum
|
|
|
|
local end_lnum = start_lnum + vim.v.count - 1
|
2021-10-31 05:40:26 -07:00
|
|
|
|
2022-08-08 04:02:15 -07:00
|
|
|
if start_lnum <= 0 or end_lnum <= 0 then
|
|
|
|
return 0
|
|
|
|
end
|
|
|
|
local bufnr = api.nvim_get_current_buf()
|
2023-07-17 09:27:16 -07:00
|
|
|
for _, client in pairs(lsp.get_clients({ bufnr = bufnr })) do
|
2023-08-03 04:03:48 -07:00
|
|
|
if client.supports_method(ms.textDocument_rangeFormatting) then
|
2022-08-08 04:02:15 -07:00
|
|
|
local params = util.make_formatting_params()
|
2023-02-25 10:47:05 -07:00
|
|
|
local end_line = vim.fn.getline(end_lnum) --[[@as string]]
|
2022-08-08 04:02:15 -07:00
|
|
|
local end_col = util._str_utfindex_enc(end_line, nil, client.offset_encoding)
|
2023-12-13 05:00:11 -07:00
|
|
|
--- @cast params +lsp.DocumentRangeFormattingParams
|
2022-08-08 04:02:15 -07:00
|
|
|
params.range = {
|
|
|
|
start = {
|
|
|
|
line = start_lnum - 1,
|
|
|
|
character = 0,
|
|
|
|
},
|
|
|
|
['end'] = {
|
|
|
|
line = end_lnum - 1,
|
|
|
|
character = end_col,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
local response =
|
2023-08-03 04:03:48 -07:00
|
|
|
client.request_sync(ms.textDocument_rangeFormatting, params, timeout_ms, bufnr)
|
2023-06-23 04:54:47 -07:00
|
|
|
if response and response.result then
|
2023-06-22 04:54:35 -07:00
|
|
|
lsp.util.apply_text_edits(response.result, 0, client.offset_encoding)
|
2021-10-31 05:40:26 -07:00
|
|
|
return 0
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- do not run builtin formatter.
|
|
|
|
return 0
|
|
|
|
end
|
|
|
|
|
2021-11-18 11:29:31 -07:00
|
|
|
--- Provides an interface between the built-in client and 'tagfunc'.
|
|
|
|
---
|
|
|
|
--- When used with normal mode commands (e.g. |CTRL-]|) this will invoke
|
|
|
|
--- the "textDocument/definition" LSP method to find the tag under the cursor.
|
|
|
|
--- Otherwise, uses "workspace/symbol". If no results are returned from
|
|
|
|
--- any LSP servers, falls back to using built-in tags.
|
|
|
|
---
|
2022-12-09 11:18:31 -07:00
|
|
|
---@param pattern string Pattern used to find a workspace symbol
|
|
|
|
---@param flags string See |tag-function|
|
2021-11-18 11:29:31 -07:00
|
|
|
---
|
2023-02-25 10:47:05 -07:00
|
|
|
---@return table[] tags A list of matching tags
|
2023-06-07 05:39:41 -07:00
|
|
|
function lsp.tagfunc(pattern, flags)
|
2024-02-03 15:47:56 -07:00
|
|
|
return vim.lsp._tagfunc(pattern, flags)
|
2021-11-18 10:26:26 -07:00
|
|
|
end
|
|
|
|
|
2020-08-19 09:17:08 -07:00
|
|
|
---Checks whether a client is stopped.
|
|
|
|
---
|
2023-03-06 23:17:52 -07:00
|
|
|
---@param client_id (integer)
|
2023-02-25 10:47:05 -07:00
|
|
|
---@return boolean stopped true if client is stopped, false otherwise.
|
2019-11-20 17:03:32 -07:00
|
|
|
function lsp.client_is_stopped(client_id)
|
2023-05-31 23:38:38 -07:00
|
|
|
assert(client_id, 'missing client_id param')
|
|
|
|
return active_clients[client_id] == nil and not uninitialized_clients[client_id]
|
2019-11-13 13:55:26 -07:00
|
|
|
end
|
|
|
|
|
2019-12-31 07:52:14 -07:00
|
|
|
--- Gets a map of client_id:client pairs for the given buffer, where each value
|
|
|
|
--- is a |vim.lsp.client| object.
|
2019-11-13 13:55:26 -07:00
|
|
|
---
|
2023-03-06 23:17:52 -07:00
|
|
|
---@param bufnr (integer|nil): Buffer handle, or 0 for current
|
2023-07-10 04:38:15 -07:00
|
|
|
---@return table result is table of (client_id, client) pairs
|
2023-07-17 09:27:16 -07:00
|
|
|
---@deprecated Use |vim.lsp.get_clients()| instead.
|
2019-11-13 13:55:26 -07:00
|
|
|
function lsp.buf_get_clients(bufnr)
|
2023-12-25 13:28:28 -07:00
|
|
|
vim.deprecate('vim.lsp.buf_get_clients()', 'vim.lsp.get_clients()', '0.12')
|
2023-12-13 05:00:11 -07:00
|
|
|
local result = {} --- @type table<integer,lsp.Client>
|
2023-07-17 09:27:16 -07:00
|
|
|
for _, client in ipairs(lsp.get_clients({ bufnr = resolve_bufnr(bufnr) })) do
|
2022-05-16 15:44:55 -07:00
|
|
|
result[client.id] = client
|
|
|
|
end
|
2019-11-13 13:55:26 -07:00
|
|
|
return result
|
|
|
|
end
|
|
|
|
|
2023-07-18 07:42:30 -07:00
|
|
|
--- Log level dictionary with reverse lookup as well.
|
|
|
|
---
|
|
|
|
--- Can be used to lookup the number from the name or the
|
|
|
|
--- name from the number.
|
|
|
|
--- Levels by name: "TRACE", "DEBUG", "INFO", "WARN", "ERROR", "OFF"
|
|
|
|
--- Level numbers begin with "TRACE" at 0
|
|
|
|
--- @nodoc
|
2019-11-13 13:55:26 -07:00
|
|
|
lsp.log_levels = log.levels
|
|
|
|
|
2019-12-31 07:52:14 -07:00
|
|
|
--- Sets the global log level for LSP logging.
|
|
|
|
---
|
2022-05-03 07:49:23 -07:00
|
|
|
--- Levels by name: "TRACE", "DEBUG", "INFO", "WARN", "ERROR", "OFF"
|
|
|
|
---
|
2019-12-31 07:52:14 -07:00
|
|
|
--- Level numbers begin with "TRACE" at 0
|
|
|
|
---
|
|
|
|
--- Use `lsp.log_levels` for reverse lookup.
|
|
|
|
---
|
2021-08-22 13:55:28 -07:00
|
|
|
---@see |vim.lsp.log_levels|
|
2019-12-31 07:52:14 -07:00
|
|
|
---
|
2023-03-06 23:17:52 -07:00
|
|
|
---@param level (integer|string) the case insensitive level name or number
|
2019-11-13 13:55:26 -07:00
|
|
|
function lsp.set_log_level(level)
|
|
|
|
if type(level) == 'string' or type(level) == 'number' then
|
|
|
|
log.set_level(level)
|
|
|
|
else
|
|
|
|
error(string.format('Invalid log level: %q', level))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-12-31 07:52:14 -07:00
|
|
|
--- Gets the path of the logfile used by the LSP client.
|
2023-02-25 10:47:05 -07:00
|
|
|
---@return string path to log file
|
2019-11-13 13:55:26 -07:00
|
|
|
function lsp.get_log_path()
|
|
|
|
return log.get_filename()
|
|
|
|
end
|
|
|
|
|
2023-06-22 04:54:35 -07:00
|
|
|
---@private
|
2021-11-29 20:31:19 -07:00
|
|
|
--- Invokes a function for each LSP client attached to a buffer.
|
|
|
|
---
|
2023-03-06 23:17:52 -07:00
|
|
|
---@param bufnr integer Buffer number
|
2021-11-29 20:31:19 -07:00
|
|
|
---@param fn function Function to run on each client attached to buffer
|
|
|
|
--- {bufnr}. The function takes the client, client ID, and
|
2023-09-14 06:23:01 -07:00
|
|
|
--- buffer number as arguments.
|
2023-07-17 09:27:16 -07:00
|
|
|
---@deprecated use lsp.get_clients({ bufnr = bufnr }) with regular loop
|
lsp: vim.lsp.diagnostic (#12655)
Breaking Changes:
- Deprecated all `vim.lsp.util.{*diagnostics*}()` functions.
- Instead, all functions must be found in vim.lsp.diagnostic
- For now, they issue a warning ONCE per neovim session. In a
"little while" we will remove them completely.
- `vim.lsp.callbacks` has moved to `vim.lsp.handlers`.
- For a "little while" we will just redirect `vim.lsp.callbacks` to
`vim.lsp.handlers`. However, we will remove this at some point, so
it is recommended that you change all of your references to
`callbacks` into `handlers`.
- This also means that for functions like |vim.lsp.start_client()|
and similar, keyword style arguments have moved from "callbacks"
to "handlers". Once again, these are currently being forward, but
will cease to be forwarded in a "little while".
- Changed the highlight groups for LspDiagnostic highlight as they were
inconsistently named.
- For more information, see |lsp-highlight-diagnostics|
- Changed the sign group names as well, to be consistent with
|lsp-highlight-diagnostics|
General Enhancements:
- Rewrote much of the getting started help document for lsp. It also
provides a much nicer configuration strategy, so as to not recommend
globally overwriting builtin neovim mappings.
LSP Enhancements:
- Introduced the concept of |lsp-handlers| which will allow much better
customization for users without having to copy & paste entire files /
functions / etc.
Diagnostic Enhancements:
- "goto next diagnostic" |vim.lsp.diagnostic.goto_next()|
- "goto prev diagnostic" |vim.lsp.diagnostic.goto_prev()|
- For each of the gotos, auto open diagnostics is available as a
configuration option
- Configurable diagnostic handling:
- See |vim.lsp.diagnostic.on_publish_diagnostics()|
- Delay display until after insert mode
- Configure signs
- Configure virtual text
- Configure underline
- Set the location list with the buffers diagnostics.
- See |vim.lsp.diagnostic.set_loclist()|
- Better performance for getting counts and line diagnostics
- They are now cached on save, to enhance lookups.
- Particularly useful for checking in statusline, etc.
- Actual testing :)
- See ./test/functional/plugin/lsp/diagnostic_spec.lua
- Added `guisp` for underline highlighting
NOTE: "a little while" means enough time to feel like most plugins and
plugin authors have had a chance to refactor their code to use the
updated calls. Then we will remove them completely. There is no need to
keep them, because we don't have any released version of neovim that
exposes these APIs. I'm trying to be nice to people following HEAD :)
Co-authored: [Twitch Chat 2020](https://twitch.tv/teej_dv)
2020-11-12 20:21:34 -07:00
|
|
|
function lsp.for_each_buffer_client(bufnr, fn)
|
2023-12-25 13:28:28 -07:00
|
|
|
vim.deprecate(
|
|
|
|
'vim.lsp.for_each_buffer_client()',
|
|
|
|
'lsp.get_clients({ bufnr = bufnr }) with regular loop',
|
|
|
|
'0.12'
|
|
|
|
)
|
lsp: vim.lsp.diagnostic (#12655)
Breaking Changes:
- Deprecated all `vim.lsp.util.{*diagnostics*}()` functions.
- Instead, all functions must be found in vim.lsp.diagnostic
- For now, they issue a warning ONCE per neovim session. In a
"little while" we will remove them completely.
- `vim.lsp.callbacks` has moved to `vim.lsp.handlers`.
- For a "little while" we will just redirect `vim.lsp.callbacks` to
`vim.lsp.handlers`. However, we will remove this at some point, so
it is recommended that you change all of your references to
`callbacks` into `handlers`.
- This also means that for functions like |vim.lsp.start_client()|
and similar, keyword style arguments have moved from "callbacks"
to "handlers". Once again, these are currently being forward, but
will cease to be forwarded in a "little while".
- Changed the highlight groups for LspDiagnostic highlight as they were
inconsistently named.
- For more information, see |lsp-highlight-diagnostics|
- Changed the sign group names as well, to be consistent with
|lsp-highlight-diagnostics|
General Enhancements:
- Rewrote much of the getting started help document for lsp. It also
provides a much nicer configuration strategy, so as to not recommend
globally overwriting builtin neovim mappings.
LSP Enhancements:
- Introduced the concept of |lsp-handlers| which will allow much better
customization for users without having to copy & paste entire files /
functions / etc.
Diagnostic Enhancements:
- "goto next diagnostic" |vim.lsp.diagnostic.goto_next()|
- "goto prev diagnostic" |vim.lsp.diagnostic.goto_prev()|
- For each of the gotos, auto open diagnostics is available as a
configuration option
- Configurable diagnostic handling:
- See |vim.lsp.diagnostic.on_publish_diagnostics()|
- Delay display until after insert mode
- Configure signs
- Configure virtual text
- Configure underline
- Set the location list with the buffers diagnostics.
- See |vim.lsp.diagnostic.set_loclist()|
- Better performance for getting counts and line diagnostics
- They are now cached on save, to enhance lookups.
- Particularly useful for checking in statusline, etc.
- Actual testing :)
- See ./test/functional/plugin/lsp/diagnostic_spec.lua
- Added `guisp` for underline highlighting
NOTE: "a little while" means enough time to feel like most plugins and
plugin authors have had a chance to refactor their code to use the
updated calls. Then we will remove them completely. There is no need to
keep them, because we don't have any released version of neovim that
exposes these APIs. I'm trying to be nice to people following HEAD :)
Co-authored: [Twitch Chat 2020](https://twitch.tv/teej_dv)
2020-11-12 20:21:34 -07:00
|
|
|
return for_each_buffer_client(bufnr, fn)
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Function to manage overriding defaults for LSP handlers.
|
2023-12-13 05:00:11 -07:00
|
|
|
---@param handler (lsp.Handler) See |lsp-handler|
|
2021-08-22 13:55:28 -07:00
|
|
|
---@param override_config (table) Table containing the keys to override behavior of the {handler}
|
lsp: vim.lsp.diagnostic (#12655)
Breaking Changes:
- Deprecated all `vim.lsp.util.{*diagnostics*}()` functions.
- Instead, all functions must be found in vim.lsp.diagnostic
- For now, they issue a warning ONCE per neovim session. In a
"little while" we will remove them completely.
- `vim.lsp.callbacks` has moved to `vim.lsp.handlers`.
- For a "little while" we will just redirect `vim.lsp.callbacks` to
`vim.lsp.handlers`. However, we will remove this at some point, so
it is recommended that you change all of your references to
`callbacks` into `handlers`.
- This also means that for functions like |vim.lsp.start_client()|
and similar, keyword style arguments have moved from "callbacks"
to "handlers". Once again, these are currently being forward, but
will cease to be forwarded in a "little while".
- Changed the highlight groups for LspDiagnostic highlight as they were
inconsistently named.
- For more information, see |lsp-highlight-diagnostics|
- Changed the sign group names as well, to be consistent with
|lsp-highlight-diagnostics|
General Enhancements:
- Rewrote much of the getting started help document for lsp. It also
provides a much nicer configuration strategy, so as to not recommend
globally overwriting builtin neovim mappings.
LSP Enhancements:
- Introduced the concept of |lsp-handlers| which will allow much better
customization for users without having to copy & paste entire files /
functions / etc.
Diagnostic Enhancements:
- "goto next diagnostic" |vim.lsp.diagnostic.goto_next()|
- "goto prev diagnostic" |vim.lsp.diagnostic.goto_prev()|
- For each of the gotos, auto open diagnostics is available as a
configuration option
- Configurable diagnostic handling:
- See |vim.lsp.diagnostic.on_publish_diagnostics()|
- Delay display until after insert mode
- Configure signs
- Configure virtual text
- Configure underline
- Set the location list with the buffers diagnostics.
- See |vim.lsp.diagnostic.set_loclist()|
- Better performance for getting counts and line diagnostics
- They are now cached on save, to enhance lookups.
- Particularly useful for checking in statusline, etc.
- Actual testing :)
- See ./test/functional/plugin/lsp/diagnostic_spec.lua
- Added `guisp` for underline highlighting
NOTE: "a little while" means enough time to feel like most plugins and
plugin authors have had a chance to refactor their code to use the
updated calls. Then we will remove them completely. There is no need to
keep them, because we don't have any released version of neovim that
exposes these APIs. I'm trying to be nice to people following HEAD :)
Co-authored: [Twitch Chat 2020](https://twitch.tv/teej_dv)
2020-11-12 20:21:34 -07:00
|
|
|
function lsp.with(handler, override_config)
|
feat(lsp)!: change handler signature
Previously, the handler signature was:
function(err, method, params, client_id, bufnr, config)
In order to better support external plugins that wish to extend the
protocol, there is other information which would be advantageous to
forward to the client, such as the original params of the request that
generated the callback.
In order to do this, we would need to break symmetry of the handlers, to
add an additional "params" as the 7th argument.
Instead, this PR changes the signature of the handlers to:
function(err, result, ctx, config)
where ctx (the context) includes params, client_id, and bufnr. This also leaves
flexibility for future use-cases.
BREAKING_CHANGE: changes the signature of the built-in client handlers, requiring
updating handler calls
2021-08-27 21:12:30 -07:00
|
|
|
return function(err, result, ctx, config)
|
|
|
|
return handler(err, result, ctx, vim.tbl_deep_extend('force', config or {}, override_config))
|
lsp: vim.lsp.diagnostic (#12655)
Breaking Changes:
- Deprecated all `vim.lsp.util.{*diagnostics*}()` functions.
- Instead, all functions must be found in vim.lsp.diagnostic
- For now, they issue a warning ONCE per neovim session. In a
"little while" we will remove them completely.
- `vim.lsp.callbacks` has moved to `vim.lsp.handlers`.
- For a "little while" we will just redirect `vim.lsp.callbacks` to
`vim.lsp.handlers`. However, we will remove this at some point, so
it is recommended that you change all of your references to
`callbacks` into `handlers`.
- This also means that for functions like |vim.lsp.start_client()|
and similar, keyword style arguments have moved from "callbacks"
to "handlers". Once again, these are currently being forward, but
will cease to be forwarded in a "little while".
- Changed the highlight groups for LspDiagnostic highlight as they were
inconsistently named.
- For more information, see |lsp-highlight-diagnostics|
- Changed the sign group names as well, to be consistent with
|lsp-highlight-diagnostics|
General Enhancements:
- Rewrote much of the getting started help document for lsp. It also
provides a much nicer configuration strategy, so as to not recommend
globally overwriting builtin neovim mappings.
LSP Enhancements:
- Introduced the concept of |lsp-handlers| which will allow much better
customization for users without having to copy & paste entire files /
functions / etc.
Diagnostic Enhancements:
- "goto next diagnostic" |vim.lsp.diagnostic.goto_next()|
- "goto prev diagnostic" |vim.lsp.diagnostic.goto_prev()|
- For each of the gotos, auto open diagnostics is available as a
configuration option
- Configurable diagnostic handling:
- See |vim.lsp.diagnostic.on_publish_diagnostics()|
- Delay display until after insert mode
- Configure signs
- Configure virtual text
- Configure underline
- Set the location list with the buffers diagnostics.
- See |vim.lsp.diagnostic.set_loclist()|
- Better performance for getting counts and line diagnostics
- They are now cached on save, to enhance lookups.
- Particularly useful for checking in statusline, etc.
- Actual testing :)
- See ./test/functional/plugin/lsp/diagnostic_spec.lua
- Added `guisp` for underline highlighting
NOTE: "a little while" means enough time to feel like most plugins and
plugin authors have had a chance to refactor their code to use the
updated calls. Then we will remove them completely. There is no need to
keep them, because we don't have any released version of neovim that
exposes these APIs. I'm trying to be nice to people following HEAD :)
Co-authored: [Twitch Chat 2020](https://twitch.tv/teej_dv)
2020-11-12 20:21:34 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Helper function to use when implementing a handler.
|
|
|
|
--- This will check that all of the keys in the user configuration
|
|
|
|
--- are valid keys and make sense to include for this handler.
|
|
|
|
---
|
|
|
|
--- Will error on invalid keys (i.e. keys that do not exist in the options)
|
2023-06-07 05:39:41 -07:00
|
|
|
--- @param name string
|
|
|
|
--- @param options table<string,any>
|
|
|
|
--- @param user_config table<string,any>
|
lsp: vim.lsp.diagnostic (#12655)
Breaking Changes:
- Deprecated all `vim.lsp.util.{*diagnostics*}()` functions.
- Instead, all functions must be found in vim.lsp.diagnostic
- For now, they issue a warning ONCE per neovim session. In a
"little while" we will remove them completely.
- `vim.lsp.callbacks` has moved to `vim.lsp.handlers`.
- For a "little while" we will just redirect `vim.lsp.callbacks` to
`vim.lsp.handlers`. However, we will remove this at some point, so
it is recommended that you change all of your references to
`callbacks` into `handlers`.
- This also means that for functions like |vim.lsp.start_client()|
and similar, keyword style arguments have moved from "callbacks"
to "handlers". Once again, these are currently being forward, but
will cease to be forwarded in a "little while".
- Changed the highlight groups for LspDiagnostic highlight as they were
inconsistently named.
- For more information, see |lsp-highlight-diagnostics|
- Changed the sign group names as well, to be consistent with
|lsp-highlight-diagnostics|
General Enhancements:
- Rewrote much of the getting started help document for lsp. It also
provides a much nicer configuration strategy, so as to not recommend
globally overwriting builtin neovim mappings.
LSP Enhancements:
- Introduced the concept of |lsp-handlers| which will allow much better
customization for users without having to copy & paste entire files /
functions / etc.
Diagnostic Enhancements:
- "goto next diagnostic" |vim.lsp.diagnostic.goto_next()|
- "goto prev diagnostic" |vim.lsp.diagnostic.goto_prev()|
- For each of the gotos, auto open diagnostics is available as a
configuration option
- Configurable diagnostic handling:
- See |vim.lsp.diagnostic.on_publish_diagnostics()|
- Delay display until after insert mode
- Configure signs
- Configure virtual text
- Configure underline
- Set the location list with the buffers diagnostics.
- See |vim.lsp.diagnostic.set_loclist()|
- Better performance for getting counts and line diagnostics
- They are now cached on save, to enhance lookups.
- Particularly useful for checking in statusline, etc.
- Actual testing :)
- See ./test/functional/plugin/lsp/diagnostic_spec.lua
- Added `guisp` for underline highlighting
NOTE: "a little while" means enough time to feel like most plugins and
plugin authors have had a chance to refactor their code to use the
updated calls. Then we will remove them completely. There is no need to
keep them, because we don't have any released version of neovim that
exposes these APIs. I'm trying to be nice to people following HEAD :)
Co-authored: [Twitch Chat 2020](https://twitch.tv/teej_dv)
2020-11-12 20:21:34 -07:00
|
|
|
function lsp._with_extend(name, options, user_config)
|
|
|
|
user_config = user_config or {}
|
|
|
|
|
2023-06-07 05:39:41 -07:00
|
|
|
local resulting_config = {} --- @type table<string,any>
|
lsp: vim.lsp.diagnostic (#12655)
Breaking Changes:
- Deprecated all `vim.lsp.util.{*diagnostics*}()` functions.
- Instead, all functions must be found in vim.lsp.diagnostic
- For now, they issue a warning ONCE per neovim session. In a
"little while" we will remove them completely.
- `vim.lsp.callbacks` has moved to `vim.lsp.handlers`.
- For a "little while" we will just redirect `vim.lsp.callbacks` to
`vim.lsp.handlers`. However, we will remove this at some point, so
it is recommended that you change all of your references to
`callbacks` into `handlers`.
- This also means that for functions like |vim.lsp.start_client()|
and similar, keyword style arguments have moved from "callbacks"
to "handlers". Once again, these are currently being forward, but
will cease to be forwarded in a "little while".
- Changed the highlight groups for LspDiagnostic highlight as they were
inconsistently named.
- For more information, see |lsp-highlight-diagnostics|
- Changed the sign group names as well, to be consistent with
|lsp-highlight-diagnostics|
General Enhancements:
- Rewrote much of the getting started help document for lsp. It also
provides a much nicer configuration strategy, so as to not recommend
globally overwriting builtin neovim mappings.
LSP Enhancements:
- Introduced the concept of |lsp-handlers| which will allow much better
customization for users without having to copy & paste entire files /
functions / etc.
Diagnostic Enhancements:
- "goto next diagnostic" |vim.lsp.diagnostic.goto_next()|
- "goto prev diagnostic" |vim.lsp.diagnostic.goto_prev()|
- For each of the gotos, auto open diagnostics is available as a
configuration option
- Configurable diagnostic handling:
- See |vim.lsp.diagnostic.on_publish_diagnostics()|
- Delay display until after insert mode
- Configure signs
- Configure virtual text
- Configure underline
- Set the location list with the buffers diagnostics.
- See |vim.lsp.diagnostic.set_loclist()|
- Better performance for getting counts and line diagnostics
- They are now cached on save, to enhance lookups.
- Particularly useful for checking in statusline, etc.
- Actual testing :)
- See ./test/functional/plugin/lsp/diagnostic_spec.lua
- Added `guisp` for underline highlighting
NOTE: "a little while" means enough time to feel like most plugins and
plugin authors have had a chance to refactor their code to use the
updated calls. Then we will remove them completely. There is no need to
keep them, because we don't have any released version of neovim that
exposes these APIs. I'm trying to be nice to people following HEAD :)
Co-authored: [Twitch Chat 2020](https://twitch.tv/teej_dv)
2020-11-12 20:21:34 -07:00
|
|
|
for k, v in pairs(user_config) do
|
|
|
|
if options[k] == nil then
|
|
|
|
error(
|
|
|
|
debug.traceback(
|
|
|
|
string.format(
|
|
|
|
'Invalid option for `%s`: %s. Valid options are:\n%s',
|
|
|
|
name,
|
|
|
|
k,
|
|
|
|
vim.inspect(vim.tbl_keys(options))
|
2022-05-09 02:23:51 -07:00
|
|
|
)
|
lsp: vim.lsp.diagnostic (#12655)
Breaking Changes:
- Deprecated all `vim.lsp.util.{*diagnostics*}()` functions.
- Instead, all functions must be found in vim.lsp.diagnostic
- For now, they issue a warning ONCE per neovim session. In a
"little while" we will remove them completely.
- `vim.lsp.callbacks` has moved to `vim.lsp.handlers`.
- For a "little while" we will just redirect `vim.lsp.callbacks` to
`vim.lsp.handlers`. However, we will remove this at some point, so
it is recommended that you change all of your references to
`callbacks` into `handlers`.
- This also means that for functions like |vim.lsp.start_client()|
and similar, keyword style arguments have moved from "callbacks"
to "handlers". Once again, these are currently being forward, but
will cease to be forwarded in a "little while".
- Changed the highlight groups for LspDiagnostic highlight as they were
inconsistently named.
- For more information, see |lsp-highlight-diagnostics|
- Changed the sign group names as well, to be consistent with
|lsp-highlight-diagnostics|
General Enhancements:
- Rewrote much of the getting started help document for lsp. It also
provides a much nicer configuration strategy, so as to not recommend
globally overwriting builtin neovim mappings.
LSP Enhancements:
- Introduced the concept of |lsp-handlers| which will allow much better
customization for users without having to copy & paste entire files /
functions / etc.
Diagnostic Enhancements:
- "goto next diagnostic" |vim.lsp.diagnostic.goto_next()|
- "goto prev diagnostic" |vim.lsp.diagnostic.goto_prev()|
- For each of the gotos, auto open diagnostics is available as a
configuration option
- Configurable diagnostic handling:
- See |vim.lsp.diagnostic.on_publish_diagnostics()|
- Delay display until after insert mode
- Configure signs
- Configure virtual text
- Configure underline
- Set the location list with the buffers diagnostics.
- See |vim.lsp.diagnostic.set_loclist()|
- Better performance for getting counts and line diagnostics
- They are now cached on save, to enhance lookups.
- Particularly useful for checking in statusline, etc.
- Actual testing :)
- See ./test/functional/plugin/lsp/diagnostic_spec.lua
- Added `guisp` for underline highlighting
NOTE: "a little while" means enough time to feel like most plugins and
plugin authors have had a chance to refactor their code to use the
updated calls. Then we will remove them completely. There is no need to
keep them, because we don't have any released version of neovim that
exposes these APIs. I'm trying to be nice to people following HEAD :)
Co-authored: [Twitch Chat 2020](https://twitch.tv/teej_dv)
2020-11-12 20:21:34 -07:00
|
|
|
)
|
2022-05-09 02:23:51 -07:00
|
|
|
)
|
2020-04-28 07:41:39 -07:00
|
|
|
end
|
lsp: vim.lsp.diagnostic (#12655)
Breaking Changes:
- Deprecated all `vim.lsp.util.{*diagnostics*}()` functions.
- Instead, all functions must be found in vim.lsp.diagnostic
- For now, they issue a warning ONCE per neovim session. In a
"little while" we will remove them completely.
- `vim.lsp.callbacks` has moved to `vim.lsp.handlers`.
- For a "little while" we will just redirect `vim.lsp.callbacks` to
`vim.lsp.handlers`. However, we will remove this at some point, so
it is recommended that you change all of your references to
`callbacks` into `handlers`.
- This also means that for functions like |vim.lsp.start_client()|
and similar, keyword style arguments have moved from "callbacks"
to "handlers". Once again, these are currently being forward, but
will cease to be forwarded in a "little while".
- Changed the highlight groups for LspDiagnostic highlight as they were
inconsistently named.
- For more information, see |lsp-highlight-diagnostics|
- Changed the sign group names as well, to be consistent with
|lsp-highlight-diagnostics|
General Enhancements:
- Rewrote much of the getting started help document for lsp. It also
provides a much nicer configuration strategy, so as to not recommend
globally overwriting builtin neovim mappings.
LSP Enhancements:
- Introduced the concept of |lsp-handlers| which will allow much better
customization for users without having to copy & paste entire files /
functions / etc.
Diagnostic Enhancements:
- "goto next diagnostic" |vim.lsp.diagnostic.goto_next()|
- "goto prev diagnostic" |vim.lsp.diagnostic.goto_prev()|
- For each of the gotos, auto open diagnostics is available as a
configuration option
- Configurable diagnostic handling:
- See |vim.lsp.diagnostic.on_publish_diagnostics()|
- Delay display until after insert mode
- Configure signs
- Configure virtual text
- Configure underline
- Set the location list with the buffers diagnostics.
- See |vim.lsp.diagnostic.set_loclist()|
- Better performance for getting counts and line diagnostics
- They are now cached on save, to enhance lookups.
- Particularly useful for checking in statusline, etc.
- Actual testing :)
- See ./test/functional/plugin/lsp/diagnostic_spec.lua
- Added `guisp` for underline highlighting
NOTE: "a little while" means enough time to feel like most plugins and
plugin authors have had a chance to refactor their code to use the
updated calls. Then we will remove them completely. There is no need to
keep them, because we don't have any released version of neovim that
exposes these APIs. I'm trying to be nice to people following HEAD :)
Co-authored: [Twitch Chat 2020](https://twitch.tv/teej_dv)
2020-11-12 20:21:34 -07:00
|
|
|
|
|
|
|
resulting_config[k] = v
|
2020-04-28 07:41:39 -07:00
|
|
|
end
|
lsp: vim.lsp.diagnostic (#12655)
Breaking Changes:
- Deprecated all `vim.lsp.util.{*diagnostics*}()` functions.
- Instead, all functions must be found in vim.lsp.diagnostic
- For now, they issue a warning ONCE per neovim session. In a
"little while" we will remove them completely.
- `vim.lsp.callbacks` has moved to `vim.lsp.handlers`.
- For a "little while" we will just redirect `vim.lsp.callbacks` to
`vim.lsp.handlers`. However, we will remove this at some point, so
it is recommended that you change all of your references to
`callbacks` into `handlers`.
- This also means that for functions like |vim.lsp.start_client()|
and similar, keyword style arguments have moved from "callbacks"
to "handlers". Once again, these are currently being forward, but
will cease to be forwarded in a "little while".
- Changed the highlight groups for LspDiagnostic highlight as they were
inconsistently named.
- For more information, see |lsp-highlight-diagnostics|
- Changed the sign group names as well, to be consistent with
|lsp-highlight-diagnostics|
General Enhancements:
- Rewrote much of the getting started help document for lsp. It also
provides a much nicer configuration strategy, so as to not recommend
globally overwriting builtin neovim mappings.
LSP Enhancements:
- Introduced the concept of |lsp-handlers| which will allow much better
customization for users without having to copy & paste entire files /
functions / etc.
Diagnostic Enhancements:
- "goto next diagnostic" |vim.lsp.diagnostic.goto_next()|
- "goto prev diagnostic" |vim.lsp.diagnostic.goto_prev()|
- For each of the gotos, auto open diagnostics is available as a
configuration option
- Configurable diagnostic handling:
- See |vim.lsp.diagnostic.on_publish_diagnostics()|
- Delay display until after insert mode
- Configure signs
- Configure virtual text
- Configure underline
- Set the location list with the buffers diagnostics.
- See |vim.lsp.diagnostic.set_loclist()|
- Better performance for getting counts and line diagnostics
- They are now cached on save, to enhance lookups.
- Particularly useful for checking in statusline, etc.
- Actual testing :)
- See ./test/functional/plugin/lsp/diagnostic_spec.lua
- Added `guisp` for underline highlighting
NOTE: "a little while" means enough time to feel like most plugins and
plugin authors have had a chance to refactor their code to use the
updated calls. Then we will remove them completely. There is no need to
keep them, because we don't have any released version of neovim that
exposes these APIs. I'm trying to be nice to people following HEAD :)
Co-authored: [Twitch Chat 2020](https://twitch.tv/teej_dv)
2020-11-12 20:21:34 -07:00
|
|
|
|
|
|
|
for k, v in pairs(options) do
|
|
|
|
if resulting_config[k] == nil then
|
|
|
|
resulting_config[k] = v
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return resulting_config
|
2020-04-26 15:36:40 -07:00
|
|
|
end
|
|
|
|
|
2021-03-12 02:19:21 -07:00
|
|
|
--- Registry for client side commands.
|
|
|
|
--- This is an extension point for plugins to handle custom commands which are
|
|
|
|
--- not part of the core language server protocol specification.
|
|
|
|
---
|
|
|
|
--- The registry is a table where the key is a unique command name,
|
|
|
|
--- and the value is a function which is called if any LSP action
|
|
|
|
--- (code action, code lenses, ...) triggers the command.
|
|
|
|
---
|
|
|
|
--- If a LSP response contains a command for which no matching entry is
|
|
|
|
--- available in this registry, the command will be executed via the LSP server
|
|
|
|
--- using `workspace/executeCommand`.
|
|
|
|
---
|
|
|
|
--- The first argument to the function will be the `Command`:
|
|
|
|
--- Command
|
|
|
|
--- title: String
|
|
|
|
--- command: String
|
|
|
|
--- arguments?: any[]
|
|
|
|
---
|
|
|
|
--- The second argument is the `ctx` of |lsp-handler|
|
2023-12-13 05:00:11 -07:00
|
|
|
--- @type table<string,function>
|
2021-03-12 02:19:21 -07:00
|
|
|
lsp.commands = setmetatable({}, {
|
|
|
|
__newindex = function(tbl, key, value)
|
|
|
|
assert(type(key) == 'string', 'The key for commands in `vim.lsp.commands` must be a string')
|
|
|
|
assert(type(value) == 'function', 'Command added to `vim.lsp.commands` must be a function')
|
|
|
|
rawset(tbl, key, value)
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
2019-11-13 13:55:26 -07:00
|
|
|
return lsp
|