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 22:21:34 -05:00
|
|
|
local log = require 'vim.lsp.log'
|
|
|
|
|
local protocol = require 'vim.lsp.protocol'
|
|
|
|
|
local util = require 'vim.lsp.util'
|
|
|
|
|
local vim = vim
|
|
|
|
|
local api = vim.api
|
|
|
|
|
local buf = require 'vim.lsp.buf'
|
|
|
|
|
|
|
|
|
|
local M = {}
|
|
|
|
|
|
|
|
|
|
-- FIXME: DOC: Expose in vimdocs
|
|
|
|
|
|
|
|
|
|
--@private
|
|
|
|
|
--- Writes to error buffer.
|
|
|
|
|
--@param ... (table of strings) Will be concatenated before being written
|
|
|
|
|
local function err_message(...)
|
2021-02-22 23:31:12 +01:00
|
|
|
vim.notify(table.concat(vim.tbl_flatten{...}), vim.log.levels.ERROR)
|
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 22:21:34 -05:00
|
|
|
api.nvim_command("redraw")
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#workspace_executeCommand
|
|
|
|
|
M['workspace/executeCommand'] = function(err, _)
|
|
|
|
|
if err then
|
|
|
|
|
error("Could not execute code action: "..err.message)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2020-12-20 21:59:25 +01:00
|
|
|
-- @msg of type ProgressParams
|
|
|
|
|
-- Basically a token of type number/string
|
2021-02-28 15:49:25 +01:00
|
|
|
local function progress_handler(_, _, params, client_id)
|
2020-12-20 21:59:25 +01:00
|
|
|
local client = vim.lsp.get_client_by_id(client_id)
|
2021-01-01 16:51:47 -06:00
|
|
|
local client_name = client and client.name or string.format("id=%d", client_id)
|
2020-12-20 21:59:25 +01:00
|
|
|
if not client then
|
2021-01-01 16:51:47 -06:00
|
|
|
err_message("LSP[", client_name, "] client has shut down after sending the message")
|
2020-12-20 21:59:25 +01:00
|
|
|
end
|
|
|
|
|
local val = params.value -- unspecified yet
|
|
|
|
|
local token = params.token -- string or number
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if val.kind then
|
|
|
|
|
if val.kind == 'begin' then
|
|
|
|
|
client.messages.progress[token] = {
|
|
|
|
|
title = val.title,
|
|
|
|
|
message = val.message,
|
|
|
|
|
percentage = val.percentage,
|
|
|
|
|
}
|
|
|
|
|
elseif val.kind == 'report' then
|
2021-01-01 16:51:47 -06:00
|
|
|
client.messages.progress[token].message = val.message;
|
|
|
|
|
client.messages.progress[token].percentage = val.percentage;
|
2020-12-20 21:59:25 +01:00
|
|
|
elseif val.kind == 'end' then
|
|
|
|
|
if client.messages.progress[token] == nil then
|
2021-01-01 16:51:47 -06:00
|
|
|
err_message("LSP[", client_name, "] received `end` message with no corresponding `begin`")
|
2020-12-20 21:59:25 +01:00
|
|
|
else
|
|
|
|
|
client.messages.progress[token].message = val.message
|
|
|
|
|
client.messages.progress[token].done = true
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
table.insert(client.messages, {content = val, show_once = true, shown = 0})
|
|
|
|
|
end
|
|
|
|
|
|
2020-12-21 20:03:50 +01:00
|
|
|
vim.api.nvim_command("doautocmd <nomodeline> User LspProgressUpdate")
|
2020-12-20 21:59:25 +01:00
|
|
|
end
|
|
|
|
|
|
2020-12-30 14:17:35 -08:00
|
|
|
--@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#progress
|
2021-02-28 15:49:25 +01:00
|
|
|
M['$/progress'] = progress_handler
|
2020-12-20 21:59:25 +01:00
|
|
|
|
2020-12-30 14:17:35 -08:00
|
|
|
--@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#window_workDoneProgress_create
|
|
|
|
|
M['window/workDoneProgress/create'] = function(_, _, params, client_id)
|
|
|
|
|
local client = vim.lsp.get_client_by_id(client_id)
|
|
|
|
|
local token = params.token -- string or number
|
2021-01-01 16:51:47 -06:00
|
|
|
local client_name = client and client.name or string.format("id=%d", client_id)
|
2020-12-30 14:17:35 -08:00
|
|
|
if not client then
|
2021-01-01 16:51:47 -06:00
|
|
|
err_message("LSP[", client_name, "] client has shut down after sending the message")
|
2020-12-30 14:17:35 -08:00
|
|
|
end
|
|
|
|
|
client.messages.progress[token] = {}
|
|
|
|
|
return vim.NIL
|
|
|
|
|
end
|
|
|
|
|
|
2020-12-30 15:09:33 -08:00
|
|
|
--@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#window_showMessageRequest
|
|
|
|
|
M['window/showMessageRequest'] = function(_, _, params)
|
|
|
|
|
|
|
|
|
|
local actions = params.actions
|
|
|
|
|
print(params.message)
|
|
|
|
|
local option_strings = {params.message, "\nRequest Actions:"}
|
|
|
|
|
for i, action in ipairs(actions) do
|
|
|
|
|
local title = action.title:gsub('\r\n', '\\r\\n')
|
|
|
|
|
title = title:gsub('\n', '\\n')
|
|
|
|
|
table.insert(option_strings, string.format("%d. %s", i, title))
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- window/showMessageRequest can return either MessageActionItem[] or null.
|
|
|
|
|
local choice = vim.fn.inputlist(option_strings)
|
|
|
|
|
if choice < 1 or choice > #actions then
|
|
|
|
|
return vim.NIL
|
|
|
|
|
else
|
2021-01-03 11:31:09 -08:00
|
|
|
return actions[choice]
|
2020-12-30 15:09:33 -08:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2021-01-18 01:11:19 -08:00
|
|
|
--@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#client_registerCapability
|
|
|
|
|
M['client/registerCapability'] = function(_, _, _, client_id)
|
|
|
|
|
local warning_tpl = "The language server %s triggers a registerCapability "..
|
|
|
|
|
"handler despite dynamicRegistration set to false. "..
|
|
|
|
|
"Report upstream, this warning is harmless"
|
|
|
|
|
local client = vim.lsp.get_client_by_id(client_id)
|
|
|
|
|
local client_name = client and client.name or string.format("id=%d", client_id)
|
|
|
|
|
local warning = string.format(warning_tpl, client_name)
|
|
|
|
|
log.warn(warning)
|
|
|
|
|
return vim.NIL
|
|
|
|
|
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 22:21:34 -05:00
|
|
|
--@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_codeAction
|
|
|
|
|
M['textDocument/codeAction'] = function(_, _, actions)
|
|
|
|
|
if actions == nil or vim.tbl_isempty(actions) then
|
|
|
|
|
print("No code actions available")
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local option_strings = {"Code Actions:"}
|
|
|
|
|
for i, action in ipairs(actions) do
|
|
|
|
|
local title = action.title:gsub('\r\n', '\\r\\n')
|
|
|
|
|
title = title:gsub('\n', '\\n')
|
|
|
|
|
table.insert(option_strings, string.format("%d. %s", i, title))
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local choice = vim.fn.inputlist(option_strings)
|
|
|
|
|
if choice < 1 or choice > #actions then
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
local action_chosen = actions[choice]
|
|
|
|
|
-- textDocument/codeAction can return either Command[] or CodeAction[].
|
|
|
|
|
-- If it is a CodeAction, it can have either an edit, a command or both.
|
|
|
|
|
-- Edits should be executed first
|
|
|
|
|
if action_chosen.edit or type(action_chosen.command) == "table" then
|
|
|
|
|
if action_chosen.edit then
|
|
|
|
|
util.apply_workspace_edit(action_chosen.edit)
|
|
|
|
|
end
|
|
|
|
|
if type(action_chosen.command) == "table" then
|
|
|
|
|
buf.execute_command(action_chosen.command)
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
buf.execute_command(action_chosen)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#workspace_applyEdit
|
|
|
|
|
M['workspace/applyEdit'] = function(_, _, workspace_edit)
|
|
|
|
|
if not workspace_edit then return end
|
|
|
|
|
-- TODO(ashkan) Do something more with label?
|
|
|
|
|
if workspace_edit.label then
|
|
|
|
|
print("Workspace edit", workspace_edit.label)
|
|
|
|
|
end
|
|
|
|
|
local status, result = pcall(util.apply_workspace_edit, workspace_edit.edit)
|
|
|
|
|
return {
|
|
|
|
|
applied = status;
|
|
|
|
|
failureReason = result;
|
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
|
2020-12-30 16:05:30 -08:00
|
|
|
--@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#workspace_configuration
|
|
|
|
|
M['workspace/configuration'] = function(err, _, params, client_id)
|
|
|
|
|
local client = vim.lsp.get_client_by_id(client_id)
|
|
|
|
|
if not client then
|
|
|
|
|
err_message("LSP[id=", client_id, "] client has shut down after sending the message")
|
2021-01-18 19:33:10 +01:00
|
|
|
return
|
2020-12-30 16:05:30 -08:00
|
|
|
end
|
|
|
|
|
if err then error(vim.inspect(err)) end
|
|
|
|
|
if not params.items then
|
|
|
|
|
return {}
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local result = {}
|
|
|
|
|
for _, item in ipairs(params.items) do
|
|
|
|
|
if item.section then
|
|
|
|
|
local value = util.lookup_section(client.config.settings, item.section) or vim.NIL
|
|
|
|
|
-- For empty sections with no explicit '' key, return settings as is
|
|
|
|
|
if value == vim.NIL and item.section == '' then
|
|
|
|
|
value = client.config.settings or vim.NIL
|
|
|
|
|
end
|
|
|
|
|
table.insert(result, value)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
return result
|
|
|
|
|
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 22:21:34 -05:00
|
|
|
M['textDocument/publishDiagnostics'] = function(...)
|
|
|
|
|
return require('vim.lsp.diagnostic').on_publish_diagnostics(...)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_references
|
|
|
|
|
M['textDocument/references'] = function(_, _, result)
|
|
|
|
|
if not result then return end
|
|
|
|
|
util.set_qflist(util.locations_to_items(result))
|
|
|
|
|
api.nvim_command("copen")
|
|
|
|
|
api.nvim_command("wincmd p")
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--@private
|
|
|
|
|
--- Prints given list of symbols to the quickfix list.
|
|
|
|
|
--@param _ (not used)
|
|
|
|
|
--@param _ (not used)
|
|
|
|
|
--@param result (list of Symbols) LSP method name
|
|
|
|
|
--@param result (table) result of LSP method; a location or a list of locations.
|
|
|
|
|
---(`textDocument/definition` can return `Location` or `Location[]`
|
|
|
|
|
local symbol_handler = function(_, _, result, _, bufnr)
|
|
|
|
|
if not result or vim.tbl_isempty(result) then return end
|
|
|
|
|
|
|
|
|
|
util.set_qflist(util.symbols_to_items(result, bufnr))
|
|
|
|
|
api.nvim_command("copen")
|
|
|
|
|
api.nvim_command("wincmd p")
|
|
|
|
|
end
|
|
|
|
|
--@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_documentSymbol
|
|
|
|
|
M['textDocument/documentSymbol'] = symbol_handler
|
|
|
|
|
--@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#workspace_symbol
|
|
|
|
|
M['workspace/symbol'] = symbol_handler
|
|
|
|
|
|
|
|
|
|
--@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_rename
|
|
|
|
|
M['textDocument/rename'] = function(_, _, result)
|
|
|
|
|
if not result then return end
|
|
|
|
|
util.apply_workspace_edit(result)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_rangeFormatting
|
|
|
|
|
M['textDocument/rangeFormatting'] = function(_, _, result)
|
|
|
|
|
if not result then return end
|
|
|
|
|
util.apply_text_edits(result)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_formatting
|
|
|
|
|
M['textDocument/formatting'] = function(_, _, result)
|
|
|
|
|
if not result then return end
|
|
|
|
|
util.apply_text_edits(result)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_completion
|
|
|
|
|
M['textDocument/completion'] = function(_, _, result)
|
|
|
|
|
if vim.tbl_isempty(result or {}) then return end
|
|
|
|
|
local row, col = unpack(api.nvim_win_get_cursor(0))
|
|
|
|
|
local line = assert(api.nvim_buf_get_lines(0, row-1, row, false)[1])
|
|
|
|
|
local line_to_cursor = line:sub(col+1)
|
|
|
|
|
local textMatch = vim.fn.match(line_to_cursor, '\\k*$')
|
|
|
|
|
local prefix = line_to_cursor:sub(textMatch+1)
|
|
|
|
|
|
|
|
|
|
local matches = util.text_document_completion_list_to_complete_items(result, prefix)
|
|
|
|
|
vim.fn.complete(textMatch+1, matches)
|
|
|
|
|
end
|
|
|
|
|
|
2021-04-06 07:58:25 +07:00
|
|
|
--- |lsp-handler| for the method "textDocument/hover"
|
|
|
|
|
--- <pre>
|
|
|
|
|
--- vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(
|
|
|
|
|
--- vim.lsp.handlers.hover, {
|
|
|
|
|
--- -- Use a sharp border with `FloatBorder` highlights
|
2021-04-06 23:51:15 -07:00
|
|
|
--- border = "single"
|
2021-04-06 07:58:25 +07:00
|
|
|
--- }
|
|
|
|
|
--- )
|
|
|
|
|
--- </pre>
|
|
|
|
|
---@param config table Configuration table.
|
|
|
|
|
--- - border: (default=nil)
|
|
|
|
|
--- - Add borders to the floating window
|
|
|
|
|
--- - See |vim.api.nvim_open_win()|
|
|
|
|
|
function M.hover(_, method, result, _, _, config)
|
|
|
|
|
config = config or {}
|
2021-04-07 00:21:56 -07:00
|
|
|
local bufnr, winnr = util.focusable_float(method, function()
|
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 22:21:34 -05:00
|
|
|
if not (result and result.contents) then
|
|
|
|
|
-- return { 'No information available' }
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
local markdown_lines = util.convert_input_to_markdown_lines(result.contents)
|
|
|
|
|
markdown_lines = util.trim_empty_lines(markdown_lines)
|
|
|
|
|
if vim.tbl_isempty(markdown_lines) then
|
|
|
|
|
-- return { 'No information available' }
|
|
|
|
|
return
|
|
|
|
|
end
|
2021-05-21 19:19:17 +02:00
|
|
|
local bufnr, winnr = util.fancy_floating_markdown(markdown_lines, 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 22:21:34 -05:00
|
|
|
util.close_preview_autocmd({"CursorMoved", "BufHidden", "InsertCharPre"}, winnr)
|
|
|
|
|
return bufnr, winnr
|
|
|
|
|
end)
|
2021-04-07 00:21:56 -07:00
|
|
|
return bufnr, winnr
|
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 22:21:34 -05:00
|
|
|
end
|
|
|
|
|
|
2021-04-06 07:58:25 +07:00
|
|
|
--@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_hover
|
|
|
|
|
M['textDocument/hover'] = M.hover
|
|
|
|
|
|
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 22:21:34 -05:00
|
|
|
--@private
|
|
|
|
|
--- Jumps to a location. Used as a handler for multiple LSP methods.
|
|
|
|
|
--@param _ (not used)
|
|
|
|
|
--@param method (string) LSP method name
|
|
|
|
|
--@param result (table) result of LSP method; a location or a list of locations.
|
|
|
|
|
---(`textDocument/definition` can return `Location` or `Location[]`
|
|
|
|
|
local function location_handler(_, method, result)
|
|
|
|
|
if result == nil or vim.tbl_isempty(result) then
|
|
|
|
|
local _ = log.info() and log.info(method, 'No location found')
|
|
|
|
|
return nil
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- textDocument/definition can return Location or Location[]
|
|
|
|
|
-- https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_definition
|
|
|
|
|
|
|
|
|
|
if vim.tbl_islist(result) then
|
|
|
|
|
util.jump_to_location(result[1])
|
|
|
|
|
|
|
|
|
|
if #result > 1 then
|
|
|
|
|
util.set_qflist(util.locations_to_items(result))
|
|
|
|
|
api.nvim_command("copen")
|
|
|
|
|
api.nvim_command("wincmd p")
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
util.jump_to_location(result)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_declaration
|
|
|
|
|
M['textDocument/declaration'] = location_handler
|
|
|
|
|
--@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_definition
|
|
|
|
|
M['textDocument/definition'] = location_handler
|
|
|
|
|
--@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_typeDefinition
|
|
|
|
|
M['textDocument/typeDefinition'] = location_handler
|
|
|
|
|
--@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_implementation
|
|
|
|
|
M['textDocument/implementation'] = location_handler
|
|
|
|
|
|
2021-04-06 07:58:25 +07:00
|
|
|
--- |lsp-handler| for the method "textDocument/signatureHelp"
|
|
|
|
|
--- <pre>
|
|
|
|
|
--- vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with(
|
|
|
|
|
--- vim.lsp.handlers.signature_help, {
|
|
|
|
|
--- -- Use a sharp border with `FloatBorder` highlights
|
2021-04-06 23:51:15 -07:00
|
|
|
--- border = "single"
|
2021-04-06 07:58:25 +07:00
|
|
|
--- }
|
|
|
|
|
--- )
|
|
|
|
|
--- </pre>
|
|
|
|
|
---@param config table Configuration table.
|
|
|
|
|
--- - border: (default=nil)
|
|
|
|
|
--- - Add borders to the floating window
|
|
|
|
|
--- - See |vim.api.nvim_open_win()|
|
|
|
|
|
function M.signature_help(_, method, result, _, bufnr, config)
|
|
|
|
|
config = config or {}
|
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 22:21:34 -05:00
|
|
|
-- When use `autocmd CompleteDone <silent><buffer> lua vim.lsp.buf.signature_help()` to call signatureHelp handler
|
|
|
|
|
-- If the completion item doesn't have signatures It will make noise. Change to use `print` that can use `<silent>` to ignore
|
|
|
|
|
if not (result and result.signatures and result.signatures[1]) then
|
|
|
|
|
print('No signature help available')
|
|
|
|
|
return
|
|
|
|
|
end
|
2021-05-21 19:19:17 +02:00
|
|
|
local p_bufnr, winnr = util.focusable_float(method, function()
|
|
|
|
|
local ft = api.nvim_buf_get_option(bufnr, 'filetype')
|
|
|
|
|
local lines = util.convert_signature_help_to_markdown_lines(result, ft)
|
|
|
|
|
lines = util.trim_empty_lines(lines)
|
|
|
|
|
if vim.tbl_isempty(lines) then
|
|
|
|
|
print('No signature help available')
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
local p_bufnr, p_winnr = util.fancy_floating_markdown(lines, config)
|
|
|
|
|
util.close_preview_autocmd({"CursorMoved", "CursorMovedI", "BufHidden", "InsertCharPre"}, p_winnr)
|
|
|
|
|
|
|
|
|
|
return p_bufnr, p_winnr
|
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 22:21:34 -05:00
|
|
|
end)
|
2021-05-21 19:19:17 +02:00
|
|
|
return p_bufnr, winnr
|
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 22:21:34 -05:00
|
|
|
end
|
|
|
|
|
|
2021-04-06 07:58:25 +07:00
|
|
|
--@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_signatureHelp
|
|
|
|
|
M['textDocument/signatureHelp'] = M.signature_help
|
|
|
|
|
|
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 22:21:34 -05:00
|
|
|
--@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_documentHighlight
|
2020-12-28 18:05:30 -05:00
|
|
|
M['textDocument/documentHighlight'] = function(_, _, result, _, 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 22:21:34 -05:00
|
|
|
if not result then return end
|
|
|
|
|
util.buf_highlight_references(bufnr, result)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--@private
|
|
|
|
|
---
|
|
|
|
|
--- Displays call hierarchy in the quickfix window.
|
|
|
|
|
---
|
|
|
|
|
--@param direction `"from"` for incoming calls and `"to"` for outgoing calls
|
|
|
|
|
--@returns `CallHierarchyIncomingCall[]` if {direction} is `"from"`,
|
|
|
|
|
--@returns `CallHierarchyOutgoingCall[]` if {direction} is `"to"`,
|
|
|
|
|
local make_call_hierarchy_handler = function(direction)
|
|
|
|
|
return function(_, _, result)
|
|
|
|
|
if not result then return end
|
|
|
|
|
local items = {}
|
|
|
|
|
for _, call_hierarchy_call in pairs(result) do
|
|
|
|
|
local call_hierarchy_item = call_hierarchy_call[direction]
|
|
|
|
|
for _, range in pairs(call_hierarchy_call.fromRanges) do
|
|
|
|
|
table.insert(items, {
|
|
|
|
|
filename = assert(vim.uri_to_fname(call_hierarchy_item.uri)),
|
|
|
|
|
text = call_hierarchy_item.name,
|
|
|
|
|
lnum = range.start.line + 1,
|
|
|
|
|
col = range.start.character + 1,
|
|
|
|
|
})
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
util.set_qflist(items)
|
|
|
|
|
api.nvim_command("copen")
|
|
|
|
|
api.nvim_command("wincmd p")
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#callHierarchy/incomingCalls
|
|
|
|
|
M['callHierarchy/incomingCalls'] = make_call_hierarchy_handler('from')
|
|
|
|
|
|
|
|
|
|
--@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#callHierarchy/outgoingCalls
|
|
|
|
|
M['callHierarchy/outgoingCalls'] = make_call_hierarchy_handler('to')
|
|
|
|
|
|
|
|
|
|
--@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#window/logMessage
|
|
|
|
|
M['window/logMessage'] = function(_, _, result, client_id)
|
|
|
|
|
local message_type = result.type
|
|
|
|
|
local message = result.message
|
|
|
|
|
local client = vim.lsp.get_client_by_id(client_id)
|
|
|
|
|
local client_name = client and client.name or string.format("id=%d", client_id)
|
|
|
|
|
if not client then
|
|
|
|
|
err_message("LSP[", client_name, "] client has shut down after sending the message")
|
|
|
|
|
end
|
|
|
|
|
if message_type == protocol.MessageType.Error then
|
|
|
|
|
log.error(message)
|
|
|
|
|
elseif message_type == protocol.MessageType.Warning then
|
|
|
|
|
log.warn(message)
|
|
|
|
|
elseif message_type == protocol.MessageType.Info then
|
|
|
|
|
log.info(message)
|
|
|
|
|
else
|
|
|
|
|
log.debug(message)
|
|
|
|
|
end
|
|
|
|
|
return result
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#window/showMessage
|
|
|
|
|
M['window/showMessage'] = function(_, _, result, client_id)
|
|
|
|
|
local message_type = result.type
|
|
|
|
|
local message = result.message
|
|
|
|
|
local client = vim.lsp.get_client_by_id(client_id)
|
|
|
|
|
local client_name = client and client.name or string.format("id=%d", client_id)
|
|
|
|
|
if not client then
|
|
|
|
|
err_message("LSP[", client_name, "] client has shut down after sending the message")
|
|
|
|
|
end
|
|
|
|
|
if message_type == protocol.MessageType.Error then
|
|
|
|
|
err_message("LSP[", client_name, "] ", message)
|
|
|
|
|
else
|
|
|
|
|
local message_type_name = protocol.MessageType[message_type]
|
|
|
|
|
api.nvim_out_write(string.format("LSP[%s][%s] %s\n", client_name, message_type_name, message))
|
|
|
|
|
end
|
|
|
|
|
return result
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- Add boilerplate error validation and logging for all of these.
|
|
|
|
|
for k, fn in pairs(M) do
|
|
|
|
|
M[k] = function(err, method, params, client_id, bufnr, config)
|
|
|
|
|
local _ = log.debug() and log.debug('default_handler', method, {
|
|
|
|
|
params = params, client_id = client_id, err = err, bufnr = bufnr, config = config
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
if err then
|
2021-02-22 23:31:12 +01:00
|
|
|
return err_message(tostring(err))
|
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 22:21:34 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
return fn(err, method, params, client_id, bufnr, config)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
return M
|
|
|
|
|
-- vim:sw=2 ts=2 et
|