mirror of
https://github.com/arkorty/Neolite.git
synced 2026-03-18 00:57:12 +00:00
Merge commits till d9dba624a9502b0b172523dad30dc080e4170811 from dev to master
This commit is contained in:
90
lua/setup/nvim-lspconfig.lua
Normal file
90
lua/setup/nvim-lspconfig.lua
Normal file
@@ -0,0 +1,90 @@
|
||||
local lspconfig_status_ok, lspconfig = pcall(require, "lspconfig")
|
||||
if not lspconfig_status_ok then
|
||||
return
|
||||
end
|
||||
|
||||
local mason_status_ok, mason = pcall(require, "mason")
|
||||
if not mason_status_ok then
|
||||
return
|
||||
end
|
||||
|
||||
local mason_lspconfig_status_ok, mason_lspconfig = pcall(require, "mason-lspconfig")
|
||||
if not mason_lspconfig_status_ok then
|
||||
return
|
||||
end
|
||||
|
||||
mason.setup({})
|
||||
|
||||
mason_lspconfig.setup({
|
||||
ensure_installed = { "lua_ls", "rust_analyzer", "clangd", "marksman" },
|
||||
})
|
||||
|
||||
local cnl_ok, cmp_nvim_lsp = pcall(require, "cmp_nvim_lsp")
|
||||
if not cnl_ok then
|
||||
return
|
||||
end
|
||||
|
||||
local capabilities = cmp_nvim_lsp.default_capabilities()
|
||||
|
||||
mason_lspconfig.setup_handlers({
|
||||
function(server)
|
||||
lspconfig[server].setup({
|
||||
capabilities = capabilities,
|
||||
})
|
||||
lspconfig.lua_ls.setup({
|
||||
capabilities = capabilities,
|
||||
settings = {
|
||||
Lua = {
|
||||
diagnostics = {
|
||||
-- Get the language server to recognize the `vim` global
|
||||
globals = { "vim" },
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
end,
|
||||
["rust_analyzer"] = function()
|
||||
local rt_ok, rust_tools = pcall(require, "rust-tools")
|
||||
if rt_ok then
|
||||
rust_tools.setup({})
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
-- Global mappings.
|
||||
-- See `:help vim.diagnostic.*` for documentation on any of the below functions
|
||||
vim.keymap.set("n", "<Leader>e", vim.diagnostic.open_float)
|
||||
vim.keymap.set("n", "[d", vim.diagnostic.goto_prev)
|
||||
vim.keymap.set("n", "]d", vim.diagnostic.goto_next)
|
||||
vim.keymap.set("n", "<Leader>q", vim.diagnostic.setloclist)
|
||||
|
||||
-- Use LspAttach autocommand to only map the following keys
|
||||
-- after the language server attaches to the current buffer
|
||||
vim.api.nvim_create_autocmd("LspAttach", {
|
||||
group = vim.api.nvim_create_augroup("UserLspConfig", {}),
|
||||
callback = function(ev)
|
||||
-- Enable completion triggered by <c-x><c-o>
|
||||
vim.bo[ev.buf].omnifunc = "v:lua.vim.lsp.omnifunc"
|
||||
|
||||
-- Buffer local mappings.
|
||||
-- See `:help vim.lsp.*` for documentation on any of the below functions
|
||||
local opts = { buffer = ev.buf }
|
||||
vim.keymap.set("n", "gD", vim.lsp.buf.declaration, opts)
|
||||
vim.keymap.set("n", "gd", vim.lsp.buf.definition, opts)
|
||||
vim.keymap.set("n", "K", vim.lsp.buf.hover, opts)
|
||||
vim.keymap.set("n", "gi", vim.lsp.buf.implementation, opts)
|
||||
vim.keymap.set("n", "<C-k>", vim.lsp.buf.signature_help, opts)
|
||||
vim.keymap.set("n", "<Leader>wa", vim.lsp.buf.add_workspace_folder, opts)
|
||||
vim.keymap.set("n", "<Leader>wr", vim.lsp.buf.remove_workspace_folder, opts)
|
||||
vim.keymap.set("n", "<Leader>wl", function()
|
||||
print(vim.inspect(vim.lsp.buf.list_workLeader_folders()))
|
||||
end, opts)
|
||||
vim.keymap.set("n", "<Leader>D", vim.lsp.buf.type_definition, opts)
|
||||
vim.keymap.set("n", "<Leader>rn", vim.lsp.buf.rename, opts)
|
||||
vim.keymap.set({ "n", "v" }, "<Leader>ca", vim.lsp.buf.code_action, opts)
|
||||
vim.keymap.set("n", "gr", vim.lsp.buf.references, opts)
|
||||
vim.keymap.set("n", "<Leader>f", function()
|
||||
vim.lsp.buf.format({ async = true })
|
||||
end, opts)
|
||||
end,
|
||||
})
|
||||
Reference in New Issue
Block a user