summary refs log tree commit diff
path: root/.vim/lua/internal/lsp.lua
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--.vim/lua/internal/lsp.lua258
1 files changed, 136 insertions, 122 deletions
diff --git a/.vim/lua/internal/lsp.lua b/.vim/lua/internal/lsp.lua
index aa2794e..2bdd270 100644
--- a/.vim/lua/internal/lsp.lua
+++ b/.vim/lua/internal/lsp.lua
@@ -1,5 +1,9 @@
-local lsp         = require('lspconfig')
-local lspstatus   = require('lsp-status')
+-- TODO vim.api.nvim_create_autocmd('LspAttach', {
+-- 	callback = function(args)
+-- 		local client = vim.lsp.get_client_by_id(args.data.client_id)
+-- 		local bufnr = args.buf
+-- 	end,
+-- })
 
 local my_attach = function(client, bufnr)
   if vim.opt.diff:get() then
@@ -13,67 +17,112 @@ local my_attach = function(client, bufnr)
     buffer = bufnr,
     group = group,
     callback = function()
-      if not _G.diagnostic_hidden then
-        vim.diagnostic.open_float(nil, {
-          focusable = false,
-          close_events = {'BufLeave', 'CursorMoved', 'InsertEnter', 'FocusLost'},
-          border = _G.floating_win_border,
-          source = 'always',
-          prefix = ' ',
-          scope = 'cursor',
-        })
+      if _G.diagnostic_hidden then
+        return
+      end
+      -- evalutate if there's already a floating preview buffer
+      local existing = vim.F.npcall(vim.api.nvim_buf_get_var, bufnr, 'lsp_floating_preview')
+      if not existing or not vim.api.nvim_win_is_valid(existing) then
+        vim.diagnostic.open_float()
       end
     end,
   })
 
-  lspstatus.on_attach(client)
+  require('lsp-status').on_attach(client)
   if client.supports_method('textDocument/documentSymbol') then
     require('nvim-navic').attach(client, bufnr)
     -- require('aerial').on_attach(client, bufnr)
     -- vim.keymap.set('n', 'g0', vim.lsp.buf.document_symbol, {buffer = bufnr})
   end
   if client.supports_method('workspace/symbol') then
-    vim.keymap.set('n', 'gW'        , vim.lsp.buf.workspace_symbol, {buffer = bufnr, desc = 'goto symbol'})
-    vim.keymap.set('n', ';s'        , require('telescope.builtin').lsp_workspace_symbols, {desc='lsp workspace symbols'})
+    vim.keymap.set(
+      'n',
+      'gW',
+      vim.lsp.buf.workspace_symbol,
+      { buffer = bufnr, desc = 'goto symbol' }
+    )
+    vim.keymap.set(
+      'n',
+      ';s',
+      require('telescope.builtin').lsp_workspace_symbols,
+      { desc = 'lsp workspace symbols' }
+    )
   end
   if client.supports_method('textDocument/definition') then
-    vim.keymap.set('n', '<C-]>'     , vim.lsp.buf.definition, {buffer = bufnr, desc = 'goto definition'})
-    vim.keymap.set('n', 'gd'        , vim.lsp.buf.definition, {buffer = bufnr, desc = 'goto definition'})
-    vim.keymap.set('n', 'gR'        , vim.lsp.buf.references, {buffer = bufnr, desc = 'goto references'})
-    vim.keymap.set('n', ';R'        , require('telescope.builtin').lsp_references, {desc='lsp references'})
+    vim.keymap.set(
+      'n',
+      '<C-]>',
+      vim.lsp.buf.definition,
+      { buffer = bufnr, desc = 'goto definition' }
+    )
+    vim.keymap.set('n', 'gd', vim.lsp.buf.definition, { buffer = bufnr, desc = 'goto definition' })
+    vim.keymap.set('n', 'gR', vim.lsp.buf.references, { buffer = bufnr, desc = 'goto references' })
+    vim.keymap.set(
+      'n',
+      ';R',
+      require('telescope.builtin').lsp_references,
+      { desc = 'lsp references' }
+    )
   end
   if client.supports_method('textDocument/hover') then
-    vim.keymap.set('n', 'K'         , vim.lsp.buf.hover, {buffer = bufnr, desc = 'hover'})
+    vim.keymap.set('n', 'K', vim.lsp.buf.hover, { buffer = bufnr, desc = 'hover' })
   end
   if client.supports_method('textDocument/rename') then
-    vim.keymap.set('n', 'grr'       , vim.lsp.buf.rename, {buffer = bufnr, desc = 'rename'})
+    vim.keymap.set('n', 'grr', vim.lsp.buf.rename, { buffer = bufnr, desc = 'rename' })
   end
   if client.supports_method('signatureHelp') then
-    vim.keymap.set('n', '<c-h>'     , vim.lsp.buf.signature_help, {buffer = bufnr, desc = 'signature help'})
+    vim.keymap.set(
+      'n',
+      '<c-h>',
+      vim.lsp.buf.signature_help,
+      { buffer = bufnr, desc = 'signature help' }
+    )
   end
   if client.supports_method('textDocument/formatting') then
     vim.api.nvim_buf_set_option(bufnr, 'formatexpr', 'v:lua.vim.lsp.formatexpr()')
-    vim.keymap.set('n', '<leader>f' , vim.lsp.buf.format, {buffer = bufnr, desc = 'format'})
+    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() require('internal.lsp').format(vim.fn.expand('<afile>:p')) end,
+      callback = function()
+        require('internal.lsp').format(vim.fn.expand('<afile>:p'))
+      end,
     })
   end
   if client.supports_method('textDocument/typeDefinition') then
-    vim.keymap.set('n', 'gT'        , vim.lsp.buf.type_definition, {buffer = bufnr, desc = 'goto typedef'})
+    vim.keymap.set(
+      'n',
+      'gT',
+      vim.lsp.buf.type_definition,
+      { buffer = bufnr, desc = 'goto typedef' }
+    )
   end
   if client.supports_method('textDocument/declaration') then
-    vim.keymap.set('n', 'gD'        , vim.lsp.buf.declaration, {buffer = bufnr, desc = 'goto declaration'})
+    vim.keymap.set(
+      'n',
+      'gD',
+      vim.lsp.buf.declaration,
+      { buffer = bufnr, desc = 'goto declaration' }
+    )
   end
   if client.supports_method('textDocument/implementation') then
-    vim.keymap.set('n', 'gI'        , vim.lsp.buf.implementation, {buffer = bufnr, desc = 'goto implementation'})
+    vim.keymap.set(
+      'n',
+      'gI',
+      vim.lsp.buf.implementation,
+      { buffer = bufnr, desc = 'goto implementation' }
+    )
   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' })
   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',
+      '<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'})
     vim.api.nvim_create_autocmd('CursorMoved', {
       callback = vim.lsp.buf.clear_references,
@@ -82,8 +131,7 @@ local my_attach = function(client, bufnr)
   end
 end
 
-local my_exit = function(_, _, _)
-end
+local my_exit = function(_, _, _) end
 
 local capabilities = function()
   local caps = vim.lsp.protocol.make_client_capabilities()
@@ -94,33 +142,22 @@ local capabilities = function()
       'documentation',
       'detail',
       'additionalTextEdits',
-    }
+    },
   }
   -- add window/workDoneProgress capability
-  caps = vim.tbl_extend('keep', caps or {}, lspstatus.capabilities)
+  caps = vim.tbl_extend('keep', caps or {}, require('lsp-status').capabilities)
   return caps
 end
 
 local servers = {
-  ccls = { disabled = true,
-    root_dir = lsp.util.root_pattern('.ccls','meson.build','.git'),
-    init_options = {
-      compilationDatabaseDirectory = "build",
-      index = { threads = 0 },
-      completion = {
-        filterAndSort = false,
-      },
-      clang = { excludeArgs = { '-frounding-math' } },
-    },
-  },
   clangd = {},
   elixirls = {
     cmd = { 'elixir-ls' },
     settings = {
       elixirLS = {
         dialyzerEnabled = false,
-      }
-    }
+      },
+    },
   },
   gopls = {
     settings = {
@@ -135,11 +172,12 @@ local servers = {
         },
         gofumpt = true,
         -- hoverKind = 'Structured',
-      }
-    }
+      },
+    },
   },
   sumneko_lua = {
-    cmd = { 'lua-language-server' },
+    -- cmd = { 'lua-language-server' },
+    cmd = { 'luals' },
     settings = {
       Lua = {
         runtime = {
@@ -153,7 +191,8 @@ local servers = {
             'error',
             'os',
             'package',
-            'pairs', 'ipairs',
+            'pairs',
+            'ipairs',
             'pcall',
             'require',
             'string',
@@ -165,14 +204,14 @@ local servers = {
           },
           neededFileStatus = {
             ['code-style-check'] = 'Any',
-          }
+          },
         },
         format = {
-          enable =  true,
+          enable = true,
           defaultConfig = {
             indent_style = 'space',
             indent_size = '2',
-          }
+          },
         },
         workspace = {
           -- library = vim.api.nvim_get_runtime_file("", true),
@@ -180,7 +219,7 @@ local servers = {
             [vim.env.VIMRUNTIME .. '/lua'] = true,
             [vim.env.VIMRUNTIME .. '/lua/vim/lsp'] = true,
             [vim.fn.stdpath('config') .. '/lua'] = true,
-          }
+          },
         },
         telemetry = {
           enable = false,
@@ -189,61 +228,69 @@ local servers = {
     },
   },
   rust_analyzer = {
-    cmd = { 'env', 'CARGO_TARGET_DIR=/tmp', 'RUST_SRC_PATH=/usr/src/rustlib/library', 'rust-analyzer' },
+    -- cmd = { 'env', 'CARGO_TARGET_DIR=/tmp', 'RUST_SRC_PATH=/usr/src/rustlib/library', 'rust-analyzer' },
     settings = {
       ['rust-analyzer'] = {
         checkOnSave = {
-          command = 'clippy'
-        }
-      }
-    },
-  },
-  tsserver = { disabled = true,
-    cmd = {
-      'toolbox', 'run', '--',
-      'sh', '-c',
-      '. /etc/profile.d/nvm.sh && typescript-language-server --stdio'
+          command = 'clippy',
+        },
+      },
     },
   },
-  zls = { disabled = true,
-  },
-  zk = { disabled = true,
-    root_dir = lsp.util.root_pattern('.zk'),
-  },
+  pylsp = {},
+  -- tsserver = { disabled = true,
+  --   cmd = {
+  --     'toolbox', 'run', '--',
+  --     'sh', '-c',
+  --     '. /etc/profile.d/nvm.sh && typescript-language-server --stdio'
+  --   },
+  -- },
+  -- zls = { disabled = true },
+  -- zk = {
+  --   cmd = {'zk', 'lsp', '--log', '/tmp/zk-lsp.log'},
+  --   autostart = true,
+  -- },
 }
 
 local setup = function()
   -- configure floating win handlers
-  vim.lsp.handlers['textDocument/hover'] = vim.lsp.with(
-    vim.lsp.handlers.hover, { 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.handlers['textDocument/hover'] = vim.lsp.with(vim.lsp.handlers.hover, {
+    focus = false,
+    zindex = 100,
+    border = _G.floating_win_border,
+  })
+  vim.lsp.handlers['textDocument/signature_help'] =
+    vim.lsp.with(vim.lsp.handlers.signature_help, { border = _G.floating_win_border })
 
   local caps = capabilities()
   for server, opts in pairs(servers) do
     if not opts.disabled then
       opts = vim.tbl_extend('error', opts, {
-        on_attach    = my_attach,
-        on_exit      = my_exit,
+        on_attach = my_attach,
+        on_exit = my_exit,
         capabilities = caps,
       })
       -- lsp-status custom handlers
-      local ok, lspstatus_ext = pcall(lspstatus.extensions[server])
+      local ok, lspstatus_ext = pcall(require('lsp-status').extensions[server])
       if ok then
         opts = vim.tbl_extend('error', opts, {
           handlers = lspstatus_ext.setup(),
         })
       end
-      lsp[server].setup(opts)
+      require('lspconfig')[server].setup(opts)
     end
   end
 end
 
 local format = function(afile)
-  if vim.g.nofmt then return end
+  if vim.g.nofmt then
+    return
+  end
 
   local ok, isMatch = pcall(string.match, afile, '^/home/robert/devel/upstream')
-  if not ok or isMatch then return end
+  if not ok or isMatch then
+    return
+  end
 
   local errhandler = function(err)
     vim.notify('fmt failed: ' .. err, vim.log.levels.ERROR)
@@ -251,54 +298,21 @@ local format = function(afile)
   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})
+    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 = {
-  -- 󰆼  󱆃
-  Array = '󰨾 ',
-  Boolean = '󰦍 ',
-  Class = '󰙀 ',
-  Color = '󰉦 ',
-  Constant = ' ',
-  Constructor = '󱇿 ',
-  Enum = ' ',
-  EnumMember = ' ',
-  Event = '󱐋 ',
-  -- Field = '󰽜 ',
-  Field = '󰆈 ',
-  File = '󰈔 ',
-  Folder = '󰝰 ',
-  Function = ' ',
-  Interface = '󱦜 ',
-  Key = '󰌋 ',
-  Keyword = '󰓽 ',
-  Method = '󰒓 ',
-  Module = '󰏖 ',
-  Namespace = '󰆧 ',
-  Null = '󰎣 ',
-  Object = '󰘦 ',
-  Operator = '󱓉 ',
-  Property = '󰐱 ',
-  Package = '󰏗 ',
-  Reference = '󰌹 ',
-  Snippet = '󰯁 ',
-  Struct = '󰙅 ',
-  Text = '󰉿 ',
-  TypeParameter = '󰌨 ',
-  Unit = '󰠱 ',
-  Value = '󰎠 ',
-  Variable = '󱄑 ',
-}
-
 return {
-  my_attach    = my_attach,
-  my_exit      = my_exit,
+  my_attach = my_attach,
+  my_exit = my_exit,
   capabilities = capabilities,
-  setup        = setup,
-  format       = format,
-  symbols       = symbols,
+  setup = setup,
+  format = format,
+  symbols = symbols,
 }