aboutsummaryrefslogtreecommitdiffstats
path: root/lua/nvim-lsp-installer/servers/eslintls.lua
blob: b8f0f44845025970ac197c8eb3bdf6e39172ac22 (plain) (blame)
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
local lspconfig = require'lspconfig'
local configs = require'lspconfig/configs'

local server = require'nvim-lsp-installer.server'

if not lspconfig.eslintls then
    configs.eslintls = {
        default_config = {
            filetypes = {'javascript', 'javascriptreact', 'typescript', 'typescriptreact'},
            root_dir = lspconfig.util.root_pattern(".eslintrc*", "package.json", ".git"),
            settings = {
                nodePath = '', -- If this is a non-null/undefined value the eslint LSP runs into runtime exceptions.
                validate = 'on',
                run = 'onType',
                workingDirectory = {mode = "auto"},
                workspaceFolder = {
                    uri = "/",
                    name = "root",
                },
                codeAction = {
                    disableRuleComment = {
                        enable = true,
                        location = "sameLine",
                    },
                    showDocumentation = {
                        enable = true
                    }
                },
            },
        },
    }
end

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;
npx tsc;
]]

return server.Server:new {
    name = "eslintls",
    root_dir = root_dir,
    install_cmd = install_cmd,
    default_options = {
        cmd = {'node', 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,
        },
    },
}