Problem:
`vim.diagnostic.set()` doesn't actually accept a list of
`vim.Diagnostic` as internally `vim.diagnostic.set()` normalizes the
diagnostics and this normalization is assumed throughout the module.
Solution:
- Add a new type `vim.Diagnostic.Set` which is the input to `vim.diagnostic.set()`
- `col` is now an optional field and defaults to `0` to be consistent
with `vim.diagnostic.match()`.
- Change `table.insert(t, x)` to `table[#table + 1] = x` for improved
type checking.
Fixes#34013
Problem:
when diagnostic is set right after EOL, underline handler looks
inconsistent compared to other handlers, visually underline is shown
starting from the next line. On top of that it's also inconsistent with
open_float and jump.
Solution:
clamp starting column position in underline handler to be right before
EOL to make it visible and consistent with other handlers, open_float
and jump.
Problem:
virtual_text diagnostics are great when skimming a file, and
virtual_lines are great when "zooming in" on a particular problem.
Having both enabled results in duplicate diagnostics on-screen.
Solution:
This PR expands the behavior of `current_line` for virtual_text and
virtual_lines by making `virtual_text.current_line = false` distinct
from `nil`. If you set:
vim.diagnostic.config({
virtual_text = { current_line = false },
virtual_lines = { current_line = true },
})
With this configuration, virtual_text will be used to display
diagnostics until the cursor reaches the same line, at which point they
will be hidden and virtual_lines will take its place.
When multiple diagnostics appear on a single line, the virtual lines for
all diagnostics except the first were rendered with progressively fewer
columns.
Compute the diagnostics per line when `show` is called, allowing for
O(1) access for the diagnostics to display when the cursor line or the
list of diagnostics haven't changed.
Problem:
The current implementation uses a global augroup for virtual lines in
diagnostics, which can lead to conflicts and unintended behavior when
multiple namespaces/buffers are involved.
Solution:
Refactor the code to use a namespace-specific augroup for virtual lines.
This ensures that each namespace has its own augroup.
Scope the clear commands to only the relevant buffer.
Problem: Right aligned virtual text can cover up buffer text if virtual
text is too long
Solution: An additional option for `virt_text_pos` called
`eol_right_align` has been added to truncate virtual text if it would
have otherwise covered up buffer text. This ensures the virtual text
extends no further left than EOL.
Making this opt-out (on by default) was the wrong choice from the
beginning. It is too visually noisy to be enabled by default.
BREAKING CHANGE: Users must opt-in to the diagnostic virtual text
handler by adding
vim.diagnostic.config({ virtual_text = true })
to their config.
BREAKING CHANGE: This changes the list of diagnostics that are passed to
a diagnostic handler. If a handler is already filtering by severity
itself then this won't break anything, since the handler's filtering
will become a no-op. But handlers which depend on receiving the full
list of diagnostics may break.
Note that diagnostics are only filtered if the handler's configuration
has the `severity` option set. If `severity` is not set, the handler
still receives the full list of diagnostics.
vim.diagnostic.set_list() uses chistory to restore the actively selected
entry whenever necessary. This however also results in it displaying
some output in the message bar, but this output isn't useful (and can
even be distracting) when opening the quickfix window. This fixes this
by silencing the chistory command.
Problem:
Regression from de794f2d24: `vim.diagnostic.setqflist{open=true}` attempts to
open the location list instead of the diagnostics quickfix list if it didn't
exist before. This is because we are using `qf_id` to decide which to open, but
`qf_id=nil` when there is no existing diagnostics quickfix list with a given
title ("Diagnostics" by default).
Solution:
- Revert to using `loclist` to decide which to open.
- Add tests.
Previously, when updating the quickfix diagnostics list, we'd update it,
and then open the quickfix buffer, but there was no guarantee that the
quickfix buffer would be displaying the quickfix diagnostics list (it
could very possibly be displaying some other quickfix list!).
This fixes things so we first select the quickfix list before opening the
quickfix buffer. If `open` is not specified, the behavior is the same as
before: we update the diagnostics quickfix list, but do not navigate to
it.
fixes https://github.com/neovim/neovim/issues/31540
The old code would always update `_qf_id` with the current quickfix,
even if you're currently looking at a completely different,
non-diagnostics quickfix list. This completely defeats the intent of
<https://github.com/neovim/neovim/pull/30868>, whoops!
1. Use the new "u" action to update the quickfix list so we don't lose
our position in the quickfix list when updating it.
2. Rather than creating a new quickfix list each time, update the
exiting one if we've already created one.
feat(diagnostics)!: sort underline with severity_sort
BREAKING CHANGE: underline will be applied with a higher value than `vim.hl.priorities.diagnostics`
Problem:
`vim.validate()` takes two forms when it only needs one.
Solution:
- Teach the fast form all the features of the spec form.
- Deprecate the spec form.
- General optimizations for both forms.
- Add a `message` argument which can be used alongside or in place
of the `optional` argument.
Problem:
- `vim.highlight` module does not follow `:help dev-name-common`, which
documents the name for "highlight" as "hl".
- Shorter names are usually preferred.
Solution:
Rename `vim.highlight` to `vim.hl`.
This is not a breaking change until 2.0 (or maybe never).
Problem: the code and docs for vim.diagnostic.JumpOpts.float send mixed
signals about what the default should be. When the option is first set,
in the global_diagnostic_options table, the comment clearly says that
the default is false. Later in the code, in goto_diagnostic, there's
a line that sets the default to true if no default is present. Finally,
the docs say that the default is true.
Solution: Change the docs to reflect the new default of false and fix
the goto_diagnostic function.
Problem:
If there are errors in the last line of a buffer, something like `Gdk` or
`G2k3J` will produce an error (at least with `lua_ls`):
Error executing vim.schedule lua callback:
.../neovim/share/nvim/runtime/lua/vim/diagnostic.lua:1446: Invalid 'line': out of range
Solution:
Only set extmarks if the target buffer line still exists