From 4ccea621d7f38d02202b3f8aff64f6b3974768ec Mon Sep 17 00:00:00 2001 From: Rosario Polito Date: Thu, 3 Apr 2025 21:32:06 +0200 Subject: [PATCH] golsp --- init.lua | 4 +-- lazy-lock.json | 8 +++++ lua/plugins/nvim-cmp.lua | 58 ++++++++++++++++++++++++++++++++++ lua/plugins/nvim-lspconfig.lua | 45 ++++++++++++++++++++++++++ pack/nvim/start/nvim-lspconfig | 1 + 5 files changed, 113 insertions(+), 3 deletions(-) create mode 100644 lua/plugins/nvim-cmp.lua create mode 100644 lua/plugins/nvim-lspconfig.lua create mode 160000 pack/nvim/start/nvim-lspconfig diff --git a/init.lua b/init.lua index 9285d56..6817f9b 100644 --- a/init.lua +++ b/init.lua @@ -15,12 +15,9 @@ vim.opt.clipboard=unnamedplus vim.opt.ttyfast=true vim.cmd("filetype plugin on") - -- quick exit all vim.api.nvim_set_keymap("n", ":Q", ":qall", { noremap = true, silent = true }) - - -- Plugins require("config.lazy") @@ -98,3 +95,4 @@ require'nvim-web-devicons'.setup { }, }; } + diff --git a/lazy-lock.json b/lazy-lock.json index 6fe5404..362a9fa 100644 --- a/lazy-lock.json +++ b/lazy-lock.json @@ -1,6 +1,14 @@ { + "LuaSnip": { "branch": "master", "commit": "c9b9a22904c97d0eb69ccb9bab76037838326817" }, "catppuccin": { "branch": "main", "commit": "5b5e3aef9ad7af84f463d17b5479f06b87d5c429" }, + "cmp-buffer": { "branch": "main", "commit": "b74fab3656eea9de20a9b8116afa3cfc4ec09657" }, + "cmp-cmdline": { "branch": "main", "commit": "d250c63aa13ead745e3a40f61fdd3470efde3923" }, + "cmp-nvim-lsp": { "branch": "main", "commit": "a8912b88ce488f411177fc8aed358b04dc246d7b" }, + "cmp-path": { "branch": "main", "commit": "c6635aae33a50d6010bf1aa756ac2398a2d54c32" }, + "cmp_luasnip": { "branch": "master", "commit": "98d9cb5c2c38532bd9bdb481067b20fea8f32e90" }, "lazy.nvim": { "branch": "main", "commit": "6c3bda4aca61a13a9c63f1c1d1b16b9d3be90d7a" }, + "nvim-cmp": { "branch": "main", "commit": "059e89495b3ec09395262f16b1ad441a38081d04" }, + "nvim-lspconfig": { "branch": "master", "commit": "ff6471d4f837354d8257dfa326b031dd8858b16e" }, "nvim-tree.lua": { "branch": "master", "commit": "6709463b2d18e77f7a946027917aa00d4aaed6f4" }, "nvim-web-devicons": { "branch": "master", "commit": "4c3a5848ee0b09ecdea73adcd2a689190aeb728c" }, "plenary.nvim": { "branch": "master", "commit": "857c5ac632080dba10aae49dba902ce3abf91b35" }, diff --git a/lua/plugins/nvim-cmp.lua b/lua/plugins/nvim-cmp.lua new file mode 100644 index 0000000..75e9830 --- /dev/null +++ b/lua/plugins/nvim-cmp.lua @@ -0,0 +1,58 @@ +return { + { + "hrsh7th/nvim-cmp", + event = "InsertEnter", + dependencies = { + "hrsh7th/cmp-nvim-lsp", + "hrsh7th/cmp-buffer", + "hrsh7th/cmp-path", + "hrsh7th/cmp-cmdline", + "L3MON4D3/LuaSnip", + "saadparwaiz1/cmp_luasnip", + }, + config = function() + local cmp = require("cmp") + local luasnip = require("luasnip") + + cmp.setup({ + snippet = { + expand = function(args) + luasnip.lsp_expand(args.body) + end, + }, + mapping = cmp.mapping.preset.insert({ + [""] = cmp.mapping.complete(), + [""] = cmp.mapping.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = true }), + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif luasnip.expand_or_jumpable() then + luasnip.expand_or_jump() + else + fallback() + end + end, { "i", "s" }), + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_prev_item() + elseif luasnip.jumpable(-1) then + luasnip.jump(-1) + else + fallback() + end + end, { "i", "s" }), + }), + sources = cmp.config.sources({ + { name = "nvim_lsp" }, + { name = "luasnip" }, + { name = "buffer" }, + { name = "path" }, + }), + experimental = { + ghost_text = true, + }, + }) + end, + }, +} + diff --git a/lua/plugins/nvim-lspconfig.lua b/lua/plugins/nvim-lspconfig.lua new file mode 100644 index 0000000..6a61396 --- /dev/null +++ b/lua/plugins/nvim-lspconfig.lua @@ -0,0 +1,45 @@ +return { + { + "neovim/nvim-lspconfig", + dependencies = { + "hrsh7th/nvim-cmp", -- Autocompletion + "hrsh7th/cmp-nvim-lsp", + }, + config = function() + local lspconfig = require("lspconfig") + local cmp_nvim_lsp = require("cmp_nvim_lsp") + + local capabilities = cmp_nvim_lsp.default_capabilities() + + lspconfig.gopls.setup { + cmd = { "gopls" }, + filetypes = { "go", "gomod", "gowork", "gotmpl" }, + root_dir = lspconfig.util.root_pattern("go.work", "go.mod", ".git"), + settings = { + gopls = { + analyses = { + unusedparams = true, + }, + staticcheck = true, + }, + }, + capabilities = capabilities, -- Autocomplete-Unterstützung + } + end, + }, + { + "hrsh7th/nvim-cmp", + config = function() + local cmp = require("cmp") + cmp.setup { + mapping = cmp.mapping.preset.insert({ + [''] = cmp.mapping.complete(), + }), + sources = { + { name = 'nvim_lsp' }, + }, + } + end + } +} + diff --git a/pack/nvim/start/nvim-lspconfig b/pack/nvim/start/nvim-lspconfig new file mode 160000 index 0000000..ff6471d --- /dev/null +++ b/pack/nvim/start/nvim-lspconfig @@ -0,0 +1 @@ +Subproject commit ff6471d4f837354d8257dfa326b031dd8858b16e