aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/lsp/handlers.lua
Commit message (Collapse)AuthorAge
* fix(lsp): assert workspace/applyEdit receives params (#21945)Mathias Fußenegger2023-01-22
| | | | | | | | | | | | | According to the specification `workspace/applyEdit` must be called with `ApplyWorkspaceEditParams`. So far the client just returned, which could lead to a misleading error on the server side because `workspace/applyEdit` must respond with a `ApplyWorkspaceEditResult`. This adds an assertion to clarify that the server is violating the specification. See https://github.com/neovim/neovim/issues/21925
* feat(float): open float relative to mouse #21531Sebastian Lyng Johansen2023-01-10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Problem: No easy way to position a LSP hover window relative to mouse. Solution: Introduce another option to the `relative` key in `nvim_open_win()`. With this PR it should be possible to override the handler and do something similar to this https://github.com/neovim/neovim/pull/19481#issuecomment-1193248674 to have hover information displayed from the mouse. Test case: ```lua local util = require('vim.lsp.util') local function make_position_param(window, offset_encoding) window = window or 0 local buf = vim.api.nvim_win_get_buf(window) local row, col local mouse = vim.fn.getmousepos() row = mouse.line col = mouse.column offset_encoding = offset_encoding or util._get_offset_encoding(buf) row = row - 1 local line = vim.api.nvim_buf_get_lines(buf, row, row + 1, true)[1] if not line then return { line = 0, character = 0 } end if #line < col then return { line = 0, character = 0 } end col = util._str_utfindex_enc(line, col, offset_encoding) return { line = row, character = col } end local make_params = function(window, offset_encoding) window = window or 0 local buf = vim.api.nvim_win_get_buf(window) offset_encoding = offset_encoding or util._get_offset_encoding(buf) return { textDocument = util.make_text_document_params(buf), position = make_position_param(window, offset_encoding), } end local hover_timer = nil vim.o.mousemoveevent = true vim.keymap.set({ '', 'i' }, '<MouseMove>', function() if hover_timer then hover_timer:close() end hover_timer = vim.defer_fn(function() hover_timer = nil local params = make_params() vim.lsp.buf_request( 0, 'textDocument/hover', params, vim.lsp.with(vim.lsp.handlers.hover, { silent = true, focusable = false, relative = 'mouse', }) ) end, 500) return '<MouseMove>' end, { expr = true }) ```
* fix(lsp): call show_document with correct argsMathias Fussenegger2022-12-04
| | | | Closes https://github.com/neovim/neovim/issues/21177
* docs(gen): support language annotation in docstringsChristian Clason2022-12-02
|
* feat(lsp): support set title in lsp relate floatwindow (#21110)Raphael2022-11-21
|
* fix(lsp): ignore hover and signatureHelp responses on buffer change (#21121)Grzegorz Rozdzialik2022-11-19
| | | | | | | | | | | | | | | | | | | Language servers can take some time to respond to the `textDocument/hover` and `textDocument/signatureHelp` messages. During that time, the user could have already moved to another buffer. The popup was always shown in the current buffer, which could be a different one than the buffer for which the request was sent. This was particularly annoying when moving to a buffer with a `BufLeave` autocmd, as that autocmd was triggered when the hover popup was shown for the original buffer. Ignoring the response from these 2 messages if they are for a buffer that is not the current one leads to less noise. The popup will only be shown for the buffer for which it was requested. A more robust solution could involve cancelling the hover/signatureHelp request if the buffer changes so the language server can free its resources. It could be implemented in the future.
* feat(lsp): run handler in coroutine to support async response (#21026)Mathias Fußenegger2022-11-19
| | | | To illustrate a use-case this also changes `window/showMessageRequest` to use `vim.ui.select`
* fix(lsp/window_showDocument): correctly handle external resources #20867lvimuser2022-10-30
| | | | | - since cmd is a list, it runs directly ('no shell') and we shouldn't escape. - typo: shellerror -> shell_error
* fix(lua): properly configure luacheck and remove `local vim = ...` lines ↵Folke Lemaitre2022-10-09
| | | | (#20551)
* feat(lsp): support window/showDocument (#19977)lvimuser2022-10-08
|
* fix(docs): invalid :help links #20345Justin M. Keyes2022-09-25
| | | | | Fix those naughty single quotes. closes #20159
* fix(lsp): prevent unexpected position jumps (#19370)rhcher2022-08-03
|
* feat(lsp): provide feedback if server can't compute rename result (#19546)Mathias Fußenegger2022-07-27
| | | | | Without some form of feedback a user cannot easily tell if the server is still computing the result (which can take a while in large projects), or whether the server couldn't compute the rename result.
* feat(lsp): allow passing custom list handler to LSP functions that return ↵Dalius Dobravolskas2022-07-25
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | lists (#19213) Currently LSP allows only using loclist or quickfix list window. I normally prefer to review all quickfix items without opening quickfix window. This fix allows passing `on_list` option which allows full control what to do with list. Here is example how to use it with quick fix list: ```lua local function on_list(options) vim.fn.setqflist({}, ' ', options) vim.api.nvim_command('cfirst') end local bufopts = { noremap=true, silent=true, buffer=bufnr } vim.keymap.set('n', '<leader>ad', function() vim.lsp.buf.declaration{on_list=on_list} end, bufopts) vim.keymap.set('n', '<leader>d', function() vim.lsp.buf.definition{on_list=on_list} end, bufopts) vim.keymap.set('n', '<leader>ai', function() vim.lsp.buf.implementation{on_list=on_list} end, bufopts) vim.keymap.set('n', '<leader>at', function() vim.lsp.buf.type_definition{on_list=on_list} end, bufopts) vim.keymap.set('n', '<leader>af', function() vim.lsp.buf.references(nil, {on_list=on_list}) end, bufopts) ``` If you prefer loclist do something like this: ```lua local function on_list(options) vim.fn.setloclist(0, {}, ' ', options) vim.api.nvim_command('lopen') end ``` close #19182 Co-authored-by: Mathias Fußenegger <mfussenegger@users.noreply.github.com>
* refactor(lsp): use autocmd api (#19407)ii142022-07-17
| | | | | | | * refactor(lsp): use autocmd api * refactor(lsp): inline BufWritePost and VimLeavePre callbacks
* refactor: use `local api = vim.api`ii142022-07-15
|
* refactor(lsp): make the use of local aliases more consistentii142022-07-15
|
* refactor(lua): reformat with stylua 0.14.0 (#19264)Christian Clason2022-07-07
| | | | * reformat Lua runtime to make lint CI pass * reduce max line length to 100
* fix(lsp): include cancellable in progress message table (#18809)Chris Kipp2022-05-31
| | | | | | | | Currently the `title`, `message` and `percentage` is stored for a progress, but there is also an optional `cancellable` that comes in with both the `WorkDoneProgressBegin` and also `WorkDoneProgressReport`. This change also stores that value so that a plugin can access it when they do a lookup in `client.messages`.
* feat(lsp): option to reuse_win for jump actions (#18577)Lewis Russell2022-05-18
|
* chore: format runtime with styluaChristian Clason2022-05-09
|
* fix(handlers): more specific error messages (#16772)kylo2522022-04-30
| | | | Specify which message, or request, was last received in case of an error instead of the same generic message
* chore(lsp): remove capabilities sanitization (#17814)Michael Lingelbach2022-04-30
| | | | | | | | | | | | | | | | * feat(lsp)!: remove capabilities sanitization Users must now access client.server_capabilities which matches the same structure as the protocol. https://microsoft.github.io/language-server-protocol/specification client.resolved_capabilities is no longer used to gate capabilities, and will be removed in a future release. BREAKING CHANGE Co-authored-by: Mathias Fussenegger <f.mathias@zignar.net>
* feat(lsp): show feedback on empty hover response (#18308)Mathias Fußenegger2022-04-29
| | | | Without any feedback it gives the impression that the language server is not working properly, which isn't the case.
* fix(lsp): unify progress message handling (#18040)runiq2022-04-20
| | | | | | | | | | | The LSP progress handler would put non-progress messages (such as from clangd or pyls; not part of the LSP spec) directly into `client.messages`, while `vim.lsp.util.get_progress_messages()` would try to fetch them from `client.messages.messages` instead (and come up empty everytime). This would result in these messages never being cleaned up by `get_progress_messages()`. This commit fixes that by treating those messages like show-once progress messages (by setting `done=true` immediately).
* fix(lsp): fix lookup of boolean values in workspace/configuration (#18026)Fredrik Ekre2022-04-15
|
* fix(lsp): use botright copen for all handlers (#17471)Michael Lingelbach2022-02-20
|
* feat(lsp): add handler for workspace/workspaceFolders (#17149)Michael Lingelbach2022-01-21
|
* fix(lsp): fetch offset_encoding from client in references (#17104)Michael Lingelbach2022-01-15
|
* feat(lsp): dynamically generate list title in response_to_list (#17081)Gregory Anders2022-01-14
| | | | | | | | | | | | | | | | This gives quickfix/location lists created by handlers which use 'response_to_list' (textDocument/documentSymbols and workspace/symbol by default) the ability to set a more useful list title. This commit gives lists created for documentSymbols a title of the form: Symbols in <filename> and lists for workspace/symbol a title of the form: Symbols matching '<query>' These are more informative than a standard "Language Server" list title and can help disambiguate results when users have multiple quickfix lists that they cycle through with `:colder` and `:cnewer`.
* fix(lsp): forward offset_encoding in rename handler (#17079)Michael Lingelbach2022-01-13
|
* fix(lsp): forward offset_encoding to apply_text_edits (#17075)Michael Lingelbach2022-01-13
|
* fix(lsp): strictly enforce passing offset encoding (#17049)Michael Lingelbach2022-01-13
| | | | | | | | | | This removes the "fallback" to utf-16 in many of our helper functions. We should always explicitly pass these around when possible except in two locations: * generating params with help utilities called by buf.lua functions * the buf.lua functions themselves Anything that is called by the handler should be passed the offset encoding.
* fix(lsp): suppress ContentModified errors from UI (#16904)Sam McCall2022-01-04
| | | | | | | | | Fixes https://github.com/neovim/neovim/issues/16900 If clients receive a ContentModified error, it generally should not show it in the UI for the end-user. Clients can resend the request if they know how to do so. https://microsoft.github.io/language-server-protocol/specifications/specification-current/#implementationConsiderations
* chore: fix typos (#16506)dundargoc2021-12-28
| | | | | | | | | Co-authored-by: Gregory Anders <8965202+gpanders@users.noreply.github.com> Co-authored-by: Evgeni Chasnovski <evgeni.chasnovski@gmail.com> Co-authored-by: zeertzjq <zeertzjq@outlook.com> Co-authored-by: Christoph Hasse <hassec@users.noreply.github.com> Co-authored-by: Alef Pereira <ealefpereira@gmail.com> Co-authored-by: AusCyber <willp@outlook.com.au> Co-authored-by: kylo252 <59826753+kylo252@users.noreply.github.com>
* refactor: replace deprecated lua functions with their new versions (#16603)dundargoc2021-12-10
| | | | | | Calling vim.lsp.buf.definition() sometimes gives a deprecation warning. This will likely solve that. Co-authored-by: Christian Clason <christian.clason@uni-due.de>
* fix(lsp): progress handlers should return vim.NIL on error (#16472)Michael Lingelbach2021-11-30
|
* fix(lsp): do not attempt to index nil client in progress handler (#16463)Michael Lingelbach2021-11-29
|
* fix(lsp): change signature of buf_highlight_references (#16345)Michael Lingelbach2021-11-17
| | | | | the prior signature did not assume an active language client this function can now be used directly by passing an offset encoding defaults to utf-16 (standard for LSP)
* fix(lsp): do not index nil client in progress (#16262)Michael Lingelbach2021-11-09
|
* fix(lsp): convert range to byte index before highlighting (#16218)elianiva2021-11-06
| | | | Co-authored-by: Mathias Fußenegger <mfussenegger@users.noreply.github.com> Co-authored-by: Michael Lingelbach <m.j.lbach@gmail.com>
* feat(lsp): default to botright for setting qflist (#16177)Michael Lingelbach2021-10-30
| | | | | | * Opens quickfix list spanning the entire nvim window in location handlers closes https://github.com/neovim/neovim/issues/12241
* feat(lsp): add codeAction/resolve support (#15818)Mathias Fußenegger2021-09-28
| | | Closes https://github.com/neovim/neovim/issues/15339 and https://github.com/neovim/neovim/issues/15828
* fix(ui): s/format_entry/format_item to match docs (#15819)Mathias Fußenegger2021-09-27
| | | Follow up to https://github.com/neovim/neovim/pull/15771
* feat(ui): add vim.ui.select and use in code actions (#15771)Mathias Fußenegger2021-09-27
| | | | | | | | | | | | | Continuation of https://github.com/neovim/neovim/pull/15202 A plugin like telescope could override it with a fancy implementation and then users would get the telescope-ui within each plugin that utilizes the vim.ui.select function. There are some plugins which override the `textDocument/codeAction` handler solely to provide a different UI. With custom client commands and soon codeAction resolve support, it becomes more difficult to implement the handler right - so having a dedicated way to override the picking function will be useful.
* fix(lsp): guard textDocument/codeAction command logic #15769Chris Kipp2021-09-23
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Problem: Error executing vim.schedule lua callback: ...ovim/HEAD-aba3979/share/nvim/runtime/lua/vim/lsp/buf.lua:502: command: expected string, got nil stack traceback: ...ovim/HEAD-aba3979/share/nvim/runtime/lua/vim/lsp/buf.lua:502: in function 'execute_command' ...HEAD-aba3979/share/nvim/runtime/lua/vim/lsp/handlers.lua:151: in function <...HEAD-aba3979/share/nvim/runtime/lua/vim/lsp/handlers.lua:113> ...ovim/HEAD-aba3979/share/nvim/runtime/lua/vim/lsp/buf.lua:465: in function 'callback' ...r/neovim/HEAD-aba3979/share/nvim/runtime/lua/vim/lsp.lua:1325: in function 'handler' ...r/neovim/HEAD-aba3979/share/nvim/runtime/lua/vim/lsp.lua:899: in function 'cb' vim.lua:281: in function <vim.lua:281> Solution: This is a follow-up to the work done in https://github.com/neovim/neovim/commit/6c03601e3adb4c3c4d47f148df8df20401b88677. There are valid situations where a `textDocument/codeAction` is returned without a command, since a command in optional. For example from Metals, the Scala language server when you get a code action to add a missing import, it looks like this: ```json Result: [ { "title": "Import \u0027Instant\u0027 from package \u0027java.time\u0027", "kind": "quickfix", "diagnostics": [ { "range": { "start": { "line": 6, "character": 10 }, "end": { "line": 6, "character": 17 } }, "severity": 1, "source": "bloop", "message": "not found: value Instant" } ], "edit": { "changes": { "file:///Users/ckipp/Documents/scala-workspace/sanity/src/main/scala/Thing.scala": [ { "range": { "start": { "line": 6, "character": 10 }, "end": { "line": 6, "character": 17 } }, "newText": "Instant" }, { "range": { "start": { "line": 1, "character": 0 }, "end": { "line": 1, "character": 0 } }, "newText": "\nimport java.time.Instant\n" } ] } } } ] ``` This change just wraps the logic that grabs the command in a conditional to skip it if there is no command.
* feat(lsp): add a registry for client side code action commandsMathias Fussenegger2021-09-20
| | | | | This builds on https://github.com/neovim/neovim/pull/14112 and closes https://github.com/neovim/neovim/issues/12326
* Merge #15585 refactor: move vim.lsp.diagnostic to vim.diagnosticJustin M. Keyes2021-09-16
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ## Overview - Move vim.lsp.diagnostic to vim.diagnostic - Refactor client ids to diagnostic namespaces - Update tests - Write/update documentation and function signatures Currently, non-LSP diagnostics in Neovim must hook into the LSP subsystem. This is what e.g. null-ls and nvim-lint do. This is necessary because none of the diagnostic API is exposed separately from the LSP subsystem. This commit addresses this by generalizing the diagnostic subsystem beyond the scope of LSP. The `vim.lsp.diagnostic` module is now simply a specific diagnostic producer and primarily maintains the interface between LSP clients and the broader diagnostic API. The current diagnostic API uses "client ids" which only makes sense in the context of LSP. We replace "client ids" with standard API namespaces generated from `nvim_create_namespace`. This PR is *mostly* backward compatible (so long as plugins are only using the publicly documented API): LSP diagnostics will continue to work as usual, as will pseudo-LSP clients like null-ls and nvim-lint. However, the latter can now use the new interface, which looks something like this: ```lua -- The namespace *must* be given a name. Anonymous namespaces will not work with diagnostics local ns = vim.api.nvim_create_namespace("foo") -- Generate diagnostics local diagnostics = generate_diagnostics() -- Set diagnostics for the current buffer vim.diagnostic.set(ns, diagnostics, bufnr) ``` Some public facing API utility methods were removed and internalized directly in `vim.diagnostic`: * `vim.lsp.util.diagnostics_to_items` ## API Design `vim.diagnostic` contains most of the same API as `vim.lsp.diagnostic` with `client_id` simply replaced with `namespace`, with some differences: * Generally speaking, functions that modify or add diagnostics require a namespace as their first argument, e.g. ```lua vim.diagnostic.set({namespace}, {bufnr}, {diagnostics}[, {opts}]) ``` while functions that read or query diagnostics do not (although in many cases one may be supplied optionally): ```lua vim.diagnostic.get({bufnr}[, {namespace}]) ``` * We use our own severity levels to decouple `vim.diagnostic` from LSP. These are designed similarly to `vim.log.levels` and currently include: ```lua vim.diagnostic.severity.ERROR vim.diagnostic.severity.WARN vim.diagnostic.severity.INFO vim.diagnostic.severity.HINT ``` In practice, these match the LSP diagnostic severity levels exactly, but we should treat this as an interface and not assume that they are the same. The "translation" between the two severity types is handled transparently in `vim.lsp.diagnostic`. * The actual "diagnostic" data structure is: (**EDIT:** Updated 2021-09-09): ```lua { lnum = <number>, col = <number>, end_lnum = <number>, end_col = <number>, severity = <vim.diagnostic.severity>, message = <string> } ``` This differs from the LSP definition of a diagnostic, so we transform them in the handler functions in vim.lsp.diagnostic. ## Configuration The `vim.lsp.with` paradigm still works for configuring how LSP diagnostics are displayed, but this is a specific use-case for the `publishDiagnostics` handler. Configuration with `vim.diagnostic` is instead done with the `vim.diagnostic.config` function: ```lua vim.diagnostic.config({ virtual_text = true, signs = false, underline = true, update_in_insert = true, severity_sort = false, }[, namespace]) ``` (or alternatively passed directly to `set()` or `show()`.) When the `namespace` argument is `nil`, settings are set globally (i.e. for *all* diagnostic namespaces). This is what user's will typically use for their local configuration. Diagnostic producers can also set configuration options for their specific namespace, although this is generally discouraged in order to respect the user's global settings. All of the values in the table passed to `vim.diagnostic.config()` are resolved in the same way that they are in `on_publish_diagnostics`; that is, the value can be a boolean, a table, or a function: ```lua vim.diagnostic.config({ virtual_text = function(namespace, bufnr) -- Only enable virtual text in buffer 3 return bufnr == 3 end, }) ``` ## Misc Notes * `vim.diagnostic` currently depends on `vim.lsp.util` for floating window previews. I think this is okay for now, although ideally we'd want to decouple these completely.
| * refactor: move vim.lsp.diagnostic to vim.diagnosticGregory Anders2021-09-15
| | | | | | | | | | | | | | | | | | | | | | This generalizes diagnostic handling outside of just the scope of LSP. LSP clients are now a specific case of a diagnostic producer, but the diagnostic subsystem is decoupled from the LSP subsystem (or will be, eventually). More discussion at [1]. [1]: https://github.com/neovim/neovim/pull/15585
* | feat(lsp): improve logging (#15636)Michael Lingelbach2021-09-15
|/ | | | | | | * Simplify rpc encode/decode messages to rpc.send/rcp.receive * Make missing handlers message throw a warning * Clean up formatting style in log * Move all non-RPC loop messages to trace instead of debug * Add format func option to log to allow newlines in per log entry