aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/lsp.lua
Commit message (Collapse)AuthorAge
* feat(api): nvim_chan_set()Justin M. Keyes11 days
| | | | | | | | | | | | | | | | | | | Problem: Only the stdio channel can "own" a server (self-exit on close). After :restart the TUI reconnects over a socket, so the restarted server does not have "self-exit" behavior when the channel closes (e.g. by UI disconnect, host-terminal close, etc.), which leaves a dangling server. Solution: - Introduce `nvim_chan_set`. (`nvim_set_client_info` doesn't fit: exposing it to Lua would require a `channel` param, which is not backwards-compatible, plus it's awkward because it doesn't merge info.) - Broadcast per-channel properties in the "restart" UI event as an opaque dict (a potentially useful pattern for other UI-events in the future). - UIs are expected to restore the channel properties on restart. - `nvim_get_chan_info()` reports "detach". - Remove `nvim__chan_set_detach()`.
* ci(lua): enable annotation and style checksLewis Russell2026-09-30
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Problem: - annotation-usage-error and code-style-check are disabled. - vim.inspect relies on a dummy self-assignment for docgen, and its help omits parameter and option details. - LuaLS fallback types obscure iterator inference. - Docgen hardcodes public function names and appends separately sorted files, leaving shared helpers under the inspector heading. Solution: - Enable annotation-usage-error and code-style-check, and fix misplaced annotations. - Document vim.inspect's callable module directly, removing the dummy assignment. Describe its parameters, option defaults and process callback. - Remove LuaLS iterator fallbacks, correct iterator signatures and check values that the improved inference identifies as optional. - Parse callable modules, require bindings and parent module references. Derive public names and inherited function docs from these links, including missing help for vim.async.semaphore() and vim.version(). - Export vim.lsp.tagfunc directly with lazy loading and document its implementation instead of maintaining a wrapper. - Group files in section_order, replacing append_only and merge_files. Merge declarations before sorting each section, placing shared helpers in the main vim section and keeping vim.inspect in alphabetical order. - Add basic parser coverage for callable modules and module links. AI-assisted
* fix(lua): enable param-type-mismatch diagnosticLewis Russell2026-09-28
| | | | | | | | | Problem: Argument type mismatches are excluded from EmmyLua checks. Solution: Correct runtime annotations and calls, document local checker workarounds, and enable the diagnostic. AI-assisted
* fix(lua): enable unnecessary-assert diagnosticLewis Russell2026-09-28
| | | | AI-assisted
* fix(lua): enable assignment type checking in runtime codeLewis Russell2026-09-25
| | | | | | | | | | | Enable EmmyLua's assign-type-mismatch diagnostic after correcting the runtime annotations and assignments it flags. Correct option, tuple, and return types, and use separate locals when a value changes representation. Add guards and narrow casts where needed so the runtime passes the stricter check. Regenerate the affected docs. AI-assisted
* fix(lua): enable nil-safety diagnostics in runtime codeLewis Russell2026-09-25
| | | | | | | | | | | | Enable EmmyLua's need-check-nil diagnostic and resolve nullable values through more precise types, explicit invariants, and guards for missing runtime state. Keep analyzer-specific workarounds local and update the affected API documentation. Exclude the bundled re.lua from analysis so its nil-check warnings do not fail CI. AI-assisted
* fix(lua): add missing param annotations (#41911)Lewis Russell2026-09-15
|
* build: enable more EmmyLua checksLewis Russell2026-09-08
| | | | | | | | | | | | | | | | - call-non-callable - missing-fields - redefined-label - redefined-local - undefined-field - unreachable-code Promote redefined-local and unreachable-code to warnings. Fix DOS line-ending handling for multiline semantic tokens, and support intersection types in the help parser. AI-assisted
* feat(lsp): fallback to textDocument/formatting from vim.lsp.formatexpr #40079Marcus Caisey2026-08-18
| | | | | | | | | | | | | | | | Problem: With the addition of the `:help al` text object, you can now easily format the whole buffer with `gqal`. However, `vim.lsp.formatexpr` only uses `textDocument/rangeFormatting` which some language servers (like gopls) don't support. Solution: - Fall back to `textDocument/formatting` if the whole buffer is being formatted and the server doesn't support `textDocument/rangeFormatting`. - In theory, these two methods should return the same response if the whole buffer is being formatted, but I preserved the existing behaviour of prioritising `textDocument/rangeFormatting` in case that does not hold (i.e. LS bug). - Also: `vim.lsp.formatexpr` had no tests at all, so actually add tests for it.
* feat(lsp): pass target buffer to `reuse_client` predicate #41163Mike J McGuirk2026-08-07
| | | | | | Problem: The reuse_client predicate does not pass the target buffer, preventing decisions from being truly made per buffer. Solution: Pass the target buffer.
* docs: func/expr options, misc #41102Justin M. Keyes2026-08-01
|
* feat(options): lua closure/function optionsJustin M. Keyes2026-07-31
| | | | | | | | | | | | | | | Problem: Cannot assign Lua functions/closures to "func" ('completefunc', 'tagfun', …) or "expr" ('foldexpr', 'indentexpr', …) options. Solution: - Store "func"/"expr" options as `Callback` instead of string. - Delete oceans of copy-pasted code. - BREAKING: LuaRef returned via RPC/Vimscript is now represented as `"<Lua N: file:line>"` (like what `:map` shows) instead of `nil`. - Note: `man.vim` still uses `v:lua` string, bc it's a vimscript ftplugin. Helped-by: Lewis Russell <lewis6991@gmail.com>
* docs: misc #40847Justin M. Keyes2026-07-25
| | | | Co-authored-by: Barrett Ruth <br@barrettruth.com> Co-authored-by: Nathan Zeng <nathan.j.zeng@gmail.com>
* docs: misc, remove some old help tags #40214Justin M. Keyes2026-07-18
| | | | | | | | | | - Remove old help tags: they add noise to cmdline completion. Co-authored-by: acehinnnqru <acehinnnqru@gmail.com> Co-authored-by: KangaZero <samuelyongw@gmail.com> Co-authored-by: Simone Ragusa <hi@interrato.dev> Co-authored-by: Chinmay Dalal <~chinmay/public-inbox@lists.sr.ht> Co-authored-by: coyaSONG <66289470+coyaSONG@users.noreply.github.com> Co-authored-by: Olivia Kinnear <git@superatomic.dev>
* refactor(api): omit optional paramJustin M. Keyes2026-07-13
|
* refactor(lsp): convert diagnostics to capability framework #40433jdrouhard2026-06-26
| | | | | | | | | | | | | | | | | | | | | | | | | Problem: Diagnostic tracking used a separate bufstates table and manual LspDetach/LspNotify autocmd management via _enable()/_refresh(), duplicating the lifecycle logic already provided by the Capability framework. This caused inconsistencies in how client attach/detach and buffer teardown were handled compared to other LSP features. Solution: Replace the ad-hoc bufstate tracking and _enable/_refresh pattern in vim.lsp.diagnostic with a proper Diagnostics subclass of Capability. This cleans up a few random places in the main lsp module and client module that were poking the diagnostics. It also fixes some pre-existing bugs and inconsistencies that were discovered: - Refresh diagnostics immediately on attach instead of lazily by the first didOpen/didChange notification - Fix Capability.active lookup in M.enable() to key by it_bufnr instead of the filter bufnr - Set lsp defaults before calling the _text_document_did_open_handler in Client:on_attach() so defaults are there before any lsp notification occurs - Log (and return early) on any error from a diagnostic request result instead of only returning early for server cancelled errors
* fix(lsp): make LspNotify more robust #40332jdrouhard2026-06-20
| | | | | | | | | | | | | | | | | | | | | | | | | | | Problem: LspNotify never passed a buffer when executing the autocmds, so buffer-local LspNotify autocmd subscriptions didn't have the correct buf in the event metadata. It was also wrapped in a schedule() so the actual autocmd was delayed until after the event loop. This could result in the wrong buffer receiving the notification if multiple LspNotify autocmds with buffer filters were added. Only the "latest" one would actually receive non-buffer-filtered autocmds, not the matching one. It also caused listeners to receive the notification "out of sync" with when the notification is actually sent. If a buffer is being deleted (which fires a textDocument/didClose notification), the notification is scheduled and fired after the buffer is already gone. Solution: For LSP notifications that pertain to a particular buffer, set it when executing the LspNotify autocmds so the callback functions that are filtered on that buffer will get the correct notifications and the metadata buf field will be correct. Additionally, there is no need to wrap the LspNotify callback in vim.schedule when it can be called inline when the notification to the rpc server is fired. This is tested by removing now-unnecessary autocmds from semantic tokens (InsertEnter and BufWinEnter should no longer be necessary now that requests are fired by LspNotify). Without this fix, simply modifying a buffer doesn't actually trigger LspNotify correctly, and the test for that fails.
* refactor: introduce nvim_on internally #39883Justin M. Keyes2026-05-20
| | | | | | | | | Problem: `nvim_create_autocmd` is too verbose and its `callback` requires extra "nesting". Solution: Introduce `nvim_on`. Start using it internally. Then we can get a feel for how it should look before making it public.
* docs: dev, lsp, indent-guides #39756Justin M. Keyes2026-05-14
| | | | | | | - document "indent guides" https://github.com/neovim/neovim/issues/39726 - document guidance for "subcommands" https://github.com/neovim/neovim/issues/32263#issuecomment-4436002808 Co-authored-by: glepnir <glephunter@gmail.com> Co-authored-by: Noa Levi <275430404+lphuc2250gma@users.noreply.github.com>
* refactor!: remove deprecated APIsYi Ming2026-05-11
|
* fix(lsp): send didClose, didOpen when languageId changes #39499phanium2026-04-30
| | | | | | | | | | | | | | | | | | | | | | Problem: If a buffer's filetype changes after the LSP client has already attached (e.g. from json to jsonc via a modeline), but the client supports both filetypes, it stays attached. It does not notify the server of the new languageId, causing the server to incorrectly process the file using the old languageId. Solution: Save the languageId used during textDocument/didOpen, and send textDocument/didClose + textDocument/didOpen when buffer's languageId changed. Lsp spec: https://github.com/microsoft/language-server-protocol/blob/0003fb53f18dc7a4ac7e51d0eb518deeea90fde5/_specifications/lsp/3.18/textDocument/didOpen.md#L5 > If the language id of a document changes, the client > needs to send a textDocument/didClose to the server followed by a > textDocument/didOpen with the new language id if the server handles > the new language id as well. AI-assisted: Gemini 3.1 Pro
* feat(lsp): highlight foldtext via treesitter #38789Yi Ming2026-04-15
| | | | | | | | | | Problem: To support `collapsedText`, which allows the LSP server to determine the content of the foldtext, we provided `vim.lsp.foldtext()`. However, such content does not have highlighting. Solution Treat the filetype of `collapsedText` as the filetype of the corresponding buffer and use tree-sitter to highlight it.
* docs: lsp, options, api #38980Justin M. Keyes2026-04-14
| | | | | | | | | docs: lsp, options - revert bogus change to `_meta/builtin_types.lua` from 3a4a66017b74 Close #38991 Co-authored-by: David Mejorado <david.mejorado@gmail.com>
* revert: "fix(lsp): only resolve LSP configs once" #38990Justin M. Keyes2026-04-12
| | | revert eb90f5d9e3a6615870f9bf0b28e30f6e84ccd6f4
* fix(lsp): send didOpen on save to all clients+groups #37454Emilv22026-04-12
| | | | | | | Problem: _get_and_set_name edits the name for the whole group, thus only one client per group gets the didOpen message. Solution: move the logic to _changetracking and loop over every client per group.
* feat(api): rename buffer to buf #35330Jordan2026-04-08
| | | | | | | | | | | | Problem: `:help dev-name-common` states that "buf" should be used instead of "buffer" but there are cases where buffer is mentioned in the lua API. Solution: - Rename occurrences of "buffer" to "buf" for consistency with the documentation. - Support (but deprecate) "buffer" for backwards compatibility. Co-authored-by: Justin M. Keyes <justinkz@gmail.com>
* Merge #38560 refactor vim.lsp.rpcJustin M. Keyes2026-04-01
|\
| * refactor(lsp): merge `vim.lsp.rpc.Client` and `vim.lsp.rpc.PublicClient`Yi Ming2026-03-30
| |
* | docs: fix syntax errors in examples #38606skewb1k2026-03-30
|/
* test(lsp): get_configs resolves only necessary configsJustin M. Keyes2026-03-24
|
* docs: api, plugins, ui2Justin M. Keyes2026-03-24
|
* feat(lsp): attach to buftype=help buffers #38412Barrett Ruth2026-03-23
| | | | | | | | Problem: `vim.lsp.enable()` skips all buffers with non-empty `buftype`, including `help` buffers. LSPs targeting `filetype='help'` never auto-attach despite help buffers being real files. Solution: Expand the `buftype` guard in `lsp_enable_callback` to allow `help` alongside `""`.
* revert: "feat(lsp): add `buftypes` field to `vim.lsp.Config`" #38421Maria Solano2026-03-22
| | | | | revert: "feat(lsp): add `buftypes` field to `vim.lsp.Config` (#38380)" This reverts commit cfcdbcf638b5957213b3c1a55d5d1b5659a2fb3e.
* feat(lsp): add `buftypes` field to `vim.lsp.Config` (#38380)Barrett Ruth2026-03-21
| | | | | | Problem: `vim.lsp.enable()` skips buffers with `buftype` set, even when `filetype` matches. Solution: Add `buftypes` field to `vim.lsp.Config`.
* feat(lua): replace `buffer` with `buf` in vim.keymap.set/del #38360skewb1k2026-03-21
| | | | | | The `buffer` option remains functional but is now undocumented. Providing both will raise an error. Since providing `buf` was disallowed before, there is no code that will break due to using `buffer` alongside `buf`.
* docs: miscJustin M. Keyes2026-03-20
|
* feat(stdlib): vim.fs.ext() returns file extension #36997Yochem van Rosmalen2026-03-20
| | | | | | | | | | | | | | | | | Problem: Checking the extension of a file is done often, e.g. in Nvim's codebase for differentiating Lua and Vimscript files in the runtime. The current way to do this in Lua is (1) a Lua pattern match, which has pitfalls such as not considering filenames starting with a dot, or (2) fnamemodify() which is both hard to discover and hard to use / read if not very familiar with the possible modifiers. vim.fs.ext() returns the file extension including the leading dot of the extension. Similar to the "file extension" implementation of many other stdlibs (including fnamemodify(file, ":e")), a leading dot doesn't indicate the start of the extension. E.g.: the .git folder in a repository doesn't have the extension .git, but it simply has no extension, similar to a folder named git or any other filename without dot(s).
* feat(lsp): vim.lsp.get_configs() #37237Olivia Kinnear2026-03-19
| | | | | | | | | | Problem: No way to iterate configs. Users need to reach for `vim.lsp.config._configs`, an internal interface. Solution: Provide vim.lsp.get_configs(). Also indirectly improves :lsp enable/disable completion by discarding invalid configs from completion.
* docs: misc, terminalJustin M. Keyes2026-03-18
| | | | | | | | Close #38319 Close #38348 Co-authored-by: zeertzjq <zeertzjq@outlook.com> Co-authored-by: Barrett Ruth <br.barrettruth@gmail.com>
* refactor: integer functions, optimize asserts #34112Lewis Russell2026-03-12
| | | | | | | | | | | | refactor(lua): add integer coercion helpers Add vim._tointeger() and vim._ensure_integer(), including optional base support, and switch integer-only tonumber()/assert call sites in the Lua runtime to use them. This also cleans up related integer parsing in LSP, health, loader, URI, tohtml, and Treesitter code. supported by AI
* docs: use "ev" convention in event-handlersJustin M. Keyes2026-03-12
| | | | | | | | | Problem: In autocmd examples, using "args" as the event-object name is vague and may be confused with a user-command. Solution: Use "ev" as the conventional event-object name.
* docs: api, messages, lsp, trustJustin M. Keyes2026-03-11
| | | | | gen_vimdoc.lua: In prepare for the upcoming release, comment-out the "Experimental" warning for prerelease features.
* fix(lsp): only resolve LSP configs once (#38007)Andrew Braxton2026-02-23
| | | | | | | | | | | | | | | `lsp.config[]` resolves an LSP config the first time it is called, and returns the cached result on subsequent calls. The change in #37571 added an extra call to `lsp.config[]` which will resolve the config *before* the server is added to `_enabled_configs`, meaning the result is discarded. That means configs will be needlessly resolved again once `lsp_enable_callback` fires for the first time. That includes an additional `loadfile()` call which is relatively expensive and can have unexpected side effects. Avoid this by storing the result of the initial call to `lsp.config[]` in `_enabled_configs` so the config is not resolved a second time once `lsp_enable_callback` is called for the first time.
* refactor: defer_fn return type #37999Justin M. Keyes2026-02-23
|
* fix(lsp): add `vim.deprecate` call to `vim.lsp.with` (#37960)Maria Solano2026-02-18
|
* fix(lsp): wait to display exit message #37925Olivia Kinnear2026-02-18
|
* fix(lsp): wait for exit_timeout on quit #37597phanium2026-02-15
| | | | | | | | | | | | | | | | | | | Problem: When quitting Nvim, LSP servers will not be force-stopped, even if ClientConfig.exit_timeout is set to an integer. pkill emmylua_ls; VIMRUNTIME=runtime/ nvim --clean -u repro.lua repro.lua ; waitpid $(pgrep emmylua_ls) vim.lsp.config('foo', { cmd = { 'emmylua_ls' }, exit_timeout = 1000 }) vim.lsp.enable('foo') vim.defer_fn(vim.cmd.quit, 500) Solution: On VimExit, wait up to `exit_timeout:integer` milliseconds for servers to exit. Do this with an explicit `vim.wait()`, because the actual force-stop is deferred, and won't be attempted if Nvim exits before then. Co-authored-by: Justin M. Keyes <justinkz@gmail.com>
* docs: lsp, options, promptbufJustin M. Keyes2026-02-12
| | | | | | | | | | | | | Close #37630 Close #37682 Close #37762 Close #37785 Co-authored-by: Daniel Schmitt <d.schmitt@lansoftware.de> Co-authored-by: Duane Hilton <duane9@gmail.com> Co-authored-by: NeOzay <colpaert.benoit@gmail.com> Co-authored-by: Yi Ming <ofseed@foxmail.com> Co-authored-by: "Justin M. Keyes" <justinkz@gmail.com>
* refactor(lsp): drop once(), use _memoize() #37829Justin M. Keyes2026-02-12
|
* fix: lsp.enable() don't work correctly inside FileType event #37538phanium2026-01-27
| | | | | | | | | | | | | | | | | | | | Problem: Two cases lsp.enable() won't work in the first FileType event 1. lsp.enable luals inside FileType or ftplugin/lua.lua, then: ``` nvim a.lua ``` 2. lsp.enable luals inside FileType or ftplugin/lua.lua, then: ``` nvim -> :edit a.lua -> :mksession! | restart +qa! so Session.vim ``` Solution: Currently `v:vim_did_enter` is used to detected two cases: 1. "maunally enabled" (lsp.enable() or `:lsp enable`) 2. "inside FileType event" To detect 2. correctly we use did_filetype().