From 70a7939080a6532ca648f3557816276bfc1fcd0e Mon Sep 17 00:00:00 2001 From: Anthony Rose Date: Wed, 4 Dec 2024 13:21:37 +0000 Subject: [PATCH] Clean up config a little --- init.lua | 37 ++----------------------------------- lua/ant_lsp.lua | 35 +++++++++++++++++++++++++++++++++++ lua/ant_tabcomplete.lua | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 77 insertions(+), 35 deletions(-) create mode 100644 lua/ant_lsp.lua create mode 100644 lua/ant_tabcomplete.lua diff --git a/init.lua b/init.lua index bb96668..b633ba5 100644 --- a/init.lua +++ b/init.lua @@ -1,37 +1,4 @@ vim.cmd("runtime vimrc") -if (vim.fn.has 'win32' == 1) then - require'lspconfig'.powershell_es.setup{ - bundle_path = os.getenv("LOCALAPPDATA") .. '\\PowerShellEditorServices', - shell = 'powershell.exe', - } -else - require'lspconfig'.powershell_es.setup{ - bundle_path = os.getenv("HOME") .. '/opt/PowerShellEditorServices', - } -end - -require'lspconfig'.gopls.setup{} - --- None of this should be needed from 0.11.0 (except maybe gd). -do - vim.keymap.set('n', 'gd', function() - vim.lsp.buf.definition() - end, { desc = 'vim.lsp.buf.definition()' }) - - vim.keymap.set('n', 'grn', function() - vim.lsp.buf.rename() - end, { desc = 'vim.lsp.buf.rename()' }) - - vim.keymap.set({ 'n', 'x' }, 'gra', function() - vim.lsp.buf.code_action() - end, { desc = 'vim.lsp.buf.code_action()' }) - - vim.keymap.set('n', 'grr', function() - vim.lsp.buf.references() - end, { desc = 'vim.lsp.buf.references()' }) - - vim.keymap.set('i', '', function() - vim.lsp.buf.signature_help() - end, { desc = 'vim.lsp.buf.signature_help()' }) -end +require('ant_tabcomplete') +require('ant_lsp') diff --git a/lua/ant_lsp.lua b/lua/ant_lsp.lua new file mode 100644 index 0000000..0d05f38 --- /dev/null +++ b/lua/ant_lsp.lua @@ -0,0 +1,35 @@ +if (vim.fn.has 'win32' == 1) then + require'lspconfig'.powershell_es.setup{ + bundle_path = os.getenv("LOCALAPPDATA") .. '\\PowerShellEditorServices', + shell = 'powershell.exe', + } +else + require'lspconfig'.powershell_es.setup{ + bundle_path = os.getenv("HOME") .. '/opt/PowerShellEditorServices', + } +end + +require'lspconfig'.gopls.setup{} + +-- None of this should be needed from 0.11.0 (except maybe gd). +do + vim.keymap.set('n', 'gd', function() + vim.lsp.buf.definition() + end, { desc = 'vim.lsp.buf.definition()' }) + + vim.keymap.set('n', 'grn', function() + vim.lsp.buf.rename() + end, { desc = 'vim.lsp.buf.rename()' }) + + vim.keymap.set({ 'n', 'x' }, 'gra', function() + vim.lsp.buf.code_action() + end, { desc = 'vim.lsp.buf.code_action()' }) + + vim.keymap.set('n', 'grr', function() + vim.lsp.buf.references() + end, { desc = 'vim.lsp.buf.references()' }) + + vim.keymap.set('i', '', function() + vim.lsp.buf.signature_help() + end, { desc = 'vim.lsp.buf.signature_help()' }) +end diff --git a/lua/ant_tabcomplete.lua b/lua/ant_tabcomplete.lua new file mode 100644 index 0000000..2f2f5b5 --- /dev/null +++ b/lua/ant_tabcomplete.lua @@ -0,0 +1,40 @@ +vim.opt.completeopt = {'menu', 'menuone', 'noselect', 'noinsert'} +vim.opt.shortmess:append('c') + +local function tab_complete() + if vim.fn.pumvisible() == 1 then + -- navigate to next item in completion menu + return '' + end + + local c = vim.fn.col('.') - 1 + local is_whitespace = c == 0 or vim.fn.getline('.'):sub(c, c):match('%s') + + if is_whitespace then + -- insert tab + return '' + end + + local lsp_completion = vim.bo.omnifunc == 'v:lua.vim.lsp.omnifunc' + + if lsp_completion then + -- trigger lsp code completion + return '' + end + + -- suggest words in current buffer + return '' +end + +local function tab_prev() + if vim.fn.pumvisible() == 1 then + -- navigate to previous item in completion menu + return '' + end + + -- insert tab + return '' +end + +vim.keymap.set('i', '', tab_complete, {expr = true}) +vim.keymap.set('i', '', tab_prev, {expr = true})