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