how to configure options for each server? #77
-
for example, in following code snippet, i have configured local function setup_lsp(on_attach)
local installed_servers = lspinstaller.get_installed_servers()
local capabilities = lsp.protocol.make_client_capabilities()
local lsp_options = {
on_attach = on_attach,
flags = {debounce_text_changes = 150, },
capabilities = require('cmp_nvim_lsp').update_capabilities(capabilities),
}
-- don't setup servers if atleast one server is installed, or it will throw an error
if #installed_servers == 0 then return end
for _, server in ipairs(installed_servers) do
local server_options = {}
-- for lua
if server.name == "sumneko_lua" then
server_options.settings = {
Lua = {
diagnostics = {
-- Get the language server to recognize the 'vim', 'use' global
globals = {'vim', 'use', 'require'},
},
workspace = {
-- Make the server aware of Neovim runtime files
library = vim.api.nvim_get_runtime_file("", true),
},
-- Do not send telemetry data containing a randomized but unique identifier
telemetry = {enable = false},
},
}
end
-- for clangd (c/c++)
-- [https://github.com/jose-elias-alvarez/null-ls.nvim/issues/428]
if server.name == "clangd" then
capabilities.offsetEncoding = { "utf-16" }
server_options.capabilities = capabilities
end
lspconfig[server.name].setup(vim.tbl_deep_extend('force', lsp_options, server_options))
end
end
|
Beta Was this translation helpful? Give feedback.
Answered by
williamboman
Jul 15, 2022
Replies: 2 comments 4 replies
-
Hello! What have you tried so far? Have you seen |
Beta Was this translation helpful? Give feedback.
4 replies
Answer selected by
shaeinst
-
I know this was already answered but here's how I handled it. Formatting is disabled because I use null-ls for that and I have the lsp mappings in another file. local vim = vim
local lspconfig = require("lspconfig")
require("mason").setup()
require("mason-lspconfig").setup({
ensure_installed = { "bashls", "sumneko_lua" },
})
local default_on_attach = function(client)
require("mappings").keys_lsp()
client.resolved_capabilities.document_formatting = false
client.resolved_capabilities.document_range_formatting = false
end
local default_capabilities = require("cmp_nvim_lsp").update_capabilities(vim.lsp.protocol.make_client_capabilities())
lspconfig.util.default_config = vim.tbl_extend("force", lspconfig.util.default_config, {
on_attach = default_on_attach,
capabilities = default_capabilities,
})
function M.setup_default()
require("mason-lspconfig").setup_handlers({
function(server_name)
lspconfig[server_name].setup({})
end,
["sumneko_lua"] = function()
lspconfig.sumneko_lua.setup({
settings = {
Lua = {
runtime = {
version = "LuaJIT",
},
diagnostics = {
globals = { "vim", "use", "require" },
},
workspace = {
library = vim.api.nvim_get_runtime_file("", true),
},
telemetry = {
enable = false,
},
},
},
})
end,
})
end |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello! What have you tried so far? Have you seen
:h mason-lspconfig
and:h mason-lspconfig-automatic-server-setup
in particular?