diff options
| author | kylo252 <[email protected]> | 2022-08-29 14:35:15 +0200 | 
|---|---|---|
| committer | kylo252 <[email protected]> | 2022-08-29 14:35:15 +0200 | 
| commit | 439e0c205a4c09545f08816ab5100fb5d9a93d3b (patch) | |
| tree | 4d3767b7e921dd707fe859b98bbaa5081fce205c /lua/lvim/lsp | |
| parent | 47e4e5b83808f784010aa480753beaaef16ac579 (diff) | |
| parent | df84e4ecce5a7c8838fd21d5de939128f3214ef4 (diff) | |
Merge remote-tracking branch 'origin/rolling'
Diffstat (limited to 'lua/lvim/lsp')
| -rw-r--r-- | lua/lvim/lsp/config.lua | 14 | ||||
| -rw-r--r-- | lua/lvim/lsp/init.lua | 5 | ||||
| -rw-r--r-- | lua/lvim/lsp/manager.lua | 67 | ||||
| -rw-r--r-- | lua/lvim/lsp/null-ls/linters.lua | 12 | ||||
| -rw-r--r-- | lua/lvim/lsp/providers/tailwindcss.lua | 8 | ||||
| -rw-r--r-- | lua/lvim/lsp/templates.lua | 11 | ||||
| -rw-r--r-- | lua/lvim/lsp/utils.lua | 29 | 
7 files changed, 92 insertions, 54 deletions
| diff --git a/lua/lvim/lsp/config.lua b/lua/lvim/lsp/config.lua index e3cd503b..2cd1bc6e 100644 --- a/lua/lvim/lsp/config.lua +++ b/lua/lvim/lsp/config.lua @@ -30,7 +30,6 @@ local skipped_servers = {    "sqlls",    "sqls",    "stylelint_lsp", -  "tailwindcss",    "tflint",    "svlangserver",    "verible", @@ -88,7 +87,6 @@ return {    },    on_attach_callback = nil,    on_init_callback = nil, -  automatic_servers_installation = true,    automatic_configuration = {      ---@usage list of servers that the automatic installer will skip      skipped_servers = skipped_servers, @@ -131,12 +129,8 @@ return {    installer = {      setup = {        ensure_installed = {}, -      ui = { -        icons = { -          server_installed = "✓", -          server_pending = "", -          server_uninstalled = "✗", -        }, +      automatic_installation = { +        exclude = {},        },      },    }, @@ -153,6 +147,8 @@ return {      setup = {},      config = {},    }, -  ---@deprecated use automatic_configuration.skipped_servers instead +  ---@deprecated use lvim.lsp.automatic_configuration.skipped_servers instead    override = {}, +  ---@deprecated use lvim.lsp.installer.setup.automatic_installation instead +  automatic_servers_installation = nil,  } diff --git a/lua/lvim/lsp/init.lua b/lua/lvim/lsp/init.lua index 53b4f248..0b361972 100644 --- a/lua/lvim/lsp/init.lua +++ b/lua/lvim/lsp/init.lua @@ -110,7 +110,10 @@ function M.setup()    end)    pcall(function() -    require("nvim-lsp-installer").setup(lvim.lsp.installer.setup) +    require("mason-lspconfig").setup(lvim.lsp.installer.setup) +    local util = require "lspconfig.util" +    -- automatic_installation is handled by lsp-manager +    util.on_setup = nil    end)    require("lvim.lsp.null-ls").setup() diff --git a/lua/lvim/lsp/manager.lua b/lua/lvim/lsp/manager.lua index 00643815..1323ace7 100644 --- a/lua/lvim/lsp/manager.lua +++ b/lua/lvim/lsp/manager.lua @@ -1,7 +1,30 @@  local M = {}  local Log = require "lvim.core.log" +local fmt = string.format  local lvim_lsp_utils = require "lvim.lsp.utils" +local is_windows = vim.loop.os_uname().version:match "Windows" + +local function resolve_mason_config(server_name) +  local found, mason_config = pcall(require, "mason-lspconfig.server_configurations." .. server_name) +  if not found then +    Log:debug(fmt("mason configuration not found for %s", server_name)) +    return {} +  end +  local server_mapping = require "mason-lspconfig.mappings.server" +  local path = require "mason-core.path" +  local pkg_name = server_mapping.lspconfig_to_package[server_name] +  local install_dir = path.package_prefix(pkg_name) +  local conf = mason_config(install_dir) +  if is_windows and conf.cmd and conf.cmd[1] then +    local exepath = vim.fn.exepath(conf.cmd[1]) +    if exepath ~= "" then +      conf.cmd[1] = exepath +    end +  end +  Log:debug(fmt("resolved mason configuration for %s, got %s", server_name, vim.inspect(conf))) +  return conf or {} +end  ---Resolve the configuration for a server by merging with the default config  ---@param server_name string @@ -65,35 +88,45 @@ function M.setup(server_name, user_config)      return    end -  local servers = require "nvim-lsp-installer.servers" -  local server_available, server = servers.get_server(server_name) +  local server_mapping = require "mason-lspconfig.mappings.server" +  local registry = require "mason-registry" -  if not server_available then +  local pkg_name = server_mapping.lspconfig_to_package[server_name] +  if not pkg_name then      local config = resolve_config(server_name, user_config)      launch_server(server_name, config)      return    end -  local install_in_progress = false +  local should_auto_install = function(name) +    local installer_settings = lvim.lsp.installer.setup +    return installer_settings.automatic_installation +      and not vim.tbl_contains(installer_settings.automatic_installation.exclude, name) +  end -  if not server:is_installed() then -    if lvim.lsp.automatic_servers_installation then +  if not registry.is_installed(pkg_name) then +    if should_auto_install(server_name) then        Log:debug "Automatic server installation detected" -      server:install() -      install_in_progress = true +      vim.notify_once(string.format("Installation in progress for [%s]", server_name), vim.log.levels.INFO) +      local pkg = registry.get_package(pkg_name) +      pkg:install():once("closed", function() +        if pkg:is_installed() then +          vim.schedule(function() +            vim.notify_once(string.format("Installation complete for [%s]", server_name), vim.log.levels.INFO) +            -- mason config is only available once the server has been installed +            local config = resolve_config(server_name, resolve_mason_config(server_name), user_config) +            launch_server(server_name, config) +          end) +        end +      end) +      return      else -      Log:debug(server.name .. " is not managed by the automatic installer") +      Log:debug(server_name .. " is not managed by the automatic installer")      end    end -  server:on_ready(function() -    if install_in_progress then -      vim.notify(string.format("Installation complete for [%s] server", server.name), vim.log.levels.INFO) -    end -    install_in_progress = false -    local config = resolve_config(server_name, server:get_default_options(), user_config) -    launch_server(server_name, config) -  end) +  local config = resolve_config(server_name, resolve_mason_config(server_name), user_config) +  launch_server(server_name, config)  end  return M diff --git a/lua/lvim/lsp/null-ls/linters.lua b/lua/lvim/lsp/null-ls/linters.lua index 07c8094b..ba7670d3 100644 --- a/lua/lvim/lsp/null-ls/linters.lua +++ b/lua/lvim/lsp/null-ls/linters.lua @@ -6,9 +6,19 @@ local null_ls = require "null-ls"  local services = require "lvim.lsp.null-ls.services"  local method = null_ls.methods.DIAGNOSTICS +local alternative_methods = { +  null_ls.methods.DIAGNOSTICS, +  null_ls.methods.DIAGNOSTICS_ON_OPEN, +  null_ls.methods.DIAGNOSTICS_ON_SAVE, +} +  function M.list_registered(filetype)    local registered_providers = services.list_registered_providers_names(filetype) -  return registered_providers[method] or {} +  local providers_for_methods = vim.tbl_flatten(vim.tbl_map(function(m) +    return registered_providers[m] or {} +  end, alternative_methods)) + +  return providers_for_methods  end  function M.list_supported(filetype) diff --git a/lua/lvim/lsp/providers/tailwindcss.lua b/lua/lvim/lsp/providers/tailwindcss.lua new file mode 100644 index 00000000..063cf89f --- /dev/null +++ b/lua/lvim/lsp/providers/tailwindcss.lua @@ -0,0 +1,8 @@ +local opts = { +  root_dir = function(fname) +    local util = require "lspconfig/util" +    return util.root_pattern("tailwind.config.js", "tailwind.config.cjs", "tailwind.js", "tailwind.cjs")(fname) +  end, +} + +return opts diff --git a/lua/lvim/lsp/templates.lua b/lua/lvim/lsp/templates.lua index 578362a7..dc2e5b11 100644 --- a/lua/lvim/lsp/templates.lua +++ b/lua/lvim/lsp/templates.lua @@ -56,21 +56,12 @@ end  ---The files are generated to a runtimepath: "$LUNARVIM_RUNTIME_DIR/site/after/ftplugin/template.lua"  ---@param servers_names? table list of servers to be enabled. Will add all by default  function M.generate_templates(servers_names) -  servers_names = servers_names or {} +  servers_names = servers_names or lvim_lsp_utils.get_supported_servers()    Log:debug "Templates installation in progress"    M.remove_template_files() -  if vim.tbl_isempty(servers_names) then -    local available_servers = require("nvim-lsp-installer.servers").get_available_servers() - -    for _, server in pairs(available_servers) do -      table.insert(servers_names, server.name) -      table.sort(servers_names) -    end -  end -    -- create the directory if it didn't exist    if not utils.is_directory(lvim.lsp.templates_dir) then      vim.fn.mkdir(ftplugin_dir, "p") diff --git a/lua/lvim/lsp/utils.lua b/lua/lvim/lsp/utils.lua index fa1ac6d9..b92ef11c 100644 --- a/lua/lvim/lsp/utils.lua +++ b/lua/lvim/lsp/utils.lua @@ -51,37 +51,34 @@ end  ---Get supported filetypes per server  ---@param server_name string can be any server supported by nvim-lsp-installer ----@return table supported filestypes as a list of strings +---@return string[] supported filestypes as a list of strings  function M.get_supported_filetypes(server_name) -  local status_ok, lsp_installer_servers = pcall(require, "nvim-lsp-installer.servers") +  local status_ok, config = pcall(require, ("lspconfig.server_configurations.%s"):format(server_name))    if not status_ok then      return {}    end -  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() +  return config.default_config.filetypes or {}  end  ---Get supported servers per filetype ----@param filetype string ----@return table list of names of supported servers -function M.get_supported_servers_per_filetype(filetype) -  local filetype_server_map = require "nvim-lsp-installer._generated.filetype_map" -  return filetype_server_map[filetype] +---@param filter { filetype: string | string[] }?: (optional) Used to filter the list of server names. +---@return string[] list of names of supported servers +function M.get_supported_servers(filter) +  local _, supported_servers = pcall(function() +    return require("mason-lspconfig").get_available_servers(filter) +  end) +  return supported_servers or {}  end  ---Get all supported filetypes by nvim-lsp-installer ----@return table supported filestypes as a list of strings +---@return string[] supported filestypes as a list of strings  function M.get_all_supported_filetypes() -  local status_ok, lsp_installer_filetypes = pcall(require, "nvim-lsp-installer._generated.filetype_map") +  local status_ok, filetype_server_map = pcall(require, "mason-lspconfig.mappings.filetype")    if not status_ok then      return {}    end -  return vim.tbl_keys(lsp_installer_filetypes or {}) +  return vim.tbl_keys(filetype_server_map or {})  end  function M.setup_document_highlight(client, bufnr) | 
