updates eslint lsp
This commit is contained in:
parent
ec65e4fdf6
commit
485abbfda4
1 changed files with 51 additions and 51 deletions
|
|
@ -2,7 +2,7 @@ local lsp = vim.lsp
|
||||||
|
|
||||||
local function validate_bufnr(bufnr)
|
local function validate_bufnr(bufnr)
|
||||||
if nvim_eleven then
|
if nvim_eleven then
|
||||||
validate('bufnr', bufnr, 'number')
|
validate("bufnr", bufnr, "number")
|
||||||
end
|
end
|
||||||
return bufnr == 0 and api.nvim_get_current_buf() or bufnr
|
return bufnr == 0 and api.nvim_get_current_buf() or bufnr
|
||||||
end
|
end
|
||||||
|
|
@ -10,7 +10,7 @@ end
|
||||||
local function fix_all(opts)
|
local function fix_all(opts)
|
||||||
opts = opts or {}
|
opts = opts or {}
|
||||||
|
|
||||||
local eslint_lsp_client = vim.lsp.get_clients({ bufnr = opts.bufnr, name = 'eslint' })[1]
|
local eslint_lsp_client = vim.lsp.get_clients({ bufnr = opts.bufnr, name = "eslint" })[1]
|
||||||
if eslint_lsp_client == nil then
|
if eslint_lsp_client == nil then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
@ -27,8 +27,8 @@ local function fix_all(opts)
|
||||||
end
|
end
|
||||||
|
|
||||||
local bufnr = util.validate_bufnr(opts.bufnr or 0)
|
local bufnr = util.validate_bufnr(opts.bufnr or 0)
|
||||||
request(0, 'workspace/executeCommand', {
|
request(0, "workspace/executeCommand", {
|
||||||
command = 'eslint.applyAllFixes',
|
command = "eslint.applyAllFixes",
|
||||||
arguments = {
|
arguments = {
|
||||||
{
|
{
|
||||||
uri = vim.uri_from_bufnr(bufnr),
|
uri = vim.uri_from_bufnr(bufnr),
|
||||||
|
|
@ -39,42 +39,42 @@ local function fix_all(opts)
|
||||||
end
|
end
|
||||||
|
|
||||||
return {
|
return {
|
||||||
cmd = { 'vscode-eslint-language-server', '--stdio' },
|
cmd = { "vscode-eslint-language-server", "--stdio" },
|
||||||
filetypes = {
|
filetypes = {
|
||||||
'javascript',
|
"javascript",
|
||||||
'javascriptreact',
|
"javascriptreact",
|
||||||
'javascript.jsx',
|
"javascript.jsx",
|
||||||
'typescript',
|
"typescript",
|
||||||
'typescriptreact',
|
"typescriptreact",
|
||||||
'typescript.tsx',
|
"typescript.tsx",
|
||||||
'vue',
|
"vue",
|
||||||
'svelte',
|
"svelte",
|
||||||
'astro',
|
"astro",
|
||||||
},
|
},
|
||||||
root_markers = {
|
root_markers = {
|
||||||
'.eslintrc',
|
".eslintrc",
|
||||||
'.eslintrc.js',
|
".eslintrc.js",
|
||||||
'.eslintrc.cjs',
|
".eslintrc.cjs",
|
||||||
'.eslintrc.yaml',
|
".eslintrc.yaml",
|
||||||
'.eslintrc.yml',
|
".eslintrc.yml",
|
||||||
'.eslintrc.json',
|
".eslintrc.json",
|
||||||
'eslint.config.js',
|
"eslint.config.js",
|
||||||
'eslint.config.mjs',
|
"eslint.config.mjs",
|
||||||
'eslint.config.cjs',
|
"eslint.config.cjs",
|
||||||
'eslint.config.ts',
|
"eslint.config.ts",
|
||||||
'eslint.config.mts',
|
"eslint.config.mts",
|
||||||
'eslint.config.cts',
|
"eslint.config.cts",
|
||||||
},
|
},
|
||||||
commands = {
|
commands = {
|
||||||
EslintFixAll = {
|
EslintFixAll = {
|
||||||
function()
|
function()
|
||||||
fix_all { sync = true, bufnr = 0 }
|
fix_all({ sync = true, bufnr = 0 })
|
||||||
end,
|
end,
|
||||||
description = 'Fix all eslint problems for this buffer',
|
description = "Fix all eslint problems for this buffer",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
settings = {
|
settings = {
|
||||||
validate = 'on',
|
validate = "on",
|
||||||
packageManager = nil,
|
packageManager = nil,
|
||||||
useESLintClass = false,
|
useESLintClass = false,
|
||||||
experimental = {
|
experimental = {
|
||||||
|
|
@ -82,25 +82,25 @@ return {
|
||||||
},
|
},
|
||||||
codeActionOnSave = {
|
codeActionOnSave = {
|
||||||
enable = true,
|
enable = true,
|
||||||
mode = 'all',
|
mode = "all",
|
||||||
},
|
},
|
||||||
format = true,
|
format = true,
|
||||||
quiet = false,
|
quiet = false,
|
||||||
onIgnoredFiles = 'off',
|
onIgnoredFiles = "off",
|
||||||
rulesCustomizations = {},
|
rulesCustomizations = {},
|
||||||
run = 'onType',
|
run = "onType",
|
||||||
problems = {
|
problems = {
|
||||||
shortenToSingleLine = false,
|
shortenToSingleLine = false,
|
||||||
},
|
},
|
||||||
-- nodePath configures the directory in which the eslint server should start its node_modules resolution.
|
-- nodePath configures the directory in which the eslint server should start its node_modules resolution.
|
||||||
-- This path is relative to the workspace folder (root dir) of the server instance.
|
-- This path is relative to the workspace folder (root dir) of the server instance.
|
||||||
nodePath = '',
|
nodePath = "",
|
||||||
-- use the workspace folder location or the file location (if no workspace folder is open) as the working directory
|
-- use the workspace folder location or the file location (if no workspace folder is open) as the working directory
|
||||||
workingDirectory = { mode = 'location' },
|
workingDirectory = { mode = "location" },
|
||||||
codeAction = {
|
codeAction = {
|
||||||
disableRuleComment = {
|
disableRuleComment = {
|
||||||
enable = true,
|
enable = true,
|
||||||
location = 'separateLine',
|
location = "separateLine",
|
||||||
},
|
},
|
||||||
showDocumentation = {
|
showDocumentation = {
|
||||||
enable = true,
|
enable = true,
|
||||||
|
|
@ -113,47 +113,47 @@ return {
|
||||||
-- file (e.g., .eslintrc).
|
-- file (e.g., .eslintrc).
|
||||||
config.settings.workspaceFolder = {
|
config.settings.workspaceFolder = {
|
||||||
uri = new_root_dir,
|
uri = new_root_dir,
|
||||||
name = vim.fn.fnamemodify(new_root_dir, ':t'),
|
name = vim.fn.fnamemodify(new_root_dir, ":t"),
|
||||||
}
|
}
|
||||||
|
|
||||||
-- Support flat config
|
-- Support flat config
|
||||||
if
|
if
|
||||||
vim.fn.filereadable(new_root_dir .. '/eslint.config.js') == 1
|
vim.fn.filereadable(new_root_dir .. "/eslint.config.js") == 1
|
||||||
or vim.fn.filereadable(new_root_dir .. '/eslint.config.mjs') == 1
|
or vim.fn.filereadable(new_root_dir .. "/eslint.config.mjs") == 1
|
||||||
or vim.fn.filereadable(new_root_dir .. '/eslint.config.cjs') == 1
|
or vim.fn.filereadable(new_root_dir .. "/eslint.config.cjs") == 1
|
||||||
or vim.fn.filereadable(new_root_dir .. '/eslint.config.ts') == 1
|
or vim.fn.filereadable(new_root_dir .. "/eslint.config.ts") == 1
|
||||||
or vim.fn.filereadable(new_root_dir .. '/eslint.config.mts') == 1
|
or vim.fn.filereadable(new_root_dir .. "/eslint.config.mts") == 1
|
||||||
or vim.fn.filereadable(new_root_dir .. '/eslint.config.cts') == 1
|
or vim.fn.filereadable(new_root_dir .. "/eslint.config.cts") == 1
|
||||||
then
|
then
|
||||||
config.settings.experimental.useFlatConfig = true
|
config.settings.experimental.useFlatConfig = true
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Support Yarn2 (PnP) projects
|
-- Support Yarn2 (PnP) projects
|
||||||
local pnp_cjs = new_root_dir .. '/.pnp.cjs'
|
local pnp_cjs = new_root_dir .. "/.pnp.cjs"
|
||||||
local pnp_js = new_root_dir .. '/.pnp.js'
|
local pnp_js = new_root_dir .. "/.pnp.js"
|
||||||
if vim.loop.fs_stat(pnp_cjs) or vim.loop.fs_stat(pnp_js) then
|
if vim.loop.fs_stat(pnp_cjs) or vim.loop.fs_stat(pnp_js) then
|
||||||
config.cmd = vim.list_extend({ 'yarn', 'exec' }, config.cmd)
|
config.cmd = vim.list_extend({ "yarn", "exec" }, config.cmd)
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
handlers = {
|
handlers = {
|
||||||
['eslint/openDoc'] = function(_, result)
|
["eslint/openDoc"] = function(_, result)
|
||||||
if result then
|
if result then
|
||||||
vim.ui.open(result.url)
|
vim.ui.open(result.url)
|
||||||
end
|
end
|
||||||
return {}
|
return {}
|
||||||
end,
|
end,
|
||||||
['eslint/confirmESLintExecution'] = function(_, result)
|
["eslint/confirmESLintExecution"] = function(_, result)
|
||||||
if not result then
|
if not result then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
return 4 -- approved
|
return 4 -- approved
|
||||||
end,
|
end,
|
||||||
['eslint/probeFailed'] = function()
|
["eslint/probeFailed"] = function()
|
||||||
vim.notify('[lspconfig] ESLint probe failed.', vim.log.levels.WARN)
|
vim.notify("[lspconfig] ESLint probe failed.", vim.log.levels.WARN)
|
||||||
return {}
|
return {}
|
||||||
end,
|
end,
|
||||||
['eslint/noLibrary'] = function()
|
["eslint/noLibrary"] = function()
|
||||||
vim.notify('[lspconfig] Unable to find ESLint library.', vim.log.levels.WARN)
|
vim.notify("[lspconfig] Unable to find ESLint library.", vim.log.levels.WARN)
|
||||||
return {}
|
return {}
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue