Support ALL THE LSP #1784
Replies: 5 comments
-
|
I was thinking it might be cool if the lsp ftplugins can detect that the server isn't installed, e.g. Enable language support for C/C++ with: LspInstall cpp This would prompt new users to get things working. |
Beta Was this translation helpful? Give feedback.
-
|
That's a good idea. I'm not sure how to check tho.. |
Beta Was this translation helpful? Give feedback.
-
|
Maybe this is to simple. Would it be a good start to check if the pre definded installation folder of the given lsp is empty? |
Beta Was this translation helpful? Give feedback.
-
|
we can check for the presence of the LSP by checking if it is executable in path or not. mayvbe that can help |
Beta Was this translation helpful? Give feedback.
-
|
Supporting all LSP servers in a unified config is a good goal — the key is a declarative approach that doesn't require manual setup for each server. The -- Automatic LSP setup via mason-lspconfig
return {
{
"williamboman/mason.nvim",
config = true,
},
{
"williamboman/mason-lspconfig.nvim",
opts = {
-- Auto-install missing LSPs
automatic_installation = true,
ensure_installed = {
"lua_ls", "pyright", "ts_ls", "rust_analyzer",
"gopls", "clangd", "jsonls", "yamlls",
},
},
},
{
"neovim/nvim-lspconfig",
config = function()
local lspconfig = require("lspconfig")
local capabilities = require("cmp_nvim_lsp").default_capabilities()
-- Default config applied to ALL servers
local default_opts = {
capabilities = capabilities,
on_attach = function(client, bufnr)
-- Keymaps applied to every LSP buffer
vim.keymap.set("n", "gd", vim.lsp.buf.definition, { buffer = bufnr })
vim.keymap.set("n", "K", vim.lsp.buf.hover, { buffer = bufnr })
vim.keymap.set("n", "<leader>ca", vim.lsp.buf.code_action, { buffer = bufnr })
end,
}
-- Server-specific overrides
local server_opts = {
lua_ls = {
settings = { Lua = { diagnostics = { globals = { "vim" } } } }
},
rust_analyzer = {
settings = { ["rust-analyzer"] = { checkOnSave = { command = "clippy" } } }
},
}
-- Apply to all installed servers
require("mason-lspconfig").setup_handlers({
function(server_name)
local opts = vim.tbl_deep_extend("force", default_opts, server_opts[server_name] or {})
lspconfig[server_name].setup(opts)
end,
})
end,
},
}This pattern means: add a server to |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
https://github.com/neovim/nvim-lspconfig/blob/master/CONFIG.md
Everything here should be supported
Beta Was this translation helpful? Give feedback.
All reactions