Last active
August 15, 2023 19:00
-
-
Save VonHeikemen/8406e6e2184207e45dd9816c81150137 to your computer and use it in GitHub Desktop.
Primeagen's LSP config without lsp-zero
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vim.opt.signcolumn = 'yes' | |
vim.diagnostic.config({ | |
virtual_text = true, | |
}) | |
vim.api.nvim_create_autocmd('LspAttach', { | |
desc = 'LSP keybindings', | |
callback = function(event) | |
local opts = {buffer = event.buf} | |
vim.keymap.set("n", "gd", function() vim.lsp.buf.definition() end, opts) | |
vim.keymap.set("n", "K", function() vim.lsp.buf.hover() end, opts) | |
vim.keymap.set("n", "<leader>vws", function() vim.lsp.buf.workspace_symbol() end, opts) | |
vim.keymap.set("n", "<leader>vd", function() vim.diagnostic.open_float() end, opts) | |
vim.keymap.set("n", "[d", function() vim.diagnostic.goto_next() end, opts) | |
vim.keymap.set("n", "]d", function() vim.diagnostic.goto_prev() end, opts) | |
vim.keymap.set("n", "<leader>vca", function() vim.lsp.buf.code_action() end, opts) | |
vim.keymap.set("n", "<leader>vrr", function() vim.lsp.buf.references() end, opts) | |
vim.keymap.set("n", "<leader>vrn", function() vim.lsp.buf.rename() end, opts) | |
vim.keymap.set("i", "<C-h>", function() vim.lsp.buf.signature_help() end, opts) | |
end | |
}) | |
local lspconfig = require('lspconfig') | |
local lsp_defaults = lspconfig.util.default_config | |
lsp_defaults.capabilities = vim.tbl_deep_extend( | |
'force', | |
lsp_defaults.capabilities, | |
require('cmp_nvim_lsp').default_capabilities() | |
) | |
require('mason').setup() | |
require('mason-lspconfig').setup({ | |
ensure_installed = { | |
'tsserver', | |
'lua_ls', | |
'rust_analyzer', | |
}, | |
handlers = { | |
function(server) | |
lspconfig[server].setup({}) | |
end, | |
lua_ls = function() | |
lspconfig.lua_ls.setup({ | |
settings = { | |
Lua = { | |
runtime = { | |
version = 'LuaJIT', | |
}, | |
diagnostics = { | |
globals = {'vim'} | |
}, | |
workspace = { | |
library = { | |
vim.env.VIMRUNTIME, | |
} | |
} | |
} | |
} | |
}) | |
end | |
} | |
}) | |
vim.opt.completeopt = {'menu', 'menuone', 'noselect'} | |
local cmp = require('cmp') | |
cmp.setup({ | |
snippet = { | |
expand = function(args) | |
require('luasnip').lsp_expand(args.body) | |
end, | |
}, | |
sources = { | |
{name = 'nvim_lsp'}, | |
{name = 'buffer'}, | |
}, | |
mapping = cmp.mapping.preset.insert({ | |
['<C-Space>'] = cmp.mapping.complete(), | |
['<C-b>'] = cmp.mapping.scroll_docs(-4), | |
['<C-f>'] = cmp.mapping.scroll_docs(4), | |
}), | |
window = { | |
documentation = cmp.config.window.bordered(), | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment