nvim-config/after/plugin/lsp.lua

199 lines
5.1 KiB
Lua
Raw Permalink Normal View History

2022-11-01 18:09:46 +01:00
local Remap = require("serxoz.keymap")
local nnoremap = Remap.nnoremap
local inoremap = Remap.inoremap
-- local sumneko_root_path = "/home/mpaulson/personal/sumneko"
-- local sumneko_binary = sumneko_root_path .. "/bin/lua-language-server"
-- Setup nvim-cmp.
local cmp = require("cmp")
local source_mapping = {
buffer = "[Buffer]",
nvim_lsp = "[LSP]",
nvim_lua = "[Lua]",
path = "[Path]",
}
local lspkind = require("lspkind")
cmp.setup({
snippet = {
expand = function(args)
-- For `vsnip` user.
-- vim.fn["vsnip#anonymous"](args.body)
-- For `luasnip` user.
require("luasnip").lsp_expand(args.body)
-- For `ultisnips` user.
-- vim.fn["UltiSnips#Anon"](args.body)
end,
},
mapping = cmp.mapping.preset.insert({
['<C-y>'] = cmp.mapping.confirm({ select = true }),
["<C-u>"] = cmp.mapping.scroll_docs(-4),
["<C-d>"] = cmp.mapping.scroll_docs(4),
["<C-Space>"] = cmp.mapping.complete(),
}),
formatting = {
format = function(entry, vim_item)
vim_item.kind = lspkind.presets.default[vim_item.kind]
local menu = source_mapping[entry.source.name]
vim_item.menu = menu
return vim_item
end,
},
sources = {
{ name = "nvim_lsp" },
-- For vsnip user.
-- { name = 'vsnip' },
-- For luasnip user.
{ name = "luasnip" },
-- For ultisnips user.
-- { name = 'ultisnips' },
{ name = "buffer" },
},
})
local function config(_config)
return vim.tbl_deep_extend("force", {
on_attach = function()
2022-12-26 16:32:50 +01:00
nnoremap("gd", function() vim.lsp.buf.definition() end, '[G]oto [D]efinition')
nnoremap("K", function() vim.lsp.buf.hover() end, 'Hover Documentation')
2022-11-01 18:09:46 +01:00
nnoremap("<leader>vws", function() vim.lsp.buf.workspace_symbol() end)
nnoremap("<leader>vd", function() vim.diagnostic.open_float() end)
nnoremap("[d", function() vim.diagnostic.goto_next() end)
nnoremap("]d", function() vim.diagnostic.goto_prev() end)
nnoremap("<leader>vca", function() vim.lsp.buf.code_action() end)
nnoremap("<leader>vco", function() vim.lsp.buf.code_action({
filter = function(code_action)
if not code_action or not code_action.data then
return false
end
local data = code_action.data.id
return string.sub(data, #data - 1, #data) == ":0"
end,
apply = true
}) end)
nnoremap("<leader>vrr", function() vim.lsp.buf.references() end)
nnoremap("<leader>vrn", function() vim.lsp.buf.rename() end)
inoremap("<C-h>", function() vim.lsp.buf.signature_help() end)
end,
}, _config or {})
end
require("lspconfig").zls.setup(config())
require("lspconfig").tsserver.setup(config())
require("lspconfig").ccls.setup(config())
require("lspconfig").jedi_language_server.setup(config())
require("lspconfig").svelte.setup(config())
require("lspconfig").solang.setup(config())
require("lspconfig").cssls.setup(config())
require("lspconfig").gopls.setup(config({
cmd = { "gopls", "serve" },
settings = {
gopls = {
analyses = {
unusedparams = true,
},
staticcheck = true,
},
},
}))
-- who even uses this?
require("lspconfig").rust_analyzer.setup(config({
cmd = { "rustup", "run", "stable", "rust-analyzer" },
2022-11-01 18:09:46 +01:00
-- cmd = { "rustup", "run", "rust-analyzer" },
-- cmd = { "rust-analyzer" },
2022-11-16 11:54:03 +01:00
[[
settings = {
rust = {
unstable_features = true,
build_on_save = false,
all_features = true,
},
["rust-analyzer"] = {
diagnostics = {
enable = true,
disabled = {"unresolved-proc-macro"},
enableExperimental = true,
},
},
}
]]
2022-11-01 18:09:46 +01:00
}))
--require("lspconfig").sumneko_lua.setup(config({
-- cmd = { sumneko_binary, "-E", sumneko_root_path .. "/main.lua" },
-- settings = {
-- Lua = {
-- runtime = {
-- -- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim)
-- version = "LuaJIT",
-- -- Setup your lua path
-- path = vim.split(package.path, ";"),
-- },
-- diagnostics = {
-- -- Get the language server to recognize the `vim` global
-- globals = { "vim" },
-- },
-- workspace = {
-- -- Make the server aware of Neovim runtime files
-- library = {
-- [vim.fn.expand("$VIMRUNTIME/lua")] = true,
-- [vim.fn.expand("$VIMRUNTIME/lua/vim/lsp")] = true,
-- },
-- },
-- },
-- },
--}))
local opts = {
-- whether to highlight the currently hovered symbol
-- disable if your cpu usage is higher than you want it
-- or you just hate the highlight
-- default: true
highlight_hovered_item = true,
-- whether to show outline guides
-- default: true
show_guides = true,
}
require("symbols-outline").setup(opts)
local snippets_paths = function()
local plugins = { "friendly-snippets" }
local paths = {}
local path
local root_path = vim.env.HOME .. "/.vim/plugged/"
for _, plug in ipairs(plugins) do
path = root_path .. plug
if vim.fn.isdirectory(path) ~= 0 then
table.insert(paths, path)
end
end
return paths
end
require("luasnip.loaders.from_vscode").lazy_load({
paths = snippets_paths(),
include = nil, -- Load all languages
exclude = {},
})