diff options
| -rw-r--r-- | .vim/lua/internal/lsp.lua | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/.vim/lua/internal/lsp.lua b/.vim/lua/internal/lsp.lua index 669c2c7..1e3dca3 100644 --- a/.vim/lua/internal/lsp.lua +++ b/.vim/lua/internal/lsp.lua @@ -72,7 +72,6 @@ local my_attach = function(client, bufnr) if client.supports_method('textDocument/codeAction') then vim.keymap.set('n', 'ga', vim.lsp.buf.code_action, {buffer = bufnr, desc = 'code action'}) end - if client.supports_method('textDocument/documentHighlight') then vim.keymap.set('n', '<leader>8', vim.lsp.buf.document_highlight, {buffer = bufnr, desc = 'document highlight'}) -- vim.keymap.set('n', '', vim.lsp.buf.clear_references, {buffer = bufnr, desc = 'clear references'}) @@ -162,7 +161,9 @@ local servers = { 'string', 'table', 'type', + 'unpack', 'vim', + 'xpcall', }, neededFileStatus = { ['code-style-check'] = 'Any', @@ -242,14 +243,20 @@ end local format = function(afile) if vim.g.nofmt then return end - if not string.match(afile, '^/home/robert/devel/upstream') then - vim.lsp.buf.format() - if string.match(afile, '.go$') then - vim.lsp.buf.code_action({ only = {'source.organizeImports'} }) - end - -- vim.notify('%#MoreMsg#%#Italic# fmt') - vim.notify('%#MoreMsg#%#Italic# fmt') + + 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) + return err + end + xpcall(vim.lsp.buf.format, errhandler) + if string.match(afile, '.go$') then + xpcall(vim.lsp.buf.code_action, errhandler, {context = {only = {'source.organizeImports'}}, apply = true}) end + -- vim.notify('%#MoreMsg#%#Italic# fmt', vim.log.levels.INFO) + vim.notify(' ', vim.log.levels.INFO) end local symbols = { |