refacto: use locally installed lsp
Also enable LSP for rust, lua, go and python.
This commit is contained in:
parent
dae839ed46
commit
d09fb0686a
1 changed files with 74 additions and 45 deletions
87
init.lua
87
init.lua
|
@ -562,11 +562,46 @@ require('lazy').setup({
|
|||
-- - capabilities (table): Override fields in capabilities. Can be used to disable certain LSP features.
|
||||
-- - settings (table): Override the default settings passed when initializing the server.
|
||||
-- For example, to see the options for `lua_ls`, you could go to: https://luals.github.io/wiki/settings/
|
||||
local servers = {
|
||||
-- clangd = {},
|
||||
-- gopls = {},
|
||||
-- pyright = {},
|
||||
-- rust_analyzer = {},
|
||||
local lspconfig = require 'lspconfig'
|
||||
|
||||
lspconfig.clangd.setup {
|
||||
capabilities = capabilities,
|
||||
}
|
||||
lspconfig.gopls.setup {
|
||||
capabilities = capabilities,
|
||||
}
|
||||
lspconfig.pylsp.setup {
|
||||
capabilities = capabilities,
|
||||
}
|
||||
|
||||
local on_attach = function(client, bufnr)
|
||||
-- require'completion'.on_attach(client)
|
||||
vim.lsp.inlay_hint.enable(true, { bufnr = bufnr })
|
||||
end
|
||||
|
||||
lspconfig.rust_analyzer.setup {
|
||||
capabilities = capabilities,
|
||||
on_attach = on_attach,
|
||||
['rust-analyzer'] = {
|
||||
diagnostics = {
|
||||
enable = true,
|
||||
},
|
||||
imports = {
|
||||
granularity = {
|
||||
group = 'module',
|
||||
},
|
||||
prefix = 'self',
|
||||
},
|
||||
cargo = {
|
||||
buildScripts = {
|
||||
enable = true,
|
||||
},
|
||||
},
|
||||
procMacro = {
|
||||
enable = true,
|
||||
},
|
||||
},
|
||||
}
|
||||
-- ... etc. See `:help lspconfig-all` for a list of all the pre-configured LSPs
|
||||
--
|
||||
-- Some languages (like typescript) have entire language plugins that can be useful:
|
||||
|
@ -576,50 +611,44 @@ require('lazy').setup({
|
|||
-- tsserver = {},
|
||||
--
|
||||
|
||||
lua_ls = {
|
||||
lspconfig.lua_ls.setup {
|
||||
-- cmd = {...},
|
||||
-- filetypes = { ...},
|
||||
-- capabilities = {},
|
||||
capabilities = capabilities,
|
||||
settings = {
|
||||
Lua = {
|
||||
completion = {
|
||||
callSnippet = 'Replace',
|
||||
},
|
||||
runtime = {
|
||||
-- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim)
|
||||
version = 'LuaJIT',
|
||||
},
|
||||
diagnostics = {
|
||||
-- Get the language server to recognize the `vim` global
|
||||
globals = { 'vim' },
|
||||
},
|
||||
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,
|
||||
},
|
||||
-- You can toggle below to ignore Lua_LS's noisy `missing-fields` warnings
|
||||
-- diagnostics = { disable = { 'missing-fields' } },
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
-- Ensure the servers and tools above are installed
|
||||
-- To check the current status of installed tools and/or manually install
|
||||
-- other tools, you can run
|
||||
-- :Mason
|
||||
--
|
||||
-- You can press `g?` for help in this menu.
|
||||
require('mason').setup()
|
||||
|
||||
-- You can add other tools here that you want Mason to install
|
||||
-- for you, so that they are available from within Neovim.
|
||||
local ensure_installed = vim.tbl_keys(servers or {})
|
||||
vim.list_extend(ensure_installed, {
|
||||
'stylua', -- Used to format Lua code
|
||||
})
|
||||
require('mason-tool-installer').setup { ensure_installed = ensure_installed }
|
||||
|
||||
require('mason-lspconfig').setup {
|
||||
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 tsserver)
|
||||
server.capabilities = vim.tbl_deep_extend('force', {}, capabilities, server.capabilities or {})
|
||||
require('lspconfig')[server_name].setup(server)
|
||||
end,
|
||||
},
|
||||
}
|
||||
end,
|
||||
},
|
||||
|
||||
|
|
Loading…
Reference in a new issue