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
119
init.lua
119
init.lua
|
@ -562,43 +562,86 @@ require('lazy').setup({
|
||||||
-- - capabilities (table): Override fields in capabilities. Can be used to disable certain LSP features.
|
-- - 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.
|
-- - 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/
|
-- For example, to see the options for `lua_ls`, you could go to: https://luals.github.io/wiki/settings/
|
||||||
local servers = {
|
local lspconfig = require 'lspconfig'
|
||||||
-- clangd = {},
|
|
||||||
-- gopls = {},
|
|
||||||
-- pyright = {},
|
|
||||||
-- rust_analyzer = {},
|
|
||||||
-- ... 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:
|
|
||||||
-- https://github.com/pmizio/typescript-tools.nvim
|
|
||||||
--
|
|
||||||
-- But for many setups, the LSP (`tsserver`) will work just fine
|
|
||||||
-- tsserver = {},
|
|
||||||
--
|
|
||||||
|
|
||||||
lua_ls = {
|
lspconfig.clangd.setup {
|
||||||
-- cmd = {...},
|
capabilities = capabilities,
|
||||||
-- filetypes = { ...},
|
}
|
||||||
-- capabilities = {},
|
lspconfig.gopls.setup {
|
||||||
settings = {
|
capabilities = capabilities,
|
||||||
Lua = {
|
}
|
||||||
completion = {
|
lspconfig.pylsp.setup {
|
||||||
callSnippet = 'Replace',
|
capabilities = capabilities,
|
||||||
},
|
}
|
||||||
-- You can toggle below to ignore Lua_LS's noisy `missing-fields` warnings
|
|
||||||
-- diagnostics = { disable = { 'missing-fields' } },
|
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
|
||||||
-- 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.
|
-- Some languages (like typescript) have entire language plugins that can be useful:
|
||||||
require('mason').setup()
|
-- https://github.com/pmizio/typescript-tools.nvim
|
||||||
|
--
|
||||||
|
-- But for many setups, the LSP (`tsserver`) will work just fine
|
||||||
|
-- tsserver = {},
|
||||||
|
--
|
||||||
|
|
||||||
|
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' } },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
-- You can add other tools here that you want Mason to install
|
-- You can add other tools here that you want Mason to install
|
||||||
-- for you, so that they are available from within Neovim.
|
-- for you, so that they are available from within Neovim.
|
||||||
|
@ -606,20 +649,6 @@ require('lazy').setup({
|
||||||
vim.list_extend(ensure_installed, {
|
vim.list_extend(ensure_installed, {
|
||||||
'stylua', -- Used to format Lua code
|
'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,
|
end,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue