moves to eslint lsp

This commit is contained in:
Dennis 2025-09-09 09:06:20 +02:00
parent 91dd752b66
commit 11eca2baa5
5 changed files with 217 additions and 71 deletions

View file

@ -5,6 +5,7 @@ vim.lsp.enable("nil_ls")
vim.lsp.enable("astro")
vim.lsp.enable("tailwindcss")
vim.lsp.enable("gopls")
vim.lsp.enable("eslint")
vim.diagnostic.config({
virtual_text = false,

View file

@ -16,7 +16,7 @@ end
function search_ancestors(startpath, func)
if nvim_eleven then
validate('func', func, 'function')
validate("func", func, "function")
end
if func(startpath) then
return startpath
@ -36,13 +36,13 @@ function search_ancestors(startpath, func)
end
local function escape_wildcards(path)
return path:gsub('([%[%]%?%*])', '\\%1')
return path:gsub("([%[%]%?%*])", "\\%1")
end
function strip_archive_subpath(path)
-- Matches regex from zip.vim / tar.vim
path = vim.fn.substitute(path, 'zipfile://\\(.\\{-}\\)::[^\\\\].*$', '\\1', '')
path = vim.fn.substitute(path, 'tarfile:\\(.\\{-}\\)::.*$', '\\1', '')
path = vim.fn.substitute(path, "zipfile://\\(.\\{-}\\)::[^\\\\].*$", "\\1", "")
path = vim.fn.substitute(path, "tarfile:\\(.\\{-}\\)::.*$", "\\1", "")
return path
end
@ -125,9 +125,32 @@ local function compile_project()
vim.cmd("startinsert")
end
local function root_markers_with_field(root_files, new_names, field, fname)
local path = vim.fn.fnamemodify(fname, ":h")
local found = vim.fs.find(new_names, { path = path, upward = true })
for _, f in ipairs(found or {}) do
-- Match the given `field`.
for line in io.lines(f) do
if line:find(field) then
root_files[#root_files + 1] = vim.fs.basename(f)
break
end
end
end
return root_files
end
local function insert_package_json(root_files, field, fname)
return root_markers_with_field(root_files, { "package.json", "package.json5" }, field, fname)
end
return {
compile_project = compile_project,
filter = filter,
filterReactDTS = filterReactDTS,
root_pattern = root_pattern
root_pattern = root_pattern,
insert_package_json = insert_package_json,
root_markers_with_field = root_markers_with_field,
}

View file

@ -1,63 +0,0 @@
return {
"nvimtools/none-ls.nvim",
dependencies = {
"nvimtools/none-ls-extras.nvim",
},
config = function()
local null_ls = require("null-ls")
local utils = require("dnsc.utils")
local string_starts_with = function(str, start)
return string.sub(str, 1, #start) == start
end
local create_runtime_condition = function(config_names)
local bufnr_cache = {}
local config_path_cache = {}
return function(params)
if bufnr_cache[params.bufnr] ~= nil then
return bufnr_cache[params.bufnr]
else
for _, cached_config_path in ipairs(config_path_cache) do
if string_starts_with(params.bufname, cached_config_path) then
bufnr_cache[params.bufnr] = true
return true
end
end
end
local config_path = utils.root_pattern(config_names)(params.bufname)
local has_config = config_path ~= nil
if has_config then
table.insert(config_path_cache, config_path)
end
bufnr_cache[params.bufnr] = has_config
return has_config
end
end
local eslint_runtime_condition = create_runtime_condition({
".eslintrc.cjs",
".eslintrc.js",
".eslintrc.json",
".eslintrc.yaml",
".eslintrc.yml",
"eslint.config.mjs",
"eslint.config.js",
"eslint.config.ts",
"eslint.config.mts",
})
null_ls.setup({
sources = {
require("none-ls.code_actions.eslint_d"),
require("none-ls.diagnostics.eslint_d").with({
runtime_condition = eslint_runtime_condition,
}),
},
})
end,
}