فهرست منبع

fix(lsp): template generator now uses lsp.override (#1813)

kylo252 3 سال پیش
والد
کامیت
3dd60bd3d4
6فایلهای تغییر یافته به همراه135 افزوده شده و 171 حذف شده
  1. 19 108
      lua/lvim/config/init.lua
  2. 94 0
      lua/lvim/config/supported_languages.lua
  3. 14 1
      lua/lvim/lsp/config.lua
  4. 2 11
      lua/lvim/lsp/manager.lua
  5. 5 33
      lua/lvim/lsp/templates.lua
  6. 1 18
      tests/lsp_spec.lua

+ 19 - 108
lua/lvim/config/init.lua

@@ -33,120 +33,31 @@ function M:init()
   local lvim_lsp_config = require "lvim.lsp.config"
   lvim.lsp = vim.deepcopy(lvim_lsp_config)
 
-  local supported_languages = {
-    "asm",
-    "bash",
-    "beancount",
-    "bibtex",
-    "bicep",
-    "c",
-    "c_sharp",
-    "clojure",
-    "cmake",
-    "comment",
-    "commonlisp",
-    "cpp",
-    "crystal",
-    "cs",
-    "css",
-    "cuda",
-    "d",
-    "dart",
-    "dockerfile",
-    "dot",
-    "elixir",
-    "elm",
-    "emmet",
-    "erlang",
-    "fennel",
-    "fish",
-    "fortran",
-    "gdscript",
-    "glimmer",
-    "go",
-    "gomod",
-    "graphql",
-    "haskell",
-    "hcl",
-    "heex",
-    "html",
-    "java",
-    "javascript",
-    "javascriptreact",
-    "jsdoc",
-    "json",
-    "json5",
-    "jsonc",
-    "julia",
-    "kotlin",
-    "latex",
-    "ledger",
-    "less",
-    "lua",
-    "markdown",
-    "nginx",
-    "nix",
-    "ocaml",
-    "ocaml_interface",
-    "perl",
-    "php",
-    "pioasm",
-    "ps1",
-    "puppet",
-    "python",
-    "ql",
-    "query",
-    "r",
-    "regex",
-    "rst",
-    "ruby",
-    "rust",
-    "scala",
-    "scss",
-    "sh",
-    "solidity",
-    "sparql",
-    "sql",
-    "supercollider",
-    "surface",
-    "svelte",
-    "swift",
-    "tailwindcss",
-    "terraform",
-    "tex",
-    "tlaplus",
-    "toml",
-    "tsx",
-    "turtle",
-    "typescript",
-    "typescriptreact",
-    "verilog",
-    "vim",
-    "vue",
-    "yaml",
-    "yang",
-    "zig",
-  }
-
+  local supported_languages = require "lvim.config.supported_languages"
   require("lvim.lsp.manager").init_defaults(supported_languages)
 end
 
-local function deprecation_notice()
-  local in_headless = #vim.api.nvim_list_uis() == 0
-  if in_headless then
-    return
+local function handle_deprecated_settings()
+  local function deprecation_notice(setting)
+    local in_headless = #vim.api.nvim_list_uis() == 0
+    if in_headless then
+      return
+    end
+
+    local msg = string.format(
+      "Deprecation notice: [%s] setting is no longer supported. See https://github.com/LunarVim/LunarVim#breaking-changes",
+      setting
+    )
+    vim.schedule(function()
+      vim.notify(msg, vim.log.levels.WARN)
+    end)
   end
 
+  ---lvim.lang.FOO.lsp
   for lang, entry in pairs(lvim.lang) do
-    local deprecated_config = entry["lvim.lsp"] or {}
+    local deprecated_config = entry["lsp"] or {}
     if not vim.tbl_isempty(deprecated_config) then
-      local msg = string.format(
-        "Deprecation notice: [lvim.lang.%s.lsp] setting is no longer supported. See https://github.com/LunarVim/LunarVim#breaking-changes",
-        lang
-      )
-      vim.schedule(function()
-        vim.notify(msg, vim.log.levels.WARN)
-      end)
+      deprecation_notice(string.format("lvim.lang.%s.lsp", lang))
     end
   end
 end
@@ -165,7 +76,7 @@ function M:load(config_path)
     end
   end
 
-  deprecation_notice()
+  handle_deprecated_settings()
 
   autocmds.define_augroups(lvim.autocommands)
 

+ 94 - 0
lua/lvim/config/supported_languages.lua

@@ -0,0 +1,94 @@
+return {
+  "asm",
+  "bash",
+  "beancount",
+  "bibtex",
+  "bicep",
+  "c",
+  "c_sharp",
+  "clojure",
+  "cmake",
+  "comment",
+  "commonlisp",
+  "cpp",
+  "crystal",
+  "cs",
+  "css",
+  "cuda",
+  "d",
+  "dart",
+  "dockerfile",
+  "dot",
+  "elixir",
+  "elm",
+  "emmet",
+  "erlang",
+  "fennel",
+  "fish",
+  "fortran",
+  "gdscript",
+  "glimmer",
+  "go",
+  "gomod",
+  "graphql",
+  "haskell",
+  "hcl",
+  "heex",
+  "html",
+  "java",
+  "javascript",
+  "javascriptreact",
+  "jsdoc",
+  "json",
+  "json5",
+  "jsonc",
+  "julia",
+  "kotlin",
+  "latex",
+  "ledger",
+  "less",
+  "lua",
+  "markdown",
+  "nginx",
+  "nix",
+  "ocaml",
+  "ocaml_interface",
+  "perl",
+  "php",
+  "pioasm",
+  "ps1",
+  "puppet",
+  "python",
+  "ql",
+  "query",
+  "r",
+  "regex",
+  "rst",
+  "ruby",
+  "rust",
+  "scala",
+  "scss",
+  "sh",
+  "solidity",
+  "sparql",
+  "sql",
+  "supercollider",
+  "surface",
+  "svelte",
+  "swift",
+  "tailwindcss",
+  "terraform",
+  "tex",
+  "tlaplus",
+  "toml",
+  "tsx",
+  "turtle",
+  "typescript",
+  "typescriptreact",
+  "verilog",
+  "vim",
+  "vue",
+  "yaml",
+  "yang",
+  "zig",
+}

+ 14 - 1
lua/lvim/lsp/config.lua

@@ -15,7 +15,6 @@ return {
     underline = true,
     severity_sort = true,
   },
-  override = {},
   document_highlight = true,
   code_lens_refresh = true,
   popup_border = "single",
@@ -42,4 +41,18 @@ return {
   null_ls = {
     setup = {},
   },
+  override = {
+    "angularls",
+    "ansiblels",
+    "denols",
+    "ember",
+    "jedi_language_server",
+    "pylsp",
+    "rome",
+    "sqlls",
+    "sqls",
+    "stylelint_lsp",
+    "tailwindcss",
+    "volar",
+  },
 }

+ 2 - 11
lua/lvim/lsp/manager.lua

@@ -1,7 +1,7 @@
 local M = {}
 
 local Log = require "lvim.core.log"
-local lsp_utils = require "lvim.lsp.utils"
+local lvim_lsp_utils = require "lvim.lsp.utils"
 
 function M.init_defaults(languages)
   for _, entry in ipairs(languages) do
@@ -15,15 +15,6 @@ function M.init_defaults(languages)
   end
 end
 
-local function is_overridden(server)
-  local overrides = lvim.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]
@@ -54,7 +45,7 @@ end
 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 lvim_lsp_utils.is_client_active(server_name) then
     return
   end
 

+ 5 - 33
lua/lvim/lsp/templates.lua

@@ -2,7 +2,7 @@ local M = {}
 
 local Log = require "lvim.core.log"
 local utils = require "lvim.utils"
-local get_supported_filetypes = require("lvim.lsp.utils").get_supported_filetypes
+local lvim_lsp_utils = require "lvim.lsp.utils"
 
 local ftplugin_dir = lvim.lsp.templates_dir
 
@@ -15,48 +15,20 @@ 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
+  if vim.tbl_contains(lvim.lsp.override, server_name) 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 = lvim_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("lvim.lsp.manager").setup(%q)]], server_name)

+ 1 - 18
tests/lsp_spec.lua

@@ -67,29 +67,12 @@ a.describe("lsp workflow", function()
     assert.True(vim.deep_equal(tsserver.filetypes, tsserver_fts))
   end)
 
-  a.it("shoud ignore all javascript servers except tsserver and tailwindcss when generating templates", function()
-    local test_server = { name = "denols", filetypes = {} }
-    test_server.filetypes = require("lvim.lsp.utils").get_supported_filetypes(test_server.name)
-
-    assert.True(vim.tbl_contains(test_server.filetypes, "javascript"))
-
-    local is_ignored = require("lvim.lsp.templates").is_ignored(test_server.name)
-    assert.True(is_ignored)
-
-    local ts_template = utils.join_paths(lvim.lsp.templates_dir, "typescript.lua")
-
-    assert.True(utils.file_contains(ts_template, "tsserver"))
-    assert.False(utils.file_contains(ts_template, test_server.name))
-  end)
-
   a.it("shoud not include blacklisted servers in the generated templates", function()
     assert.True(utils.is_directory(lvim.lsp.templates_dir))
     require("lvim.lsp").setup()
 
-    local blacklisted = { "jedi_language_server", "pylsp", "sqlls", "sqls", "angularls", "ansiblels" }
-
     for _, file in ipairs(vim.fn.glob(lvim.lsp.templates_dir .. "/*.lua", 1, 1)) do
-      for _, server in ipairs(blacklisted) do
+      for _, server in ipairs(lvim.lsp.override) do
         assert.False(utils.file_contains(file, server))
       end
     end