Przeglądaj źródła

implement language overrides (#1081)

Co-authored-by: Chris <chris@macbook.local>
Christian Chiarulli 4 lat temu
rodzic
commit
1c3b80d041
3 zmienionych plików z 36 dodań i 1 usunięć
  1. 1 0
      lua/default-config.lua
  2. 34 1
      lua/lsp/init.lua
  3. 1 0
      lua/lsp/null-ls.lua

+ 1 - 0
lua/default-config.lua

@@ -42,6 +42,7 @@ lvim = {
       signs = true,
       underline = true,
     },
+    override = {},
     document_highlight = true,
     popup_border = "single",
     default_keybinds = true,

+ 34 - 1
lua/lsp/init.lua

@@ -272,13 +272,46 @@ require("lv-utils").define_augroups {
   },
 }
 
+local function is_table(t)
+  return type(t) == "table"
+end
+
+local function is_string(t)
+  return type(t) == "string"
+end
+
+local function has_value(tab, val)
+  for index, value in ipairs(tab) do
+    if value == val then
+      return true
+    end
+  end
+
+  return false
+end
+
 function lsp_config.setup(lang)
-  lang_server = lvim.lang[lang].lsp
+  local lang_server = lvim.lang[lang].lsp
   require("lsp.null-ls").setup "python"
   local provider = lang_server.provider
   if require("lv-utils").check_lsp_client_active(provider) then
     return
   end
+
+  local overrides = lvim.lsp.override
+
+  if is_table(overrides) then
+    if has_value(overrides, lang) then
+      return
+    end
+  end
+
+  if is_string(overrides) then
+    if overrides == lang then
+      return
+    end
+  end
+
   require("lspconfig")[provider].setup(lang_server.setup)
   require("lsp.null-ls").setup(lang)
 end

+ 1 - 0
lua/lsp/null-ls.lua

@@ -45,6 +45,7 @@ local function setup_ls(exe, type)
 end
 
 local function setup(filetype, type)
+  local executables = nil
   if type == "diagnostics" then
     executables = lvim.lang[filetype].linters
   end