From 1e985677c2c8d930aa919171edb71b441e6952d2 Mon Sep 17 00:00:00 2001 From: Seymur Bagirov Date: Sat, 20 Jan 2024 01:45:39 +0400 Subject: [PATCH] reenable lsp functionality and fix some stuff for lazy --- nvim/lua/themystery/plugins/init.lua | 50 ++++---- nvim/lua/themystery/plugins/lsp.lua | 169 +++++++++++++++++++++++++++ 2 files changed, 192 insertions(+), 27 deletions(-) create mode 100644 nvim/lua/themystery/plugins/lsp.lua diff --git a/nvim/lua/themystery/plugins/init.lua b/nvim/lua/themystery/plugins/init.lua index b7a50e3..83d10ed 100644 --- a/nvim/lua/themystery/plugins/init.lua +++ b/nvim/lua/themystery/plugins/init.lua @@ -16,9 +16,20 @@ return { vim.keymap.set("n", "u", vim.cmd.UndotreeToggle) end }, - "lewis6991/gitsigns.nvim", - "windwp/nvim-ts-autotag", - "windwp/nvim-autopairs", + { + "lewis6991/gitsigns.nvim", + opts = {} + }, + { + "windwp/nvim-ts-autotag", + event = "InsertEnter", + opts = {} + }, + { + "windwp/nvim-autopairs", + event = "InsertEnter", + opts = {} + }, { "kosayoda/nvim-lightbulb", opts = { @@ -27,7 +38,15 @@ return { }, { "lukas-reineke/indent-blankline.nvim", main = "ibl", opts = {} }, "mfussenegger/nvim-dap", - "folke/neodev.nvim", + { + "folke/neodev.nvim", + dependencies = { "rcarriga/nvim-dap-ui" }, + config = function() + require("neodev").setup({ + library = { plugins = { "nvim-dap-ui" }, types = true } + }) + end + }, { "ionide/Ionide-vim", event = "VimEnter" @@ -41,27 +60,4 @@ return { }, "SmiteshP/nvim-navic", "Decodetalkers/csharpls-extended-lsp.nvim", - { - 'VonHeikemen/lsp-zero.nvim', - branch = 'v3.x', - dependencies = { - -- LSP Support - 'neovim/nvim-lspconfig', - 'williamboman/mason.nvim', - 'williamboman/mason-lspconfig.nvim', - - -- Autocompletion - 'hrsh7th/nvim-cmp', - 'hrsh7th/cmp-buffer', - 'hrsh7th/cmp-path', - 'saadparwaiz1/cmp_luasnip', - 'hrsh7th/cmp-nvim-lsp', - 'hrsh7th/cmp-nvim-lua', - - -- Snippets - 'L3MON4D3/LuaSnip', - 'rafamadriz/friendly-snippets', - } - } - } diff --git a/nvim/lua/themystery/plugins/lsp.lua b/nvim/lua/themystery/plugins/lsp.lua new file mode 100644 index 0000000..22c93ea --- /dev/null +++ b/nvim/lua/themystery/plugins/lsp.lua @@ -0,0 +1,169 @@ +return { + 'VonHeikemen/lsp-zero.nvim', + branch = 'v3.x', + dependencies = { + -- LSP Support + 'neovim/nvim-lspconfig', + 'williamboman/mason.nvim', + 'williamboman/mason-lspconfig.nvim', + + -- Autocompletion + 'hrsh7th/nvim-cmp', + 'hrsh7th/cmp-buffer', + 'hrsh7th/cmp-path', + 'saadparwaiz1/cmp_luasnip', + 'hrsh7th/cmp-nvim-lsp', + 'hrsh7th/cmp-nvim-lua', + + -- Snippets + 'L3MON4D3/LuaSnip', + 'rafamadriz/friendly-snippets', + + -- extras + "SmiteshP/nvim-navic", + "Decodetalkers/csharpls-extended-lsp.nvim", + }, + config = function() + local lsp = require("lsp-zero") + + lsp.configure('csharp_ls', { + handlers = { + ["textDocument/definition"] = require("csharpls_extended").handler, + ["textDocument/typeDefinition"] = require("csharpls_extended").handler + } + }) + + lsp.configure('clangd', { + cmd = { 'clangd', '--offset-encoding=utf-16' }, + }) + -- this code makes it so that the css language server doesn't complain about tailwindcss classes + lsp.configure("cssls", { + settings = { + css = { + lint = { unknownAtRules = "ignore" } + }, + scss = { + lint = { unknownAtRules = "ignore" } + }, + less = { + lint = { unknownAtRules = "ignore" } + } + } + }) + + lsp.set_server_config({ + capabilities = { + textDocument = { + foldingRange = { + dynamicRegistration = false, + lineFoldingOnly = true + } + } + } + }) + + + local cmp = require('cmp') + local cmp_action = lsp.cmp_action() + local cmp_format = lsp.cmp_format() + + require('luasnip.loaders.from_vscode').lazy_load() + + vim.opt.completeopt = {'menu', 'menuone', 'noselect'} + + cmp.setup({ + formatting = cmp_format, + preselect = 'item', + completion = { + completeopt = 'menu,menuone,noinsert' + }, + window = { + documentation = cmp.config.window.bordered(), + }, + sources = { + {name = 'path'}, + {name = 'nvim_lsp'}, + {name = 'nvim_lua'}, + {name = 'buffer', keyword_length = 3}, + {name = 'luasnip', keyword_length = 2}, + }, + mapping = cmp.mapping.preset.insert({ + -- confirm completion item + [''] = cmp.mapping.confirm({select = false, behavior = cmp.ConfirmBehavior.Insert}), + [''] = cmp.mapping.confirm({select = false, behavior = cmp.ConfirmBehavior.Replace}), + + -- toggle completion menu + [''] = cmp_action.toggle_completion(), + + -- tab complete + -- [''] = cmp_action.tab_complete(), + [''] = cmp.mapping.select_prev_item(), + + -- navigate between snippet placeholder + [''] = cmp_action.luasnip_jump_forward(), + [''] = cmp_action.luasnip_jump_backward(), + + -- scroll documentation window + [''] = cmp.mapping.scroll_docs(5), + [''] = cmp.mapping.scroll_docs(-5), + }), + }) + + + local navic = require("nvim-navic") + + lsp.on_attach(function(client, bufnr) + local opts = { buffer = bufnr, remap = false } + lsp.default_keymaps({buffer = bufnr}) + if client.server_capabilities.documentSymbolProvider then + navic.attach(client, bufnr) + end + vim.keymap.set("n", "gd", function() vim.lsp.buf.definition() end, opts) + vim.keymap.set("n", "dc", function() vim.lsp.buf.hover() end, opts) + vim.keymap.set("n", "vws", function() vim.lsp.buf.workspace_symbol() end, opts) + vim.keymap.set("n", "ed", 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) + -- for the code action key map to work you need to change key binding('.' symbol) of your terminal, otherwise it won't work + vim.keymap.set("n", "", function() vim.lsp.buf.code_action() end, opts) + vim.keymap.set("n", "vrr", function() vim.lsp.buf.references() end, opts) + vim.keymap.set("n", "vrn", function() vim.lsp.buf.rename() end, opts) + vim.keymap.set("i", "", function() vim.lsp.buf.signature_help() end, opts) + -- sometimes lsp fails, we can restart it with this keymap + vim.keymap.set('n', "lr", vim.cmd.LspRestart, opts) + end) + + require("mason").setup({}); + require("mason-lspconfig").setup({ + ensure_installed = {'tsserver', 'tailwindcss', 'svelte', 'lua_ls'}, + handlers = { + lsp.default_setup, + lua_ls = function() + local lua_opts = lsp.nvim_lua_ls() + require('lspconfig').lua_ls.setup(lua_opts) + end, + } + }) + + + lsp.set_sign_icons({ + error = '✘', + warn = '▲', + hint = '⚑', + info = '' + }) + + vim.diagnostic.config({ + virtual_text = false, + severity_sort = true, + float = { + style = 'minimal', + border = 'rounded', + source = 'always', + header = '', + prefix = '', + }, + }) + + end +}