From ad3ba3a009b8202bab72639463108d6ca1616296 Mon Sep 17 00:00:00 2001 From: bumpsoo Date: Tue, 14 Nov 2023 13:50:26 +0000 Subject: [PATCH] lspconfig --- .../nvim/lua/bumpsoo/plugins/lspconfig.lua | 79 ++++++++++++++++++- .config/nvim/lua/bumpsoo/set.lua | 4 + 2 files changed, 81 insertions(+), 2 deletions(-) diff --git a/.config/nvim/lua/bumpsoo/plugins/lspconfig.lua b/.config/nvim/lua/bumpsoo/plugins/lspconfig.lua index 5e4eb06..f90b0a6 100644 --- a/.config/nvim/lua/bumpsoo/plugins/lspconfig.lua +++ b/.config/nvim/lua/bumpsoo/plugins/lspconfig.lua @@ -1,6 +1,81 @@ return { "neovim/nvim-lspconfig", - config = function() - require'lspconfig'.gopls.setup{} + dependencies = { + "hrsh7th/cmp-nvim-lsp", + 'hrsh7th/cmp-buffer', + 'hrsh7th/cmp-path', + 'hrsh7th/cmp-cmdline', + 'hrsh7th/nvim-cmp', + }, + event = { "BufReadPre", "BufNewFile" }, + config = function() + vim.opt.completeopt = { "menu", "menuone", "noselect" } + local has_words_before = function() + local line, col = unpack(vim.api.nvim_win_get_cursor(0)) + return + col ~= 0 and + vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil + end + local feedkey = function(key, mode) + vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(key, true, true, true), mode, true) + end + local cmp = require('cmp') + cmp.setup({ + mapping = { + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif has_words_before() then + cmp.complete() + else + fallback() + end + end, { "i", "s" }), + [""] = cmp.mapping(function() + if cmp.visible() then + cmp.select_prev_item() + end + end, { "i", "s" }), + }, + sources = cmp.config.sources({ + { name = 'nvim_lsp' }, + }, { + { name = 'buffer' }, + }) + }) + local capabilities = require('cmp_nvim_lsp').default_capabilities() + local on_attach = function(client, bufnr) + local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end + local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end + + buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc') + end + local signs = { Error = " ", Warn = " ", Hint = "󰠠 ", Info = " " } + for type, icon in pairs(signs) do + local hl = "DiagnosticSign" .. type + vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = "" }) + end + + local nvim_lsp = require('lspconfig') + nvim_lsp.gopls.setup{ + cmd = {'gopls'}, + on_attach = on_attach, + capabilities = capabilities, + settings = { + gopls = { + experimentalPostfixCompletions = true, + analyses = { + unusedparams = true, + shadow = true, + }, + staticcheck = true, + gofumpt = true, + }, + }, + init_options = { + usePlaceholders = true, + } + } end } + diff --git a/.config/nvim/lua/bumpsoo/set.lua b/.config/nvim/lua/bumpsoo/set.lua index 3135fe4..81f6038 100644 --- a/.config/nvim/lua/bumpsoo/set.lua +++ b/.config/nvim/lua/bumpsoo/set.lua @@ -9,3 +9,7 @@ vim.opt.listchars = { space = "·", nbsp = "+", } + +vim.opt.tabstop = 4 +vim.opt.softtabstop = 4 +vim.opt.shiftwidth = 4