1444 Commits

Author SHA1 Message Date
Oleh Volynets
ef130902cf fix(lsp): clear push diagnostics on detach #40634
Problem: when an LS client detaches from the buffer, only pull diagnostics
are cleared via capability framework. Push diagnostics remain stuck even
when client stops/restarts.

Solution: clear push diagnostics on client detach.

ref #33864
2026-07-08 12:00:21 -04:00
Caleb White
653f2092ce fix(lsp): refresh document-pull buffers on workspace/diagnostic/refresh #40623
When a server supports both document and workspace pull diagnostics,
`on_refresh` only dispatched a `workspace/diagnostic` request.  The
workspace response handler skips buffers with `pull_kind == "document"`
(i.e. all buffers opened by the user), so their diagnostics went stale
until the next `didChange` or `didOpen` event.

Change `on_refresh` to always refresh document-pull buffers via
`textDocument/diagnostic`, regardless of whether the server also
supports workspace diagnostics.  This ensures that opened buffers
see updated diagnostics (e.g. after a save triggers an external
tool like PHPStan) without requiring the user to re-enter insert
mode.
2026-07-08 07:26:22 -04:00
jdrouhard
6a6431cb99 refactor(lsp): use LspNotify for codelens #40604
Problem: The codelens LSP module was using its own raw buffer events and
its own debounce mechanism for refreshing code lens in attached buffers.

Solution: Switch the module to using the LspNotify autocmd events.
LspNotify fires just after document versions are synced with the server
and provides a built in debounce mechanism for changes.

Additionally, this fixes some bugs with the previous implementation:

1. The workspace/codeLens/refresh handler  re-requested codelens for all
   buffers but when the response came back, it forced an extra redraw
   after clearing the work the handler had just done.
2. Document synchronization was reworked to be more resilient to
   multiple clients providing codelens for a single buffer. The latest
   document version is now separately tracked per client (and per
   client's lenses per row) instead of for the buffer as a whole. This
   allows the on_win() function to properly redraw all codelens even
   when different clients' responses for a particular document version
   come back at different times.
2026-07-07 12:23:59 -04:00
jdrouhard
1f18ea1cf7 feat(lsp): convert inlay_hint to capability framework #40569
Problem:
Inlay hints used separate global and per-buffer bufstates tables and
bespoke global autocmds for managing the inlay hint state across buffers
and clients, duplicating the lifecycle logic already provided by the
Capability framework. This caused inconsistencies in how client state
was handled and inlay hint state lifecycle was managed compared to other
LSP features.

Solution:
Replace the ad-hoc bufstate tracking and global autocmds in
vim.lsp.inlay_hint with a proper InlayHint subclass of Capability.

This also refactors the way inlay hint state is managed and fixes bugs I
found while doing this:

1. For each line with inlay hints, the list of the hints along with
   whether they have been applied is stored in a current result on the
   client state. This allows the on_win decorator to clear all inlay
   hints for an old document version once, and then re-add the new
   version's hints line-by-line as they are drawn to the screen,
   modeling the semantic tokens module.
2. It fixes problems with mixing results from multiple clients attached
   to the buffer by fully moving each client's state to its own table.
   Previously, only the most recent document version used to populate a
   line's inlay hints was stored, but there was no distinction for which
   client the hints may have come from. (Fixes #36318)
3. It fixes the workspace/inlayHint/refresh server->client notification
   behavior. Previously it would only re-request inlay hints for buffers
   currently displayed in a window but would not invalidate them in
   non-displayed buffers (or provide any mechanism for those buffers to
   re-request at a later time). Model semantic token module here again
   by invalidating all buffers, and adding a BufWinEnter autocmd to
   refresh hints.
4. Add a mechanism to cancel in-flight requests if a new request for a
   newer document version is made before the last one returned
5. Handle stale results by simply dropping them.
2026-07-05 12:47:30 -04:00
Justin M. Keyes
a0fd59352a Merge #40520 nvim_win_resize 2026-07-05 12:06:13 -04:00
XiaowenHu96
ce718e31f4 feat(api): add nvim_win_resize()
Ref #6645

Problem:
When a window is resized it takes space from the window right/below first,
and only falls back to the window left/above when there is no more room.
Sometimes a user wants the space to come from a specific direction.

Solution:
Add nvim_win_resize(win, width, height, {anchor}) which resizes a window
with a choosable anchor edge, letting a window grow leftwards or upwards
by taking space from the window to the left or above first. The default
anchor reproduces nvim_win_set_width()/nvim_win_set_height().
2026-07-05 21:47:34 +08:00
Barrett Ruth
81e01a80b9 fix(lsp): support -1 column in format range #40570
Problem:
`vim.lsp.buf.format()` accepts ranges using nvim indexing, where an
end column of -1 means end of line. LSP ranges cannot use that,
which is confusing for things like range formatting.

Solution:
Resolve -1 end columns to the line length before converting the range to
LSP positions.
2026-07-05 06:14:55 -04:00
jdrouhard
f0559997dd fix(lsp): semantic tokens reset_timer() usage #40554
Problem: reset_timer() was being called without checking for whether the
client state for the client_id still existed. debounce_request() starts
a timer that defers a call to send_request() which then calls
reset_timer(). If the timer fires after the client_state is erased, then
the deferred function attempts to dereference the timer on a nil client
state.

Solution: Change reset_timer to take a state directly so it can't be nil
and move the reset_timer() call inside a guard that ensures state
exists. Additionally, reset a client's timer when the client detaches so
it doesn't become dangling.
2026-07-04 11:22:34 -04:00
jdrouhard
29db6ce84c fix(lsp): use LspNotify for document_color #40571
Problem: The document_color lsp module was already using the capability
framework but was still using raw buffer events to handle requests and
reloading. This means that every keystroke was sending a document_color
request to the server since there was no debounce in the raw handlers.

Solution: Switch to using LspNotify autocmd events. LspNotify fires just
after new document versions are synced with the server and provides a
built in debounce mechanism for changes. It also provides the signal for
when the current state should be cleared (didClose). The detach part is
already handled by the capability framework.

Fixes #39785
2026-07-04 09:29:05 -04:00
Barrett Ruth
6cbc5ea13d docs(lsp): document rpc Client request/notify as fields #40573
Problem:
`request()` and `notify()` are methods of the object returned by
`vim.lsp.rpc.start()`/`connect()`, but were rendered with module-level
helptags (`vim.lsp.rpc.request()`, `vim.lsp.rpc.notify()`) (erroneously
implying module functions that do not exist).

Solution:
Mark the wrappers `@private` and describe them on `vim.lsp.rpc.Client` instead.
2026-07-04 09:24:25 -04:00
nikolightsaber
3f8be434e1 docs: pos argument in vim.lsp.ListOpts should be optional #40550
Problem: the pos argument in ListOps for lsp is an optional parameter,
but the lua_ls typing system doesn't reflect that

Solution: let pos be optional

Co-authored-by: nikolightsaber <nikolightsaber@gmail.com>
2026-07-02 15:25:44 -04:00
jdrouhard
b19962e827 fix(lsp): request semantic tokens in BufWinEnter (#40510)
Problem: A previous refactor removed the BufWinEnter autocmd that
initiated a token request. When an LSP server sends a refresh
notification, then buffers that aren't shown in any window lost their
only trigger to request new tokens.

Solution: Add the BufWinEnter autocmd back which simply requests tokens
for all clients attached to the buffer.
2026-06-30 14:35:07 -07:00
jdrouhard
cd8f609520 fix(lsp): process semantic tokens LspNotify callback only when attached #40450
Problem: LspNotify will fire for any attached client. If there's at
least two clients where one has semantic tokens enabled and one that
doesn't, the disabled one will get the LspNotify requests but won't have
a client state.

Solution: Only process LspNotify autocmds if there's a client state to
act on.

Fixes #40448
2026-06-27 10:46:22 -04:00
jdrouhard
150088551e fix(lsp): define autocmds for capabilities once per buffer #40435
fix(lsp): define autocmds for capabilities in new(), not on_attach()

Problem: Defining autocmds in on_attach() caused issues when multiple
clients provide the same capability for a buffer. Each attaching client
would "replace" the previously defined one since they are all identical.
Then the first one to detach clears them out and any remaining attached
clients would no longer trigger the autocmd for the capability. Further,
the semantic tokens module itself didn't quite work with multiple
clients since any LspNotify (from any client) would send a token request
to all attached clients with no differentiation and the debounce timer
was shared across all clients.

Solution: Always define the buffer-local autocmds in the capability's
`new()` function, and don't mess with the autocmds in on_attach or
on_detach. The capability framework itself will clear the autocmds when
the last client detaches. Also, refactor a bit of the semantic tokens
module so that the various methods take a specific client_id to perform
the work on, and split out timers so each client has its own.
2026-06-26 15:19:42 -04:00
jdrouhard
c98c93fcf8 refactor(lsp): convert diagnostics to capability framework #40433
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
2026-06-26 14:41:26 -04:00
Barrett Ruth
85718f9874 fix(lsp): use root_dir as cmd CWD #40331
Problem:
cmd given as string[] always starts using Nvim's CWD, which is arbitrary.

Solution:
If cmd_cwd is not given, use root_dir as CWD.

BREAKING CHANGE: LSP commands given as string arrays now use `root_dir` as
the process working directory when `cmd_cwd` is unset.

Co-authored-by: Justin M. Keyes <justinkz@gmail.com>
2026-06-26 14:12:33 -04:00
Barrett Ruth
4d9e5acfb5 fix(lsp): skip invalid file watcher globs #40376 #40396
Some servers register `workspace/didChangeWatchedFiles` watchers for URI
schemes that cannot be watched locally. Skipping the unsupported glob
and keep the rest of the registration batch active.
2026-06-25 03:44:33 -04:00
jdrouhard
3c924d13fe fix(lsp): fire LspNotify didChange autocmds after undo/redo #40404
Problem: LspNotify autocmds were not being triggered for didChange
requests when being used during undo/redo (and possibly other) actions.
autocmds are blocked when calling on_lines() callbacks while doing the
undo/redo action.

Solution: Defer firing the autocmd until after the action is complete.
This is closer to what existed before, but now there's a check in the
deferred function to only fire the autocmd if the client is still
active and the buffer is still attached, if applicable.
2026-06-25 03:37:39 -04:00
jdrouhard
54188fa242 fix(lsp): make LspNotify more robust #40332
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.
2026-06-20 12:46:58 -04:00
jdrouhard
6bc6461eac fix(lsp): multiline semantic token processing #40339
Problem: When multiline semantic token support was introduced, the loop
that finds the end line for a particular token didn't sanitize the token
length sent back by the LSP server. If the server returned an overflowed
length (near uint32 max), neovim would burn cpu and loop for an
extremely long time while trying to find the "end line" represented by
the massively large token, causing neovim to seemingly hang.

Solution: Stop looping once the calculated end_line reaches the actual
last line of the buffer.

Fixes #36257
2026-06-20 10:51:21 -04:00
jdrouhard
b5181300ae refactor(lsp): refactor linked_editing_range to use vim.lsp._capability (#40327)
Problem: linked_editing_range was still doing most of the capability
boilerplate itself.

Solution: refactor it to make use of the common Capability framework for
handling enabling, disabling, etc.
2026-06-19 10:42:14 -07:00
Gregory Anders
ed267268b8 fix(lsp): allow specifying bufnr + client_id filter when enabling capabilities #37690
Today there is a constraint that these arguments to the enable filter be
mutually exclusive, but I do not know why such a constraint exists (it
is perfectly reasonable to want to enable a capabilility for just one
buffer and just one client).
2026-06-17 07:26:18 -04:00
Steve Huff
942778c758 fix(lsp): catch another nil buffer state #40285 2026-06-16 16:20:17 -04:00
glepnir
02b7415324 fix(lsp): requery empty isIncomplete completion lists #40100
Problem:
an empty `{ isIncomplete = true, items = {} }` ends completion
instead of requerying.

Solution:
keep isIncomplete on empty lists and retrigger on keypress while incomplete.
Reset on <C-e> so it doesn't immediately re-query.
2026-06-15 18:29:27 -04:00
jdrouhard
859790e244 feat(lsp): clean up semantic token initialization and debounce #40254
Problem: The refactor to use Capability left around some cruft and
semi-broken configuration for debounce.

Solution: Clean up now-unnecessary helper methods and simplify
deprecated ones to pass through to the non-deprecated ones. `debounce`
now defaults to 200 for all buffers but is overridable via the
deprecated start() method, which continues to take the max value
specified for any client attached to the buffer.

If we wish to expose changing the debounce in a non-deprecated way, we
will need to consider a "configuration" function, or even a bespoke
method to set the debounce time on the main metaclass (or provide
options to override for a particular buffer). General configuration of
specific LSP features is an as-of-yet unsolved problem.
2026-06-15 07:19:09 -04:00
Justin M. Keyes
6f3446c970 Merge #40087 from ofseed/pos-util-follow-up
feat(pos): create a cursor position by using the current of a window
2026-06-14 12:42:52 -04:00
jdrouhard
3d6393540e feat(lsp): use LspNotify for semantic tokens #40224
Problem: The semantic token module is using its own debounce timer for
the buffer on_lines event. If its internal debounce is shorter than the
changetracking module's debounce, it's possible for semantic token
requests to fire for changed buffers before the textDocument/didChange
notification is sent to the server.

Solution: Trigger semantic token requests from the LspNotify autocmd
when the method is the didChange or didOpen notifications, which
enforces a strict happens-before relationship for the sync change
notification followed by a semantic token request.

Note: There is still an internal debounce mechanism in the semantic
token module to handle other debouncing needs specific to its
functionality, such as debouncing server refresh notifications and
handling WinScrolled events when using range requests.
2026-06-14 11:10:59 -04:00
Jay Madden
3ed78daf83 perf(lsp): overscan semantic_token range requests #40036
Problem:
Flickering may occur when paging up/down in big files, as ranges for semantic
tokens are requested. This happens with LSP servers like gopls which return
"/full" semantic tokens if the file is too big, where we fall back to
viewport-range token retrievals.

Solution:
Broaden the requested ranges to one viewport of "overscan" on each side plus
some padding if possible:

    (viewport_topline - viewport_height)..(viewport_botline + viewport_height)
2026-06-11 17:16:54 -04:00
Aaron Tinio
d42f7ee9dc fix(lsp): trailing blank line when edit inserts past end of buffer #40133
Problem:
A text edit positioned entirely past the last buffer line, with
newText ending in a newline, leaves a stray blank line: the
past-the-end path appends the trailing empty fragment produced by
vim.split() and does not set has_eol_text_edit, so the end-of-buffer
cleanup is skipped. Formatting servers emit such edits whenever
formatting moves text to the end of a document.

Regression from ec94014cd1 (#20137), which split the past-the-end
fast path off the clamp path that sets the flag.

Solution:
Set has_eol_text_edit in the past-the-end path, like the adjacent
path that clamps end_row.
2026-06-10 23:25:13 +00:00
Tristan Knight
16549f2f40 fix(lsp): refresh codelens despite pending debounce #40154
Problem:
When a server sends workspace/codeLens/refresh while an automatic codelens
request is already scheduled, Nvim ignores the server refresh. This can leave
rendered codelens text stale until another buffer edit triggers a new request.

Solution:
Cancel the pending automatic request and send the server-requested refresh
immediately. This preserves request coalescing while giving explicit server
refreshes priority.
2026-06-10 19:18:48 -04:00
Tristan Knight
2899e350ff docs(lsp): bump protocol/meta to 3.18 #37273
fixes glob spec regression related to "zero or more" vs "one or more" for `*`
ref: https://github.com/microsoft/language-server-protocol/issues/2217
2026-06-10 17:02:12 -04:00
Yi Ming
2bd13177b8 feat(pos): create a cursor position by using the current of a window
Problem:
`vim.pos.cursor(vim.api.nvim_get_current_buf(win), vim.api.nvim_win_get_cursor(win))`
is too verbose to create a cursor position of a window,
but it is a common use case.

Solution:
Overload `vim.pos.cursor()`, so that it accepts `win` as an argument when `pos` is omitted.
2026-06-08 19:52:51 +08:00
Yi Ming
fecc151d03 fix(lsp): always respond to requests, even on handler error #40076
Problem:
We perform validations after the request handler is called.
When these validations fail, `error()` and `assert()` will prevent the
subsequent code from running, meaning the server will never receive a response.

Solution:
Always respond to requests.
2026-06-04 07:02:19 -04:00
Justin M. Keyes
cbadc4f164 docs: misc, lsp
Problem:
This doc on `vim.lsp.completion.get()`:

    --- Used by the default LSP |omnicompletion| provider |vim.lsp.omnifunc()|, thus |i_CTRL-X_CTRL-O|
    --- invokes this in LSP-enabled buffers. Use CTRL-Y to select an item from the completion menu.
    --- |complete_CTRL-Y|

...makes two wrong claims:

1. "Used by the default LSP omnicompletion provider vim.lsp.omnifunc()"
    - `_omnifunc` does not call `M.get()`, it calls the internal `trigger()` directly.
2. "thus |i_CTRL-X_CTRL-O| invokes this in LSP-enabled buffers"
    - The two paths use different client sets:
        - `M.get()` reads `buf_handles[bufnr].clients` (clients
          explicitly registered via `vim.lsp.completion.enable(true, ...)`).
        - `_omnifunc` reads `lsp.get_clients({method='textDocument/completion'})` (every
          completion client, regardless of `enable()`).

Solution:
Update docs.

Co-authored-by: Koichi Shiraishi <zchee.io@gmail.com>
Co-authored-by: y9san9 / Alex Sokol <y9san9@gmail.com>
Co-authored-by: adv0r <>
2026-06-03 12:27:30 +02:00
Yi Ming
cf9ad39267 fix(lsp): handle requests with null id #40073
Problem:
PR #38340 prevented messages we receive with id:null from being
incorrectly classified as notifications, but caused us to ignore all
messages with id:null, including requests.

Solution:
Handle requests with id:null. When we receive a request, we only need to
respond based on the `method` and `param`.

(The original so-called `notification_received` in the test was actually
semantically `request_or_notification_received`.)
2026-06-02 17:39:56 -04:00
Justin M. Keyes
7f233449f1 Merge #40083 from ofseed/pos-get-lines-improve
fix(pos): various improvements on `pos._util.get_lines()`
2026-06-02 09:56:49 -04:00
Yi Ming
a7408beae3 refactor(net): parameterize transport logging #40022 2026-06-02 08:41:36 -04:00
Yi Ming
241a725e17 fix(pos): get_lines() return empty table when file opening fails
Problem:
`get_lines()` may returns empty table when file opening fails,
so every existing caller use `get_line() or ''` to avoid nil result.

This also does not match the annotated return type of `get_line()`,
which is `string` instead of `string?`.

Solution:
Make `get_line()` return empty string when file opening fails.
2026-06-02 18:17:03 +08:00
Justin M. Keyes
88f3f0eeec fix(health): sort "Active Features" by name 2026-05-30 12:57:24 +02:00
Yi Ming
5d85669a33 refactor: rename vim.transport to vim.net.transport #40021 2026-05-28 10:37:45 -04:00
Puneet Dixit
5acb2a1d33 docs(lsp): document on_list deduplication #39941
Problem:
Deduplicating LSP locations in the default handler changes list behavior for every user, while some configurations may intentionally return matching locations from multiple clients.

Solution:
Document how users can deduplicate locations in an on_list handler with vim.list.unique().

Co-authored-by: Deepak kudi <deepakkudi23@adsl-172-10-9-116.dsl.sndg02.sbcglobal.net>
Co-authored-by: Puneet Dixit <236133619+puneetdixit200@users.noreply.github.com>
2026-05-27 10:21:45 -04:00
luukvbaal
cad5a4cf5c fix(lsp): unwanted redraw for buffer not in window #40002
Problem:  Redrawing when a loaded buffer is not shown in any window on
          the current tabpage.
Solution: Check that buffer is shown in a (normal) window before redrawing.
2026-05-27 09:27:25 -04:00
acehinnnqru
a9d7cbd722 fix(lsp): calc correct screen_width when opts.relative == 'editor' (#39977) 2026-05-24 15:00:53 -07:00
Yi Ming
680ab13951 refactor(lsp): avoid using coroutine when parsing frames 2026-05-22 18:20:55 +08:00
Yi Ming
0e81835fae refactor(lsp): message stream abstraction for message framing 2026-05-22 18:20:51 +08:00
Yi Ming
929e644a5a refactor(lsp): move vim.lsp._transport to vim.net._transport 2026-05-22 18:19:19 +08:00
Justin M. Keyes
b576807410 Merge #39939 from marcuscaisey/lsp-completion-details 2026-05-22 04:39:55 -04:00
Maria Solano
71c72c3409 fix(lsp): validate that workspace_edit isn't nil (#39947) 2026-05-21 19:00:02 -07:00
Marcus Caisey
2845f95171 fix(lsp): advertise that CompletionItem.detail can be resolved (#39934)
Problem:
We can resolve the `CompletionItem.detail` field but don't advertise
this capability.

Solution:
Add `detail` to
`textDocument.completion.completionItem.resolveSupport.properties`.
2026-05-21 13:57:53 -07:00
Marcus Caisey
c75365d22a refactor(lsp): centralise complete item info generation logic
Problem:
The logic for generating the complete item `info` is spread across
`_lsp_to_complete_items`, the `CompleteChanged` event handler, and
`CompletionResolver:request`. This has previously caused the `info`
shown for resolved (via `completionItem/resolve`) and unresolved items
to differ.

Solution:
Centralise the logic in a new `complete_item_info` function which is now
solely responsible for determining:
1. The `info` to show.
2. The markup kind of the `info`.
3. Whether the `info` is complete.

This simplifies the interaction between the 3 functions mentioned in the
problem:
- `_lsp_to_complete_items` calls `complete_item_info` and passes along
  the markup kind and whether the item needs resolving via the complete
  item's `user_data`.
- The `CompleteChanged` consumes the markup kind and whether the
  item needs resolving from the complete item's `user_data`.
- `CompletionResolver:request`, like `_lsp_to_complete_items` calls
  `complete_item_info` again and updates the current `info` if it's
  changed.
2026-05-21 18:22:13 +01:00