Skip to content

fix(#2519): Diagnostics Not Updated When Tree Not Visible #2597

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Dec 30, 2023

Conversation

iusmac
Copy link
Contributor

@iusmac iusmac commented Dec 22, 2023

The diagnostic changed event has been untied from the current tree state to ensure the data availability at any time. Now, the diagnostics will be picked up "on the fly" whenever the tree is about to be (re-)drawn, which makes absolute sense, especially, when incrementally exploring the file system structure or when (re-)opening the tree and the diagnostic changed event has already occurred.

All in all, this effectively solves any inconsistencies (see #2517), and ensures that the tree shows the freshest diagnostics, regardless of the tree's state and when diagnostics change.

@iusmac iusmac changed the title feat(#2519): diagnostics overhaul fix(#2519): Diagnostics Not Updated When Tree Not Visible Dec 23, 2023
@iusmac
Copy link
Contributor Author

iusmac commented Dec 23, 2023

I've just noticed that fetching diagnostics with coc is completely broken when setting nvim-tree.diagnostics.severity.max to something else than ERROR (default).

The current implementation will find the highest severity, then discard items that are out of range.
Reversing the order fixes and simplifies everything.

Now, the lsp and coc functions look pretty much the same, which makes sense, as there's no big difference between the two, except that with coc we have to bother about the severity limit of each item.

The commit that introduced this bug: 874b7be.

Signed-off-by: iusmac <iusico.maxim@libero.it>
Also, while we're at it, refactor the lsp function for consistency.
There should be no functional change, just cosmetic.

Signed-off-by: iusmac <iusico.maxim@libero.it>
Copy link
Member

@alex-courtis alex-courtis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking great - many thanks for dealing with the regressive behaviour.


---@param path string
---@return string
local function uniformize_path(path)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice name!

@@ -413,6 +413,8 @@ end
function Builder:_build_line(node, idx, num_children, unloaded_bufnr)
local copy_paste = require "nvim-tree.actions.fs.copy-paste"

require("nvim-tree.diagnostics").update_node_severity_level(node)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is very concerning from a performance perspective; we go out of our way to avoid such calls on drawing each line.

Could we improve via one of:

  • do this once for all nodes prior to rendering
  • short-circuit this so that it's only called when there is no diagnostic info

log.node("diagnostics", buffer_severity_dict, "update")
log.profile_end(profile)
if view.is_buf_valid(view.get_bufnr()) then
require("nvim-tree.renderer").draw()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/ nit please require once at the start of the file

if is_using_coc() then
buffer_severity = from_coc()
buffer_severity_dict = from_coc()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/ nit no dict please - we're not writing python here ;)

Signed-off-by: iusmac <iusico.maxim@libero.it>
Signed-off-by: iusmac <iusico.maxim@libero.it>
Causes circular requires after the previous commit.

This reverts commit 7413041.
Signed-off-by: iusmac <iusico.maxim@libero.it>
Signed-off-by: iusmac <iusico.maxim@libero.it>
Signed-off-by: iusmac <iusico.maxim@libero.it>
@iusmac
Copy link
Contributor Author

iusmac commented Dec 25, 2023

While we're at it, implement error handling for coc.nvim.

If you're lucky and hit CTRL-C while NvimTree is fetching diagnostics from coc.nvim, it can cause a deadlock state in the utils.debounce() that will never release its debouncer.executing flag due the exception in the callback. All subsequent diagnostic update events will be discarded.

Error executing vim.schedule lua callback: function CocAction[4]..coc#rpc#request[4]..<SNR>38_request, line 31: Error on request: Vim:Interrupt
stack traceback:
        [C]: in function 'CocAction'
        ....vim/plugged/nvim-tree.lua/lua/nvim-tree/diagnostics.lua:69: in function 'from_coc'
        ....vim/plugged/nvim-tree.lua/lua/nvim-tree/diagnostics.lua:123: in function 'callback'
        ...usmac/.vim/plugged/nvim-tree.lua/lua/nvim-tree/utils.lua:400: in function <...usmac/.vim/plugged/nvim-tree.lua/lua/nvim-tree/utils.lua:399>


--- The buffer-severity mappings derived during the last diagnostic list update.
---@type table
local BUFFER_SEVERITY = {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking good; we have a cache similar to git's.

It'll take me a while to properly review and test this one.

iusmac and others added 3 commits December 26, 2023 09:18
Signed-off-by: iusmac <iusico.maxim@libero.it>
Signed-off-by: iusmac <iusico.maxim@libero.it>
Copy link
Member

@alex-courtis alex-courtis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, works well.

I did not test COC. In the unlikely event of any issues I'll call on you ;)

Added some doc and some minor tidies.

Many thanks for all your work!

local log = require "nvim-tree.log"

local M = {}

local severity_levels = {
---TODO add "$VIMRUNTIME" to "workspace.library" and use the @enum instead of this integer
Copy link
Member

@alex-courtis alex-courtis Dec 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That one's a work in progress #2546

@alex-courtis alex-courtis merged commit 96a783f into nvim-tree:master Dec 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants