From 81ecb915c7cae4969b195d4cd1723301460ba6b3 Mon Sep 17 00:00:00 2001 From: asari <32879431+deomorxsy@users.noreply.github.com> Date: Sun, 8 Sep 2024 03:56:16 -0300 Subject: [PATCH] fix: lsp_zero setup leveraging syntax from nvim-lspconfig and cmp-nvim-lsp for gopls --- .config/nvim/after/plugin/lsp.lua | 67 +++++++++++++++++--------- .config/nvim/init.lua | 8 ++- .config/nvim/{ => lua}/config/lazy.lua | 0 3 files changed, 50 insertions(+), 25 deletions(-) rename .config/nvim/{ => lua}/config/lazy.lua (100%) diff --git a/.config/nvim/after/plugin/lsp.lua b/.config/nvim/after/plugin/lsp.lua index 7978589..f52079f 100644 --- a/.config/nvim/after/plugin/lsp.lua +++ b/.config/nvim/after/plugin/lsp.lua @@ -17,45 +17,66 @@ end) require('mason').setup({}) require('mason-lspconfig').setup({ - ensure_installed = {'tsserver', 'rust_analyzer', 'eslint', }, + ensure_installed = {'tsserver', 'rust_analyzer', 'eslint', 'gopls'}, handlers = { lsp_zero.default_setup, lua_ls = function() local lua_opts = lsp_zero.nvim_lua_ls() require('lspconfig').lua_ls.setup(lua_opts) end, + + function(server_name) + if server_name == "tsserver" then + server_name = "ts_ls" + end + local capabilities = require("cmp_nvim_lsp").default_capabilities() + require("lspconfig")[server_name].setup({ + capabilities = capabilities, + }) + end, } }) local cmp = require('cmp') -local cmp_select = {behavior = cmp.SelectBehavior.Select} +--local cmp_select = {behavior = cmp.SelectBehavior.Select} local cmp_action = require("lsp-zero").cmp_action() + + cmp.setup({ - mapping = { + mapping = cmp.mapping.preset.insert({ [""] = cmp.mapping.confirm({ - behavior = cmp.ConfirmBehavior.Replace, select=true - }), + behavior = cmp.ConfirmBehavior.Replace, select=true + }), [""] = cmp_action.luasnip_supertab(), [""] = cmp_action.luasnip_shift_supertab(), + --formatting = { + -- format = require("lspkind").cmp_format({mode = "symbol"}) + --} + --[''] = cmp.mapping.select_prev_item(cmp_select), + --[''] = cmp.mapping.select_next_item(cmp_select), + [''] = cmp.mapping.select_prev_item(), + [''] = cmp.mapping.select_next_item(), + [''] = cmp.mapping.confirm({ select = true }), + [''] = cmp.mapping.complete(), + }), + sources = { + {name = 'path'}, + {name = 'nvim_lsp'}, + {name = 'nvim_lua'}, }, - - --formatting = { - -- format = require("lspkind").cmp_format({mode = "symbol"}) - --} + formatting = lsp_zero.cmp_format(), }) +--local on_attach = require("plugins.configs.lspconfig").on_attach +--local capabilities = require("plugins.configs.lspconfig").capabilities -cmp.setup({ - sources = { - {name = 'path'}, - {name = 'nvim_lsp'}, - {name = 'nvim_lua'}, - }, - formatting = lsp_zero.cmp_format(), - mapping = cmp.mapping.preset.insert({ - [''] = cmp.mapping.select_prev_item(cmp_select), - [''] = cmp.mapping.select_next_item(cmp_select), - [''] = cmp.mapping.confirm({ select = true }), - [''] = cmp.mapping.complete(), - }), -}) +local lspconfig = require("lspconfig") +local util = require "lspconfig/util" + +lspconfig.gopls.setup { + on_attach = lsp_zero.on_attach, + capabilities = require("cmp_nvim_lsp").default_capabilities(), + cmd = {"gopls"}, + filetypes = { "go", "gomod", "gowork", "gotmpl" }, + root_dir = util.root_pattern("go.work", "go.mod", ".git"), +} diff --git a/.config/nvim/init.lua b/.config/nvim/init.lua index 4053463..2f91070 100644 --- a/.config/nvim/init.lua +++ b/.config/nvim/init.lua @@ -1,7 +1,11 @@ +-- or just format it from a bash heredoc and redirect after. +vim.g.python3_host_prog = os.getenv("HOME") .. '/.config/nvim/venv_nvim/neovim3/bin/python3' + +require("config.lazy") + require("user.remap") require("tools") ---require("settings") -- user.set +require("settings") -- user.set --require("user.packer") -require("config.lazy") --require("plugins.packerSpecs") -- Ensure the plugins are loaded. diff --git a/.config/nvim/config/lazy.lua b/.config/nvim/lua/config/lazy.lua similarity index 100% rename from .config/nvim/config/lazy.lua rename to .config/nvim/lua/config/lazy.lua