Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Diagnostics Disabled flag seems do not work #2791

Closed
LLMChild opened this issue Jun 5, 2024 · 0 comments
Closed

Diagnostics Disabled flag seems do not work #2791

LLMChild opened this issue Jun 5, 2024 · 0 comments

Comments

@LLMChild
Copy link

LLMChild commented Jun 5, 2024

is_disabled = vim.diagnostic.is_disabled()

I am trying to write a keybind to turn off diagnostics.

vim.g.diagnostics_active = true
function _G.toggle_diagnostics()
if vim.g.diagnostics_active then
  vim.g.diagnostics_active = false
  vim.diagnostic.hide()
  vim.lsp.handlers["textDocument/publishDiagnostics"] = function() end
  vim.notify("Diagnostics are now off", vim.log.levels.INFO, { title = "Diagnostics" })
else
  vim.g.diagnostics_active = true
  vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(
    vim.lsp.diagnostic.on_publish_diagnostics, {
      virtual_text = false,
      signs = true,
      underline = true,
      update_in_insert = true,
    }
  )
  vim.notify("Diagnostics are now no", vim.log.levels.INFO, { title = "Diagnostics" })
end
end
map('n', '<leader>td', ':call v:lua.toggle_diagnostics()<CR>',  {noremap = true, silent = true, desc = "Toggle Diagnostics"})

This works for my diagnostics all buffers but does not work for nvim-tree.
So I am trying to find a function which can toggle Diagnostics for nvim-tree in runtime.
Sadly, nvim-tree does not have anything like this.
So I checked the code , and I found this flag.
Then I add enable and enable(false) in my keybindings.
like this

function _G.toggle_diagnostics()
if vim.g.diagnostics_active then
  vim.g.diagnostics_active = false
  vim.diagnostic.hide()
  vim.diagnostic.enable(false)
  vim.lsp.handlers["textDocument/publishDiagnostics"] = function() end
  vim.notify("Diagnostics are now off", vim.log.levels.INFO, { title = "Diagnostics" })
else
  vim.g.diagnostics_active = true
  vim.diagnostic.enable()
  vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(
    vim.lsp.diagnostic.on_publish_diagnostics, {
      virtual_text = false,
      signs = true,
      underline = true,
      update_in_insert = true,
    }
  )

It didn't not work either, and I checked status using :lua print(vim.diagnostic.is_disabled()).
But nvim-tree still won't hide the diagnostic.
Can anybody in this community help me?

@nvim-tree nvim-tree locked and limited conversation to collaborators Jun 5, 2024
@gegoune gegoune converted this issue into discussion #2792 Jun 5, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant