New neovim config.
I've been using neovim for a while but the config got messy so here is a cleaner config. Signed-off-by: Louis Hollingworth <louis@hollingworth.nl>
This commit is contained in:
commit
c5000e27eb
11 changed files with 389 additions and 0 deletions
135
after/plugin/lsp.lua
Normal file
135
after/plugin/lsp.lua
Normal file
|
|
@ -0,0 +1,135 @@
|
|||
local keymap = vim.keymap.set
|
||||
|
||||
require('mason').setup({
|
||||
ui = {
|
||||
icons = {
|
||||
server = " ",
|
||||
lsp = " ",
|
||||
linter = " ",
|
||||
formatter = " ",
|
||||
|
||||
package_installed = "✓",
|
||||
package_pending = "➜",
|
||||
package_uninstalled = "✗"
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
require("mason-lspconfig").setup({
|
||||
automatic_installation = true,
|
||||
})
|
||||
|
||||
local lsp = require('lspconfig')
|
||||
|
||||
local cmp = require('cmp')
|
||||
local cmp_select = {behavior = cmp.SelectBehavior.Select}
|
||||
|
||||
local opts = { noremap=true, silent=true }
|
||||
--keymap('i', '<C-Space>', vim.diagnostic.open_float, opts)
|
||||
--keymap('i', '<C-p>', vim.diagnostic.goto_prev, opts)
|
||||
--keymap('i', '<C-n>', vim.diagnostic.goto_next, opts)
|
||||
--keymap('i', '<C-Space>', cmp.mapping.complete(), opts)
|
||||
--keymap('i', '<CR>', vim.diagnostic.setloclist, opts)
|
||||
keymap('n', '<C-Space>', vim.diagnostic.open_float, opts)
|
||||
keymap('n', '<C-p>', vim.diagnostic.goto_prev, opts)
|
||||
keymap('n', '<C-n>', vim.diagnostic.goto_next, opts)
|
||||
--keymap('i', '<C-Space>', cmp.mapping.complete(), opts)
|
||||
keymap('n', '<CR>', vim.diagnostic.setloclist, opts)
|
||||
|
||||
cmp.setup({
|
||||
snippet = {
|
||||
expand = function(args)
|
||||
require('luasnip').lsp_expand(args.body)
|
||||
end,
|
||||
},
|
||||
mapping = {
|
||||
['<C-p>'] = cmp.mapping.select_prev_item(cmp_select),
|
||||
['<C-n>'] = cmp.mapping.select_next_item(cmp_select),
|
||||
['<C-Space>'] = cmp.mapping.complete(cmp_select),
|
||||
['<C-e>'] = cmp.mapping.close(),
|
||||
['<CR>'] = cmp.mapping.confirm({
|
||||
behavior = cmp.ConfirmBehavior.Replace,
|
||||
select = true,
|
||||
}),
|
||||
},
|
||||
sources = {
|
||||
{ name = 'nvim_lsp' },
|
||||
{ name = 'luasnip' },
|
||||
{ name = 'buffer' },
|
||||
},
|
||||
})
|
||||
|
||||
vim.diagnostic.config({
|
||||
virtual_text = true,
|
||||
})
|
||||
|
||||
local on_attach = function(client, bufnr)
|
||||
local function buf_set_keymap(...)
|
||||
vim.api.nvim_buf_set_keymap(bufnr, ...)
|
||||
end
|
||||
|
||||
-- Mappings.
|
||||
local opts = { noremap = true, silent = true, buffer = bufnr}
|
||||
|
||||
-- See `:help vim.lsp.*` for documentation on any of the below functions
|
||||
vim.keymap.set("n", "gd", "<cmd>Telescope lsp_definitions<CR>", opts)
|
||||
vim.keymap.set("n", "gr", "<cmd>Telescope lsp_references<CR>", opts)
|
||||
|
||||
vim.keymap.set("n", "<C-j>", "<cmd>Telescope lsp_document_symbols<CR>", opts)
|
||||
vim.keymap.set("n", "<C-k>", "<cmd>lua vim.lsp.buf.signature_help()<CR>", opts)
|
||||
|
||||
vim.keymap.set("n", "gi", "<cmd>Telescope lsp_implementations<CR>", opts)
|
||||
vim.keymap.set("n", "K", "<cmd>lua vim.lsp.buf.hover()<CR>", opts)
|
||||
vim.keymap.set("n", "<leader>D", "<cmd>Telescope lsp_type_definitions<CR>", opts)
|
||||
vim.keymap.set("n", "<leader>rn", "<cmd>lua vim.lsp.buf.rename()<CR>", opts)
|
||||
vim.keymap.set("n", "<leader>ca", "<cmd>Telescope lsp_code_actions<CR>", opts)
|
||||
vim.keymap.set("n", "gt", vim.lsp.buf.type_definition, {buffer=0})
|
||||
vim.keymap.set("n", "gi", vim.lsp.buf.implementation, {buffer=0})
|
||||
vim.keymap.set("n", "<leader>dj", vim.diagnostic.goto_next, {buffer=0})
|
||||
vim.keymap.set("n", "<leader>dk", vim.diagnostic.goto_prev, {buffer=0})
|
||||
vim.keymap.set("n", "<leader>dl", "<cmd>Telescope diagnostics<cr>", {buffer=0})
|
||||
vim.keymap.set("n", "<leader>r", vim.lsp.buf.rename, {buffer=0})
|
||||
vim.keymap.set("n", "<leader>ca", vim.lsp.buf.code_action, {buffer=0})
|
||||
|
||||
-- Set autocommands conditional on server_capabilities
|
||||
if client.server_capabilities.document_highlight then
|
||||
vim.cmd([[
|
||||
augroup lsp_document_highlight
|
||||
autocmd! * <buffer>
|
||||
autocmd CursorHold <buffer> lua vim.lsp.buf.document_highlight()
|
||||
autocmd CursorMoved <buffer> lua vim.lsp.buf.clear_references()
|
||||
augroup END
|
||||
]])
|
||||
end
|
||||
end
|
||||
|
||||
lsp.gopls.setup({
|
||||
on_attach = on_attach,
|
||||
flags = lsp_flags,
|
||||
settings = {
|
||||
gopls = {
|
||||
analyses = {
|
||||
unusedparams = true,
|
||||
},
|
||||
staticcheck = true,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
lsp['lua_ls'].setup{
|
||||
on_attach = on_attach,
|
||||
flags = lsp_flags,
|
||||
}
|
||||
|
||||
lsp['rust_analyzer'].setup{
|
||||
on_attach = on_attach,
|
||||
flags = lsp_flags,
|
||||
cmd = {
|
||||
"rustup", "run", "stable", "rust-analyzer",
|
||||
}
|
||||
}
|
||||
|
||||
lsp.tsserver.setup{
|
||||
on_attach = on_attach,
|
||||
flags = lsp_flags,
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue