From 7906ecc0e38ff6b1be54668e49ea10906b743bc1 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sun, 15 Sep 2024 09:49:48 +0300 Subject: feat(plugins): Properly implemented lsp --- lua/plugins/lsp.lua | 102 ++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 92 insertions(+), 10 deletions(-) (limited to 'lua/plugins/lsp.lua') diff --git a/lua/plugins/lsp.lua b/lua/plugins/lsp.lua index 8144527..d778448 100644 --- a/lua/plugins/lsp.lua +++ b/lua/plugins/lsp.lua @@ -9,8 +9,10 @@ vim.api.nvim_create_autocmd({ "CursorHold", "CursorHoldI" }, { callback = functi end}) return { + -- Syntax parsing (for highlighting) { - "nvim-treesitter/nvim-treesitter", -- Advanced syntax parsing + "nvim-treesitter/nvim-treesitter", + lazy = false, build = ":TSUpdate", opts = { ensure_installed = "all", @@ -23,19 +25,99 @@ return { require("nvim-treesitter.configs").setup(opts) end, }, + -- LSP server utilisation { "neovim/nvim-lspconfig", - enabled = false, -- Figure out config property - event = "LazyFile", - -- dependencies = { - -- "mason.nvim", - -- { "williamboman/mason-lspconfig.nvim", config = function() end }, - -- }, + dependencies = { 'VonHeikemen/lsp-zero.nvim' }, + lazy = true, opts = { - servers = { - awk_ls = { settings = {}, }, + awk_ls = { }, + lua_ls = { }, + }, + config = function(_, opts) + for k,v in pairs(opts) do + require("lspconfig")[k].setup(v) + end + end, + }, + -- Auto-completion + { + 'hrsh7th/cmp-nvim-lsp', + config = true, + lazy = true + }, + { + 'hrsh7th/nvim-cmp', + lazy = false, + opts = { + sources = { { name = 'nvim_lsp' } }, + snippet = { + expand = function(args) + vim.snippet.expand(args.body) + end, + }, + }, + config = function(_, opts) + local cmp = require('cmp') + opts.mapping = cmp.mapping.preset.insert({ + -- -- `Enter` key to confirm completion + -- [''] = cmp.mapping.confirm({select = false}), + -- + -- -- Ctrl+Space to trigger completion menu + [''] = cmp.mapping.complete(), + -- + -- -- Navigate between snippet placeholder + -- [''] = cmp_action.vim_snippet_jump_forward(), + -- [''] = cmp_action.vim_snippet_jump_backward(), + -- + -- -- Scroll up and down in the completion documentation + -- [''] = cmp.mapping.scroll_docs(-4), + -- [''] = cmp.mapping.scroll_docs(4), + }) + cmp.setup(opts) + end, + }, + -- Helper functions + { + 'VonHeikemen/lsp-zero.nvim', + branch = 'v3.x', + lazy = true, + dependencies = { 'hrsh7th/cmp-nvim-lsp' }, + opts = { + sign_text = true, + capabailities = "", + lsp_attach = function(client, bufnr) + local opts = {buffer = bufnr} + + vim.keymap.set('n', 'K', 'lua vim.lsp.buf.hover()', opts) + vim.keymap.set('n', 'gd', 'lua vim.lsp.buf.definition()', opts) + vim.keymap.set('n', 'gD', 'lua vim.lsp.buf.declaration()', opts) + vim.keymap.set('n', 'gi', 'lua vim.lsp.buf.implementation()', opts) + vim.keymap.set('n', 'go', 'lua vim.lsp.buf.type_definition()', opts) + vim.keymap.set('n', 'gr', 'lua vim.lsp.buf.references()', opts) + vim.keymap.set('n', 'gs', 'lua vim.lsp.buf.signature_help()', opts) + vim.keymap.set('n', '', 'lua vim.lsp.buf.rename()', opts) + vim.keymap.set({'n', 'x'}, '', 'lua vim.lsp.buf.format({async = true})', opts) + vim.keymap.set('n', '', 'lua vim.lsp.buf.code_action()', opts) + end, + }, + config = function(_, opts) + opts.capabilities = require('cmp_nvim_lsp').default_capabilities() + require("lsp-zero").extend_lspconfig(opts) + end, + }, + -- Download plugins automatically + { 'williamboman/mason.nvim', config = true, }, + { + 'williamboman/mason-lspconfig.nvim', + lazy = false, + dependencies = { 'neovim/nvim-lspconfig' }, + opts = { + handlers = { + function(server_name) + require('lspconfig')[server_name].setup({}) + end, }, }, - setup = {}, }, } -- cgit v1.3.1-23-gd82d