summaryrefslogtreecommitdiff
path: root/.config/nvim/lua/lsp
diff options
context:
space:
mode:
authorGustaf Rydholm <gustaf.rydholm@gmail.com>2021-11-08 23:13:05 +0100
committerGustaf Rydholm <gustaf.rydholm@gmail.com>2021-11-08 23:13:05 +0100
commitc9e2adbbc8fd7a5398c8c66d21f0e02dc7b60203 (patch)
tree274263ba15e0197180af8bb681e22c4780d5de05 /.config/nvim/lua/lsp
parente4ea22e223bbd6b4091610c6fa093862cbd32f75 (diff)
Add new lunarvin updates
Diffstat (limited to '.config/nvim/lua/lsp')
-rw-r--r--.config/nvim/lua/lsp/config.lua24
-rw-r--r--.config/nvim/lua/lsp/handlers.lua13
-rw-r--r--.config/nvim/lua/lsp/init.lua11
-rw-r--r--.config/nvim/lua/lsp/manager.lua70
-rw-r--r--.config/nvim/lua/lsp/null-ls/formatters.lua3
-rw-r--r--.config/nvim/lua/lsp/null-ls/init.lua17
-rw-r--r--.config/nvim/lua/lsp/null-ls/linters.lua3
-rw-r--r--.config/nvim/lua/lsp/templates.lua41
-rw-r--r--.config/nvim/lua/lsp/utils.lua19
9 files changed, 102 insertions, 99 deletions
diff --git a/.config/nvim/lua/lsp/config.lua b/.config/nvim/lua/lsp/config.lua
index 9c25249..673f924 100644
--- a/.config/nvim/lua/lsp/config.lua
+++ b/.config/nvim/lua/lsp/config.lua
@@ -1,5 +1,5 @@
return {
- templates_dir = join_paths(get_config_dir(), "ftplugin"),
+ templates_dir = join_paths(get_runtime_dir(), "site", "after", "ftplugin"),
diagnostics = {
signs = {
active = true,
@@ -15,7 +15,6 @@ return {
underline = true,
severity_sort = true,
},
- override = {},
document_highlight = true,
code_lens_refresh = true,
popup_border = "single",
@@ -42,4 +41,25 @@ return {
null_ls = {
setup = {},
},
+ override = {
+ "angularls",
+ "ansiblels",
+ "denols",
+ "ember",
+ "emmet_ls",
+ "eslint",
+ "eslintls",
+ "graphql",
+ "jedi_language_server",
+ "ltex",
+ "phpactor",
+ "pylsp",
+ "rome",
+ "sqlls",
+ "sqls",
+ "stylelint_lsp",
+ "tailwindcss",
+ "tflint",
+ "volar",
+ },
}
diff --git a/.config/nvim/lua/lsp/handlers.lua b/.config/nvim/lua/lsp/handlers.lua
index 6801045..01666be 100644
--- a/.config/nvim/lua/lsp/handlers.lua
+++ b/.config/nvim/lua/lsp/handlers.lua
@@ -132,7 +132,18 @@ function M.show_line_diagnostics()
table.sort(diagnostics, function(a, b)
return a.severity < b.severity
end)
- for i, diagnostic in ipairs(diagnostics) do
+
+ local hash = {}
+ local diagnostics_no_dupes = {}
+ for _, v in ipairs(diagnostics) do
+ if not hash[v["message"]] then
+ diagnostics_no_dupes[#diagnostics_no_dupes + 1] = v -- you could print here instead of saving to result table if you wanted
+ hash[v["message"]] = true
+ end
+ end
+ -- print(vim.inspect(diagnostics_no_dupes))
+
+ for i, diagnostic in ipairs(diagnostics_no_dupes) do
local source = diagnostic.source
diag_message = diagnostic.message:gsub("[\n\r]", " ")
if source then
diff --git a/.config/nvim/lua/lsp/init.lua b/.config/nvim/lua/lsp/init.lua
index 42c2536..f92ecd3 100644
--- a/.config/nvim/lua/lsp/init.lua
+++ b/.config/nvim/lua/lsp/init.lua
@@ -95,17 +95,16 @@ function M.common_capabilities()
end
local function select_default_formater(client)
- local client_formatting = client.resolved_capabilities.document_formatting
- or client.resolved_capabilities.document_range_formatting
- if client.name == "null-ls" or not client_formatting then
+ if
+ client.name == "null-ls" or not client.resolved_capabilities.document_formatting
+ then
return
end
Log:debug("Checking for formatter overriding for " .. client.name)
+ local formatters = require "lvim.lsp.null-ls.formatters"
local client_filetypes = client.config.filetypes or {}
for _, filetype in ipairs(client_filetypes) do
- if
- options.lang[filetype] and #vim.tbl_keys(options.lang[filetype].formatters) > 0
- then
+ if #vim.tbl_keys(formatters.list_registered_providers(filetype)) > 0 then
Log:debug(
"Formatter overriding detected. Disabling formatting capabilities for "
.. client.name
diff --git a/.config/nvim/lua/lsp/manager.lua b/.config/nvim/lua/lsp/manager.lua
index a7d6892..24fb6e3 100644
--- a/.config/nvim/lua/lsp/manager.lua
+++ b/.config/nvim/lua/lsp/manager.lua
@@ -15,15 +15,6 @@ function M.init_defaults(languages)
end
end
-local function is_overridden(server)
- local overrides = options.lsp.override
- if type(overrides) == "table" then
- if vim.tbl_contains(overrides, server) then
- return true
- end
- end
-end
-
---Resolve the configuration for a server based on both common and user configuration
---@param name string
---@param user_config table [optional]
@@ -35,11 +26,8 @@ local function resolve_config(name, user_config)
capabilities = require("lsp").common_capabilities(),
}
- local status_ok, custom_config = pcall(
- require,
- "lsp/providers/" .. name
- )
- if status_ok then
+ local has_custom_provider, custom_config = pcall(require, "lsp/providers/" .. name)
+ if has_custom_provider then
Log:debug("Using custom configuration for requested server: " .. name)
config = vim.tbl_deep_extend("force", config, custom_config)
end
@@ -51,38 +39,56 @@ local function resolve_config(name, user_config)
return config
end
+-- manually start the server and don't wait for the usual filetype trigger from lspconfig
+local function buf_try_add(server_name, bufnr)
+ bufnr = bufnr or vim.api.nvim_get_current_buf()
+ require("lspconfig")[server_name].manager.try_add_wrapper(bufnr)
+end
+
---Setup a language server by providing a name
---@param server_name string name of the language server
---@param user_config table [optional] when available it will take predence over any default configurations
function M.setup(server_name, user_config)
vim.validate { name = { server_name, "string" } }
- if lsp_utils.is_client_active(server_name) or is_overridden(server_name) then
+ 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 server_available, requested_server = require("nvim-lsp-installer.servers").get_server(server_name)
+ local server_available, requested_server = servers.get_server(server_name)
- local function ensure_installed(server)
- if server:is_installed() then
- return true
- end
- if not lvim.lsp.automatic_servers_installation then
- Log:debug(server.name .. " is not managed by the automatic installer")
- return false
+ 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
- Log:debug(string.format("Installing [%s]", server.name))
- server:install()
- vim.schedule(function()
- vim.cmd [[LspStart]]
- end)
- end
- if server_available and ensure_installed(requested_server) then
- requested_server:setup(config)
+ 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
- require("lspconfig")[server_name].setup(config)
+ -- 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
+ require("lspconfig")[server_name].setup(config)
+ buf_try_add(server_name)
+ end
end
end
diff --git a/.config/nvim/lua/lsp/null-ls/formatters.lua b/.config/nvim/lua/lsp/null-ls/formatters.lua
index 577a0d9..991f613 100644
--- a/.config/nvim/lua/lsp/null-ls/formatters.lua
+++ b/.config/nvim/lua/lsp/null-ls/formatters.lua
@@ -4,7 +4,7 @@ local null_ls = require "null-ls"
local services = require "lsp.null-ls.services"
local Log = require "core.log"
-function M.list_supported_names(filetype)
+function M.list_registered_providers(filetype)
local null_ls_methods = require "null-ls.methods"
local formatter_method = null_ls_methods.internal["FORMATTING"]
local registered_providers = services.list_registered_providers_names(filetype)
@@ -24,6 +24,7 @@ function M.list_available(filetype)
end
end
+ table.sort(formatters)
return formatters
end
diff --git a/.config/nvim/lua/lsp/null-ls/init.lua b/.config/nvim/lua/lsp/null-ls/init.lua
index a18209b..9560240 100644
--- a/.config/nvim/lua/lsp/null-ls/init.lua
+++ b/.config/nvim/lua/lsp/null-ls/init.lua
@@ -1,8 +1,6 @@
local M = {}
local Log = require "core.log"
-local formatters = require "lsp.null-ls.formatters"
-local linters = require "lsp.null-ls.linters"
function M:setup()
local status_ok, null_ls = pcall(require, "null-ls")
@@ -17,21 +15,8 @@ function M:setup()
if vim.tbl_isempty(options.lsp.null_ls.setup or {}) then
options.lsp.null_ls.setup = default_opts
end
+
require("lspconfig")["null-ls"].setup(options.lsp.null_ls.setup)
- for filetype, config in pairs(options.lang) do
- if not vim.tbl_isempty(config.formatters) then
- vim.tbl_map(function(c)
- c.filetypes = { filetype }
- end, config.formatters)
- formatters.setup(config.formatters)
- end
- if not vim.tbl_isempty(config.linters) then
- vim.tbl_map(function(c)
- c.filetypes = { filetype }
- end, config.formatters)
- linters.setup(config.linters)
- end
- end
end
return M
diff --git a/.config/nvim/lua/lsp/null-ls/linters.lua b/.config/nvim/lua/lsp/null-ls/linters.lua
index 3f834ba..85555ba 100644
--- a/.config/nvim/lua/lsp/null-ls/linters.lua
+++ b/.config/nvim/lua/lsp/null-ls/linters.lua
@@ -4,7 +4,7 @@ local null_ls = require "null-ls"
local services = require "lsp.null-ls.services"
local Log = require "core.log"
-function M.list_supported_names(filetype)
+function M.list_registered_providers(filetype)
local null_ls_methods = require "null-ls.methods"
local linter_method = null_ls_methods.internal["DIAGNOSTICS"]
local registered_providers = services.list_registered_providers_names(filetype)
@@ -24,6 +24,7 @@ function M.list_available(filetype)
end
end
+ table.sort(linters)
return linters
end
diff --git a/.config/nvim/lua/lsp/templates.lua b/.config/nvim/lua/lsp/templates.lua
index 2cce567..084c1f9 100644
--- a/.config/nvim/lua/lsp/templates.lua
+++ b/.config/nvim/lua/lsp/templates.lua
@@ -2,7 +2,7 @@ local M = {}
local Log = require "core.log"
local utils = require "utils"
-local get_supported_filetypes = require("lsp.utils").get_supported_filetypes
+local lsp_utils = require "lsp.utils"
local ftplugin_dir = options.lsp.templates_dir
@@ -15,48 +15,23 @@ function M.remove_template_files()
end
end
----Checks if a server is ignored by default because of a conflict
----Only TSServer is enabled by default for the javascript-family
----@param server_name string
-function M.is_ignored(server_name, filetypes)
- --TODO: this is easy to be made configurable once stable
- filetypes = filetypes or get_supported_filetypes(server_name)
-
- if vim.tbl_contains(filetypes, "javascript") then
- if server_name == "tsserver" then
- return false
- else
- return true
- end
- end
-
- local blacklist = {
- "jedi_language_server",
- "pylsp",
- "sqlls",
- "sqls",
- "angularls",
- "ansiblels",
- }
- return vim.tbl_contains(blacklist, server_name)
-end
-
---Generates an ftplugin file based on the server_name in the selected directory
---@param server_name string name of a valid language server, e.g. pyright, gopls, tsserver, etc.
---@param dir string the full path to the desired directory
function M.generate_ftplugin(server_name, dir)
- -- we need to go through lspconfig to get the corresponding filetypes currently
- local filetypes = get_supported_filetypes(server_name) or {}
- if not filetypes then
+ local has_custom_provider, _ = pcall(require, "lsp/providers/" .. server_name)
+ if
+ vim.tbl_contains(options.lsp.override, server_name) and not has_custom_provider
+ then
return
end
- if M.is_ignored(server_name, filetypes) then
+ -- we need to go through lspconfig to get the corresponding filetypes currently
+ local filetypes = lsp_utils.get_supported_filetypes(server_name) or {}
+ if not filetypes then
return
end
- -- print("got associated filetypes: " .. vim.inspect(filetypes))
-
for _, filetype in ipairs(filetypes) do
local filename = join_paths(dir, filetype .. ".lua")
local setup_cmd = string.format([[require("lsp.manager").setup(%q)]], server_name)
diff --git a/.config/nvim/lua/lsp/utils.lua b/.config/nvim/lua/lsp/utils.lua
index 5900340..afc3eba 100644
--- a/.config/nvim/lua/lsp/utils.lua
+++ b/.config/nvim/lua/lsp/utils.lua
@@ -49,14 +49,19 @@ function M.get_client_capabilities(client_id)
end
function M.get_supported_filetypes(server_name)
- -- print("got filetypes query request for: " .. server_name)
- local configs = require "lspconfig/configs"
- pcall(require, ("lspconfig/" .. server_name))
- for _, config in pairs(configs) do
- if config.name == server_name then
- return config.document_config.default_config.filetypes or {}
- end
+ -- temporary workaround: https://github.com/neovim/nvim-lspconfig/pull/1358
+ if server_name == "dockerls" then
+ return { "dockerfile" }
+ end
+ local lsp_installer_servers = require "nvim-lsp-installer.servers"
+ local server_available, requested_server = lsp_installer_servers.get_server(
+ server_name
+ )
+ if not server_available then
+ return {}
end
+
+ return requested_server:get_supported_filetypes()
end
return M