Skip to content
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

Bug: Diagnostic virtual text is not updated in the treesitter context #509

Open
benelan opened this issue Oct 20, 2024 · 3 comments
Open
Labels
bug Something isn't working

Comments

@benelan
Copy link

benelan commented Oct 20, 2024

Description

Diagnostic virtual text does not get updated in the treesitter context until you go out of the scope and then back in. It can be confusing when there is diagnostic virtual text displayed in the context and it doesn't go away after fixing the issue.

I pinned commit 8198ad4 for now, which doesn't display virtual text in the treesitter context at all.

Neovim version

v0.10.2

Expected behavior

Diagnostic virtual text gets updated in the treesitter context when it changes.

Actual behavior

Diagnostic virtual text does not get updated in the treesitter context until you go out of the scope and then back in.

Minimal config

local plugins = {
  ts = "https://github.com/nvim-treesitter/nvim-treesitter",
  ts_context = "https://github.com/nvim-treesitter/nvim-treesitter-context",
  lspconfig = "https://github.com/neovim/nvim-lspconfig",
  mason = "https://github.com/williamboman/mason.nvim",
  mason_lspconfig = "https://github.com/williamboman/mason-lspconfig.nvim",
}

for name, url in pairs(plugins) do
  local install_path = "/tmp/nvim/site/" .. name
  if vim.fn.isdirectory(install_path) == 0 then
    vim.fn.system({ "git", "clone", "--depth=1", url, install_path })
  end
  vim.o.runtimepath = install_path .. "," .. vim.o.runtimepath
end

-- ADD INIT.LUA SETTINGS THAT IS _NECESSARY_ FOR REPRODUCING THE ISSUE
vim.diagnostic.config({ virtual_text = true })

require("mason").setup()
require("mason-lspconfig").setup({
  ensure_installed = { "bashls" },
  handlers = {
    ["bashls"] = function()
      require("lspconfig")["bashls"].setup({
        capabilities = vim.lsp.protocol.make_client_capabilities(),
      })
    end,
  },
})

Steps to reproduce

Save the following as test.sh next to minimal.lua:

#!/usr/bin/env bash
test() {
    echo "test"
    #
    #
    #
    #
    #
    #
    #
    #
    #
    #
    #
    #
    #
    #
    #
    #
    #
    #
    #
    #
    #
    #
    #
    #
    #
    #
    #
    #
    #
    #
    #
    #
    #
    #
    #
    #
    #
    #
    #
    #
    #
    #
    #
    #
    #
    #
    #
    #
    #
    #
    #
}
  1. nvim --clean -u minimal.lua test.sh
  2. Press G
  3. Press dd
  4. Notice there is no virtual text on the treesitter context
  5. Press gg
  6. Notice the virtual text on line 2
  7. Press G
  8. Notice the virtual text on the treesitter context
  9. Press u
  10. Notice the virtual text is still on the treesitter context
  11. Press gg
  12. Notice there is no virtual text on line 2
@benelan benelan added the bug Something isn't working label Oct 20, 2024
@benelan
Copy link
Author

benelan commented Oct 20, 2024

Note: fixed the minimal.lua snippet in case you are reading this via email

@benelan
Copy link
Author

benelan commented Oct 29, 2024

Here is a workaround, but I'm sure there's a more performant way to handle this internally

vim.api.nvim_create_autocmd({ "DiagnosticChanged" }, {
  callback = function()
    local tsc = require("treesitter-context")
    if tsc.enabled() then
      tsc.disable()
      tsc.enable()
    end
  end,
})

@benelan
Copy link
Author

benelan commented Dec 20, 2024

Thanks for working on this! However, I don't see diagnostic virtual text on the context at all when following the repro steps above. Tested on both v.10.0 and nightly.

@lewis6991 lewis6991 reopened this Dec 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants