fix(nvim): js/ts lint selector
This commit is contained in:
parent
c929c34310
commit
1214454969
@ -6,6 +6,7 @@
|
||||
shellAliases = {
|
||||
grep = "grep --color";
|
||||
ssh = "TERM=xterm-256color ssh";
|
||||
flush_dns = "sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder";
|
||||
};
|
||||
profileExtra = ''
|
||||
SHELL="$BASH"
|
||||
|
@ -12,7 +12,9 @@ local on_attach = function(client, bufnr)
|
||||
vim.api.nvim_create_autocmd("BufWritePre", {
|
||||
group = augroup,
|
||||
buffer = bufnr,
|
||||
callback = function() vim.lsp.buf.format({async = false}) end
|
||||
callback = function()
|
||||
vim.lsp.buf.format({async = false, timeout_ms = 2000})
|
||||
end
|
||||
})
|
||||
end
|
||||
|
||||
@ -24,8 +26,9 @@ local on_attach = function(client, bufnr)
|
||||
vim.keymap.set('n', '<leader>ln', vim.lsp.buf.rename, bufopts)
|
||||
vim.keymap.set('n', '<leader>lr', vim.lsp.buf.references, bufopts)
|
||||
vim.keymap.set('n', '<leader>lt', vim.lsp.buf.type_definition, bufopts)
|
||||
vim.keymap.set('n', '<leader>lf',
|
||||
function() vim.lsp.buf.format {async = true} end, bufopts)
|
||||
vim.keymap.set('n', '<leader>lf', function()
|
||||
vim.lsp.buf.format {async = true, timeout_ms = 2000}
|
||||
end, bufopts)
|
||||
end
|
||||
|
||||
local on_attach_no_formatting = function(client, bufnr)
|
||||
@ -138,49 +141,33 @@ nvim_lsp.golangci_lint_ls.setup {
|
||||
------------------------------------------------------
|
||||
local null_ls = require("null-ls")
|
||||
|
||||
local function has_file_in_parents(current_dir, file_pattern)
|
||||
-- Check if directory has file pattern
|
||||
local function has_file(dir)
|
||||
local handle = vim.loop.fs_scandir(dir)
|
||||
if handle then
|
||||
while true do
|
||||
local name, type = vim.loop.fs_scandir_next(handle)
|
||||
if not name then break end
|
||||
if type == "file" and name:match(file_pattern) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
local eslintFiles = {
|
||||
'.eslintrc', '.eslintrc.js', '.eslintrc.cjs', '.eslintrc.yaml',
|
||||
'.eslintrc.yml', '.eslintrc.json', 'eslint.config.js', 'eslint.config.mjs',
|
||||
'eslint.config.cjs', 'eslint.config.ts', 'eslint.config.mts',
|
||||
'eslint.config.cts'
|
||||
}
|
||||
|
||||
-- Continously walk upwards
|
||||
while true do
|
||||
if has_file(current_dir) then return true end
|
||||
local parent_dir = vim.fn.fnamemodify(current_dir, ":h")
|
||||
if parent_dir == current_dir then break end
|
||||
current_dir = parent_dir
|
||||
end
|
||||
has_eslint_in_parents = function(fname)
|
||||
root_file = nvim_lsp.util.insert_package_json(eslintFiles, 'eslintConfig',
|
||||
fname)
|
||||
return nvim_lsp.util.root_pattern(unpack(root_file))(fname)
|
||||
|
||||
-- No match found
|
||||
return false
|
||||
end
|
||||
|
||||
null_ls.setup({
|
||||
end, null_ls.setup({
|
||||
sources = {
|
||||
-- Prettier Formatting
|
||||
null_ls.builtins.formatting.prettier.with({
|
||||
condition = function(utils)
|
||||
return not has_file_in_parents(vim.fn.getcwd(), "^%.eslintrc%.")
|
||||
return not has_eslint_in_parents(vim.fn.getcwd())
|
||||
end
|
||||
}), -- ESLint Diagnostics & Formatting
|
||||
null_ls.builtins.diagnostics.eslint_d.with({
|
||||
condition = function(utils)
|
||||
return has_file_in_parents(vim.fn.getcwd(), "^%.eslintrc%.")
|
||||
return has_eslint_in_parents(vim.fn.getcwd())
|
||||
end
|
||||
}), null_ls.builtins.formatting.eslint_d.with({
|
||||
condition = function(utils)
|
||||
return has_file_in_parents(vim.fn.getcwd(), "^%.eslintrc%.")
|
||||
return has_eslint_in_parents(vim.fn.getcwd())
|
||||
end
|
||||
}), null_ls.builtins.formatting.djlint.with({filetypes = {"template"}}),
|
||||
null_ls.builtins.completion.spell,
|
||||
@ -196,7 +183,7 @@ null_ls.setup({
|
||||
group = augroup,
|
||||
buffer = bufnr,
|
||||
callback = function()
|
||||
vim.lsp.buf.format({async = false})
|
||||
vim.lsp.buf.format({async = false, timeout_ms = 2000})
|
||||
end
|
||||
})
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user