Skip to content

plugins/lsp: use vim.lsp native API #3204

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 1 commit into from
Apr 23, 2025

Conversation

GaetanLepage
Copy link
Member

@GaetanLepage GaetanLepage commented Apr 22, 2025

Use Neovim's native vim.lsp API instead of legacy require('lspconfig').*.setup().

nvim-lspconfig aims to become a bank of configuration for popular language servers.
Its API has been deprecated in favor of Neovim 0.11's new vim.lsp native one.

Hence, we need to adapt how we configure nvim-lspconfig in lua and migrate it to the new API.

I have not yet really understand how nvim-lspconfig interacts with the native API to inject its configs.

Note

This is a parallel effort of #3203
Ultimately, we should be able to use our top-level lsp module in plugins.lsp's (nvim-lspconfig) implementation.

Open questions

  • Quid of plugins.lsp.servers.*.capabilities? Do we need to provide them to vim.lsp.config?

Resources

Fixes #3201

@MattSturgeon
Copy link
Member

MattSturgeon commented Apr 22, 2025

I have not yet really understand how nvim-lspconfig interacts with the native API to inject its configs.

I suspect they are using the new rtp lsp directory to merge in their configs.

Any file in <plugin>/lsp/<foo>.lua will be merged with vim.lsp.config('foo').

Alternatively, they may just be setting vim.lsp.config. Multiple calls to vim.lsp.config('foo') are also merged:

Note

The merge semantics of configurations follow the behaviour of vim.tbl_deep_extend().

See :h lsp-config

@khaneliman
Copy link
Contributor

Seems to work fine on my end.

@MattSturgeon
Copy link
Member

MattSturgeon commented Apr 22, 2025

Open questions

  • Quid of plugins.lsp.servers.*.capabilities? Do we need to provide them to vim.lsp.config?

Looking at :h lsp-attach, I believe this API has not changed:

To use LSP features beyond those provided by Nvim (see :h lsp-buf), you can set keymaps and options on Client:on_attach() or LspAttach.
Not all language servers provide the same capabilities; check supports_method() in your LspAttach handler.
Example: Enable auto-completion and auto-formatting ("linting"):

?

EDIT: actually, they give an example of setting capabilities via vim.lsp.config too:

vim.lsp.config('*', {
  capabilities = {
    textDocument = {
      semanticTokens = {
        multilineTokenSupport = true,
      }
    }
  },
  root_markers = { '.git' },
})

They also note:

You can configure LSP behavior statically via vim.lsp.config(), and dynamically via lsp-attach or Client:on_attach().

So we'd continue to use on_attach if we needed to dynamically check what capabilities are available, but we can use the static vim.lsp.config() function to configure things unconditionally.

@GaetanLepage GaetanLepage force-pushed the plugins-lsp branch 2 times, most recently from 6dac135 to 2f9a61a Compare April 23, 2025 07:31
Copy link
Member

@MattSturgeon MattSturgeon left a comment

Choose a reason for hiding this comment

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

The diff looks good.

One question and one nit below, but no blockers if CI passes.

I'll briefly test my config against this branch and report back

Copy link
Member

@MattSturgeon MattSturgeon left a comment

Choose a reason for hiding this comment

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

Tested my config with nixd, seems to be working. Above nits still relevant if you're interested in them.

@GaetanLepage GaetanLepage marked this pull request as draft April 23, 2025 08:49
@GaetanLepage GaetanLepage marked this pull request as ready for review April 23, 2025 09:13
@GaetanLepage GaetanLepage force-pushed the plugins-lsp branch 2 times, most recently from 2d91b58 to 18d4382 Compare April 23, 2025 13:25
Copy link
Contributor

@khaneliman khaneliman left a comment

Choose a reason for hiding this comment

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

Still works here in latest setup

@GaetanLepage

This comment was marked as resolved.

This comment has been minimized.

Copy link
Contributor

mergify bot commented Apr 23, 2025

This pull request, with head sha 78f6ff036918dcb6369f8b48abcef6a8788096e8, has been successfully merged with fast-forward by Mergify.

This pull request will be automatically closed by GitHub.

As soon as GitHub detects that the sha 78f6ff036918dcb6369f8b48abcef6a8788096e8 is part of the main branch, it will mark this pull request as merged.

It is possible for this pull request to remain open if this detection does not happen, this usually happens when a force-push is done on this branch plugins-lsp, this means GitHub will fail to detect the merge.

@mergify mergify bot merged commit 78f6ff0 into nix-community:main Apr 23, 2025
4 checks passed
@mergify mergify bot temporarily deployed to github-pages April 23, 2025 13:59 Inactive
@GaetanLepage GaetanLepage deleted the plugins-lsp branch April 23, 2025 14:01
@MattSturgeon
Copy link
Member

@GaetanLepage I think we may have to revert this for a while, as not all nvim-lspconfig configs are updated to work with the new API.

Our users are running into issues like:

Which may not be fully resolvable until neovim/nvim-lspconfig#3705 is complete and propagated to nixpkgs.

@GaetanLepage
Copy link
Member Author

GaetanLepage commented Apr 27, 2025

@GaetanLepage I think we may have to revert this for a while, as not all nvim-lspconfig configs are updated to work with the new API.

Our users are running into issues like:

Which may not be fully resolvable until neovim/nvim-lspconfig#3705 is complete and propagated to nixpkgs.

Sad. But yes, it is the wisest thing to do I guess.

MattSturgeon added a commit to MattSturgeon/nixvim that referenced this pull request Apr 27, 2025
MattSturgeon added a commit to MattSturgeon/nixvim that referenced this pull request Apr 28, 2025
@jfly
Copy link
Contributor

jfly commented May 4, 2025

Which may not be fully resolvable until neovim/nvim-lspconfig#3705 is complete and propagated to nixpkgs.

I haven't looked at the relevant code at all, but would it be possible to have a knob for "use vim.lsp native API" that for now defaults to false? I've submitted a number of bugfixes recently (neovim/neovim#33707, neovim/neovim#33703, neovim/neovim#33702) for the native API that I'd like to test out/benefit from.

@khaneliman
Copy link
Contributor

Which may not be fully resolvable until neovim/nvim-lspconfig#3705 is complete and propagated to nixpkgs.

I haven't looked at the relevant code at all, but would it be possible to have a knob for "use vim.lsp native API" that for now defaults to false? I've submitted a number of bugfixes recently (neovim/neovim#33707, neovim/neovim#33703, neovim/neovim#33702) for the native API that I'd like to test out/benefit from.

This Pr was reverted, lspconfig doesn't use it again.

@MattSturgeon
Copy link
Member

MattSturgeon commented May 4, 2025

I've submitted a number of bugfixes recently (neovim/neovim#33707, neovim/neovim#33703, neovim/neovim#33702) for the native API that I'd like to test out/benefit from.

Thanks! 😍

would it be possible to have a knob for "use vim.lsp native API" that for now defaults to false?

We kinda have that already; we're developing a new way of managing LSP in parallel to the old way staying mostly as-is for now.

The new design consists of plugins.lspconfig for installing nvim-lspconfg; this is basically just an enable option and a package option. Along with a top-level lsp module for managing the new vim.lsp.* lua API.

We're still calling the top-level lsp module experimental; e.g. some options may be renamed (feedback wanted there or on matrix!), but it should be working roughly as well as using the lua API manually 🤞

See:

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.

[BUG] Use nvim 0.11+ LSP API
4 participants