-
Notifications
You must be signed in to change notification settings - Fork 36k
feat: add support for new LSP config API in Neovim 0.11+ #1475
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
base: master
Are you sure you want to change the base?
Changes from all commits
3f0cd75
f70dcb3
4b81900
5502cea
a590ab6
dac395d
531073d
81c5210
9e0c7b6
0018683
f9628e5
718c90d
82949b8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -655,12 +655,6 @@ require('lazy').setup({ | |
}, | ||
} | ||
|
||
-- LSP servers and clients are able to communicate to each other what features they support. | ||
-- By default, Neovim doesn't support everything that is in the LSP specification. | ||
-- When you add blink.cmp, luasnip, etc. Neovim now has *more* capabilities. | ||
-- So, we create new capabilities with blink.cmp, and then broadcast that to the servers. | ||
local capabilities = require('blink.cmp').get_lsp_capabilities() | ||
|
||
-- Enable the following language servers | ||
-- Feel free to add/remove any LSPs that you want here. They will automatically be installed. | ||
-- | ||
|
@@ -699,6 +693,11 @@ require('lazy').setup({ | |
}, | ||
}, | ||
} | ||
---@type MasonLspconfigSettings | ||
---@diagnostic disable-next-line: missing-fields | ||
require('mason-lspconfig').setup { | ||
automatic_enable = vim.tbl_keys(servers or {}), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I looked into the source code of mason-lspconfig. When the keys of In the -- To only enable certain servers to be automatically enabled:
-- ```lua
-- automatic_enable = {
-- "lua_ls",
-- "vimls"
-- }
-- ``` In the function M.setup(config)
if config then
settings.set(config)
end
--- ...
local registry = require "mason-registry"
registry.refresh(vim.schedule_wrap(function(success, updated_registries)
if success and #updated_registries > 0 and settings.current.automatic_enable ~= false then
require("mason-lspconfig.features.automatic_enable").enable_all()
end
end))
if settings.current.automatic_enable ~= false then
require("mason-lspconfig.features.automatic_enable").init()
end
-- ...
end In return {
init = function()
enabled_servers = {}
_.each(enable_server, registry.get_installed_package_names())
-- We deregister the event handler primarily for testing purposes where .setup() is called multiple times in the
-- same instance.
registry:off("package:install:success", enable_server_scheduled)
registry:on("package:install:success", enable_server_scheduled)
end,
enable_all = function()
_.each(enable_server, registry.get_installed_package_names())
end,
} However, in local function enable_server(mason_pkg)
-- ...
local lspconfig_name = mappings.get_mason_map().package_to_lspconfig[mason_pkg]
-- ...
local automatic_enable = settings.current.automatic_enable
if type(automatic_enable) == "table" then
local exclude = automatic_enable.exclude
if exclude then
if _.any(_.equals(lspconfig_name), exclude) then
-- This server is explicitly excluded.
return
end
else
if not _.any(_.equals(lspconfig_name), automatic_enable) then
-- This server is not explicitly enabled.
return
end
end
elseif automatic_enable == false then
return
end
-- ...
vim.lsp.enable(lspconfig_name)
-- ...
end In other words, even if I’ve already installed the LSPs via Mason, I still have to list all the LSPs I use in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems you are right about Despite that , I still prefer declarativly specifying all the LSPs in the config file, instead of downloading them using the mason interface. Though I guess this is a matter of taste, and could break setups for people that were used to the old way, so I'm ok with both options :) @umutondersu @SetsuikiHyoryu what do you think? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Personally, I prefer the more “lazy” approach, but I tend to follow the method recommended by the Neovim official because I feel it’s more native. That means the operational habits won’t differ too much even when I have to work in a barebones environment. However, I’m not entirely sure what the official philosophy is on this. Judging from the existence of the
Sorry, it seems that |
||
} | ||
|
||
-- Ensure the servers and tools above are installed | ||
-- | ||
|
@@ -719,20 +718,14 @@ require('lazy').setup({ | |
}) | ||
require('mason-tool-installer').setup { ensure_installed = ensure_installed } | ||
|
||
require('mason-lspconfig').setup { | ||
ensure_installed = {}, -- explicitly set to an empty table (Kickstart populates installs via mason-tool-installer) | ||
automatic_installation = false, | ||
handlers = { | ||
function(server_name) | ||
local server = servers[server_name] or {} | ||
-- This handles overriding only values explicitly passed | ||
-- by the server configuration above. Useful when disabling | ||
-- certain features of an LSP (for example, turning off formatting for ts_ls) | ||
server.capabilities = vim.tbl_deep_extend('force', {}, capabilities, server.capabilities or {}) | ||
require('lspconfig')[server_name].setup(server) | ||
end, | ||
}, | ||
} | ||
-- Installed LSPs are configured and enabled automatically with mason-lspconfig | ||
-- The loop below is for overriding the default configuration of LSPs with the ones in the servers table | ||
for server_name, config in pairs(servers) do | ||
vim.lsp.config(server_name, config) | ||
umutondersu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
end | ||
|
||
-- NOTE: Some servers may require an old setup until they are updated. For the full list refer here: https://github.com/neovim/nvim-lspconfig/issues/3705 | ||
-- These servers will have to be manually set up with require("lspconfig").server_name.setup{} | ||
end, | ||
}, | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.