summaryrefslogtreecommitdiffstats
path: root/.config/nvim/lua/module/lsp.lua
diff options
context:
space:
mode:
authorRevaz Nakhutsrishvili <r@revaz.xyz>2024-09-03 11:02:19 +0400
committerRevaz Nakhutsrishvili <r@revaz.xyz>2024-09-03 11:02:19 +0400
commit72bac3930e8442faaea834724c2ef80440c505ed (patch)
tree0910c73f912cc9f747921f408decbd73a97fecb9 /.config/nvim/lua/module/lsp.lua
parentaa8c3484100b2b7e84a7aa8c7e416dde484b25ee (diff)
add neovim config
Diffstat (limited to '.config/nvim/lua/module/lsp.lua')
-rw-r--r--.config/nvim/lua/module/lsp.lua72
1 files changed, 72 insertions, 0 deletions
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", "<leader>r", "<cmd>lua vim.lsp.buf.rename()<cr>", opts)
+ vim.keymap.set("n", "<leader>ca", "<cmd>lua vim.lsp.buf.code_action()<cr>", opts)
+ vim.keymap.set("v", "<leader>fc", "<cmd>lua vim.lsp.buf.format()<cr>", opts)
+end)
+
+local cmp = require "cmp"
+
+cmp.setup {
+ mapping = cmp.mapping.preset.insert({
+ ["<CR>"] = cmp.mapping.confirm({ select = false }),
+ ["<C-Space>"] = cmp.mapping.complete(),
+ ["<C-j>"] = cmp.mapping.select_next_item(),
+ ["<C-k>"] = cmp.mapping.select_prev_item(),
+ ["<C-u>"] = cmp.mapping.scroll_docs(-4),
+ ["<C-d>"] = 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,
+ }
+}