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', '', vim.diagnostic.open_float, opts) --keymap('i', '', vim.diagnostic.goto_prev, opts) --keymap('i', '', vim.diagnostic.goto_next, opts) --keymap('i', '', cmp.mapping.complete(), opts) --keymap('i', '', vim.diagnostic.setloclist, opts) keymap('n', '', vim.diagnostic.open_float, opts) keymap('n', '', vim.diagnostic.goto_prev, opts) keymap('n', '', vim.diagnostic.goto_next, opts) --keymap('i', '', cmp.mapping.complete(), opts) keymap('n', '', vim.diagnostic.setloclist, opts) cmp.setup({ snippet = { expand = function(args) require('luasnip').lsp_expand(args.body) end, }, mapping = { [''] = cmp.mapping.select_prev_item(cmp_select), [''] = cmp.mapping.select_next_item(cmp_select), [''] = cmp.mapping.complete(cmp_select), [''] = cmp.mapping.close(), [''] = 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", "Telescope lsp_definitions", opts) vim.keymap.set("n", "gr", "Telescope lsp_references", opts) vim.keymap.set("n", "", "Telescope lsp_document_symbols", opts) vim.keymap.set("n", "", "lua vim.lsp.buf.signature_help()", opts) vim.keymap.set("n", "gi", "Telescope lsp_implementations", opts) vim.keymap.set("n", "K", "lua vim.lsp.buf.hover()", opts) vim.keymap.set("n", "D", "Telescope lsp_type_definitions", opts) vim.keymap.set("n", "rn", "lua vim.lsp.buf.rename()", opts) vim.keymap.set("n", "ca", "Telescope lsp_code_actions", 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", "dj", vim.diagnostic.goto_next, {buffer=0}) vim.keymap.set("n", "dk", vim.diagnostic.goto_prev, {buffer=0}) vim.keymap.set("n", "dl", "Telescope diagnostics", {buffer=0}) vim.keymap.set("n", "r", vim.lsp.buf.rename, {buffer=0}) vim.keymap.set("n", "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! * autocmd CursorHold lua vim.lsp.buf.document_highlight() autocmd CursorMoved 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, }