Skip to content
This repository has been archived by the owner on Jul 6, 2021. It is now read-only.

[IMPORTANT] Deprecation & Transition Strategy #73

Open
tjdevries opened this issue Nov 6, 2020 · 14 comments
Open

[IMPORTANT] Deprecation & Transition Strategy #73

tjdevries opened this issue Nov 6, 2020 · 14 comments

Comments

@tjdevries
Copy link
Member

tjdevries commented Nov 6, 2020

Now that neovim/neovim#12655 is merged, we are deprecating diagnostic-nvim. For full information and commit message, see: neovim/neovim@f75be5e

Any features that were in diagnostic-nvim have now been implemented in Neovim core! This was always the plan for diagnostic-nvim, as it was a playground and testing area for features and interfaces for the builtin LSP

You should remove any on_attach calls from diagnostic-nvim in your configuration. They are no longer required.

Common Actions

  • PrevDiagnosticCycle and NextDiagnosticCycle:
    • New methods:
      • vim.lsp.diagnostic.goto_prev()
      • vim.lsp.diagnostic.goto_next()
    • Example Mappings:
      • nnoremap <leader>dn <cmd>lua vim.lsp.diagnostic.goto_next()<CR>
  • PrevDiagnostic and NextDiagnostic
    • New methods:
      • vim.lsp.diagnostic.goto_prev { wrap = false }
      • vim.lsp.diagnostic.goto_next { wrap = false }
    • Example Mappings:
      • nnoremap <leader>dn <cmd>lua vim.lsp.diagnostic.goto_next { wrap = false }<CR>
  • OpenDiagnostic
    • New method:
      • vim.lsp.diagnostic.set_loclist()

Configuring LSP Diagnostic Display

  • Configuration of the LSP diagnostic display is now done with lsp-handlers.
    • You can read more about them by doing :help lsp-handler
    • For example, to disable virtual text, you would do this in your init.vim
lua << EOF
vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(
  vim.lsp.diagnostic.on_publish_diagnostics, {
    -- This will disable virtual text, like doing:
    -- let g:diagnostic_enable_virtual_text = 0
    virtual_text = false,

    -- This is similar to:
    -- let g:diagnostic_show_sign = 1
    -- To configure sign display,
    --  see: ":help vim.lsp.diagnostic.set_signs()"
    signs = true,

    -- This is similar to:
    -- "let g:diagnostic_insert_delay = 1"
    update_in_insert = false,
  }
)
EOF

Also note, the highlight group names have changed to now be consistent with each other. From the commit message in neovim core:

- Changed the highlight groups for LspDiagnostic highlight as they were
  inconsistently named.
    - For more information, see |lsp-highlight-diagnostics|

For example, the highlight that was formerly LspDiagnosticsError is now LspDiagnosticsVirtualTextError. It can also be configured by changing the default highlight group, LspDiagnosticsDefaultError. For more information, read :help lsp-highlight-diagnostics.

Advanced configuration

  • To configure more advanced usage, first, you should read the new help for ":help vim.lsp.diagnostic.on_publish_diagnostics"
  • After reading, you can override diagnostic-nvim configuration values, like sign configuration and virtual text spacing using something similar to the following:
vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(
  vim.lsp.diagnostic.on_publish_diagnostics, {
    -- Enable underline, use default values
    underline = true,
    -- Enable virtual text, override spacing to 4
    virtual_text = {
      spacing = 4,
      prefix = '~',
    },
    -- Use a function to dynamically turn signs off
    -- and on, using buffer local variables
    signs = function(bufnr, client_id)
      local ok, result = pcall(vim.api.nvim_buf_get_var, bufnr, 'show_signs')
      -- No buffer local variable set, so just enable by default
      if not ok then
        return true
      end

      return result
    end,
    -- Disable a feature
    update_in_insert = false,
  }
)
@tjdevries tjdevries pinned this issue Nov 11, 2020
@tjdevries tjdevries changed the title Deprecation Strategy [IMPORTANT] Deprecation & Transition Strategy Nov 11, 2020
pyrho added a commit to pyrho/embark that referenced this issue Nov 13, 2020
ahmedelgabri added a commit to ahmedelgabri/dotfiles that referenced this issue Nov 13, 2020
zhaozg added a commit to zhaozg/neospace that referenced this issue Nov 14, 2020
nvim-lua/diagnostic.nvim is deprecated.
[migration
guide](nvim-lua/diagnostic-nvim#73)
zhaozg added a commit to zhaozg/neospace that referenced this issue Nov 14, 2020
nvim-lua/diagnostic.nvim is deprecated.
[migration
guide](nvim-lua/diagnostic-nvim#73)
jubnzv added a commit to jubnzv/dotfiles that referenced this issue Nov 17, 2020
cappyzawa pushed a commit to cappyzawa/dotfiles that referenced this issue Nov 23, 2020
zachbai added a commit to zachbai/dotfiles that referenced this issue Nov 25, 2020
@Scupake
Copy link

Scupake commented Nov 29, 2020

Can someone please show me to how to do this autocmd CursorHold * lua vim.lsp.util.show_line_diagnostics() now?

@sentriz
Copy link

sentriz commented Nov 29, 2020

Can someone please show me to how to do this autocmd CursorHold * lua vim.lsp.util.show_line_diagnostics() now?

have you tried autocmd CursorHold * lua vim.lsp.diagnostic.show_line_diagnostics()

@Scupake
Copy link

Scupake commented Nov 29, 2020

have you tried autocmd CursorHold * lua vim.lsp.diagnostic.show_line_diagnostics()

Oh, hey that worked. Thanks!

@lucax88x
Copy link

lucax88x commented Dec 9, 2020

Was someone able to change the signs icons? I tried several ways but nothing worked.

@tjdevries
Copy link
Member Author

have you tried :help vim.lsp.diagnostics.set_signs() info?

    sign define LspDiagnosticsSignError text=E texthl=LspDiagnosticsSignError linehl= numhl=
    sign define LspDiagnosticsSignWarning text=W texthl=LspDiagnosticsSignWarning linehl= numhl=
    sign define LspDiagnosticsSignInformation text=I texthl=LspDiagnosticsSignInformation linehl= numhl=
    sign define LspDiagnosticsSignHint text=H texthl=LspDiagnosticsSignHint linehl= numhl=

@lucax88x
Copy link

lucax88x commented Dec 9, 2020

Yep,

I tried this in the init.vim and all the possible lua versions

vim.api.nvim_call_function("sign_define", {"LspDiagnosticsErrorSign",
{text = "", texthl = "LspDiagnosticsError"}})
vim.fn.sign_define("LspDiagnosticsErrorSign",
{text = "", texthl = "LspDiagnosticsError"})
vim.cmd [[ sign define LspDiagnosticsErrorSign text= texthl=LspDiagnosticsError linehl= numhl= ]]

I tried them on_attach, in the new beforeDiagnostick callback, before and after any lsp setting, noone worked, to me.

@tjdevries
Copy link
Member Author

That todo is for a different thing (there was some error when trying to find the signs that had been displayed. it's an internal bug I think, not related or due to the code).

Have you tried it via the ex command, not using sign_define? I think there may be some bugs related to sign functions and commands (I do not know for sure though, I have not had time to investigate)

@lucax88x
Copy link

No worries, cosmetics is not as important as functionalities, and for now LSP is a great piece of software so I can definitely wait.

(truth is I don't know know what parameters to pass to :lua vim.lsp.diagnostic.set_signs, still a newb on lua :D)

@tjdevries
Copy link
Member Author

Ah, I meant to just try the ex commands listed in the docs to configure the signs.

@lucax88x
Copy link

Wow, I am truly sorry.

LspDiagnosticsErrorSign => LspDiagnosticsSignError

I'm gonna hide behind a mountain.

@tjdevries
Copy link
Member Author

😆 such is life. No worries. I changed the names in the PR because they were randomly named before and now follow a pattern, so at least you're not too crazy :)

@runiq
Copy link

runiq commented May 21, 2021

Might wanna archive this repo, maybe.

@wllenyj
Copy link

wllenyj commented Jul 5, 2021

autocmd CursorHold * lua vim.lsp.diagnostic.show_line_diagnostics{focusable=false}

focusable=false is very useful

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants