2021-07-04 00:50:21 +02:00
|
|
|
-- Example configuations here: https://github.com/mattn/efm-langserver
|
|
|
|
local M = {}
|
|
|
|
|
|
|
|
M.setup = function()
|
2021-07-18 20:38:41 +02:00
|
|
|
vim.cmd "let proj = FindRootDirectory()"
|
|
|
|
local root_dir = vim.api.nvim_get_var "proj"
|
|
|
|
|
|
|
|
local get_linter_instance = function()
|
|
|
|
-- prioritize local instance over global
|
|
|
|
local local_instance = root_dir .. "/node_modules/.bin/" .. O.lang.tsserver.linter
|
|
|
|
if vim.fn.executable(local_instance) == 1 then
|
|
|
|
return local_instance
|
|
|
|
end
|
|
|
|
return O.lang.tsserver.linter
|
|
|
|
end
|
|
|
|
|
2021-07-09 14:07:25 +02:00
|
|
|
local tsserver_args = {}
|
2021-07-18 20:38:41 +02:00
|
|
|
local formattingSupported = false
|
2021-07-04 00:50:21 +02:00
|
|
|
|
2021-07-11 15:36:35 +02:00
|
|
|
if O.lang.tsserver.linter == "eslint" or O.lang.tsserver.linter == "eslint_d" then
|
|
|
|
local eslint = {
|
2021-07-18 20:38:41 +02:00
|
|
|
lintCommand = get_linter_instance() .. " -f visualstudio --stdin --stdin-filename ${INPUT}",
|
2021-07-11 15:36:35 +02:00
|
|
|
lintStdin = true,
|
2021-07-17 15:46:31 +02:00
|
|
|
lintFormats = {
|
|
|
|
"%f(%l,%c): %tarning %m",
|
2021-07-18 20:38:41 +02:00
|
|
|
"%f(%l,%c): %trror %m",
|
2021-07-17 15:46:31 +02:00
|
|
|
},
|
|
|
|
lintSource = O.lang.tsserver.linter,
|
2021-07-11 15:36:35 +02:00
|
|
|
lintIgnoreExitCode = true,
|
2021-07-04 00:50:21 +02:00
|
|
|
}
|
2021-07-11 15:36:35 +02:00
|
|
|
table.insert(tsserver_args, eslint)
|
2021-07-18 20:38:41 +02:00
|
|
|
-- Only eslint_d supports --fix-to-stdout
|
|
|
|
if string.find(get_linter_instance(), "eslint_d") then
|
|
|
|
formattingSupported = true
|
|
|
|
local eslint_fix = {
|
|
|
|
formatCommand = get_linter_instance() .. " --fix-to-stdout --stdin --stdin-filename ${INPUT}",
|
|
|
|
formatStdin = true,
|
|
|
|
}
|
|
|
|
table.insert(tsserver_args, eslint_fix)
|
|
|
|
end
|
2021-07-09 14:07:25 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
require("lspconfig").efm.setup {
|
|
|
|
-- init_options = {initializationOptions},
|
|
|
|
cmd = { DATA_PATH .. "/lspinstall/efm/efm-langserver" },
|
2021-07-18 20:38:41 +02:00
|
|
|
init_options = { documentFormatting = formattingSupported, codeAction = false },
|
2021-07-12 23:03:20 +02:00
|
|
|
root_dir = require("lspconfig").util.root_pattern(".git/", "package.json"),
|
2021-07-11 15:36:35 +02:00
|
|
|
filetypes = {
|
|
|
|
"vue",
|
|
|
|
"javascript",
|
|
|
|
"javascriptreact",
|
|
|
|
"typescript",
|
|
|
|
"typescriptreact",
|
|
|
|
"javascript.jsx",
|
|
|
|
"typescript.tsx",
|
|
|
|
},
|
2021-07-09 14:07:25 +02:00
|
|
|
settings = {
|
|
|
|
rootMarkers = { ".git/", "package.json" },
|
|
|
|
languages = {
|
2021-07-11 15:36:35 +02:00
|
|
|
vue = tsserver_args,
|
|
|
|
javascript = tsserver_args,
|
|
|
|
javascriptreact = tsserver_args,
|
|
|
|
["javascript.jsx"] = tsserver_args,
|
|
|
|
typescript = tsserver_args,
|
|
|
|
["typescript.tsx"] = tsserver_args,
|
|
|
|
typescriptreact = tsserver_args,
|
2021-07-09 14:07:25 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2021-07-04 00:50:21 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
return M
|