This allows the user to detach an active buffer from the language
client. If no clients remain attached to a buffer, the on_lines callback
is used to cancel nvim_buf_attach.
Previously, the `_str_utfindex_enc` and `_str_byteindex_enc` helper functions would return `nil` when `offset_encoding == "utf-8"` and `index == nil`. Clearly, this doesn't reflect the expected behavior of the functions they're wrapping which would return the length of the line in this case. This should fix behavior with servers that use UTF-8 `offset_encoding` when applying text edits, formatting a range, and doing range code actions (though this isn't tested currently).
Closes https://github.com/neovim/neovim/issues/16562https://github.com/neovim/neovim/issues/16249https://github.com/neovim/neovim/issues/16297
* buf_attach_client can be called on an unloaded buffer
* on_attach will prematurely fail, while the language server client
tracks this buffer as attached
* The language server client will track this buffer as attached despite
textDocument/didChange notifications not being sent to the server
* Instead, check if the buffer is loaded and return early, warning via
the lsp logger that buf_attach_client was called on an invalid buffer
The `prefix_source` function only evaluates the sources from the
diagnostics passed to it; however, because each namespace draws its own
virtual text, its diagnostics will never contain more than a single
source (by definition). This requires changing the semantics of what
"if_many" means from "multiple sources in a single 'batch' of
diagnostics" to "multiple sources of all diagnostics within a buffer".
Closes#16624
Fixes two issues with aligning the start position and end position to
codepoints when calculating the start and end range.
When aligning the start position:
* use aligned byte index to calculate character index rather than
the unadjusted byte
When aligning the end position:
* do not adjust the end byte if it falls on a UTF-8 codepoint
* align byte to the first byte of the next codepoint rather than the
last byte of the current codepoint
* compute character character end range on the aligned byte index
This commit also adds additional test coverage, including multibyte operations
that previously failed before this commit.
The on_exit handler provided to the client configuration is called after
the client's context is cleared (e.g. which buffers the client was
attached to). Calling the handler sooner allows these handlers to access
the client object and do their own cleanup with the full context.
Line number and column are required and much of the diagnostic API
assumes that these are both present. When one of the two is missing,
cryptic errors pop up in other parts of the diagnostic subsystem.
Instead, assert that diagnostics are well formed when they are entered
into the cache, which provides a clearer error.
When buffer is visible in two splits simultaneously, BufHidden event is
not triggered, causing the floating window to remain on screen after
switching to another buffer.
Remove BufHidden event from close_events defaults, and close the window
if we changed the buffer to something other than the buffer that spawned
the floating window or the floating window buffer itself.
Based on https://github.com/neovim/neovim/pull/14445
This extends `vim.treesitter.query.get_node_text` to return the text
that spans a node's range even if start_row ~= end_row.
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>
The overwhelming majority of use cases for `open_float` are to view
diagnostics from the current buffer in a floating window. Thus, most use
cases will just `0` or `nil` as the first argument, which makes the
argument effectively useless and wasteful.
In the cause of optimizing for the primary use case, make the `bufnr`
parameter an optional parameter in the options table. This still allows
using an alternative buffer for those that wish to do so, but makes the
"primary" use case much easier.
The old signature is preserved for backward compatibility, though it can
likely be fully deprecated at some point.
Closes https://github.com/neovim/neovim/issues/16492
Despite having logic for setting the maximum diagnostic line
number to at minimum 0, previously the conditional statement only
checked if lnum and end_lnum were greater than the line count.
Fix: also check if lnum and end_lnum are less than 0.
The examples are relevant and applicable for both Lua and Vimscript
configurations and the `vim.api.nvim_command` prefixes just add noise
that doesn't contribute to the example.
When the 'focusable' and 'focus_id' parameters are set,
`open_floating_preview` assumes that it should always move focus to an
existing floating window with the same 'focus_id'. However, there are
cases where we want to make a floating window focusable, but do not want
to focus it upon calling `open_floating_preview`. To distinguish these
cases, add a boolean parameter 'focus' that, when false, prevents
moving focus.
When `vim.diagnostic.set()` is called, the diagnostics passed to it are
added to the diagnostic cache. `set()` then calls `show()` and passes
those diagnostics along exactly as they were given to `set()`. However,
we sometimes want to do some kind of post-processing on diagnostics when
they come out of the cache, e.g. clamping line numbers. By forwarding
the diagnostics to `show()` verbatim, `set()` skips this post-processing
which can cause other bugs downstream.
Instead of passing the diagnostics directly, make the `show()` call from
within `set()` retrieve diagnostics from the cache. In general, all
diagnostics operations should follow the pattern of "producers put
things in the cache" and "consumers get things out of the cache" and
this change better adheres to that pattern.
This allows users to hook into diagnostic events with finer granularity
(e.g. per-buffer or file).
BREAKING CHANGE: DiagnosticsChanged and LspDiagnosticsChanged user
autocommands are removed.
Previously, the built-in language server client checked if the first
argument of cmd was executable via vim.fn.executable. This ignores PATH
injected via cmd_env. Instead, we now start the client via uv.spawn, and
handle the failure mode, reporting the error back to the user.
Co-authored-by: Mathias Fußenegger <mfussenegger@users.noreply.github.com>
Floating windows opened by `goto_next` and `goto_prev` should not be
focused when repeating the `goto_` function. The float can still be
focused by calling `open_float` with `scope = "cursor"`.
Reverts 5b0d8f85fd.
Diagnostic producers can send diagnostics for buffers that are not
loaded, for which we cannot retrieve the line count to clamp line
numbers. This means that some diagnostics in the quickfix list could be
line-clamped and others not. The quickfix list can already handle line
numbers past the end of the buffer (i.e. it *already* clamps line
numbers) so just use the "raw" diagnostic positions sent from the
producer.