aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/diagnostic.lua
Commit message (Collapse)AuthorAge
...
* fix(diagnostic): assert that diagnostics have line number and column (#16683)Gregory Anders2021-12-16
| | | | | | | 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.
* fix(diagnostic): set effective buffer number in autocmd (again) (#16589)Gregory Anders2021-12-08
| | | Follow up to #16474.
* refactor(diagnostic): remove bufnr parameter from open_float (#16579)Gregory Anders2021-12-08
| | | | | | | | | | | | | | 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.
* refactor: format diagnostic.lua (#16540)Gregory Anders2021-12-05
|
* fix(diagnostic): escape special chars in file names (#16527)Matthew Toohey2021-12-05
| | | | Co-authored-by: zeertzjq <zeertzjq@outlook.com> Co-authored-by: Gregory Anders <greg@gpanders.com>
* feat(lsp,diagnostic): open folds in jump-related functions (#16520)Dmytro Meleshko2021-12-04
|
* fix(diagnostic): clamp diagnostics on negative line numbers (#16496)Michael Lingelbach2021-12-02
| | | | | | | | | 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.
* fix(diagnostic): set effective buffer number for DiagnosticChanged autocmd ↵Gregory Anders2021-12-01
| | | | | | (#16474) This enables use of <abuf> in autocommand handlers for DiagnosticChanged.
* feat(lsp): add 'focus' option to open_floating_preview (#16465)Gregory Anders2021-11-29
| | | | | | | | | 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.
* feat(diagnostic): use `scope = 'line'` by default for `open_float()` (#16456)cbarrete2021-11-28
| | | | | Closes #16453 Co-authored-by: Cédric Barreteau <cbarrete@users.noreply.github.com>
* fix(diagnostic): make set() go through cache when calling show()Gregory Anders2021-11-27
| | | | | | | | | | | | | | | | 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.
* chore: fix typos (#16361)dundargoc2021-11-27
| | | | | | | | | | | | | | | | | | | | | | | | | | Co-authored-by: Brede Yabo Sherling Kristensen <bredeyabo@hotmail.com> Co-authored-by: zeertzjq <zeertzjq@outlook.com> Co-authored-by: István Donkó <istvan.donko@gmail.com> Co-authored-by: Julian Berman <Julian@GrayVines.com> Co-authored-by: bryant <bryant@users.noreply.github.com> Co-authored-by: Michael Lingelbach <m.j.lbach@gmail.com> Co-authored-by: nlueb <9465658+nlueb@users.noreply.github.com> Co-authored-by: Leonhard Saam <leonhard.saam@yahoo.com> Co-authored-by: Jesse Wertheim <jaawerth@gmail.com> Co-authored-by: dm1try <me@dmitry.it> Co-authored-by: Jakub Łuczyński <doubleloop@o2.pl> Co-authored-by: Louis Lebrault <louis.lebrault@gmail.com> Co-authored-by: Brede Yabo Sherling Kristensen <bredeyabo@hotmail.com> Co-authored-by: zeertzjq <zeertzjq@outlook.com> Co-authored-by: István Donkó <istvan.donko@gmail.com> Co-authored-by: Julian Berman <Julian@GrayVines.com> Co-authored-by: bryant <bryant@users.noreply.github.com> Co-authored-by: Michael Lingelbach <m.j.lbach@gmail.com> Co-authored-by: nlueb <9465658+nlueb@users.noreply.github.com> Co-authored-by: Leonhard Saam <leonhard.saam@yahoo.com> Co-authored-by: Jesse Wertheim <jaawerth@gmail.com> Co-authored-by: dm1try <me@dmitry.it> Co-authored-by: Jakub Łuczyński <doubleloop@o2.pl> Co-authored-by: Louis Lebrault <louis.lebrault@gmail.com>
* feat(diagnostic)!: make DiagnosticChanged a first class autocmd (#16098)Gregory Anders2021-11-25
| | | | | | | 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.
* Merge pull request #16434 from gpanders/diagnostic-clampageMichael Lingelbach2021-11-25
|\ | | | | fix(diagnostic): line clamping fixes
| * fix(diagnostic): don't clamp line numbers in setqflistGregory Anders2021-11-24
| | | | | | | | | | | | | | | | | | | | | | | | Reverts 5b0d8f85fdb705b07143fc4019189a9dcfe3c108. 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.
| * fix(diagnostic): get line count per buffer when clampingGregory Anders2021-11-24
| | | | | | | | | | | | Fixes a bug when `get_diagnostics` is called with a nil `bufnr`. Diagnostics should be clamped for the buffer they reside in, not the current buffer.
* | fix(diagnostic): do not focus floats in goto functions (#16433)Gregory Anders2021-11-24
|/ | | | | 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"`.
* fix(diagnostic): resolve buffer number in get() (#16407)Gregory Anders2021-11-22
|
* fix(diagnostics): don't allow 0 bufnr for metatable index (#16405)Gregory Anders2021-11-22
| | | | | | | | | | | | | | | | | | | | 04bfd20bb introduced a subtle bug where using 0 as the buffer number in the diagnostic cache resets the cache for the current buffer. This happens because we were not checking to see if the _resolved_ buffer number already existed in the cache; rather, when the __index metamethod was called we assumed the index did not exist so we set its value to an empty table. The fix for this is to check `rawget()` for the resolved buffer number to see if the index already exists. However, the reason this bug was introduced in the first place was because we are simply being too clever by allowing a 0 buffer number as the index which is automatically resolved to a real buffer number. In the interest of minimizing metatable magic, remove this "feature" by requiring the buffer number index to always be a valid buffer. This ensures that the __index metamethod is only ever called for non-existing buffers (which is what we wanted originally) as well as reduces some of the cognitive overhead for understanding how the diagnostic cache works. The tradeoff is that all public API functions must now resolve 0 buffer numbers to the current buffer number.
* fix(diagnostic): remove invalid buffers from cache (#16397)smolck2021-11-21
| | | | | | | | | Errors were being caused by invalid buffers being kept around in diagnostic_cache, so add a metatable to diagnostic_cache which attaches to new buffers in the cache, removing them after they are invalidated. Closes #16391. Co-authored-by: Gregory Anders <8965202+gpanders@users.noreply.github.com>
* fix(diagnostic): clamp line numbers in setqflist and setloclistGregory Anders2021-11-19
|
* fix(diagnostic): fix navigation with diagnostics placed past end of lineGregory Anders2021-11-19
|
* fix(diagnostic): deepcopy diagnostics before clamping line numbersGregory Anders2021-11-19
| | | | | | | | | | | | | | The current 'clamp_line_numbers' implementation modifies diagnostics in place, which can have adverse downstream side effects. Before clamping line numbers, make a copy of the diagnostic. This commit also merges the 'clamp_line_numbers' method into a new 'get_diagnostics' local function which also implements the more general "get" method. The public 'vim.diagnostic.get()' API now just uses this function (without clamping). This has the added benefit that other internal API functions that need to use get() no longer have to go through vim.validate. Finally, reorganize the source code a bit by grouping all of the data structures together near the top of the file.
* fix(diagnostic): don't use nil col if missing from qflist (#16357)Gregory Anders2021-11-18
| | | | | If the quickfixlist item doesn't contain a column it is reported as 0. Rather than using a nil value in such a case (which breaks diagnostics elsewhere), just keep the 0 value.
* Merge pull request #16328 from gpanders/diagnostic-prefix-hiGregory Anders2021-11-16
|\
| * refactor(diagnostic)!: rename 'show_header' to 'header'Gregory Anders2021-11-15
| | | | | | | | | | | | Rename the `show_header` option in `open_float` to simply `header` and allow users to specify both the header string as well as the highlight group.
| * feat(diagnostic): allow 'prefix' option to return highlightGregory Anders2021-11-15
| | | | | | | | | | Extend the 'prefix' option for `open_float` to also provide an optional highlight group for the prefix string.
* | refactor(diagnostic): make bufnr arguments consistent (#16323)Gregory Anders2021-11-16
|/ | | | | | | Make the bufnr argument have similar semantics across API functions; namely, a nil value means "all buffers" while 0 means "current buffer". This increases the flexibility of the API by allowing functions such as enable() and disable() to apply globally or per-namespace, rather than only on a specific buffer.
* feat(diagnostic): add 'prefix' option to open_float (#16321)Gregory Anders2021-11-14
| | | | The 'prefix' option accepts a function or a string that is used to add a prefix string to each diagnostic displayed in the floating window.
* feat(diagnostic): do not require namespace for hide() and show() (#16261)Gregory Anders2021-11-09
| | | | | | | Also fix a few other small bugs regarding saving and restoring extmarks. In particular, now that the virtual text and underline handlers have their own dedicated namespaces, they should be responsible for saving and restoring their own extmarks. Also fix the wrong argument ordering in the call to `clear_diagnostic_cache` in the `on_detach` callback.
* fix(diagnostic): fix option resolution in open_float (#16229)Gregory Anders2021-11-04
|
* refactor(diagnostic): make display handlers generic (#16137)Gregory Anders2021-10-29
| | | | | | | Rather than treating virtual_text, signs, and underline specially, introduce the concept of generic "handlers", of which those three are simply the defaults bundled with Nvim. Handlers are called in `vim.diagnostic.show()` and `vim.diagnostic.hide()` and are used to handle how diagnostics are displayed.
* fix(diagnostic): allow floats to be focusable (#16093)Gregory Anders2021-10-19
| | | | Setting focus_id allows the float to be focused by calling the function a second time (a feature of open_floating_preview).
* fix(diagnostic): handle diagnostics placed past the end of line (#16095)Gregory Anders2021-10-19
|
* refactor(diagnostic)!: replace 'show_*' functions with 'open_float' (#16057)Gregory Anders2021-10-19
| | | | | | | | | | | | | | | | | | | | 'show_line_diagnostics()' and 'show_position_diagnostics()' are almost identical; they differ only in the fact that the latter also accepts a column to form a full position, rather than just a line. This is not enough to justify two separate interfaces for this common functionality. Renaming this to simply 'show_diagnostics()' is one step forward, but that is also not a good name as the '_diagnostics()' suffix is redundant. However, we cannot name it simply 'show()' since that function already exists with entirely different semantics. Instead, combine these two into a single 'open_float()' function that handles all of the cases of showing diagnostics in a floating window. Also add a "float" key to 'vim.diagnostic.config()' to provide global values of configuration options that can be overridden ephemerally. This makes the float API consistent with the rest of the diagnostic API. BREAKING CHANGE
* fix(diagnostic): do not override existing config settings #16043Gregory Anders2021-10-17
| | | | | | | | | | | When using `true` as the value of a configuration option, the option is configured to use default values. For example, if a user configures virtual text to include the source globally (using vim.diagnostic.config) and a specific namespace or producer configures virtual text with `virt_text = true`, the user's global configuration is overriden. Instead, interpret a value of `true` to mean "use existing settings if defined, otherwise use defaults".
* fix(diagnostic): error on invalid severity value (#15965)Gregory Anders2021-10-08
| | | | | | | Users can pass string values for severities that match with the enum names (e.g. "Warn" or "Info") which are converted to the corresponding numerical value in `to_severity`. Invalid strings were simply left as-is, which caused confusing errors later on. Instead, report an invalid severity string right up front to make the problem clear.
* fix: support severity_sort option for show_diagnostic functions (#15948)Gregory Anders2021-10-07
| | | Support the severity_sort option for show_{line,position}_diagnostics.
* feat(diagnostic): update jumplist on goto_next/prev (#15942)Sean Dewar2021-10-07
|
* refactor(diagnostics): always make 'set' go through 'show'Gregory Anders2021-10-02
| | | | | | | | | | | | Always make calls to `vim.diagnostic.set` call `vim.diagnostic.show`. This creates an easier to reason about code path and is also less surprising when users wish to override override `vim.diagnostic.show` with custom behavior and `vim.diagnostic.set` is called with empty diagnostics. Functionally, the end result is the same: when `show` is called with an empty diagnostics list, it just calls `hide` and then returns, which is exactly what `reset` does right now.
* feat(diagnostics): add vim.diagnostic.get_namespaces (#15866)Michael Lingelbach2021-10-01
| | | | | | | | | | | | | | | | | Many vim.diagnostic functions expect the user to pass in a namespace id. This PR allows the user to list active diagnostic namespaces: ```lua :lua print(vim.inspect(vim.diagnostic.get_namespaces())) { [7] = { name = "vim.lsp.client-1", opts = {}, sign_group = "vim.diagnostic.vim.lsp.client-1" } } ```
* docs(diagnostics): add "priority" option to signs table (#15860)Gregory Anders2021-10-01
| | | | This feature was added in #15785, but the docs for vim.diagnostic.config() weren't updated.
* refactor(diagnostic): use sign priority for severity_sort #15785Gregory Anders2021-09-26
| | | | | | | Rather than relying on the order in which signs are placed to dictate the order in which they are displayed, explicitly set the priority of the sign according to the severity of the diagnostic and the value of severity_sort. If severity_sort is false or unset then all signs use the same priority.
* fix(diagnostic): check for nil in show_diagnostics (#15772)Gregory Anders2021-09-23
|
* fix(diagnostic): don't return nil when callers expect a table (#15765)Gregory Anders2021-09-23
| | | | | | diagnostic_lines() returns a table, so make the early exit condition an empty table rather than 'nil'. This way, functions that use the input from diagnostic_lines don't have to do a bunch of defensive nil checking and can always assume they're operating on a table.
* feat(diagnostic): allow customized diagnostic messages (#15742)Gregory Anders2021-09-22
| | | | Provide a 'format' option for virtual text and floating window previews that allows the displayed text of a diagnostic to be customized.
* refactor(diagnostic): remove get_virt_text_chunks()Gregory Anders2021-09-21
| | | | | | | | | This function isn't compatible with including diagnostic sources when "source" is "if_many" since it only has access to diagnostics for a single line. Rather than having an inconsistent or incomplete interface, make this function private. It is still exported as part of the module for backward compatibility with vim.lsp.diagnostics, but it can eventually be made into a local function.
* feat(diagnostic): add option to include diagnostic sourceGregory Anders2021-09-21
| | | | | Add an option to virtual text display and floating window previews to include diagnostic source in the diagnostic message.
* fix(diagnostic): clamp line numbers in display layer (#15729)Gregory Anders2021-09-20
| | | | | | Some parts of LSP need to use cached diagnostics as sent from the LSP server unmodified. Rather than fixing invalid line numbers when diagnostics are first set, fix them when they are displayed to the user (e.g. in show() or one of the get_next/get_prev family of functions).
* feat(diagnostic): match(), tolist(), fromlist() #15704Gregory Anders2021-09-19
| | | | | | * feat(diagnostic): add vim.diagnostic.match() Provide vim.diagnostic.match() to generate a diagnostic from a string and a Lua pattern. * feat(diagnostic): add tolist() and fromlist()