diff options
Diffstat (limited to '.config/nvim/lua/lsp')
-rw-r--r-- | .config/nvim/lua/lsp/init.lua | 43 | ||||
-rw-r--r-- | .config/nvim/lua/lsp/null-ls/formatters.lua | 2 | ||||
-rw-r--r-- | .config/nvim/lua/lsp/null-ls/linters.lua | 2 | ||||
-rw-r--r-- | .config/nvim/lua/lsp/null-ls/services.lua | 24 | ||||
-rw-r--r-- | .config/nvim/lua/lsp/utils.lua | 3 |
5 files changed, 31 insertions, 43 deletions
diff --git a/.config/nvim/lua/lsp/init.lua b/.config/nvim/lua/lsp/init.lua index 067375f..b693dec 100644 --- a/.config/nvim/lua/lsp/init.lua +++ b/.config/nvim/lua/lsp/init.lua @@ -5,10 +5,7 @@ function M.config() vim.lsp.protocol.CompletionItemKind = options.lsp.completion.item_kind for _, sign in ipairs(options.lsp.diagnostics.signs.values) do - vim.fn.sign_define( - sign.name, - { texthl = sign.name, text = sign.text, numhl = sign.name } - ) + vim.fn.sign_define(sign.name, { texthl = sign.name, text = sign.text, numhl = sign.name }) end require("lsp.handlers").setup() @@ -37,7 +34,11 @@ local function lsp_highlight_document(client) end local function add_lsp_buffer_keybindings(bufnr) - local wk = require "which-key" + local status_ok, wk = pcall(require, "which-key") + if not status_ok then + return + end + local keys = { ["K"] = { "<cmd>lua vim.lsp.buf.hover()<CR>", "Show hover" }, ["gd"] = { "<cmd>lua vim.lsp.buf.definition()<CR>", "Goto Definition" }, @@ -54,14 +55,6 @@ local function add_lsp_buffer_keybindings(bufnr) wk.register(keys, { mode = "n", buffer = bufnr }) end -local function set_smart_cwd(client) - local proj_dir = client.config.root_dir - if options.lsp.smart_cwd and proj_dir ~= "/" then - vim.api.nvim_set_current_dir(proj_dir) - require("core.nvimtree").change_tree_dir(proj_dir) - end -end - function M.common_capabilities() local capabilities = vim.lsp.protocol.make_client_capabilities() capabilities.textDocument.completion.completionItem.snippetSupport = true @@ -111,18 +104,10 @@ function M.common_on_init(client, bufnr) end local formatters = options.lang[vim.bo.filetype].formatters - if - not vim.tbl_isempty(formatters) - and formatters[1]["exe"] ~= nil - and formatters[1].exe ~= "" - then + if not vim.tbl_isempty(formatters) and formatters[1]["exe"] ~= nil and formatters[1].exe ~= "" then client.resolved_capabilities.document_formatting = false Log:get_default().info( - string.format( - "Overriding language server [%s] with format provider [%s]", - client.name, - formatters[1].exe - ) + string.format("Overriding language server [%s] with format provider [%s]", client.name, formatters[1].exe) ) end end @@ -134,7 +119,6 @@ function M.common_on_attach(client, bufnr) end lsp_highlight_document(client) add_lsp_buffer_keybindings(bufnr) - set_smart_cwd(client) require("lsp.null-ls").setup(vim.bo.filetype) end @@ -154,6 +138,17 @@ function M.setup(lang) if lsp.provider ~= nil and lsp.provider ~= "" then local lspconfig = require "lspconfig" + + if not lsp.setup.on_attach then + lsp.setup.on_attach = M.common_on_attach + end + if not lsp.setup.on_init then + lsp.setup.on_init = M.common_on_init + end + if not lsp.setup.capabilities then + lsp.setup.capabilities = M.common_capabilities() + end + lspconfig[lsp.provider].setup(lsp.setup) end end diff --git a/.config/nvim/lua/lsp/null-ls/formatters.lua b/.config/nvim/lua/lsp/null-ls/formatters.lua index e69c824..cf62615 100644 --- a/.config/nvim/lua/lsp/null-ls/formatters.lua +++ b/.config/nvim/lua/lsp/null-ls/formatters.lua @@ -66,7 +66,7 @@ function M.list_configured(formatter_configs) end function M.setup(filetype, option) - if formatters_by_ft[filetype] and not option.force_reload then + if not options.lang[filetype] or (formatters_by_ft[filetype] and not option.force_reload) then return end diff --git a/.config/nvim/lua/lsp/null-ls/linters.lua b/.config/nvim/lua/lsp/null-ls/linters.lua index a0675a7..a4eaa89 100644 --- a/.config/nvim/lua/lsp/null-ls/linters.lua +++ b/.config/nvim/lua/lsp/null-ls/linters.lua @@ -66,7 +66,7 @@ function M.list_configured(linter_configs) end function M.setup(filetype, option) - if linters_by_ft[filetype] and not option.force_reload then + if not options.lang[filetype] or (linters_by_ft[filetype] and not option.force_reload) then return end diff --git a/.config/nvim/lua/lsp/null-ls/services.lua b/.config/nvim/lua/lsp/null-ls/services.lua index 80bf66e..a1e3a06 100644 --- a/.config/nvim/lua/lsp/null-ls/services.lua +++ b/.config/nvim/lua/lsp/null-ls/services.lua @@ -1,28 +1,20 @@ local M = {} -local logger = require("core.log"):get_default() - local function find_root_dir() - if options.builtin.rooter.active then - --- use vim-rooter to set root_dir - vim.cmd "let root_dir = FindRootDirectory()" - return vim.api.nvim_get_var "root_dir" - end - - -- TODO: Rework this to not make it javascript specific - --- use LSP to set root_dir + local util = require "lspconfig/util" local lsp_utils = require "lsp.utils" - local ts_client = lsp_utils.get_active_client_by_ft "typescript" - if ts_client == nil then - logger.error "Unable to determine root directory since tsserver didn't start correctly" - return nil - end - return ts_client.config.root_dir + local status_ok, ts_client = lsp_utils.is_client_active "typescript" + if status_ok then + return ts_client.config.root_dir + end + local dirname = vim.fn.expand "%:p:h" + return util.root_pattern "package.json"(dirname) end local function from_node_modules(command) local root_dir = find_root_dir() + if not root_dir then return nil end diff --git a/.config/nvim/lua/lsp/utils.lua b/.config/nvim/lua/lsp/utils.lua index af265de..e024a0c 100644 --- a/.config/nvim/lua/lsp/utils.lua +++ b/.config/nvim/lua/lsp/utils.lua @@ -4,12 +4,13 @@ function M.is_client_active(name) local clients = vim.lsp.get_active_clients() for _, client in pairs(clients) do if client.name == name then - return true + return true, client end end return false end +-- FIXME: this should return a list instead function M.get_active_client_by_ft(filetype) if not options.lang[filetype] or not options.lang[filetype].lsp then return nil |