aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/lsp.lua
Commit message (Collapse)AuthorAge
* 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
* feat(lsp): include original request params in handler ctxMathias Fussenegger2021-09-20
| | | | | | | | | | | This is mostly motivated by https://github.com/neovim/neovim/issues/12326 Client side commands might need to access the original request parameters. Currently this is already possible by using closures with `vim.lsp.buf_request`, but the global handlers so far couldn't access the request parameters.
* 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
* Merge pull request #15504 from mjlbach/feat/change-handler-signatureMichael Lingelbach2021-09-05
|\ | | | | feat(lsp)!: change handler signature
| * feat(lsp)!: change handler signatureMichael Lingelbach2021-09-05
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* | fix(lsp): resolve bufnr in buf_is_attached (#15523)Jose Alvarez2021-08-30
| |
* | fix(lsp): check if buffer is valid in changetracking (#15505)Jose Alvarez2021-08-28
|/
* docs: make Lua docstrings consistent #15255Gregory Anders2021-08-22
| | | | | | | | | | | | The official developer documentation in in :h dev-lua-doc specifies to use "--@" for special/magic tokens. However, this format is not consistent with EmmyLua notation (used by some Lua language servers) nor with the C version of the magic docstring tokens which use three comment characters. Further, the code base is currently split between usage of "--@", "---@", and "--- @". In an effort to remain consistent, change all Lua magic tokens to use "---@" and update the developer documentation accordingly.
* feat(lsp): allow root_dir to be nil (#15430)Mathias Fußenegger2021-08-19
| | | | | | | | According to the protocol definition `rootPath`, `rootUri` and `workspaceFolders` are allowed to be null. Some language servers utilize this to provide "single file" support. If all three are null, they don't attempt to index a directory but instead only provide capabilities for a single file.
* docs(lsp): prevent internal comments from showing as vim.lsp.init docsMathias Fussenegger2021-08-16
|
* feat(lsp): implement vim.lsp.diagnostic.redraw() (#15203)Gregory Anders2021-07-29
| | | | | | | | | | | | | Add a new function to redraw diagnostics from the current diagnostic cache, without receiving a "publishDiagnostics" message from the server. This is already being done in two places in the Lua stdlib, so this function unifies that functionality in addition to providing it to third party plugins. An example use case for this could be a command or key-binding for toggling diagnostics virtual text. The virtual text configuration option can be toggled using `vim.lsp.with` followed by `vim.lsp.diagnostic.redraw()` to immediately redraw the diagnostics with the updated setting.
* lsp(start_client): Allow passing custom workspaceFolders to the LSP (#15132)sim2021-07-20
| | | | | | | | | | | | | | Some language servers *cough*rust-analyzer*cough* need an empty/custom workspaceFolders for certain usecases. For example, rust-analyzer needs an empty workspaceFolders table for standalone file support (See https://github.com/rust-analyzer/rust-analyzer/pull/8955). This can also be useful for other languages that need to commonly open a certain directory (like flutter or lua), which would help prevent spinning up a new language server altogether. In case no workspaceFolders are passed, we fallback to what we had before.
* feat(lsp): Add codelens supportMathias Fussenegger2021-06-14
|
* fix(lsp): check mode in omnifunc callbackJose Alvarez2021-06-01
|
* Increase default LSP sync timeout to 1000msKarim Abou Zeid2021-05-02
|
* Add client.request_sync docKarim Abou Zeid2021-05-02
|
* doc clarificationKarim Abou Zeid2021-05-02
|
* Add formatting_seq_sync, change formatting and formatting_syncKarim Abou Zeid2021-05-01
|
* Merge pull request #14429 from ckipp01/forceMichael Lingelbach2021-04-23
|\ | | | | [LSP] - Don't automatically force shutdown on second restart.
| * Don't automatically force shutdown on second restart.ckipp012021-04-23
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is maybe a bit of a niche case, but I hit on this often as I'm developing a server, and therefore continually restarting it to get the latest changes of the server. Previously, I could only do this once since if you send in a request to restart/shut down the server, it will register it as a `tried_graceful_shutdown = true` meaning that the next restart would force it to be killed instead of another graceful exit. Instead, this changes the name a bit and now it will only mark `graceful_shutdown_failed = true` _if_ it actually fails to gracefully shutdown. This change allows for a user to restart multiple times in a situation like mine where nothing is going wrong, but I just want to restart continually as I'm developing without having to close and reopen.
* | Revert "lsp: fix blocking in closing of clients"Michael Lingelbach2021-04-23
|/ | | | | | | | This reverts commit 2e6c09838f88803f31d229002715628639631897. * Fixes #14428 * This commit caused neovim to close while open handles to the uv timer to kill active language servers were still open
* Merge pull request #14180 from oberblastmeister/lsp_exit_perfMichael Lingelbach2021-04-19
|\ | | | | fix slow closing of lsp clients when exiting vim
| * lsp: fix blocking in closing of clientsBrian Shu2021-04-19
| |
* | lsp: add lsp.buf_request_all for invoking asynchronous callbacksBrian Shu2021-04-15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | fixed nil issue changed poll to 10 changed wording added docs to once comma english
* | lsp: Add a flag to debounce didChange notificationsMathias Fussenegger2021-04-13
| | | | | | | | Would help with cases as reported in https://github.com/neovim/neovim/issues/14087
* | Merge pull request #14264 from mjlbach/feature/handle_reloading_bufferMichael Lingelbach2021-04-01
|\ \ | | | | | | lsp: add on_reload callback for buffer edits outside of neovim
| * | lsp: add on_reload callback for buffer edits outside of neovimMichael Lingelbach2021-03-31
| | |
* | | Merge pull request #14262 from mjlbach/feature/lsp_did_save_autocommandMichael Lingelbach2021-04-01
|\ \ \ | | | | | | | | lsp: clear did_save handler autocommand on each attach
| * | | lsp: clear did_save handler autocommand on each attachMichael Lingelbach2021-03-31
| |/ /
* / / lsp: fix textDocument/workspaceSymbol -> workspace/symbolMichael Lingelbach2021-03-31
|/ /
* | lsp: use utf-8 when utf-16 not requestedMichael Lingelbach2021-03-30
| |
* | lsp: Force re-display of diagnostics when opening a fileTJ DeVries2021-03-22
| |
* | lsp: Use incremental sync by defaultMathias Fussenegger2021-03-11
| | | | | | | | | | | | | | | | | | With the new implementation added in https://github.com/neovim/neovim/pull/14079 I think this is now working well enough to enable it by default. There are high CPU usage issues popping up now and then and they might at least partially be related to the full-text sync.
* | lsp: Resolve codeLense server capabilities (#14056)Josa Gesell2021-03-10
| |
* | lsp: get_language_id (#14092)TJ DeVries2021-03-10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Allow specifying a languageId for a lsp For some languages the filetype might not match the languageId the language server accepts. In these cases the config for the language server can contain a function which gets the current buffer and filetype and returns a languageId. When it isn't provided the filetype is used instead. Example: ```lua require'lspconfig'.sourcekit.setup{ get_language_id = function(bufnr, ft) return 'swift' end; } ``` Closes #13093 * lsp: Change to get_language_id Co-authored-by: Jan Dammshäuser <mail@jandamm.de>
* | lsp: fix endline such that it cannot point outside the buffer rangeMichael Lingelbach2021-03-10
| |
* | lsp: add incremental text synchronizationMichael Lingelbach2021-03-09
| | | | | | | | | | * Implementation derived from and validated by vim-lsc authored by Nate Bosch
* | lsp: don't invoke vim.notify on sigterm of language serverMichael Lingelbach2021-03-04
| |
* | lsp: invoke vim.notify when client exits with code or signal other than 0Michael Lingelbach2021-03-04
| |
* | lsp: remove deprecated references to 'callbacks' (#13945)Matthieu Coudron2021-02-23
| | | | | | | | | | vim.lsp.callbacks was deprecated a few months ago. This is a cleanup before the release. Use vim.lsp.handlers instead.
* | lsp: client stop cleanups (#13877)Michael Lingelbach2021-02-19
|/ | | | | | | | * lsp: client stop cleanups * Add diagnostic clearing to client.stop() method used by nvim-lspconfig * Clear diagnostic cache to prevent stale diagnostics on client restart * lsp: Add test for vim.lsp.diagnostic.reset
* lsp: match textDocument/didChange eol behavior (#13792)Michael Lingelbach2021-01-25
| | | We should be consistent in sending the EOL character to servers(I think). Julia expects this to match on bufwrite, or it crashes when vim appends the newline during the write process.
* lsp: clear diagnostics on client shutdown (#13788)Michael Lingelbach2021-01-23
|
* lsp: remove duplicate settings validation (#13789)Michael Lingelbach2021-01-18
|
* lsp: validate and document server settings (#13698)Michael Lingelbach2021-01-18
| | | | * update lua documentation * run docgen
* LSP: Fix nil settings handling in workspace/configuration (#13708)Mathias Fußenegger2021-01-18
| | | | | | | | | The `workspace/configuration` handler could fail with the following error if `config.settings` is nil: runtime/lua/vim/lsp/util.lua:1432: attempt to index local 'settings' (a nil value)" This ensures that `config.settings` is always initialized to an empty table.
* LSP: Add in clientInfo to initalize_params. (#13757)Chris Kipp2021-01-18
| | | | | | | | | | | | * Add in clienInfo to initalize_params. Some servers (like Metals in my case) will actually pull this info from the initalize_params and display it in the logs. I know from the server perspective it helps at times to have this available to pull from to have more details about the client and version. You can see that this is part of the spec here: microsoft.github.io/language-server-protocol/specification#initialize
* lsp: fix on_attach signature documentation (#13723)Michael Lingelbach2021-01-12
| | | * trim trailing whitespace from docs