1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
local lspconfig = require("lspconfig")
local configs = require("lspconfig/configs")
local server = require("nvim-lsp-installer.server")
local path = require("nvim-lsp-installer.path")
local shell = require("nvim-lsp-installer.installers.shell")
configs.eslintls = {
default_config = {
filetypes = {"javascript", "javascriptreact", "typescript", "typescriptreact"},
root_dir = lspconfig.util.root_pattern(".eslintrc*", "package.json", ".git"),
-- Refer to https://github.com/Microsoft/vscode-eslint#settings-options for documentation.
settings = {
validate = "on",
run = "onType",
codeAction = {
disableRuleComment = {
enable = true,
-- "sameLine" might not work as expected, see https://github.com/williamboman/nvim-lsp-installer/issues/4
location = "separateLine"
},
showDocumentation = {
enable = true
}
},
rulesCustomizations = {},
-- Automatically determine working directory by locating .eslintrc config files.
--
-- It's recommended not to change this.
workingDirectory = {mode = "auto"},
-- If nodePath is a non-null/undefined value the eslint LSP runs into runtime exceptions.
--
-- It's recommended not to change this.
nodePath = "",
-- The "workspaceFolder" is a VSCode concept. We set it to the root
-- directory to not restrict the LPS server when it traverses the
-- file tree when locating a .eslintrc config file.
--
-- It's recommended not to change this.
workspaceFolder = {
uri = "/",
name = "root"
}
}
}
}
local ConfirmExecutionResult = {
deny = 1,
confirmationPending = 2,
confirmationCanceled = 3,
approved = 4
}
local root_dir = server.get_server_root_path("eslint")
local install_cmd = [[
git clone https://github.com/microsoft/vscode-eslint .;
npm install;
cd server;
npm install;
../node_modules/.bin/tsc;
]]
return server.Server:new {
name = "eslintls",
root_dir = root_dir,
install_cmd = shell.raw(install_cmd),
default_options = {
cmd = { "node", path.concat { root_dir, "server", "out", "eslintServer.js" }, "--stdio" },
handlers = {
["eslint/openDoc"] = function (_, _, open_doc)
os.execute(string.format("open %q", open_doc.url))
return {id = nil, result = true}
end,
["eslint/confirmESLintExecution"] = function ()
-- VSCode language servers have a policy to request explicit approval
-- before applying code changes. We just approve it immediately.
return ConfirmExecutionResult.approved
end,
["eslint/probeFailed"] = function ()
vim.api.nvim_err_writeln("ESLint probe failed.")
return {id = nil, result = true}
end,
["eslint/noLibrary"] = function ()
vim.api.nvim_err_writeln("Unable to find ESLint library.")
return {id = nil, result = true}
end,
["eslint/noConfig"] = function ()
vim.api.nvim_err_writeln("Unable to find ESLint configuration.")
return {id = nil, result = true}
end,
},
},
}
|