Explorar o código

Hotfix/eslint d (#1198)

Abouzar Parvan %!s(int64=4) %!d(string=hai) anos
pai
achega
30ad4b81f5
Modificáronse 2 ficheiros con 13 adicións e 16 borrados
  1. 5 1
      lua/lsp/handlers.lua
  2. 8 15
      lua/lsp/null-ls.lua

+ 5 - 1
lua/lsp/handlers.lua

@@ -27,7 +27,11 @@ function M.setup()
     local diagnostics = params.diagnostics
 
     for i, v in ipairs(diagnostics) do
-      diagnostics[i].message = string.format("%s: %s", v.source, v.message)
+      local source = v.source
+      if string.find(v.source, "/") then
+        source = string.sub(v.source, string.find(v.source, "([%w-_]+)$"))
+      end
+      diagnostics[i].message = string.format("%s: %s", source, v.message)
 
       if vim.tbl_contains(vim.tbl_keys(v), "code") then
         diagnostics[i].message = diagnostics[i].message .. string.format(" [%s]", v.code)

+ 8 - 15
lua/lsp/null-ls.lua

@@ -34,18 +34,17 @@ end
 
 local function is_provider_found(provider)
   local retval = { is_local = false, path = nil }
-  if vim.fn.executable(provider._opts.command) == 1 then
-    return false, provider._opts.command
-  end
   if is_nodejs_provider(provider) then
     vim.cmd "let root_dir = FindRootDirectory()"
     local root_dir = vim.api.nvim_get_var "root_dir"
     local local_provider_command = root_dir .. "/node_modules/.bin/" .. provider._opts.command
     if vim.fn.executable(local_provider_command) == 1 then
-      retval.is_local = true
-      retval.path = local_provider_command
+      return true, local_provider_command
     end
   end
+  if vim.fn.executable(provider._opts.command) == 1 then
+    return false, provider._opts.command
+  end
   return retval.is_local, retval.path
 end
 
@@ -78,23 +77,17 @@ function M.setup(filetype)
     -- builtin_diagnoser._opts.args = linter.args or builtin_diagnoser._opts.args
     -- builtin_diagnoser._opts.to_stdin = linter.stdin or builtin_diagnoser._opts.to_stdin
     -- NOTE: validate before inserting to table
-    if validate_provider(builtin_diagnoser) then
-      table.insert(M.requested_providers, builtin_diagnoser)
-    end
     -- special case: fallback to "eslint"
     -- https://github.com/jose-elias-alvarez/null-ls.nvim/blob/9b8458bd1648e84169a7e8638091ba15c2f20fc0/doc/BUILTINS.md#eslint
     if linter.exe == "eslint_d" then
-      table.insert(M.requested_providers, null_ls.builtins.diagnostics.eslint.with { command = "eslint_d" })
+      builtin_diagnoser = null_ls.builtins.diagnostics.eslint.with { command = "eslint_d" }
+    end
+    if validate_provider(builtin_diagnoser) then
+      table.insert(M.requested_providers, builtin_diagnoser)
     end
     u.lvim_log(string.format("Using linter provider: [%s]", linter.exe))
   end
 
-  -- FIXME: why would we need to remove if we never add?
-  for idx, provider in pairs(M.requested_providers) do
-    if not validate_provider(provider) then
-      table.remove(M.requested_providers, idx)
-    end
-  end
   null_ls.register { sources = M.requested_providers }
 end