2020-12-08 19:09:33 -07:00
|
|
|
local if_nil = vim.F.if_nil
|
|
|
|
|
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 default_handlers = require 'vim.lsp.handlers'
|
2019-11-13 13:55:26 -07:00
|
|
|
local log = require 'vim.lsp.log'
|
|
|
|
local lsp_rpc = require 'vim.lsp.rpc'
|
|
|
|
local protocol = require 'vim.lsp.protocol'
|
|
|
|
local util = require 'vim.lsp.util'
|
|
|
|
|
2019-11-24 04:14:03 -07:00
|
|
|
local vim = vim
|
2019-11-13 13:55:26 -07:00
|
|
|
local nvim_err_writeln, nvim_buf_get_lines, nvim_command, nvim_buf_get_option
|
|
|
|
= vim.api.nvim_err_writeln, vim.api.nvim_buf_get_lines, vim.api.nvim_command, vim.api.nvim_buf_get_option
|
|
|
|
local uv = vim.loop
|
|
|
|
local tbl_isempty, tbl_extend = vim.tbl_isempty, vim.tbl_extend
|
|
|
|
local validate = vim.validate
|
|
|
|
|
|
|
|
local lsp = {
|
|
|
|
protocol = protocol;
|
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 = default_handlers;
|
|
|
|
|
2019-11-20 17:03:32 -07:00
|
|
|
buf = require'vim.lsp.buf';
|
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
|
|
|
diagnostic = require'vim.lsp.diagnostic';
|
2020-10-26 03:50:57 -07:00
|
|
|
codelens = require'vim.lsp.codelens';
|
2019-11-13 13:55:26 -07:00
|
|
|
util = 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
|
|
|
|
2019-11-13 13:55:26 -07:00
|
|
|
-- Allow raw RPC access.
|
|
|
|
rpc = lsp_rpc;
|
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
|
|
|
|
2019-11-13 13:55:26 -07:00
|
|
|
-- Export these directly from rpc.
|
|
|
|
rpc_response_error = lsp_rpc.rpc_response_error;
|
|
|
|
}
|
|
|
|
|
2020-10-24 21:28:15 -07:00
|
|
|
-- maps request name to the required resolved_capability in the client.
|
|
|
|
lsp._request_name_to_capability = {
|
|
|
|
['textDocument/hover'] = 'hover';
|
|
|
|
['textDocument/signatureHelp'] = 'signature_help';
|
|
|
|
['textDocument/definition'] = 'goto_definition';
|
|
|
|
['textDocument/implementation'] = 'implementation';
|
|
|
|
['textDocument/declaration'] = 'declaration';
|
|
|
|
['textDocument/typeDefinition'] = 'type_definition';
|
|
|
|
['textDocument/documentSymbol'] = 'document_symbol';
|
|
|
|
['textDocument/prepareCallHierarchy'] = 'call_hierarchy';
|
|
|
|
['textDocument/rename'] = 'rename';
|
2021-10-08 11:30:18 -07:00
|
|
|
['textDocument/prepareRename'] = 'rename';
|
2020-10-24 21:28:15 -07:00
|
|
|
['textDocument/codeAction'] = 'code_action';
|
2021-03-10 15:02:09 -07:00
|
|
|
['textDocument/codeLens'] = 'code_lens';
|
|
|
|
['codeLens/resolve'] = 'code_lens_resolve';
|
2020-10-24 21:28:15 -07:00
|
|
|
['workspace/executeCommand'] = 'execute_command';
|
2021-03-31 23:49:12 -07:00
|
|
|
['workspace/symbol'] = 'workspace_symbol';
|
2020-10-24 21:28:15 -07:00
|
|
|
['textDocument/references'] = 'find_references';
|
|
|
|
['textDocument/rangeFormatting'] = 'document_range_formatting';
|
|
|
|
['textDocument/formatting'] = 'document_formatting';
|
|
|
|
['textDocument/completion'] = 'completion';
|
|
|
|
['textDocument/documentHighlight'] = 'document_highlight';
|
|
|
|
}
|
|
|
|
|
2019-11-13 13:55:26 -07:00
|
|
|
-- TODO improve handling of scratch buffers with LSP attached.
|
|
|
|
|
2021-08-22 13:55:28 -07:00
|
|
|
---@private
|
2020-08-19 09:17:08 -07:00
|
|
|
--- Concatenates and writes a list of strings to the Vim error buffer.
|
|
|
|
---
|
2021-08-22 13:55:28 -07:00
|
|
|
---@param {...} (List of strings) 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
|
|
|
|
|
2021-08-22 13:55:28 -07:00
|
|
|
---@private
|
2020-08-19 09:17:08 -07:00
|
|
|
--- Returns the buffer number for the given {bufnr}.
|
|
|
|
---
|
2021-08-22 13:55:28 -07:00
|
|
|
---@param bufnr (number) Buffer number to resolve. Defaults to the current
|
2020-08-19 09:17:08 -07:00
|
|
|
---buffer if not given.
|
2021-08-22 13:55:28 -07:00
|
|
|
---@returns bufnr (number) Number of requested buffer
|
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
|
|
|
|
return vim.api.nvim_get_current_buf()
|
|
|
|
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
|
|
|
|
|
2021-08-22 13:55:28 -07:00
|
|
|
---@private
|
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
|
|
|
|
---@returns 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';
|
|
|
|
}
|
|
|
|
|
|
|
|
local client_index = 0
|
2021-08-22 13:55:28 -07:00
|
|
|
---@private
|
2020-08-19 09:17:08 -07:00
|
|
|
--- Returns a new, unused client id.
|
|
|
|
---
|
2021-08-22 13:55:28 -07:00
|
|
|
---@returns (number) 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
|
|
|
|
local active_clients = {}
|
|
|
|
local all_buffer_active_clients = {}
|
|
|
|
local uninitialized_clients = {}
|
|
|
|
|
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
|
|
|
--- Invokes a function for each LSP client attached to the buffer {bufnr}.
|
2020-08-19 09:17:08 -07:00
|
|
|
---
|
2021-08-22 13:55:28 -07:00
|
|
|
---@param bufnr (Number) of buffer
|
|
|
|
---@param fn (function({client}, {client_id}, {bufnr}) Function to run on
|
2020-08-19 09:17:08 -07:00
|
|
|
---each client attached to that buffer.
|
2021-10-10 22:32:50 -07:00
|
|
|
---@param restrict_client_ids table list of client ids on which to restrict function application.
|
|
|
|
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
|
2021-10-11 08:52:11 -07:00
|
|
|
local filtered_client_ids = {}
|
|
|
|
for client_id in pairs(client_ids) do
|
|
|
|
if vim.tbl_contains(restrict_client_ids, client_id) then
|
|
|
|
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
|
|
|
|
|
|
|
|
-- 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.
|
|
|
|
lsp.client_errors = tbl_extend("error", lsp_rpc.client_errors, vim.tbl_add_reverse_lookup {
|
|
|
|
ON_INIT_CALLBACK_ERROR = table.maxn(lsp_rpc.client_errors) + 1;
|
|
|
|
})
|
|
|
|
|
2021-08-22 13:55:28 -07:00
|
|
|
---@private
|
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
|
|
|
|
---@returns (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))
|
|
|
|
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.
|
|
|
|
---
|
2021-08-22 13:55:28 -07:00
|
|
|
---@param input (List)
|
|
|
|
---@returns (string) the command
|
|
|
|
---@returns (list of strings) its arguments
|
2020-02-11 22:48:25 -07:00
|
|
|
function lsp._cmd_parts(input)
|
2020-05-26 05:55:45 -07:00
|
|
|
vim.validate{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
|
|
|
|
vim.validate{["cmd argument"]={v, "s"}}
|
|
|
|
if i > 1 then
|
|
|
|
table.insert(cmd_args, v)
|
2019-11-13 13:55:26 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
return cmd, cmd_args
|
|
|
|
end
|
|
|
|
|
2021-08-22 13:55:28 -07:00
|
|
|
---@private
|
2020-08-19 09:17:08 -07:00
|
|
|
--- Augments a validator function with support for optional (nil) values.
|
|
|
|
---
|
2021-08-22 13:55:28 -07:00
|
|
|
---@param fn (function(v)) The original validator function; should return a
|
2020-08-19 09:17:08 -07:00
|
|
|
---bool.
|
2021-08-22 13:55:28 -07:00
|
|
|
---@returns (function(v)) 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
|
|
|
|
|
2021-08-22 13:55:28 -07:00
|
|
|
---@private
|
2020-08-19 09:17:08 -07:00
|
|
|
--- Validates a client configuration as given to |vim.lsp.start_client()|.
|
|
|
|
---
|
2021-08-22 13:55:28 -07:00
|
|
|
---@param config (table)
|
|
|
|
---@returns (table) "Cleaned" config, containing only the command, its
|
2020-08-19 09:17:08 -07:00
|
|
|
---arguments, and a valid encoding.
|
|
|
|
---
|
2021-08-22 13:55:28 -07:00
|
|
|
---@see |vim.lsp.start_client()|
|
2019-11-13 13:55:26 -07:00
|
|
|
local function validate_client_config(config)
|
|
|
|
validate {
|
|
|
|
config = { config, 't' };
|
|
|
|
}
|
|
|
|
validate {
|
2021-08-19 09:15:18 -07:00
|
|
|
root_dir = { config.root_dir, optional_validator(is_dir), "directory" };
|
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 };
|
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 };
|
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'),
|
|
|
|
"flags.debounce_text_changes must be nil or a number with the debounce time in milliseconds"
|
|
|
|
)
|
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
|
|
|
|
2020-02-11 22:48:25 -07:00
|
|
|
local cmd, cmd_args = lsp._cmd_parts(config.cmd)
|
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
|
|
|
|
2019-11-13 13:55:26 -07:00
|
|
|
return {
|
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
|
|
|
cmd = cmd;
|
|
|
|
cmd_args = cmd_args;
|
2019-11-13 13:55:26 -07:00
|
|
|
offset_encoding = offset_encoding;
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2021-08-22 13:55:28 -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.
|
|
|
|
---@returns Buffer text as string.
|
2019-11-21 02:29:54 -07:00
|
|
|
local function buf_get_full_text(bufnr)
|
|
|
|
local text = table.concat(nvim_buf_get_lines(bufnr, 0, -1, true), '\n')
|
|
|
|
if nvim_buf_get_option(bufnr, 'eol') then
|
|
|
|
text = text .. '\n'
|
|
|
|
end
|
|
|
|
return text
|
|
|
|
end
|
|
|
|
|
2021-08-22 13:55:28 -07:00
|
|
|
---@private
|
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
|
|
|
---
|
2021-08-22 13:55:28 -07:00
|
|
|
---@param fn (function) Function to run
|
|
|
|
---@returns (function) Memoized function
|
2021-03-12 07:01:41 -07:00
|
|
|
local function once(fn)
|
|
|
|
local value
|
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
|
|
|
|
value = fn(...)
|
|
|
|
ran = true
|
|
|
|
end
|
2021-03-12 07:01:41 -07:00
|
|
|
return value
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
local changetracking = {}
|
|
|
|
do
|
2021-08-16 11:24:30 -07:00
|
|
|
--@private
|
2021-03-12 07:01:41 -07:00
|
|
|
--- client_id → state
|
|
|
|
---
|
|
|
|
--- state
|
|
|
|
--- pending_change?: function that the timer starts to trigger didChange
|
|
|
|
--- pending_changes: list of tables with the pending changesets; for incremental_sync only
|
|
|
|
--- use_incremental_sync: bool
|
|
|
|
--- buffers?: table (bufnr → lines); for incremental sync only
|
|
|
|
--- timer?: uv_timer
|
|
|
|
local state_by_client = {}
|
|
|
|
|
|
|
|
function changetracking.init(client, bufnr)
|
|
|
|
local state = state_by_client[client.id]
|
|
|
|
if not state then
|
|
|
|
state = {
|
|
|
|
pending_changes = {};
|
|
|
|
use_incremental_sync = (
|
|
|
|
if_nil(client.config.flags.allow_incremental_sync, true)
|
|
|
|
and client.resolved_capabilities.text_document_did_change == protocol.TextDocumentSyncKind.Incremental
|
|
|
|
);
|
|
|
|
}
|
|
|
|
state_by_client[client.id] = state
|
|
|
|
end
|
|
|
|
if not state.use_incremental_sync then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
if not state.buffers then
|
|
|
|
state.buffers = {}
|
|
|
|
end
|
|
|
|
state.buffers[bufnr] = nvim_buf_get_lines(bufnr, 0, -1, true)
|
|
|
|
end
|
|
|
|
|
|
|
|
function changetracking.reset_buf(client, bufnr)
|
|
|
|
local state = state_by_client[client.id]
|
|
|
|
if state then
|
|
|
|
changetracking._reset_timer(state)
|
|
|
|
if state.buffers then
|
|
|
|
state.buffers[bufnr] = nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function changetracking.reset(client_id)
|
|
|
|
local state = state_by_client[client_id]
|
|
|
|
if state then
|
|
|
|
state_by_client[client_id] = nil
|
|
|
|
changetracking._reset_timer(state)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function changetracking.prepare(bufnr, firstline, new_lastline, changedtick)
|
|
|
|
local incremental_changes = function(client)
|
|
|
|
local cached_buffers = state_by_client[client.id].buffers
|
|
|
|
local lines = nvim_buf_get_lines(bufnr, 0, -1, true)
|
|
|
|
local startline = math.min(firstline + 1, math.min(#cached_buffers[bufnr], #lines))
|
|
|
|
local endline = math.min(-(#lines - new_lastline), -1)
|
|
|
|
local incremental_change = vim.lsp.util.compute_diff(
|
|
|
|
cached_buffers[bufnr], lines, startline, endline, client.offset_encoding or 'utf-16')
|
|
|
|
cached_buffers[bufnr] = lines
|
|
|
|
return incremental_change
|
|
|
|
end
|
|
|
|
local full_changes = once(function()
|
|
|
|
return {
|
|
|
|
text = buf_get_full_text(bufnr);
|
|
|
|
};
|
|
|
|
end)
|
|
|
|
local uri = vim.uri_from_bufnr(bufnr)
|
|
|
|
return function(client)
|
|
|
|
if client.resolved_capabilities.text_document_did_change == protocol.TextDocumentSyncKind.None then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
local state = state_by_client[client.id]
|
|
|
|
local debounce = client.config.flags.debounce_text_changes
|
|
|
|
if not debounce then
|
|
|
|
local changes = state.use_incremental_sync and incremental_changes(client) or full_changes()
|
|
|
|
client.notify("textDocument/didChange", {
|
|
|
|
textDocument = {
|
|
|
|
uri = uri;
|
|
|
|
version = changedtick;
|
|
|
|
};
|
|
|
|
contentChanges = { changes, }
|
|
|
|
})
|
|
|
|
return
|
|
|
|
end
|
|
|
|
changetracking._reset_timer(state)
|
|
|
|
if state.use_incremental_sync then
|
|
|
|
-- This must be done immediately and cannot be delayed
|
|
|
|
-- The contents would further change and startline/endline may no longer fit
|
|
|
|
table.insert(state.pending_changes, incremental_changes(client))
|
|
|
|
end
|
|
|
|
state.pending_change = function()
|
|
|
|
state.pending_change = nil
|
2021-08-28 02:57:06 -07:00
|
|
|
if client.is_stopped() or not vim.api.nvim_buf_is_valid(bufnr) then
|
2021-03-12 07:01:41 -07:00
|
|
|
return
|
|
|
|
end
|
|
|
|
local contentChanges
|
|
|
|
if state.use_incremental_sync then
|
|
|
|
contentChanges = state.pending_changes
|
|
|
|
state.pending_changes = {}
|
|
|
|
else
|
|
|
|
contentChanges = { full_changes(), }
|
|
|
|
end
|
|
|
|
client.notify("textDocument/didChange", {
|
|
|
|
textDocument = {
|
|
|
|
uri = uri;
|
|
|
|
version = changedtick;
|
|
|
|
};
|
|
|
|
contentChanges = contentChanges
|
|
|
|
})
|
|
|
|
end
|
|
|
|
state.timer = vim.loop.new_timer()
|
|
|
|
-- Must use schedule_wrap because `full_changes()` calls nvim_buf_get_lines
|
|
|
|
state.timer:start(debounce, 0, vim.schedule_wrap(state.pending_change))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function changetracking._reset_timer(state)
|
|
|
|
if state.timer then
|
|
|
|
state.timer:stop()
|
|
|
|
state.timer:close()
|
|
|
|
state.timer = nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Flushes any outstanding change notification.
|
|
|
|
function changetracking.flush(client)
|
|
|
|
local state = state_by_client[client.id]
|
|
|
|
if state then
|
|
|
|
changetracking._reset_timer(state)
|
|
|
|
if state.pending_change then
|
|
|
|
state.pending_change()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2021-08-22 13:55:28 -07:00
|
|
|
---@private
|
2020-08-19 09:17:08 -07:00
|
|
|
--- Default handler for the 'textDocument/didOpen' LSP notification.
|
|
|
|
---
|
2021-08-22 13:55:28 -07:00
|
|
|
---@param bufnr (Number) Number of the buffer, or 0 for current
|
|
|
|
---@param 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)
|
2019-11-13 13:55:26 -07:00
|
|
|
if not client.resolved_capabilities.text_document_open_close then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
if not vim.api.nvim_buf_is_loaded(bufnr) then
|
|
|
|
return
|
|
|
|
end
|
2021-03-10 14:53:23 -07:00
|
|
|
local filetype = nvim_buf_get_option(bufnr, 'filetype')
|
|
|
|
|
2019-11-13 13:55:26 -07:00
|
|
|
local params = {
|
|
|
|
textDocument = {
|
|
|
|
version = 0;
|
|
|
|
uri = vim.uri_from_bufnr(bufnr);
|
2021-03-10 14:53:23 -07:00
|
|
|
languageId = client.config.get_language_id(bufnr, filetype);
|
2019-11-21 02:29:54 -07:00
|
|
|
text = buf_get_full_text(bufnr);
|
2019-11-13 13:55:26 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
client.notify('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-07-29 09:02:17 -07:00
|
|
|
vim.lsp.diagnostic.redraw(bufnr, client.id)
|
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
|
|
|
|
--- |vim.lsp.get_client_by_id()| or |vim.lsp.get_active_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
|
|
|
---
|
|
|
|
--- - 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
|
|
|
---
|
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.
|
|
|
|
---
|
2020-08-19 09:17:08 -07:00
|
|
|
--- - {resolved_capabilities} (table): Normalized table of
|
2019-12-31 07:52:14 -07:00
|
|
|
--- capabilities that we have detected based on the initialize
|
|
|
|
--- response from the server in `server_capabilities`.
|
|
|
|
function lsp.client()
|
|
|
|
error()
|
|
|
|
end
|
2019-11-13 13:55:26 -07:00
|
|
|
|
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
|
|
|
---
|
2019-12-31 08:51:54 -07:00
|
|
|
--- Parameters `cmd` and `root_dir` are required.
|
2019-12-31 07:52:14 -07:00
|
|
|
---
|
2020-08-19 09:17:08 -07:00
|
|
|
--- The following parameters describe fields in the {config} table.
|
|
|
|
---
|
2021-08-22 13:55:28 -07:00
|
|
|
---@param root_dir: (string) Directory where the LSP server will base
|
2019-12-31 08:51:54 -07:00
|
|
|
--- its rootUri on initialization.
|
2019-12-31 07:52:14 -07:00
|
|
|
---
|
2021-08-22 13:55:28 -07:00
|
|
|
---@param cmd: (required, string or list treated like |jobstart()|) Base command
|
2019-12-31 08:51:54 -07:00
|
|
|
--- that initiates the LSP client.
|
2019-12-31 07:52:14 -07:00
|
|
|
---
|
2021-08-22 13:55:28 -07:00
|
|
|
---@param cmd_cwd: (string, default=|getcwd()|) Directory to launch
|
2019-12-31 08:51:54 -07:00
|
|
|
--- the `cmd` process. Not related to `root_dir`.
|
2019-12-31 07:52:14 -07:00
|
|
|
---
|
2021-08-22 13:55:28 -07:00
|
|
|
---@param cmd_env: (table) Environment flags to pass to the LSP on
|
2019-12-31 08:51:54 -07:00
|
|
|
--- spawn. Can be specified using keys like a map or as a list with `k=v`
|
|
|
|
--- pairs or both. Non-string values are coerced to string.
|
|
|
|
--- Example:
|
|
|
|
--- <pre>
|
|
|
|
--- { "PRODUCTION=true"; "TEST=123"; PORT = 8080; HOST = "0.0.0.0"; }
|
|
|
|
--- </pre>
|
2019-12-31 07:52:14 -07:00
|
|
|
---
|
2021-08-22 13:55:28 -07:00
|
|
|
---@param capabilities Map overriding the default capabilities defined by
|
2019-12-31 07:52:14 -07:00
|
|
|
--- |vim.lsp.protocol.make_client_capabilities()|, passed to the language
|
|
|
|
--- server on initialization. Hint: use make_client_capabilities() and modify
|
|
|
|
--- its result.
|
|
|
|
--- - Note: To send an empty dictionary use
|
|
|
|
--- `{[vim.type_idx]=vim.types.dictionary}`, else it will be encoded as an
|
|
|
|
--- array.
|
|
|
|
---
|
2021-08-22 13:55:28 -07:00
|
|
|
---@param handlers Map of language server method names to |lsp-handler|
|
2019-12-31 07:52:14 -07:00
|
|
|
---
|
2021-08-22 13:55:28 -07:00
|
|
|
---@param settings Map with language server specific settings. These are
|
2021-01-18 12:11:37 -07:00
|
|
|
--- returned to the language server if requested via `workspace/configuration`.
|
|
|
|
--- Keys are case-sensitive.
|
|
|
|
---
|
2021-08-22 13:55:28 -07:00
|
|
|
---@param init_options Values to pass in the initialization request
|
2019-12-31 07:52:14 -07:00
|
|
|
--- as `initializationOptions`. See `initialize` in the LSP spec.
|
|
|
|
---
|
2021-08-22 13:55:28 -07:00
|
|
|
---@param name (string, default=client-id) Name in log messages.
|
2021-07-20 13:00:38 -07:00
|
|
|
--
|
2021-08-22 13:55:28 -07:00
|
|
|
---@param workspace_folders (table) List of workspace folders passed to the
|
2021-07-20 13:00:38 -07:00
|
|
|
--- language server. Defaults to root_dir if not set. See `workspaceFolders` in
|
|
|
|
--- the LSP spec
|
2019-12-31 07:52:14 -07:00
|
|
|
---
|
2021-08-22 13:55:28 -07:00
|
|
|
---@param get_language_id function(bufnr, filetype) -> language ID as string.
|
2021-03-10 14:53:23 -07:00
|
|
|
--- Defaults to the filetype.
|
|
|
|
---
|
2021-08-22 13:55:28 -07:00
|
|
|
---@param offset_encoding (default="utf-16") One of "utf-8", "utf-16",
|
2019-12-31 08:51:54 -07:00
|
|
|
--- or "utf-32" which is the encoding that the LSP server expects. Client does
|
|
|
|
--- not verify this is correct.
|
2019-12-31 07:52:14 -07:00
|
|
|
---
|
2021-08-22 13:55:28 -07:00
|
|
|
---@param on_error Callback with parameters (code, ...), invoked
|
2019-12-31 08:51:54 -07:00
|
|
|
--- 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.client_errors| for possible errors.
|
|
|
|
--- Use `vim.lsp.client_errors[code]` to get human-friendly name.
|
|
|
|
---
|
2021-08-22 13:55:28 -07:00
|
|
|
---@param before_init Callback with parameters (initialize_params, config)
|
2019-12-31 08:51:54 -07:00
|
|
|
--- invoked before the LSP "initialize" phase, where `params` contains the
|
|
|
|
--- parameters being sent to the server and `config` is the config that was
|
2020-08-19 09:17:08 -07:00
|
|
|
--- passed to |vim.lsp.start_client()|. You can use this to modify parameters before
|
2019-12-31 08:51:54 -07:00
|
|
|
--- they are sent.
|
2019-12-31 07:52:14 -07:00
|
|
|
---
|
2021-08-22 13:55:28 -07:00
|
|
|
---@param on_init Callback (client, initialize_result) invoked after LSP
|
2019-12-31 08:51:54 -07:00
|
|
|
--- "initialize", where `result` is a table of `capabilities` and anything else
|
|
|
|
--- the server may send. For example, clangd sends
|
2019-12-31 07:52:14 -07:00
|
|
|
--- `initialize_result.offsetEncoding` if `capabilities.offsetEncoding` was
|
|
|
|
--- sent to it. You can only modify the `client.offset_encoding` here before
|
2021-01-18 12:11:37 -07:00
|
|
|
--- any notifications are sent. Most language servers expect to be sent client specified settings after
|
|
|
|
--- initialization. Neovim does not make this assumption. A
|
|
|
|
--- `workspace/didChangeConfiguration` notification should be sent
|
|
|
|
--- to the server during on_init.
|
2019-12-31 07:52:14 -07:00
|
|
|
---
|
2021-08-22 13:55:28 -07:00
|
|
|
---@param on_exit Callback (code, signal, client_id) invoked on client
|
2019-12-31 07:52:14 -07:00
|
|
|
--- exit.
|
|
|
|
--- - code: exit code of the process
|
|
|
|
--- - signal: number describing the signal used to terminate (if any)
|
|
|
|
--- - client_id: client handle
|
|
|
|
---
|
2021-08-22 13:55:28 -07:00
|
|
|
---@param on_attach Callback (client, bufnr) invoked when client
|
2019-12-31 07:52:14 -07:00
|
|
|
--- attaches to a buffer.
|
|
|
|
---
|
2021-08-22 13:55:28 -07:00
|
|
|
---@param trace: "off" | "messages" | "verbose" | nil passed directly to the language
|
2019-12-31 07:52:14 -07:00
|
|
|
--- server in the initialize request. Invalid/empty values will default to "off"
|
2021-08-22 13:55:28 -07:00
|
|
|
---@param flags: A table with flags for the client. The current (experimental) flags are:
|
2021-03-11 08:01:40 -07:00
|
|
|
--- - allow_incremental_sync (bool, default true): Allow using incremental sync for buffer edits
|
2021-03-12 07:01:41 -07:00
|
|
|
--- - debounce_text_changes (number, default nil): Debounce didChange
|
|
|
|
--- notifications to the server by the given number in milliseconds. No debounce
|
|
|
|
--- occurs if nil
|
2021-10-21 09:36:01 -07:00
|
|
|
--- - exit_timeout (number, default 500): 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.
|
2021-08-22 13:55:28 -07:00
|
|
|
---@returns 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)
|
|
|
|
local cleaned_config = validate_client_config(config)
|
|
|
|
local cmd, cmd_args, offset_encoding = cleaned_config.cmd, cleaned_config.cmd_args, cleaned_config.offset_encoding
|
|
|
|
|
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
|
|
|
|
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
|
|
|
--- 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
|
|
|
|
---@returns (fn) The 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)
|
|
|
|
return handlers[method] or default_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)
|
2021-09-15 11:35:04 -07:00
|
|
|
local _ = log.trace() and log.trace('notification', method, params)
|
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
|
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)
|
2021-09-15 11:35:04 -07:00
|
|
|
local _ = log.trace() and log.trace('server_request', method, params)
|
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
|
2021-09-15 11:35:04 -07:00
|
|
|
local _ = log.trace() and log.trace("server_request: found handler for", method)
|
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
|
2021-09-15 11:35:04 -07:00
|
|
|
local _ = log.warn() and log.warn("server_request: no handler found for", method)
|
2019-11-13 13:55:26 -07:00
|
|
|
return nil, lsp.rpc_response_error(protocol.ErrorCodes.MethodNotFound)
|
|
|
|
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.
|
|
|
|
---
|
2021-08-22 13:55:28 -07:00
|
|
|
---@param code (number) Error code
|
|
|
|
---@param err (...) Other arguments may be passed depending on the error kind
|
|
|
|
---@see |vim.lsp.client_errors| for possible errors. Use
|
2020-08-19 09:17:08 -07:00
|
|
|
---`vim.lsp.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)
|
2019-11-13 13:55:26 -07:00
|
|
|
local _ = log.error() and log.error(log_prefix, "on_error", { code = lsp.client_errors[code], err = err })
|
2019-11-20 17:16:13 -07:00
|
|
|
err_message(log_prefix, ': Error ', lsp.client_errors[code], ': ', vim.inspect(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
|
|
|
|
local _ = log.error() and log.error(log_prefix, "user on_error failed", { err = usererr })
|
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
|
|
|
|
|
2021-08-22 13:55:28 -07:00
|
|
|
---@private
|
2020-08-19 09:17:08 -07:00
|
|
|
--- Invoked on client exit.
|
|
|
|
---
|
2021-08-22 13:55:28 -07:00
|
|
|
---@param code (number) exit code of the process
|
|
|
|
---@param signal (number) 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)
|
2019-11-13 13:55:26 -07:00
|
|
|
active_clients[client_id] = nil
|
|
|
|
uninitialized_clients[client_id] = nil
|
2021-02-19 20:05:49 -07:00
|
|
|
|
|
|
|
lsp.diagnostic.reset(client_id, all_buffer_active_clients)
|
2021-03-12 07:01:41 -07:00
|
|
|
changetracking.reset(client_id)
|
2021-02-19 20:05:49 -07:00
|
|
|
for _, client_ids in pairs(all_buffer_active_clients) do
|
2019-11-13 13:55:26 -07:00
|
|
|
client_ids[client_id] = nil
|
|
|
|
end
|
2021-02-19 20:05:49 -07:00
|
|
|
|
2021-03-04 14:50:35 -07:00
|
|
|
if code ~= 0 or (signal ~= 0 and signal ~= 15) then
|
2021-03-02 13:36:35 -07:00
|
|
|
local msg = string.format("Client %s quit with exit code %s and signal %s", client_id, code, signal)
|
|
|
|
vim.schedule(function()
|
|
|
|
vim.notify(msg, vim.log.levels.WARN)
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
|
2019-11-13 13:55:26 -07:00
|
|
|
if config.on_exit then
|
|
|
|
pcall(config.on_exit, code, signal, client_id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Start the RPC client.
|
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 rpc = lsp_rpc.start(cmd, cmd_args, dispatch, {
|
2019-11-13 13:55:26 -07:00
|
|
|
cwd = config.cmd_cwd;
|
|
|
|
env = config.cmd_env;
|
|
|
|
})
|
|
|
|
|
|
|
|
local client = {
|
|
|
|
id = client_id;
|
|
|
|
name = name;
|
|
|
|
rpc = rpc;
|
|
|
|
offset_encoding = offset_encoding;
|
|
|
|
config = config;
|
2021-10-20 09:33:09 -07:00
|
|
|
attached_buffers = {};
|
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;
|
2021-10-29 05:45:01 -07:00
|
|
|
requests = {};
|
|
|
|
|
2020-12-20 13:59:25 -07:00
|
|
|
-- for $/progress report
|
2021-10-29 05:45:01 -07:00
|
|
|
messages = { name = name, messages = {}, progress = {}, status = {} };
|
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;
|
|
|
|
|
2021-08-22 13:55:28 -07:00
|
|
|
---@private
|
2019-11-13 13:55:26 -07:00
|
|
|
local function initialize()
|
|
|
|
local valid_traces = {
|
|
|
|
off = 'off'; messages = 'messages'; verbose = 'verbose';
|
|
|
|
}
|
2021-01-18 02:13:26 -07:00
|
|
|
local version = vim.version()
|
2021-07-20 13:00:38 -07:00
|
|
|
|
2021-08-19 09:15:18 -07:00
|
|
|
if config.root_dir and not config.workspace_folders then
|
2021-07-20 13:00:38 -07:00
|
|
|
config.workspace_folders = {{
|
|
|
|
uri = vim.uri_from_fname(config.root_dir);
|
|
|
|
name = string.format("%s", config.root_dir);
|
|
|
|
}};
|
|
|
|
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.
|
|
|
|
processId = uv.getpid();
|
2021-01-18 02:13:26 -07:00
|
|
|
-- Information about the client
|
|
|
|
-- since 3.15.0
|
|
|
|
clientInfo = {
|
|
|
|
name = "Neovim",
|
|
|
|
version = string.format("%s.%s.%s", version.major, version.minor, version.patch)
|
|
|
|
};
|
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.
|
2020-02-08 23:51:02 -07:00
|
|
|
rootPath = config.root_dir;
|
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-08-19 09:15:18 -07:00
|
|
|
rootUri = config.root_dir and vim.uri_from_fname(config.root_dir);
|
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)
|
|
|
|
capabilities = config.capabilities or protocol.make_client_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';
|
|
|
|
-- 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.
|
|
|
|
--
|
|
|
|
-- Since 3.6.0
|
|
|
|
-- workspaceFolders?: WorkspaceFolder[] | null;
|
|
|
|
-- export interface WorkspaceFolder {
|
|
|
|
-- -- The associated URI for this workspace folder.
|
|
|
|
-- uri
|
|
|
|
-- -- The name of the workspace folder. Used to refer to this
|
|
|
|
-- -- workspace folder in the user interface.
|
|
|
|
-- name
|
|
|
|
-- }
|
2021-07-20 13:00:38 -07:00
|
|
|
workspaceFolders = config.workspace_folders,
|
2019-11-13 13:55:26 -07:00
|
|
|
}
|
2019-11-21 16:19:06 -07:00
|
|
|
if config.before_init then
|
|
|
|
-- TODO(ashkan) handle errors here.
|
|
|
|
pcall(config.before_init, initialize_params, config)
|
|
|
|
end
|
2021-09-15 11:35:04 -07:00
|
|
|
local _ = log.trace() and log.trace(log_prefix, "initialize_params", initialize_params)
|
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
|
2020-11-25 13:07:02 -07:00
|
|
|
client.workspaceFolders = initialize_params.workspaceFolders
|
2019-11-13 13:55:26 -07:00
|
|
|
client.server_capabilities = assert(result.capabilities, "initialize result doesn't contain capabilities")
|
|
|
|
-- These are the cleaned up capabilities we use for dynamically deciding
|
|
|
|
-- when to send certain events to clients.
|
|
|
|
client.resolved_capabilities = protocol.resolve_capabilities(client.server_capabilities)
|
2020-10-24 21:28:15 -07:00
|
|
|
client.supports_method = function(method)
|
|
|
|
local required_capability = lsp._request_name_to_capability[method]
|
|
|
|
-- if we don't know about the method, assume that the client supports it.
|
|
|
|
if not required_capability then
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
return client.resolved_capabilities[required_capability]
|
|
|
|
end
|
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
|
|
|
|
pcall(handlers.on_error, lsp.client_errors.ON_INIT_CALLBACK_ERROR, err)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
local _ = log.debug() and log.debug(log_prefix, "server_capabilities", client.server_capabilities)
|
|
|
|
local _ = log.info() and log.info(log_prefix, "initialized", { resolved_capabilities = client.resolved_capabilities })
|
|
|
|
|
|
|
|
-- 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
|
|
|
|
|
2021-08-22 13:55:28 -07:00
|
|
|
---@private
|
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
|
|
|
---
|
2021-08-22 13:55:28 -07:00
|
|
|
---@param method (string) LSP method name.
|
|
|
|
---@param params (table) LSP request params.
|
|
|
|
---@param handler (function, optional) Response |lsp-handler| for this method.
|
|
|
|
---@param bufnr (number) Buffer handle (0 for current).
|
|
|
|
---@returns ({status}, [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.
|
2021-08-22 13:55:28 -07:00
|
|
|
---@see |vim.lsp.buf_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 client.request(method, params, handler, bufnr)
|
|
|
|
if not handler then
|
|
|
|
handler = resolve_handler(method)
|
|
|
|
or error(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
|
|
|
|
changetracking.flush(client)
|
2021-10-29 05:45:01 -07:00
|
|
|
bufnr = resolve_bufnr(bufnr)
|
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 _ = log.debug() and log.debug(log_prefix, "client.request", client_id, method, params, handler, bufnr)
|
2021-10-29 05:45:01 -07:00
|
|
|
local success, request_id = rpc.request(method, params, function(err, result)
|
2021-03-11 15:49:59 -07:00
|
|
|
handler(err, result, {method=method, client_id=client_id, bufnr=bufnr, params=params})
|
2021-10-29 05:45:01 -07:00
|
|
|
end, function(request_id)
|
|
|
|
client.requests[request_id] = nil
|
|
|
|
nvim_command("doautocmd <nomodeline> User LspRequest")
|
2019-11-13 13:55:26 -07:00
|
|
|
end)
|
2021-10-29 05:45:01 -07:00
|
|
|
|
|
|
|
if success then
|
|
|
|
client.requests[request_id] = { type='pending', bufnr=bufnr, method=method }
|
|
|
|
nvim_command("doautocmd <nomodeline> User LspRequest")
|
|
|
|
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.
|
|
|
|
---@param timeout_ms (number, optional, default=1000) Maximum time in
|
2021-04-30 04:40:20 -07:00
|
|
|
---milliseconds to wait for a result.
|
2021-08-22 13:55:28 -07:00
|
|
|
---@param bufnr (number) Buffer handle (0 for current).
|
|
|
|
---@returns { err=err, result=result }, a dictionary, where `err` and `result` come from the |lsp-handler|.
|
2021-04-30 04:40:20 -07:00
|
|
|
---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
|
|
|
|
client.cancel_request(request_id)
|
|
|
|
return nil, wait_result_reason[reason]
|
|
|
|
end
|
|
|
|
return request_result
|
|
|
|
end
|
|
|
|
|
2021-08-22 13:55:28 -07:00
|
|
|
---@private
|
2020-08-19 09:17:08 -07:00
|
|
|
--- Sends a notification to an LSP server.
|
|
|
|
---
|
2021-08-22 13:55:28 -07:00
|
|
|
---@param method (string) LSP method name.
|
|
|
|
---@param params (optional, table) LSP request params.
|
|
|
|
---@param bufnr (number) Buffer handle, or 0 for current.
|
|
|
|
---@returns {status} (bool) 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).
|
2019-11-13 13:55:26 -07:00
|
|
|
function client.notify(...)
|
|
|
|
return rpc.notify(...)
|
|
|
|
end
|
|
|
|
|
2021-08-22 13:55:28 -07:00
|
|
|
---@private
|
2020-08-19 09:17:08 -07:00
|
|
|
--- Cancels a request with a given request id.
|
|
|
|
---
|
2021-08-22 13:55:28 -07:00
|
|
|
---@param id (number) id of request to cancel
|
|
|
|
---@returns true if any client returns true; false otherwise
|
|
|
|
---@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'
|
|
|
|
nvim_command("doautocmd <nomodeline> User LspRequest")
|
|
|
|
end
|
2019-11-13 13:55:26 -07:00
|
|
|
return rpc.notify("$/cancelRequest", { id = id })
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Track this so that we can escalate automatically if we've alredy tried a
|
|
|
|
-- graceful shutdown
|
2021-04-23 05:26:33 -07:00
|
|
|
local graceful_shutdown_failed = false
|
2021-08-22 13:55:28 -07:00
|
|
|
---@private
|
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.
|
|
|
|
---
|
2021-08-22 13:55:28 -07:00
|
|
|
---@param force (bool, optional)
|
2019-11-13 13:55:26 -07:00
|
|
|
function client.stop(force)
|
2021-02-19 20:05:49 -07:00
|
|
|
|
|
|
|
lsp.diagnostic.reset(client_id, all_buffer_active_clients)
|
2021-03-12 07:01:41 -07:00
|
|
|
changetracking.reset(client_id)
|
2021-02-19 20:05:49 -07:00
|
|
|
for _, client_ids in pairs(all_buffer_active_clients) do
|
|
|
|
client_ids[client_id] = nil
|
|
|
|
end
|
|
|
|
|
2019-11-13 13:55:26 -07:00
|
|
|
local handle = rpc.handle
|
|
|
|
if handle:is_closing() then
|
|
|
|
return
|
|
|
|
end
|
2021-04-23 05:26:33 -07:00
|
|
|
if force or (not client.initialized) or graceful_shutdown_failed then
|
2019-11-13 13:55:26 -07:00
|
|
|
handle:kill(15)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
-- Sending a signal after a process has exited is acceptable.
|
|
|
|
rpc.request('shutdown', nil, function(err, _)
|
|
|
|
if err == nil then
|
|
|
|
rpc.notify('exit')
|
|
|
|
else
|
|
|
|
-- If there was an error in the shutdown request, then term to be safe.
|
|
|
|
handle:kill(15)
|
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.
|
|
|
|
---
|
2021-08-22 13:55:28 -07:00
|
|
|
---@returns (bool) 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()
|
|
|
|
return rpc.handle:is_closing()
|
|
|
|
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.
|
2021-08-22 13:55:28 -07:00
|
|
|
---@param bufnr (number) Buffer number
|
2019-11-13 13:55:26 -07:00
|
|
|
function client._on_attach(bufnr)
|
|
|
|
text_document_did_open_handler(bufnr, client)
|
|
|
|
if config.on_attach then
|
|
|
|
-- TODO(ashkan) handle errors.
|
|
|
|
pcall(config.on_attach, client, bufnr)
|
|
|
|
end
|
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
|
|
|
|
|
2021-08-22 13:55:28 -07:00
|
|
|
---@private
|
|
|
|
---@fn text_document_did_change_handler(_, bufnr, changedtick, firstline, lastline, new_lastline, old_byte_size, old_utf32_size, old_utf16_size)
|
2020-08-19 09:17:08 -07:00
|
|
|
--- Notify all attached clients that a buffer has changed.
|
2019-11-13 13:55:26 -07:00
|
|
|
local text_document_did_change_handler
|
|
|
|
do
|
|
|
|
text_document_did_change_handler = function(_, bufnr, changedtick,
|
|
|
|
firstline, lastline, new_lastline, old_byte_size, old_utf32_size,
|
|
|
|
old_utf16_size)
|
2020-06-10 21:04:12 -07:00
|
|
|
|
|
|
|
local _ = log.debug() and log.debug(
|
|
|
|
string.format("on_lines bufnr: %s, changedtick: %s, firstline: %s, lastline: %s, new_lastline: %s, old_byte_size: %s, old_utf32_size: %s, old_utf16_size: %s",
|
|
|
|
bufnr, changedtick, firstline, lastline, new_lastline, old_byte_size, old_utf32_size, old_utf16_size),
|
|
|
|
nvim_buf_get_lines(bufnr, firstline, new_lastline, true)
|
|
|
|
)
|
2020-06-10 21:09:05 -07:00
|
|
|
|
2019-11-13 13:55:26 -07:00
|
|
|
-- Don't do anything if there are no clients attached.
|
|
|
|
if tbl_isempty(all_buffer_active_clients[bufnr] or {}) then
|
|
|
|
return
|
|
|
|
end
|
2020-01-24 04:31:52 -07:00
|
|
|
util.buf_versions[bufnr] = changedtick
|
2021-03-12 07:01:41 -07:00
|
|
|
local compute_change_and_notify = changetracking.prepare(bufnr, firstline, new_lastline, changedtick)
|
|
|
|
for_each_buffer_client(bufnr, compute_change_and_notify)
|
2019-11-13 13:55:26 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Buffer lifecycle handler for textDocument/didSave
|
|
|
|
function lsp._text_document_did_save_handler(bufnr)
|
|
|
|
bufnr = resolve_bufnr(bufnr)
|
|
|
|
local uri = vim.uri_from_bufnr(bufnr)
|
2021-01-25 09:52:40 -07:00
|
|
|
local text = once(buf_get_full_text)
|
2019-11-13 13:55:26 -07:00
|
|
|
for_each_buffer_client(bufnr, function(client, _client_id)
|
|
|
|
if client.resolved_capabilities.text_document_save then
|
|
|
|
local included_text
|
|
|
|
if client.resolved_capabilities.text_document_save_include_text then
|
|
|
|
included_text = text()
|
|
|
|
end
|
|
|
|
client.notify('textDocument/didSave', {
|
|
|
|
textDocument = {
|
|
|
|
uri = uri;
|
2020-12-20 10:12:39 -07:00
|
|
|
};
|
|
|
|
text = included_text;
|
2019-11-13 13:55:26 -07:00
|
|
|
})
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
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.
|
|
|
|
---
|
2021-08-22 13:55:28 -07:00
|
|
|
---@param bufnr (number) Buffer handle, or 0 for current
|
|
|
|
---@param client_id (number) Client id
|
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)
|
|
|
|
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)
|
2021-03-31 20:06:34 -07:00
|
|
|
local buf_did_save_autocommand = [=[
|
|
|
|
augroup lsp_c_%d_b_%d_did_save
|
|
|
|
au!
|
|
|
|
au BufWritePost <buffer=%d> lua vim.lsp._text_document_did_save_handler(0)
|
|
|
|
augroup END
|
|
|
|
]=]
|
|
|
|
vim.api.nvim_exec(string.format(buf_did_save_autocommand, client_id, bufnr, bufnr), false)
|
2019-11-13 13:55:26 -07:00
|
|
|
-- First time, so attach and set up stuff.
|
|
|
|
vim.api.nvim_buf_attach(bufnr, false, {
|
|
|
|
on_lines = text_document_did_change_handler;
|
2021-03-31 22:41:00 -07:00
|
|
|
on_reload = function()
|
|
|
|
local params = { textDocument = { uri = uri; } }
|
|
|
|
for_each_buffer_client(bufnr, function(client, _)
|
|
|
|
if client.resolved_capabilities.text_document_open_close then
|
|
|
|
client.notify('textDocument/didClose', params)
|
|
|
|
end
|
|
|
|
text_document_did_open_handler(bufnr, client)
|
|
|
|
end)
|
|
|
|
end;
|
2019-11-13 13:55:26 -07:00
|
|
|
on_detach = function()
|
|
|
|
local params = { textDocument = { uri = uri; } }
|
2021-01-23 09:43:06 -07:00
|
|
|
for_each_buffer_client(bufnr, function(client, _)
|
2019-11-13 13:55:26 -07:00
|
|
|
if client.resolved_capabilities.text_document_open_close then
|
|
|
|
client.notify('textDocument/didClose', params)
|
|
|
|
end
|
2021-03-12 07:01:41 -07:00
|
|
|
changetracking.reset_buf(client, bufnr)
|
2019-11-13 13:55:26 -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 return 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
|
|
|
|
|
2019-12-31 07:52:14 -07:00
|
|
|
--- Checks if a buffer is attached for a particular client.
|
|
|
|
---
|
|
|
|
---@param bufnr (number) Buffer handle, or 0 for current
|
|
|
|
---@param client_id (number) 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.
|
|
|
|
--
|
2021-10-20 09:33:09 -07:00
|
|
|
---@param client_id number client id
|
2019-12-31 07:52:14 -07:00
|
|
|
---
|
2021-08-22 13:55:28 -07:00
|
|
|
---@returns |vim.lsp.client| object, or nil
|
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.
|
|
|
|
--
|
2021-10-20 09:33:09 -07:00
|
|
|
---@param client_id number client id
|
2021-08-22 13:55:28 -07:00
|
|
|
---@returns 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:
|
|
|
|
---
|
|
|
|
--- <pre>
|
2020-08-31 00:51:35 -07:00
|
|
|
--- vim.lsp.stop_client(vim.lsp.get_active_clients())
|
2019-12-31 08:51:54 -07:00
|
|
|
--- </pre>
|
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.
|
|
|
|
---
|
2021-08-22 13:55:28 -07:00
|
|
|
---@param client_id client id or |vim.lsp.client| object, or list thereof
|
|
|
|
---@param force boolean (optional) 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
|
|
|
|
|
2019-12-31 07:52:14 -07:00
|
|
|
--- Gets all active clients.
|
|
|
|
---
|
2021-08-22 13:55:28 -07:00
|
|
|
---@returns Table of |vim.lsp.client| objects
|
2019-11-13 13:55:26 -07:00
|
|
|
function lsp.get_active_clients()
|
|
|
|
return vim.tbl_values(active_clients)
|
|
|
|
end
|
|
|
|
|
|
|
|
function lsp._vim_exit_handler()
|
|
|
|
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
|
|
|
|
2021-10-21 09:36:01 -07:00
|
|
|
local timeouts = {}
|
|
|
|
local max_timeout = 0
|
|
|
|
local send_kill = false
|
|
|
|
|
|
|
|
for client_id, client in pairs(active_clients) do
|
|
|
|
local timeout = if_nil(client.config.flags.exit_timeout, 500)
|
|
|
|
if timeout then
|
|
|
|
send_kill = true
|
|
|
|
timeouts[client_id] = timeout
|
|
|
|
max_timeout = math.max(timeout, max_timeout)
|
|
|
|
else
|
|
|
|
active_clients[client_id] = nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local poll_time = 50
|
|
|
|
|
|
|
|
local function check_clients_closed()
|
|
|
|
for client_id, _ in pairs(active_clients) do
|
|
|
|
timeouts[client_id] = timeouts[client_id] - poll_time
|
|
|
|
if timeouts[client_id] < 0 then
|
|
|
|
active_clients[client_id] = nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return tbl_isempty(active_clients)
|
|
|
|
end
|
|
|
|
|
|
|
|
if send_kill then
|
|
|
|
if not vim.wait(max_timeout, check_clients_closed, poll_time) then
|
|
|
|
for _, client in pairs(active_clients) do
|
|
|
|
client.stop(true)
|
|
|
|
end
|
2019-11-13 13:55:26 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
nvim_command("autocmd VimLeavePre * lua vim.lsp._vim_exit_handler()")
|
|
|
|
|
|
|
|
|
2019-12-31 07:52:14 -07:00
|
|
|
--- Sends an async request for all active clients attached to the
|
|
|
|
--- buffer.
|
|
|
|
---
|
2021-08-22 13:55:28 -07:00
|
|
|
---@param bufnr (number) Buffer handle, or 0 for current.
|
|
|
|
---@param method (string) LSP method name
|
|
|
|
---@param params (optional, table) Parameters to send to the server
|
|
|
|
---@param handler (optional, function) 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
|
|
|
--
|
2021-08-22 13:55:28 -07:00
|
|
|
---@returns 2-tuple:
|
2019-12-31 07:52:14 -07:00
|
|
|
--- - Map of client-id:request-id pairs for all successful 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
|
|
|
}
|
|
|
|
|
2021-10-10 22:32:50 -07:00
|
|
|
local supported_clients = {}
|
2020-10-24 21:28:15 -07:00
|
|
|
local method_supported = false
|
2021-10-10 22:32:50 -07:00
|
|
|
for_each_buffer_client(bufnr, function(client, client_id)
|
2020-10-24 21:28:15 -07:00
|
|
|
if client.supports_method(method) then
|
|
|
|
method_supported = true
|
2021-10-10 22:32:50 -07:00
|
|
|
table.insert(supported_clients, client_id)
|
2019-11-13 13:55:26 -07:00
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
2021-10-10 22:32:50 -07:00
|
|
|
-- if has client but no clients support the given method, notify the user
|
2020-12-02 23:00:54 -07:00
|
|
|
if not tbl_isempty(all_buffer_active_clients[resolve_bufnr(bufnr)] or {}) and not method_supported then
|
2021-10-10 22:32:50 -07:00
|
|
|
vim.notify(lsp._unsupported_method(method), vim.log.levels.ERROR)
|
|
|
|
vim.api.nvim_command("redraw")
|
2021-10-31 04:44:45 -07:00
|
|
|
return {}, function() end
|
2020-10-24 21:28:15 -07:00
|
|
|
end
|
|
|
|
|
2021-10-10 22:32:50 -07:00
|
|
|
local client_request_ids = {}
|
|
|
|
for_each_buffer_client(bufnr, function(client, client_id, resolved_bufnr)
|
|
|
|
local request_success, request_id = client.request(method, params, handler, resolved_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
|
|
|
|
end, supported_clients)
|
|
|
|
|
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
|
|
|
|
|
2021-04-15 04:42:25 -07:00
|
|
|
---Sends an async request for all active clients attached to the buffer.
|
|
|
|
---Executes the callback on the combined result.
|
|
|
|
---Parameters are the same as |vim.lsp.buf_request()| but the return result and callback are
|
|
|
|
---different.
|
|
|
|
---
|
2021-08-22 13:55:28 -07:00
|
|
|
---@param bufnr (number) Buffer handle, or 0 for current.
|
|
|
|
---@param method (string) LSP method name
|
|
|
|
---@param params (optional, table) Parameters to send to the server
|
|
|
|
---@param callback (function) The callback to call when all requests are finished.
|
2021-04-15 04:42:25 -07:00
|
|
|
-- Unlike `buf_request`, this will collect all the responses from each server instead of handling them.
|
|
|
|
-- A map of client_id:request_result will be provided to the callback
|
|
|
|
--
|
2021-08-22 13:55:28 -07:00
|
|
|
---@returns (function) A function that will cancel all requests which is the same as the one returned from `buf_request`.
|
2021-04-15 04:42:25 -07:00
|
|
|
function lsp.buf_request_all(bufnr, method, params, callback)
|
|
|
|
local request_results = {}
|
|
|
|
local result_count = 0
|
|
|
|
local expected_result_count = 0
|
|
|
|
|
2021-10-10 22:32:50 -07:00
|
|
|
local set_expected_result_count = once(function ()
|
|
|
|
for_each_buffer_client(bufnr, function(client)
|
|
|
|
if client.supports_method(method) then
|
|
|
|
expected_result_count = expected_result_count + 1
|
|
|
|
end
|
|
|
|
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)
|
|
|
|
request_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
|
|
|
|
callback(request_results)
|
|
|
|
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.
|
2019-12-31 07:52:14 -07:00
|
|
|
--- Parameters are the same as |vim.lsp.buf_request()| but the return result is
|
2021-05-02 08:08:57 -07:00
|
|
|
--- different. Wait maximum of {timeout_ms} (default 1000) ms.
|
2019-12-31 07:52:14 -07:00
|
|
|
---
|
2021-08-22 13:55:28 -07:00
|
|
|
---@param bufnr (number) Buffer handle, or 0 for current.
|
|
|
|
---@param method (string) LSP method name
|
|
|
|
---@param params (optional, table) Parameters to send to the server
|
|
|
|
---@param timeout_ms (optional, number, default=1000) Maximum time in
|
2019-12-31 07:52:14 -07:00
|
|
|
--- milliseconds to wait for a result.
|
|
|
|
---
|
2021-08-22 13:55:28 -07:00
|
|
|
---@returns Map of client_id:request_result. On timeout, cancel or error,
|
2019-12-31 07:52:14 -07:00
|
|
|
--- returns `(nil, err)` where `err` is a string describing the failure
|
|
|
|
--- reason.
|
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
|
2021-08-22 13:55:28 -07:00
|
|
|
---@param bufnr [number] (optional): The number of the buffer
|
|
|
|
---@param method [string]: Name of the request method
|
|
|
|
---@param params [string]: Arguments to send to the server
|
2020-07-02 04:09:17 -07:00
|
|
|
---
|
2021-08-22 13:55:28 -07:00
|
|
|
---@returns 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
|
2020-02-22 05:20:38 -07:00
|
|
|
for_each_buffer_client(bufnr, function(client, _client_id, _resolved_bufnr)
|
2020-02-26 12:22:14 -07:00
|
|
|
if client.rpc.notify(method, params) then resp = true end
|
2019-11-13 13:55:26 -07:00
|
|
|
end)
|
2020-02-26 12:22:14 -07:00
|
|
|
return resp
|
2019-11-13 13:55:26 -07:00
|
|
|
end
|
|
|
|
|
2021-10-08 08:47:59 -07:00
|
|
|
|
|
|
|
---@private
|
|
|
|
local function adjust_start_col(lnum, line, items, encoding)
|
|
|
|
local min_start_char = nil
|
|
|
|
for _, item in pairs(items) do
|
|
|
|
if item.textEdit and item.textEdit.range.start.line == lnum - 1 then
|
|
|
|
if min_start_char and min_start_char ~= item.textEdit.range.start.character then
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
min_start_char = item.textEdit.range.start.character
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if min_start_char then
|
|
|
|
if encoding == 'utf-8' then
|
|
|
|
return min_start_char
|
|
|
|
else
|
|
|
|
return vim.str_byteindex(line, min_start_char, encoding == 'utf-16')
|
|
|
|
end
|
|
|
|
else
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
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
|
|
|
---
|
2021-08-22 13:55:28 -07:00
|
|
|
---@param findstart 0 or 1, decides behavior
|
|
|
|
---@param base If findstart=0, text to match against
|
2020-01-13 00:41:55 -07:00
|
|
|
---
|
2021-10-19 12:55:22 -07:00
|
|
|
---@returns (number) 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)
|
|
|
|
local _ = log.debug() and log.debug("omnifunc.findstart", { findstart = findstart, base = base })
|
|
|
|
|
|
|
|
local bufnr = resolve_bufnr()
|
|
|
|
local has_buffer_clients = not tbl_isempty(all_buffer_active_clients[bufnr] or {})
|
|
|
|
if not has_buffer_clients then
|
|
|
|
if findstart == 1 then
|
|
|
|
return -1
|
|
|
|
else
|
|
|
|
return {}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-12-20 23:49:29 -07:00
|
|
|
-- Then, perform standard completion request
|
|
|
|
local _ = log.info() and log.info("base ", base)
|
|
|
|
|
|
|
|
local pos = vim.api.nvim_win_get_cursor(0)
|
|
|
|
local line = vim.api.nvim_get_current_line()
|
|
|
|
local line_to_cursor = line:sub(1, pos[2])
|
|
|
|
local _ = log.trace() and log.trace("omnifunc.line", pos, line)
|
|
|
|
|
2020-01-13 00:41:55 -07:00
|
|
|
-- Get the start position of the current keyword
|
2019-12-20 23:49:29 -07:00
|
|
|
local textMatch = vim.fn.match(line_to_cursor, '\\k*$')
|
2020-02-17 21:38:52 -07:00
|
|
|
|
2019-12-20 23:49:29 -07:00
|
|
|
local params = util.make_position_params()
|
|
|
|
|
|
|
|
local items = {}
|
2021-10-08 08:47:59 -07:00
|
|
|
lsp.buf_request(bufnr, 'textDocument/completion', params, function(err, result, ctx)
|
2021-06-01 06:13:21 -07:00
|
|
|
if err or not result or vim.fn.mode() ~= "i" then return end
|
2021-10-08 08:47:59 -07:00
|
|
|
|
|
|
|
-- Completion response items may be relative to a position different than `textMatch`.
|
|
|
|
-- Concrete example, with sumneko/lua-language-server:
|
|
|
|
--
|
|
|
|
-- require('plenary.asy|
|
|
|
|
-- ▲ ▲ ▲
|
|
|
|
-- │ │ └── cursor_pos: 20
|
|
|
|
-- │ └────── textMatch: 17
|
|
|
|
-- └────────────── textEdit.range.start.character: 9
|
|
|
|
-- .newText = 'plenary.async'
|
|
|
|
-- ^^^
|
|
|
|
-- prefix (We'd remove everything not starting with `asy`,
|
|
|
|
-- so we'd eliminate the `plenary.async` result
|
|
|
|
--
|
|
|
|
-- `adjust_start_col` is used to prefer the language server boundary.
|
|
|
|
--
|
|
|
|
local client = lsp.get_client_by_id(ctx.client_id)
|
|
|
|
local encoding = client and client.offset_encoding or 'utf-16'
|
|
|
|
local candidates = util.extract_completion_items(result)
|
|
|
|
local startbyte = adjust_start_col(pos[1], line, candidates, encoding) or textMatch
|
|
|
|
local prefix = line:sub(startbyte + 1, pos[2])
|
2020-02-17 21:38:52 -07:00
|
|
|
local matches = util.text_document_completion_list_to_complete_items(result, prefix)
|
2019-12-20 23:49:29 -07:00
|
|
|
-- TODO(ashkan): is this the best way to do this?
|
|
|
|
vim.list_extend(items, matches)
|
2021-10-08 08:47:59 -07:00
|
|
|
vim.fn.complete(startbyte + 1, items)
|
2019-12-20 23:49:29 -07:00
|
|
|
end)
|
2019-12-20 03:46:47 -07:00
|
|
|
|
2019-12-20 23:49:29 -07:00
|
|
|
-- Return -2 to signal that we should continue completion so that we can
|
|
|
|
-- async complete.
|
|
|
|
return -2
|
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`
|
|
|
|
--- via `vim.api.nvim_buf_set_option(bufnr, 'formatexpr', 'v:lua.vim.lsp.formatexpr()')`.
|
|
|
|
---
|
|
|
|
--- Can additionally be wrapped with a function that passes an optional table for customization.
|
|
|
|
---
|
|
|
|
---@param opts table options for customizing the formatting expression which takes the
|
|
|
|
--- following keys:
|
|
|
|
--- * 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
|
|
|
|
|
|
|
|
if vim.tbl_contains({'i', 'R', 'ic', 'ix'}, vim.fn.mode()) then
|
|
|
|
-- `formatexpr` is also called when exceeding `textwidth` in insert mode
|
|
|
|
-- fall back to internal formatting
|
|
|
|
return 1
|
|
|
|
end
|
|
|
|
|
|
|
|
local start_line = vim.v.lnum
|
|
|
|
local end_line = start_line + vim.v.count - 1
|
|
|
|
|
|
|
|
if start_line > 0 and end_line > 0 then
|
|
|
|
local params = {
|
|
|
|
textDocument = util.make_text_document_params();
|
|
|
|
range = {
|
|
|
|
start = { line = start_line - 1; character = 0; };
|
|
|
|
["end"] = { line = end_line - 1; character = 0; };
|
|
|
|
};
|
|
|
|
};
|
|
|
|
params.options = util.make_formatting_params().options
|
|
|
|
local client_results = vim.lsp.buf_request_sync(0, "textDocument/rangeFormatting", params, timeout_ms)
|
|
|
|
|
|
|
|
-- Apply the text edits from one and only one of the clients.
|
|
|
|
for _, response in pairs(client_results) do
|
|
|
|
if response.result then
|
|
|
|
vim.lsp.util.apply_text_edits(response.result, 0)
|
|
|
|
return 0
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- do not run builtin formatter.
|
|
|
|
return 0
|
|
|
|
end
|
|
|
|
|
2020-08-19 09:17:08 -07:00
|
|
|
---Checks whether a client is stopped.
|
|
|
|
---
|
2021-08-22 13:55:28 -07:00
|
|
|
---@param client_id (Number)
|
|
|
|
---@returns true if client is stopped, false otherwise.
|
2019-11-20 17:03:32 -07:00
|
|
|
function lsp.client_is_stopped(client_id)
|
|
|
|
return active_clients[client_id] == nil
|
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
|
|
|
---
|
2021-08-22 13:55:28 -07:00
|
|
|
---@param bufnr (optional, number): Buffer handle, or 0 for current
|
2019-11-13 13:55:26 -07:00
|
|
|
function lsp.buf_get_clients(bufnr)
|
|
|
|
bufnr = resolve_bufnr(bufnr)
|
|
|
|
local result = {}
|
|
|
|
for_each_buffer_client(bufnr, function(client, client_id)
|
|
|
|
result[client_id] = client
|
|
|
|
end)
|
|
|
|
return result
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Log level dictionary with reverse lookup as well.
|
|
|
|
--
|
|
|
|
-- Can be used to lookup the number from the name or the
|
|
|
|
-- name from the number.
|
2019-12-31 07:52:14 -07:00
|
|
|
-- Levels by name: "trace", "debug", "info", "warn", "error"
|
|
|
|
-- Level numbers begin with "trace" at 0
|
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.
|
|
|
|
---
|
|
|
|
--- Levels by name: "trace", "debug", "info", "warn", "error"
|
|
|
|
--- 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
|
|
|
---
|
2021-08-22 13:55:28 -07:00
|
|
|
---@param level [number|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.
|
2021-08-22 13:55:28 -07:00
|
|
|
---@returns (String) Path to logfile.
|
2019-11-13 13:55:26 -07:00
|
|
|
function lsp.get_log_path()
|
|
|
|
return log.get_filename()
|
|
|
|
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
|
|
|
--- Call {fn} for every client attached to {bufnr}
|
|
|
|
function lsp.for_each_buffer_client(bufnr, fn)
|
|
|
|
return for_each_buffer_client(bufnr, fn)
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Function to manage overriding defaults for LSP handlers.
|
2021-08-22 13:55:28 -07:00
|
|
|
---@param handler (function) See |lsp-handler|
|
|
|
|
---@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)
|
|
|
|
function lsp._with_extend(name, options, user_config)
|
|
|
|
user_config = user_config or {}
|
|
|
|
|
|
|
|
local resulting_config = {}
|
|
|
|
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))
|
|
|
|
)))
|
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|
|
|
|
|
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
|
|
|
|
-- vim:sw=2 ts=2 et
|