diff options
| author | Robert Günzler <r@gnzler.io> | 2024-05-15 09:00:31 +0200 |
|---|---|---|
| committer | Robert Günzler <r@gnzler.io> | 2024-05-15 09:00:31 +0200 |
| commit | 3dbe74f2eef627e2dc19b79fe06753d5dc09003f (patch) | |
| tree | b78d1cdab62cec9ed4bbe35447108547b935ef03 /.vim/lua/internal/lsp.lua | |
| parent | 0ab72c1113139c196115c974eadaded449002c32 (diff) | |
update nvim
Signed-off-by: Robert Günzler <r@gnzler.io>
Diffstat (limited to '.vim/lua/internal/lsp.lua')
| -rw-r--r-- | .vim/lua/internal/lsp.lua | 66 |
1 files changed, 36 insertions, 30 deletions
diff --git a/.vim/lua/internal/lsp.lua b/.vim/lua/internal/lsp.lua index 1c8c29c..b0aa7dc 100644 --- a/.vim/lua/internal/lsp.lua +++ b/.vim/lua/internal/lsp.lua @@ -8,7 +8,7 @@ local my_attach = function(client, bufnr) if vim.opt.diff:get() then vim.notify('not running LSP client in diff mode', vim.log.levels.WARN) - vim.lsp.stop_client() + vim.lsp.stop_client(client) return end @@ -79,14 +79,16 @@ local my_attach = function(client, bufnr) ) end if client.supports_method('textDocument/formatting') then - vim.api.nvim_buf_set_option(bufnr, 'formatexpr', 'v:lua.vim.lsp.formatexpr()') + -- if client.server_capabilities.documentFormattingProvider then + vim.api.nvim_set_option_value('formatexpr', 'v:lua.vim.lsp.formatexpr()', { buf = bufnr }) vim.keymap.set('n', '<leader>f', vim.lsp.buf.format, { buffer = bufnr, desc = 'format' }) vim.api.nvim_create_autocmd('BufWritePre', { buffer = bufnr, - group = group, callback = function() + vim.cmd.mkview({ bang = true }) require('internal.lsp').format(vim.fn.expand('<afile>:p')) end, + group = vim.api.nvim_create_augroup('LspAutoFormat', {}), }) end if client.supports_method('textDocument/typeDefinition') then @@ -114,7 +116,8 @@ local my_attach = function(client, bufnr) ) end if client.supports_method('textDocument/codeAction') then - vim.keymap.set('n', 'ga', vim.lsp.buf.code_action, { buffer = bufnr, desc = 'code action' }) + -- vim.keymap.set('n', 'ga', vim.lsp.buf.code_action, { buffer = bufnr, desc = 'code action' }) + vim.keymap.set('n', 'ga', vim.cmd.CodeActionMenu, { buffer = bufnr, desc = 'code action' }) end if client.supports_method('textDocument/documentHighlight') then vim.keymap.set( @@ -135,22 +138,25 @@ local my_exit = function(_, _, _) end local capabilities = function() local caps = vim.lsp.protocol.make_client_capabilities() + -- enable lsp-based snippets - caps.textDocument.completion.completionItem.snippetSupport = true - caps.textDocument.completion.completionItem.resolveSupport = { - properties = { - 'documentation', - 'detail', - 'additionalTextEdits', - }, - } + caps = vim.tbl_extend('keep', caps or {}, require('cmp_nvim_lsp').default_capabilities()) + -- add window/workDoneProgress capability caps = vim.tbl_extend('keep', caps or {}, require('lsp-status').capabilities) return caps end local servers = { - clangd = {}, + clangd = { + cmd = { + 'clangd', + '--clang-tidy', + '--header-insertion=iwyu', + '--import-insertions', + '--header-insertion-decorators', + } + }, elixirls = { cmd = { 'elixir-ls' }, settings = { @@ -177,7 +183,7 @@ local servers = { }, lua_ls = { -- cmd = { 'lua-language-server' }, - cmd = { 'luals' }, + cmd = { 'luals' }, -- custom firejail-wrapped settings = { Lua = { runtime = { @@ -237,15 +243,9 @@ local servers = { }, }, }, + tsserver = {}, pylsp = {}, - -- tsserver = { disabled = true, - -- cmd = { - -- 'toolbox', 'run', '--', - -- 'sh', '-c', - -- '. /etc/profile.d/nvm.sh && typescript-language-server --stdio' - -- }, - -- }, - -- zls = { disabled = true }, + zls = {}, } local setup = function() @@ -256,7 +256,7 @@ local setup = function() border = _G.floating_win_border, }) vim.lsp.handlers['textDocument/signature_help'] = - vim.lsp.with(vim.lsp.handlers.signature_help, { border = _G.floating_win_border }) + vim.lsp.with(vim.lsp.handlers.signature_help, { border = _G.floating_win_border }) local caps = capabilities() for server, opts in pairs(servers) do @@ -283,16 +283,18 @@ local format = function(afile) return end - local ok, isMatch = pcall(string.match, afile, '^/home/robert/devel/upstream') - if not ok or isMatch then - return - end - local errhandler = function(err) - vim.notify('fmt failed: ' .. err, vim.log.levels.ERROR) + vim.notify('internal.lsp.format: ' .. err, vim.log.levels.ERROR) return err end + + -- save folds + pcall(vim.cmd.mkview, { bang = true }) + + -- run lsp format xpcall(vim.lsp.buf.format, errhandler) + + -- run organize imports for go if string.match(afile, '.go$') then xpcall( vim.lsp.buf.code_action, @@ -300,8 +302,12 @@ local format = function(afile) { context = { only = { 'source.organizeImports' } }, apply = true } ) end + + -- restore folds + pcall(vim.cmd.silent, { 'loadview', bank = true }) + -- vim.notify('%#MoreMsg#%#Italic# fmt', vim.log.levels.INFO) - vim.notify(' ', vim.log.levels.INFO) + vim.notify('internal.lsp.format: ', vim.log.levels.INFO) end return { |