diff --git a/lua/lsp_settings.lua b/lua/lsp_settings.lua index 5880314..b8f66e8 100644 --- a/lua/lsp_settings.lua +++ b/lua/lsp_settings.lua @@ -54,6 +54,9 @@ require('mason-lspconfig').setup_handlers { capabilities = capabilities, settings = { Lua = { + completion = { + callSnippet = 'Replace', + }, diagnostics = { globals = { 'vim' } } @@ -66,8 +69,17 @@ require('mason-lspconfig').setup_handlers { capabilities = capabilities, settings = { gopls = { - gofumpt = true + experimentalPostfixCompletions = true, + gofumpt = true, + analyses = { + unusedparams = true, + shadow = true, + }, + staticcheck = true, } + }, + init_options = { + usePlaceHolders = true, } } end diff --git a/lua/options.lua b/lua/options.lua index fb8de93..156222c 100644 --- a/lua/options.lua +++ b/lua/options.lua @@ -5,7 +5,7 @@ vim.o.termguicolors = true vim.o.cmdheight = 1 -- You will have bad experience for diagnostic messages when it's default 4000. -vim.o.updatetime = 300 +vim.o.updatetime = 100 vim.o.mmp = 5000 -- don't give |ins-completion-menu| messages. diff --git a/lua/plugins.lua b/lua/plugins.lua index a602e0f..901f3a2 100644 --- a/lua/plugins.lua +++ b/lua/plugins.lua @@ -44,6 +44,10 @@ return { vim.g.go_highlight_fields = 1 vim.g.go_highlight_functions = 1 vim.g.go_highlight_function_calls = 1 + vim.g.go_highlight_operators = 1 + vim.g.go_highlight_extra_types = 1 + vim.g.go_highlight_build_constraints = 1 + vim.g.go_auto_type_info = 1 vim.g.go_metalinter_command = 'golangci-lint' end }, @@ -206,16 +210,36 @@ return { { "L3MON4D3/LuaSnip" }, { "saadparwaiz1/cmp_luasnip" }, { "rafamadriz/friendly-snippets" }, + { "onsails/lspkind.nvim" }, }, config = function() - require('luasnip.loaders.from_vscode').lazy_load() + local lspkind = require('lspkind') + local has_words_before = function() + unpack = unpack or table.unpack + 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 cmp = require 'cmp' + local luasnip = require("luasnip") cmp.setup({ + experimental = { + ghost_text = true + }, snippet = { expand = function(args) - require('luasnip').lsp_expand(args.body) + luasnip.lsp_expand(args.body) end, }, + formatting = { + format = lspkind.cmp_format({ + mode = 'symbol', + maxwidth = 50, + ellipsis_char = '...', + before = function(entry, vim_item) + return vim_item + end + }) + }, window = { completion = cmp.config.window.bordered(), documentation = cmp.config.window.bordered(), @@ -226,6 +250,28 @@ return { [''] = cmp.mapping.complete(), [''] = cmp.mapping.abort(), [''] = cmp.mapping.confirm({ select = false }), + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + -- You could replace the expand_or_jumpable() calls with expand_or_locally_jumpable() + -- they way you will only jump inside the snippet region + elseif luasnip.expand_or_jumpable() then + luasnip.expand_or_jump() + elseif has_words_before() then + cmp.complete() + 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' }, @@ -233,6 +279,8 @@ return { { name = 'path' }, { name = 'luasnip' }, { name = 'neorg' }, + }, { + { name = 'buffer' }, }) }) @@ -259,6 +307,7 @@ return { { name = 'cmdline' } }) }) + require('luasnip.loaders.from_vscode').lazy_load() end, },