Commit Graph

204 Commits

Author SHA1 Message Date
3b6084ddf4 fix: type fixes
Type fixes caught by emmylua
2025-06-06 15:36:48 +01:00
2b21c9c23f fix(diagnostic): ensure autocmd always is always sent diagnostics 2025-06-05 13:02:56 +01:00
533cc0ab35 fix(vim.diagnostic): improve typing
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.
2025-06-03 20:25:07 +01:00
9641ad9369 fix(diagnostics): diagnostic just after EOL is not highlighted #34085
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.
2025-06-03 07:22:36 -07:00
62ba6e8a76 fix: use nvim namespace convention #34010 2025-05-22 03:40:08 -07:00
2e0158650a fix(diagnostic): accept multiple namespace in open_float() (#34073) 2025-05-21 10:54:43 -07:00
19efabafc5 fix(diagnostics): fixed virtual_text cursormoved autocmd error (#34017) 2025-05-21 10:20:37 -05:00
dbe17da120 fix(diagnostic): deprecate float in vim.diagnostic.Opts.Jump (#34037) 2025-05-19 19:44:26 -07:00
4fae013a21 feat(diagnostic): add enabled filter (#33981) 2025-05-13 19:32:00 -07:00
2f24ae8de4 feat(diagnostic): add format option to setloclist/setqflist (#33977) 2025-05-12 20:50:37 -04:00
c681336e3c fix(diagnostic): accept multiple namespaces when setting loclist/qflist (#33982) 2025-05-12 20:13:26 -04:00
c65817774d feat(diagnostic): add on_jump callback option 2025-05-05 19:59:22 -07:00
d567f899ef fix(diagnostic): allow virtual_{lines,text} cursor exclusivity #33517
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.
2025-05-01 03:54:39 -07:00
71e133e5e6 docs(diagnostic): mention severity in Opts.VirtualLines (#33293)
Problem: `severity` field is recognized by
  `vim.diagnostic.Opts.VirtualLines`, but it is not explicitly
  documented.

Solution: document it.
2025-04-03 10:19:37 -05:00
9acb52c8f3 refactor(diagnostic)!: remove deprecated diagnostic APIs (#33072) 2025-03-26 13:56:23 -05:00
f1fcf653cb fix(diagnostic): clear virtual_lines autocmd only for valid buf #32979 2025-03-19 05:27:20 -07:00
xzb
17c25a66fc fix(diagnostic): virtual lines should scroll horizontally 2025-03-16 12:31:29 +01:00
c78728a384 fix(diagnostic): clear autocmd only for valid buf (#32861) 2025-03-12 09:30:05 -05:00
fb842dfc22 fix(diagnostic): virtual_lines diagnostic columns (#32703)
When multiple diagnostics appear on a single line, the virtual lines for
all diagnostics except the first were rendered with progressively fewer
columns.
2025-03-04 08:59:37 -06:00
0e8e4a07f5 fix(diagnostic): don't include diagnostic code when using custom formatter #32464 2025-02-16 12:13:29 -08:00
38a52caec0 feat(diagnostic): add current_line option for virtual_text handler 2025-02-05 15:27:09 +01:00
445ecca398 feat(diagnostic): format() can filter diagnostics by returning nil #32302 2025-02-03 00:54:31 -08:00
48e3ac60c6 perf(diagnostics): cache line diagnostics when current_line is set #32288
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.
2025-02-02 03:40:43 -08:00
5bc948c050 fix(diagnostic): improve current_line refresh logic #32275
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.
2025-02-02 01:56:01 -08:00
6aa42e8f92 fix: resolve all remaining LuaLS diagnostics 2025-01-27 16:37:50 +00:00
1759b7844a feat(diagnostic): virtual_lines #31959 2025-01-26 15:33:03 -08:00
931ee5591f feat(extmarks): virtual text can be right-aligned, truncated #31921
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.
2025-01-24 19:57:45 -08:00
51ccd12b3d fix(diagnostic)!: make virtual text handler opt-in (#32079)
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.
2025-01-18 07:43:21 -06:00
09e01437c9 refactor: use nvim.foo.bar format for autocommand groups 2025-01-14 21:25:25 -08:00
850084b519 refactor: use nvim.foo.bar format for namespaces 2025-01-14 19:55:29 -08:00
a119aae4d3 feat(diagnostic)!: filter diagnostics by severity before passing to handlers (#30070)
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.
2025-01-11 12:54:43 -06:00
4cbeb6fa3c fix(diagnostic): silence :chistory #31701
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.
2024-12-23 11:57:15 -08:00
6c975515c5 fix(diagnostic): vim.diagnostic.setqflist() opens loclist on first call #31585
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.
2024-12-16 06:38:57 -08:00
de794f2d24 fix(diagnostic): broken variable reference #31557 2024-12-12 02:41:57 -08:00
5eda7aafe9 fix(diagnostic): setqflist() is stuck after vim.lsp.buf.document_symbol #31553
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
2024-12-11 17:32:07 -08:00
21961967ff feat(diagnostic): update quickfix list by title #31486
Previously, there was a singleton diagnostics quickfix list. Now there's
effectively one per title (up to vim's internal limit on quickfix
lists).

Suggested by mfussenegger https://github.com/neovim/neovim/pull/30868#pullrequestreview-2385761374.
2024-12-11 17:29:54 -08:00
668d2569b4 refactor: add vim._resolve_bufnr 2024-12-07 16:58:40 +00:00
fd902b1cb2 fix(diagnostic): only store quickfix id when creating a new one #31466
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!
2024-12-05 13:59:33 -08:00
7579af3c51 feat(diagnostic): vim.diagnostic.setqflist improvements #30868
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.
2024-12-04 07:49:57 -08:00
99e7323aa3 feat(diagnostic): inherit parent 'path' option in open_float (#31273)
Diagnostics sometimes contain stack traces, it's useful being able to
use `CTRL-W F` on them to open related files from within the diagnostic
window.
2024-11-25 17:11:22 +01:00
1d4ba8c1ed fix: another round of type annotation fixes 2024-10-31 11:55:23 +00:00
a9e725b26e feat(diagnostics)!: sort underline severity_sort (#30898)
feat(diagnostics)!: sort underline with severity_sort

BREAKING CHANGE: underline will be applied with a higher value than `vim.hl.priorities.diagnostics`
2024-10-27 11:36:39 -05:00
3572319b4c feat(vim.validate): improve fast form and deprecate spec form
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.
2024-10-21 11:32:06 +01:00
18b43c331d refactor: rename vim.highlight => vim.hl
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).
2024-10-21 00:54:43 +02:00
3f3e4837d5 perf(validate): use lighter version
- Also fix `vim.validate()` for PUC Lua when showing errors for values
  that aren't string or number.
2024-10-17 16:53:52 +01:00
921dc22fc0 fix(diagnostic): correct severity type on setqflist, setloclist (#30506)
fix(diagnostic): correct severity type on setqflist, setloclist
2024-09-25 10:10:50 -05:00
d918ebe3b8 fix(diagnostic): fix backwards compatibility for goto_next and goto_prev (#29593) 2024-07-09 14:08:12 -05:00
4b3be56a03 fix(diagnostic): make docs agree with code (#29561)
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.
2024-07-04 12:15:35 -05:00
aa6b9c677d refactor: use vim._with where possible
This mostly means replacing `nvim_buf_call` and `nvim_win_call` with
`vim._with`.
2024-06-28 19:58:31 +02:00
e5e81262af fix(diagnostics): don't apply extmarks to invalid lines #29321
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
2024-06-19 09:28:44 -07:00