summaryrefslogtreecommitdiff
path: root/.config/nvim/lua/lsp
diff options
context:
space:
mode:
Diffstat (limited to '.config/nvim/lua/lsp')
-rw-r--r--.config/nvim/lua/lsp/manager.lua56
-rw-r--r--.config/nvim/lua/lsp/null-ls/code_actions.lua81
-rw-r--r--.config/nvim/lua/lsp/null-ls/formatters.lua8
-rw-r--r--.config/nvim/lua/lsp/null-ls/linters.lua8
4 files changed, 123 insertions, 30 deletions
diff --git a/.config/nvim/lua/lsp/manager.lua b/.config/nvim/lua/lsp/manager.lua
index 24fb6e3..268e90d 100644
--- a/.config/nvim/lua/lsp/manager.lua
+++ b/.config/nvim/lua/lsp/manager.lua
@@ -54,42 +54,42 @@ function M.setup(server_name, user_config)
if lsp_utils.is_client_active(server_name) then
return
end
- local servers = require "nvim-lsp-installer.servers"
local config = resolve_config(server_name, user_config)
+ local servers = require "nvim-lsp-installer.servers"
local server_available, requested_server = servers.get_server(server_name)
- if server_available then
- local install_notification = false
-
- if not requested_server:is_installed() then
- if options.lsp.automatic_servers_installation then
- Log:debug "Automatic server installation detected"
- requested_server:install()
- install_notification = true
- else
- Log:debug(requested_server.name .. " is not managed by the automatic installer")
- end
- end
-
- requested_server:on_ready(function()
- if install_notification then
- vim.notify(
- string.format("Installation complete for [%s] server", requested_server.name),
- vim.log.levels.INFO
- )
- end
- install_notification = false
- requested_server:setup(config)
- end)
- else
- -- since it may not be installed, don't attempt to configure the LSP unless there is a custom provider
- local has_custom_provider, _ = pcall(require, "lsp/providers/" .. server_name)
- if has_custom_provider then
+ local is_overridden = vim.tbl_contains(options.lsp.override, server_name)
+ if not server_available or is_overridden then
+ pcall(function()
require("lspconfig")[server_name].setup(config)
buf_try_add(server_name)
+ end)
+ return
+ end
+
+ local install_notification = false
+
+ if not requested_server:is_installed() then
+ if options.lsp.automatic_servers_installation then
+ Log:debug "Automatic server installation detected"
+ requested_server:install()
+ install_notification = true
+ else
+ Log:debug(requested_server.name .. " is not managed by the automatic installer")
end
end
+
+ requested_server:on_ready(function()
+ if install_notification then
+ vim.notify(
+ string.format("Installation complete for [%s] server", requested_server.name),
+ vim.log.levels.INFO
+ )
+ end
+ install_notification = false
+ requested_server:setup(config)
+ end)
end
return M
diff --git a/.config/nvim/lua/lsp/null-ls/code_actions.lua b/.config/nvim/lua/lsp/null-ls/code_actions.lua
new file mode 100644
index 0000000..70cecda
--- /dev/null
+++ b/.config/nvim/lua/lsp/null-ls/code_actions.lua
@@ -0,0 +1,81 @@
+local M = {}
+
+local null_ls = require "null-ls"
+local services = require "lsp.null-ls.services"
+local Log = require "core.log"
+
+local METHOD = null_ls.methods.CODE_ACTION
+
+local is_registered = function(name)
+ local query = {
+ name = name,
+ method = METHOD,
+ }
+ return require("null-ls.sources").is_registered(query)
+end
+
+function M.list_registered_providers(filetype)
+ local registered_providers = services.list_registered_providers_names(filetype)
+ return registered_providers[METHOD] or {}
+end
+
+function M.list_available(filetype)
+ local availables = require("null-ls.sources").get_available(filetype, METHOD)
+ local actors = vim.tbl_map(function(src)
+ return src.name
+ end, availables)
+ table.sort(actors)
+ return actors
+end
+
+function M.list_configured(actions_configs)
+ local actors, errors = {}, {}
+
+ for _, config in ipairs(actions_configs) do
+ vim.validate {
+ ["config.name"] = { config.name, "string" },
+ }
+
+ local name = config.name:gsub("-", "_")
+ local actor = null_ls.builtins.code_actions[name]
+
+ if not actor then
+ Log:error("Not a valid code_actions: " .. config.name)
+ errors[name] = {} -- Add data here when necessary
+ elseif is_registered(config.name) then
+ Log:trace "Skipping registering the source more than once"
+ else
+ local command
+ if actor._opts.command then
+ command = services.find_command(actor._opts.command)
+ end
+ if not command and actor._opts.command ~= nil then
+ Log:warn("Not found: " .. actor._opts.command)
+ errors[name] = {} -- Add data here when necessary
+ else
+ Log:debug("Using code_actions: " .. (command or config.name))
+ table.insert(
+ actors,
+ actor.with {
+ command = command, -- could be nil
+ extra_args = config.args,
+ filetypes = config.filetypes,
+ }
+ )
+ end
+ end
+ end
+
+ return { supported = actors, unsupported = errors }
+end
+
+function M.setup(actions_configs)
+ if vim.tbl_isempty(actions_configs) then
+ return
+ end
+
+ local actions = M.list_configured(actions_configs)
+ null_ls.register { sources = actions.supported }
+end
+
+return M
diff --git a/.config/nvim/lua/lsp/null-ls/formatters.lua b/.config/nvim/lua/lsp/null-ls/formatters.lua
index 7bd4dc4..72d622a 100644
--- a/.config/nvim/lua/lsp/null-ls/formatters.lua
+++ b/.config/nvim/lua/lsp/null-ls/formatters.lua
@@ -4,7 +4,13 @@ local null_ls = require "null-ls"
local services = require "lsp.null-ls.services"
local Log = require "core.log"
-local is_registered = require("null-ls.sources").is_registered
+local is_registered = function(name)
+ local query = {
+ name = name,
+ method = require("null-ls").methods.FORMATTING,
+ }
+ return require("null-ls.sources").is_registered(query)
+end
function M.list_registered_providers(filetype)
local null_ls_methods = require "null-ls.methods"
diff --git a/.config/nvim/lua/lsp/null-ls/linters.lua b/.config/nvim/lua/lsp/null-ls/linters.lua
index 0d34365..ec5e25a 100644
--- a/.config/nvim/lua/lsp/null-ls/linters.lua
+++ b/.config/nvim/lua/lsp/null-ls/linters.lua
@@ -4,7 +4,13 @@ local null_ls = require "null-ls"
local services = require "lsp.null-ls.services"
local Log = require "core.log"
-local is_registered = require("null-ls.sources").is_registered
+local is_registered = function(name)
+ local query = {
+ name = name,
+ method = require("null-ls").methods.DIAGNOSTICS,
+ }
+ return require("null-ls.sources").is_registered(query)
+end
function M.list_registered_providers(filetype)
local null_ls_methods = require "null-ls.methods"