summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--.vim/lua/lsp.lua217
1 files changed, 123 insertions, 94 deletions
diff --git a/.vim/lua/lsp.lua b/.vim/lua/lsp.lua
index d8a4818..64a6895 100644
--- a/.vim/lua/lsp.lua
+++ b/.vim/lua/lsp.lua
@@ -74,73 +74,82 @@ local capabilities = function()
   return caps
 end
 
-local setup = function()
-  local caps = capabilities()
-  -- spinner_lsp.setup()
-  -- spinner_lsp.init_capabilities(caps)
+-- overwrite codeAction handler to not ask for confirmation if only a single
+-- action is given
+local my_code_action_handler = function(_, _, actions)
+  -- skip printing 'no code actions available'
+  if (not actions) or #actions == 0 then return end
+
+  local action_chosen
+  if #actions == 1 then
+    action_chosen = actions[1]
+  else
+    local option_strings = {}
+    for i, action in ipairs(actions) do
+      local title = action.title:gsub('\r\n', '\\r\\n')
+      title = title:gsub('\n', '\\n')
+      table.insert(option_strings, string.format('%d. %s', i, title))
+    end
+    vim.ui.select(option_strings,
+      {
+        prompt = 'Code Actions',
+      },
+      function(choice)
+        if choice < 1 or choice > #actions then
+          return
+        end
+        action_chosen = actions[choice]
+    end)
+  end
 
-  -- handler overwrites
-  -- overwrite codeAction handler to not ask for confirmation if only a single
-  -- action is given
-  -- vim.lsp.handlers['textDocument/codeAction'] = function(_, _, actions) -- {{{
-  --   if actions == nil or #actions == 0 then
-  --     -- skip printing 'no code actions available'
-  --     return
-  --   end
-  --
-  --   local action_chosen
-  --   if #actions == 1 then
-  --     action_chosen = actions[1]
-  --   else
-  --     local option_strings = {}
-  --     for i, action in ipairs(actions) do
-  --       local title = action.title:gsub('\r\n', '\\r\\n')
-  --       title = title:gsub('\n', '\\n')
-  --       table.insert(option_strings, string.format('%d. %s', i, title))
-  --     end
-  --
-  --     vim.ui.select(option_strings,
-  --       {
-  --         prompt = 'Code Actions: blabla',
-  --       },
-  --       function(choice)
-  --         if choice < 1 or choice > #actions then
-  --           return
-  --         end
-  --         action_chosen = actions[choice]
-  --     end)
-  --   end
-  --
-  --   if action_chosen.edit or type(action_chosen.command) == 'table' then
-  --     if action_chosen.edit then
-  --       vim.lsp.util.apply_workspace_edit(action_chosen.edit)
-  --     end
-  --     if type(action_chosen.command) == 'table' then
-  --       vim.lsp.buf.execute_command(action_chosen.command)
-  --     end
-  --   else
-  --     vim.lsp.buf.execute_command(action_chosen)
-  --   end
-  -- end
-  -- }}}
+  if action_chosen.edit or type(action_chosen.command) == 'table' then
+    if action_chosen.edit then
+      vim.lsp.util.apply_workspace_edit(action_chosen.edit)
+    end
+    if type(action_chosen.command) == 'table' then
+      vim.lsp.buf.execute_command(action_chosen.command)
+    end
+  else
+    vim.lsp.buf.execute_command(action_chosen)
+  end
+end
+
+local handlers = {
+  -- ['textDocument/hover'] = vim.lsp.with(vim.lsp.handlers.hover, {border = border}),
+  -- ['textDocument/signatureHelp'] = vim.lsp.with(vim.lsp.handlers.signatureHelp, {border = border}),
+  ['textDocument/codeAction'] = my_code_action_handler,
+}
+-- }}}
+
+
+-- local lua_runtime_path = vim.split(package.path, ';')
+-- table.insert(lua_runtime_path, 'lua/?.lua')
+-- table.insert(lua_runtime_path, 'lua/?/init.lua')
 
-  lsp.ccls.setup {
-    on_attach = my_attach,
-    on_exit = my_exit,
-    capabilities = caps,
-    root_dir = lsp.util.root_pattern('.ccls','meson.build', 'Makefile','.git'),
+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 = {
+    root_dir = lsp.util.root_pattern('.ccls','meson.build','.git'),
+  },
+  elixirls = {
+    cmd = { 'elixir-ls' },
+    settings = {
+      elixirLS = {
+        dialyzerEnabled = false,
       }
     }
-  }
-
-  lsp.gopls.setup {
-    on_attach = my_attach,
-    on_exit = my_exit,
-    capabilities = caps,
+  },
+  gopls = {
     settings = {
       gopls = {
         analyses = {
@@ -155,57 +164,77 @@ local setup = function()
         -- hoverKind = 'Structured',
       }
     }
-  }
-
-  lsp.sumneko_lua.setup {
-    on_attach = my_attach,
-    on_exit = my_exit,
-    capabilities = caps,
-    cmd = { 'lua-language-server' };
+  },
+  sumneko_lua = {
+    cmd = { 'lua-language-server' },
     settings = {
       Lua = {
         runtime = {
           version = 'LuaJIT',
+          path = lua_runtime_path,
         },
         diagnostics = {
-          globals = {'vim'},
+          globals = { 'vim' },
+        },
+        -- workspace = {
+        --   library = vim.api.nvim_get_runtime_file('', true)
+        -- },
+        telemetry = {
+          enable = false,
         },
-        workspace = {
-          library = {
-            [vim.fn.expand('$VIMRUNTIME/lua')] = true,
-            [vim.fn.expand('$VIMRUNTIME/lua/vim/lsp')] = true,
-          }
+      },
+    },
+  },
+  rust_analyzer = {
+    cmd = { 'env', 'CARGO_TARGET_DIR=/tmp', 'RUST_SRC_PATH=/usr/src/rustlib/library', 'rust-analyzer' },
+    settings = {
+      ['rust-analyzer'] = {
+        checkOnSave = {
+          command = 'clippy'
         }
       }
-    }
-  }
-
-  lsp.rust_analyzer.setup {
-    on_attach = my_attach,
-    on_exit = my_exit,
-    capabilities = caps,
-    cmd = { 'env', 'CARGO_TARGET_DIR=/tmp', 'RUST_SRC_PATH=/usr/src/rustlib/library', 'rust-analyzer' },
-  }
-
-  lsp.zls.setup {
-    on_attach = my_attach,
-    on_exit = my_exit,
-    capabilities = caps,
-  }
+    },
+  },
+  tsserver = { disabled = true,
+    cmd = {
+      'toolbox', 'run', '--',
+      'sh', '-c',
+      '. /etc/profile.d/nvm.sh && typescript-language-server --stdio'
+    },
+  },
+  zls = { disabled = true },
+  zk = { disabled = true,
+    root_dir = lsp.util.root_pattern('.zk'),
+  },
+}
 
+local setup = function()
+  local caps = capabilities()
+  -- spinner_lsp.setup()
+  -- spinner_lsp.init_capabilities(caps)
+  for server, opts in pairs(servers) do
+    if not opts.disabled then
+      opts = vim.tbl_extend('keep', opts, {
+        on_attach    = my_attach,
+        on_exit      = my_exit,
+        capabilities = caps,
+        handlers     = handlers,
+      })
+      lsp[server].setup(opts)
+    end
+  end
 end
 
 return {
-  my_attach = my_attach,
-  my_exit = my_exit,
+  my_attach    = my_attach,
+  my_exit      = my_exit,
   capabilities = capabilities,
-  setup = setup,
+  setup        = setup,
 
   format = function(afile)
-    local doit = true
-    doit = doit and not string.match(afile, "^/home/robert/devel/upstream")
-    if doit then
-      print('Formatting using LSP:', afile)
+    local condition = not string.match(afile, "^/home/robert/devel/upstream")
+    if condition then
+      -- vim.notify('%#MoreMsg#󰃢%#Italic# fmt')
       vim.lsp.buf.formatting_seq_sync(nil, 1000)
     end
   end,