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

lsp: vim.lsp.diagnostics and lsp-handlers #12655

Merged
merged 1 commit into from Nov 13, 2020

Conversation

tjdevries
Copy link
Contributor

@tjdevries tjdevries commented Jul 18, 2020

PREFACE: Uninstall diagnostic-nvim before updating if you don't want errors. Not much I can do about it if you update them not in sync.

Also, please check the commit message for this PR, as it contains a lot of valuable information for users. You may need to make distclean; make when you build the latest master.

Configuration Part 1: https://clips.twitch.tv/ZanySincereCookieFeelsBadMan
Virtual Text Configuration: https://clips.twitch.tv/RudeDistinctMuleImGlitch

Show Line Diagnostics: https://clips.twitch.tv/HomelyEnergeticThymePraiseIt
Filtering Diagnostics by Severity: https://clips.twitch.tv/ElatedImpossibleVanillaHeyGirl

Example for Plugin Authors (and @ThePrimeagen) for configuring virtual text diagnostics: https://clips.twitch.tv/PlausibleGleamingWolfImGlitch
( with corresponding gist: https://gist.github.com/tjdevries/ccbe3b79bd918208f2fa8dfe15b95793 )

Original, Very Old PR : #12333

This is only focused on diagnostics. It includes fixes for:

  1. Multiple servers running for one buffer
  2. Provides additional features like "move to next diagnostic" or "move to previous diagnostic"
  3. Much better performance for looking up count of errors, etc. because it caches them between runs (this is good for the status line example)
  4. Much better testing (added lots of new tests)
  5. Improved documentation
  6. Concept of "vim.lsp.with" and |lsp-handlers| (as well as on_publish_diagnostic improvements and configuration).

NOTE: You should uninstall diagnostic-nvim if you're using it and follow the guide here: nvim-lua/diagnostic-nvim#73

Highlights

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.

Same goes for signs.

The basic layout is: LspDiagnostics{Name of Thing}{Level} -> LspDiagnosticsSignError, etc.

@tjdevries
Copy link
Contributor Author

@justinmk when we chatted about this, you menteiond that we alredy have the concept of handlers. I think that's actually what I'm making here in actions.

If I replace actions with handlers, does it make more sense and seem within the right scope?

@justinmk
Copy link
Member

justinmk commented Sep 7, 2020

If I replace actions with handlers, does it make more sense and seem within the right scope?

Maybe. Will look at this now. I also see we have "hooks", at least internally, as implied by add_hook_before:

https://github.com/neovim/nvim-lspconfig/blob/4b440038709599f1c42712dda45aa8f2b6d591c0/lua/nvim_lsp/util.lua#L258

This is too many similar-but different concepts. It's unnecessary and puts the work of tying these concepts together on the user (or at least contributors) instead of doing that work in the API design.

So a user or plugin author has to internalize

  1. autocmds/events
  2. notifications (RPC)
  3. "attach"
  4. callbacks
  5. hooks
  6. handlers
  7. and now maybe also "actions".

All with semantics that are accidentally different, not essentially different. Just because we didn't do the work of designing a better abstraction. It is easy/fast to add a new "inner platform", but painful for users/contributors, documentation, discussion, debugging, reasoning.

@tjdevries
Copy link
Contributor Author

Yes, I agree with you.

I think callbacks, handlers and (my mentioned here) actions call all be the same item for what we're going for here. I'd suggest when lookin at this PR to probably just thinking of everything with the word actions to just be changed to handler. These should be able to be used as the callback for requests sent to LSP servers.

I do not know what hooks are for -- they don't appear in core as far as I know. I haven't done much in lsp configs in awhile.

I have a few goals tha I want to accomplish with a PR , some of the more long term. I suppose they don't have to live in core, but some of include:

  1. Allow users to easily customize behavior for builtin callbacks
  2. Provide library of functions to centralize interacting with LSP items (like jump_to_location, or highlight_location), since I think some of them could be useful for more purposes (and there are many difficult things, like handling multibyte situations, for example).
  3. Not make users have to copy and paste code from core into their init.vim to change one line (for common cases) so that their experience doesn't become stale or regress over time.

But maybe it's too late in the day and I'm not making sense.

Perhaps one of the Location handlers might make more sense why I was going for this structure, which was why I started writing the code in this fashion before.

@tjdevries tjdevries force-pushed the tjdevries/lsp_diagnostics branch 2 times, most recently from 7d60bd6 to 3a09fae Compare September 9, 2020 00:31
@justinmk justinmk added needs:design needs a clear design proposal lsp labels Sep 9, 2020
@justinmk
Copy link
Member

justinmk commented Sep 9, 2020

What I gathered from our (very productive!) discussion:

  • M['textDocument/foo'] = vim.lsp.with(M['textDocument/foo'], { flag=bar }) seems like a good interface for lettings users override LSP handlers with configuration.
  • Put LSP modules like diagnostics directly into vim.lsp.diagnostics. Don't need submodules of submodules (vim.lsp.foo.bar.diagnostics).
    • LSP's topics largely dictate our API surface area, little we can do about this (we did decide to implement an LSP client), except to avoid overthinking it.
  • Don't need "actions" as a new concept, but it could make sense to put these handlers in callbacks.lua.
    • Naming convention: on_xx

@tjdevries
Copy link
Contributor Author

Note to self: Update docs w/ new signature.

@tjdevries
Copy link
Contributor Author

Note to self: lsp-callbacks should exist again by the time I'm done w/ the PR

@tjdevries tjdevries force-pushed the tjdevries/lsp_diagnostics branch 2 times, most recently from ac2af08 to 57e658f Compare September 13, 2020 01:36
@norcalli
Copy link

add_hook_before is a generic utility function, it doesn't imply the existence of a concept of a hook outside of the singular case of adding a hook before the second parameter, aka chaining functions, but it's the old name I used to use for that utility. I also sometimes call it fn_then.

@tjdevries
Copy link
Contributor Author

  mapper(
    'n',
    '<leader>dn',
    '<cmd>lua vim.lsp.diagnostic.buf_move_next_diagnostic()<CR>'
  )

  mapper(
    'n',
    '<leader>dp',
    '<cmd>lua vim.lsp.diagnostic.buf_move_prev_diagnostic()<CR>'
  )

runtime/doc/lsp.txt Outdated Show resolved Hide resolved
runtime/doc/lsp.txt Outdated Show resolved Hide resolved
@rockerBOO
Copy link
Contributor

rockerBOO commented Oct 31, 2020

Error using the util endpoint for code_action AND range_code_action:

E5108: Error executing lua /usr/local/share/nvim/runtime/lua/vim/lsp/buf.lua:281: attempt to call field 'get_line_di
agnostics' (a nil value)
  context = context or { diagnostics = util.get_line_diagnostics() }

Copy link

@megalithic megalithic left a comment

Choose a reason for hiding this comment

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

Minor spelling/language changes to lsp-extensions.txt doc.

runtime/doc/lsp-extension.txt Outdated Show resolved Hide resolved
runtime/doc/lsp-extension.txt Outdated Show resolved Hide resolved
runtime/doc/lsp-extension.txt Outdated Show resolved Hide resolved
runtime/doc/lsp-extension.txt Outdated Show resolved Hide resolved
@tjdevries tjdevries changed the title lsp: Multiple diagnostic updates lsp: vim.lsp.diagnostics and lsp-handlers Nov 4, 2020
@tjdevries
Copy link
Contributor Author

mapper(
'n',
'dn',
'lua vim.lsp.diagnostic.goto_next()'
)

mapper(
'n',
'dp',
'lua vim.lsp.diagnostic.goto_prev()'
)

@sunzoje
Copy link

sunzoje commented Nov 6, 2020

Running :lua vim.lsp.diagnostic.set_loclist() on build 83e278ead returns E5108: Error executing lua runtime/lua/vim/lsp/diagnostic.lua:1032: attempt to index local 'opts' (a nil value).

bluz71 added a commit to bluz71/vim-nightfly-colors that referenced this pull request Nov 16, 2020
mrossinek added a commit to mrossinek/dotfiles that referenced this pull request Nov 16, 2020
Its functionality has been merged into Neovim core:
neovim/neovim#12655
gbrlsnchs added a commit to gbrlsnchs/nord-vim that referenced this pull request Nov 16, 2020
After neovim/neovim#12655 has been merged,
highlights have changed a little, so this commit updates the obsolete
highlight groups.
gbrlsnchs added a commit to gbrlsnchs/nord-vim that referenced this pull request Nov 16, 2020
After neovim/neovim#12655 has been merged,
highlights have changed a little, so this commit updates the obsolete
highlight groups.
sentriz added a commit to sentriz/dotfiles that referenced this pull request Nov 19, 2020
@nabezokodaikon
Copy link

I have underline enabled but it doesn't show up.
How will it be displayed?

My setting

vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(
    vim.lsp.diagnostic.on_publish_diagnostics, {
        underline = true,
        virtual_text = true,
        signs = true,
        update_in_insert = true,
  }
)

@glepnir
Copy link
Member

glepnir commented Dec 15, 2020

you should config underline highlight group .

@tjdevries
Copy link
Contributor Author

If you're having issues with this branch, please make an issue on neovim, follow the issue template and then tag me so I can take a look at it there. Thanks.

@nabezokodaikon
Copy link

It's done. Thank you!

function! SetLSPHighlights()
    highlight LspDiagnosticsUnderlineError guifg=#EB4917 gui=undercurl
    highlight LspDiagnosticsUnderlineWarning guifg=#EBA217 gui=undercurl
    highlight LspDiagnosticsUnderlineInformation guifg=#17D6EB, gui=undercurl
    highlight LspDiagnosticsUnderlineHint guifg=#17EB7A gui=undercurl
endfunction

autocmd ColorScheme * call SetLSPHighlights()

gbrlsnchs added a commit to gbrlsnchs/nord-vim that referenced this pull request Jan 1, 2021
After neovim/neovim#12655 has been merged,
highlights have changed a little, so this commit updates the obsolete
highlight groups.
gbrlsnchs added a commit to gbrlsnchs/nord-vim that referenced this pull request Jan 1, 2021
After neovim/neovim#12655 has been merged,
highlights have changed a little, so this commit updates the obsolete
highlight groups.
kengkiat added a commit to kengkiat/wincent that referenced this pull request Mar 20, 2021
neovim/neovim#12655 made breaking changes renaming highlight groups for
LspDiagnostic. It also moved `vim.lsp.callbacks` to `vim.lsp.handlers`

Since we're installing the nightly build, we should update this so that
a fresh init can work off the bat.
arcticicestudio pushed a commit to nordtheme/vim that referenced this pull request May 29, 2021
To ensure compatibility with the latest versions of Neovim LSP the
highlighting groups for diagnostics have been adapted to the changes
of neovim/neovim#12655 [1].
See :help lsp-highlight-diagnostics [2] for more details.

Note that LSP will be available as of Neovim 0.5 which is (at the time
of this commit) still in development and only available as nighly build.
Also see great articles from Nord Vim contributors like "Neovim (0.5) Is
Overpowering" [3] for more information about Neovim 0.5 features,
including LSP.

[1]: neovim/neovim#12655
[2]: https://neovim.io/doc/user/lsp.html
[3]: https://crispgm.com/page/neovim-is-overpowering.html

Co-authored-by: Sven Greb <development@svengreb.de>

Closes GH-229
Closes GH-248
crispgm pushed a commit to crispgm/nord-vim that referenced this pull request Jun 10, 2021
To ensure compatibility with the latest versions of Neovim LSP the
highlighting groups for diagnostics have been adapted to the changes
of neovim/neovim#12655 [1].
See :help lsp-highlight-diagnostics [2] for more details.

Note that LSP will be available as of Neovim 0.5 which is (at the time
of this commit) still in development and only available as nighly build.
Also see great articles from Nord Vim contributors like "Neovim (0.5) Is
Overpowering" [3] for more information about Neovim 0.5 features,
including LSP.

[1]: neovim/neovim#12655
[2]: https://neovim.io/doc/user/lsp.html
[3]: https://crispgm.com/page/neovim-is-overpowering.html

Co-authored-by: Sven Greb <development@svengreb.de>

Closes nordthemeGH-229
Closes nordthemeGH-248
'LspDiagnosticsDefaultError',
'LspDiagnosticsDefaultHint',
'LspDiagnosticsDefaultInformation',
'LspDiagnosticsDefaultWarning',
Copy link
Member

@justinmk justinmk Aug 16, 2021

Choose a reason for hiding this comment

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

nit: name could be less verbose by omitting "Default", which is largely implied by the nature of builtin highlight groups. We should at least not repeat this pattern in the future.

edit: fixed in #15585 and related PRs.

kluen added a commit to kluen/nvim-metals that referenced this pull request Sep 15, 2021
The naming layout for the diagnostic signs has changed:
neovim/neovim#12655
@@ -471,7 +471,7 @@ local function start(cmd, cmd_args, handlers, extra_spawn_params)
local function handle_body(body)
local decoded, err = json_decode(body)
if not decoded then
on_error(client_errors.INVALID_SERVER_JSON, err)
-- on_error(client_errors.INVALID_SERVER_JSON, err)
Copy link
Member

Choose a reason for hiding this comment

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

@tjdevries was this remove intentionally? Not mentioned in the commit message nor PR, afaict.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, I was having some problems with sumneko locally and I think I commented this out to test something and never uncommented. We can just add this back I'm pretty sure. Sorry about that.

Copy link
Member

Choose a reason for hiding this comment

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

np, will do in #15803

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lsp needs:design needs a clear design proposal
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet