From 72bac3930e8442faaea834724c2ef80440c505ed Mon Sep 17 00:00:00 2001 From: Revaz Nakhutsrishvili Date: Tue, 3 Sep 2024 11:02:19 +0400 Subject: add neovim config --- .config/nvim/lua/module/lsp.lua | 72 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 .config/nvim/lua/module/lsp.lua (limited to '.config/nvim/lua/module/lsp.lua') diff --git a/.config/nvim/lua/module/lsp.lua b/.config/nvim/lua/module/lsp.lua new file mode 100644 index 0000000..89b96cd --- /dev/null +++ b/.config/nvim/lua/module/lsp.lua @@ -0,0 +1,72 @@ +local lsp_zero = require "lsp-zero" + +lsp_zero.on_attach(function(client, bufnr) + lsp_zero.default_keymaps({ buffer = bufnr }) + + local opts = { buffer = bufnr } + vim.keymap.set("n", "r", "lua vim.lsp.buf.rename()", opts) + vim.keymap.set("n", "ca", "lua vim.lsp.buf.code_action()", opts) + vim.keymap.set("v", "fc", "lua vim.lsp.buf.format()", opts) +end) + +local cmp = require "cmp" + +cmp.setup { + mapping = cmp.mapping.preset.insert({ + [""] = cmp.mapping.confirm({ select = false }), + [""] = cmp.mapping.complete(), + [""] = cmp.mapping.select_next_item(), + [""] = cmp.mapping.select_prev_item(), + [""] = cmp.mapping.scroll_docs(-4), + [""] = cmp.mapping.scroll_docs(4), + }), + sources = cmp.config.sources({ + { name = "nvim_lsp" }, + }, { + { name = "buffer" }, + }) +} + +cmp.setup.cmdline({ "/", "?" }, { + mapping = cmp.mapping.preset.cmdline(), + sources = { + { name = "buffer" } + } +}) + +cmp.setup.cmdline(":", { + mapping = cmp.mapping.preset.cmdline(), + sources = cmp.config.sources({ + { name = "path" } + }, { + { name = "cmdline" } + }), + matching = { disallow_symbol_nonprefix_matching = false } +}) + +local lspconfig = require "lspconfig" +local mason = require "mason" +mason.setup {} + +local cmp_nvim = require "cmp_nvim_lsp" +local mason_lspconfig = require "mason-lspconfig" +mason_lspconfig.setup { + ensure_installed = { + "lua_ls", + "rust_analyzer", + "jedi_language_server", + "tsserver", + "eslint", + "jsonls", + "clangd", + "cmake", + "bashls" + }, + handlers = { + function(server_name) + lspconfig[server_name].setup { + capabilities = cmp_nvim.default_capabilities() + } + end, + } +} -- cgit v1.2.3-70-g09d2