summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ftplugin/javascript.lua2
-rw-r--r--ftplugin/javascriptreact.lua2
-rw-r--r--ftplugin/typescript.lua2
-rw-r--r--ftplugin/typescriptreact.lua2
-rw-r--r--lua/lsp/efm-general-ls.lua58
-rw-r--r--lua/lsp/ts-fmt-lint.lua66
6 files changed, 74 insertions, 58 deletions
diff --git a/ftplugin/javascript.lua b/ftplugin/javascript.lua
index 173f6693..16254da3 100644
--- a/ftplugin/javascript.lua
+++ b/ftplugin/javascript.lua
@@ -36,6 +36,8 @@ require'lspconfig'.tsserver.setup {
}
}
+require'lsp.ts-fmt-lint'.setup()
+
if O.lang.tsserver.autoformat then
require('lv-utils').define_augroups({
_javascript_autoformat = {
diff --git a/ftplugin/javascriptreact.lua b/ftplugin/javascriptreact.lua
index 173f6693..16254da3 100644
--- a/ftplugin/javascriptreact.lua
+++ b/ftplugin/javascriptreact.lua
@@ -36,6 +36,8 @@ require'lspconfig'.tsserver.setup {
}
}
+require'lsp.ts-fmt-lint'.setup()
+
if O.lang.tsserver.autoformat then
require('lv-utils').define_augroups({
_javascript_autoformat = {
diff --git a/ftplugin/typescript.lua b/ftplugin/typescript.lua
index 173f6693..16254da3 100644
--- a/ftplugin/typescript.lua
+++ b/ftplugin/typescript.lua
@@ -36,6 +36,8 @@ require'lspconfig'.tsserver.setup {
}
}
+require'lsp.ts-fmt-lint'.setup()
+
if O.lang.tsserver.autoformat then
require('lv-utils').define_augroups({
_javascript_autoformat = {
diff --git a/ftplugin/typescriptreact.lua b/ftplugin/typescriptreact.lua
index 173f6693..16254da3 100644
--- a/ftplugin/typescriptreact.lua
+++ b/ftplugin/typescriptreact.lua
@@ -36,6 +36,8 @@ require'lspconfig'.tsserver.setup {
}
}
+require'lsp.ts-fmt-lint'.setup()
+
if O.lang.tsserver.autoformat then
require('lv-utils').define_augroups({
_javascript_autoformat = {
diff --git a/lua/lsp/efm-general-ls.lua b/lua/lsp/efm-general-ls.lua
deleted file mode 100644
index 8b4b8449..00000000
--- a/lua/lsp/efm-general-ls.lua
+++ /dev/null
@@ -1,58 +0,0 @@
--- Example configuations here: https://github.com/mattn/efm-langserver
-
--- tsserver/web javascript react, vue, json, html, css, yaml
-local prettier = {formatCommand = "prettier --stdin-filepath ${INPUT}", formatStdin = true}
--- You can look for project scope Prettier and Eslint with e.g. vim.fn.glob("node_modules/.bin/prettier") etc. If it is not found revert to global Prettier where needed.
--- local prettier = {formatCommand = "./node_modules/.bin/prettier --stdin-filepath ${INPUT}", formatStdin = true}
-
-local eslint = {
- lintCommand = "./node_modules/.bin/eslint -f unix --stdin --stdin-filename ${INPUT}",
- lintIgnoreExitCode = true,
- lintStdin = true,
- lintFormats = {"%f:%l:%c: %m"},
- formatCommand = "./node_modules/.bin/eslint --fix-to-stdout --stdin --stdin-filename=${INPUT}",
- formatStdin = true
-}
-
-local tsserver_args = {}
-
-if O.lang.tsserver.formatter == 'prettier' then table.insert(tsserver_args, prettier) end
-
-if O.lang.tsserver.linter == 'eslint' then table.insert(tsserver_args, eslint) end
-
--- local markdownlint = {
--- -- TODO default to global lintrc
--- -- lintcommand = 'markdownlint -s -c ./markdownlintrc',
--- lintCommand = 'markdownlint -s',
--- lintStdin = true,
--- lintFormats = {'%f:%l %m', '%f:%l:%c %m', '%f: %l: %m'}
--- }
-
-local markdownPandocFormat = {formatCommand = 'pandoc -f markdown -t gfm -sp --tab-stop=2', formatStdin = true}
-
-require"lspconfig".efm.setup {
- -- init_options = {initializationOptions},
- cmd = {DATA_PATH .. "/lspinstall/efm/efm-langserver"},
- init_options = {documentFormatting = true, codeAction = false},
- filetypes = {"lua", "python", "javascriptreact", "javascript", "typescript","typescriptreact","sh", "html", "css", "yaml", "markdown", "vue"},
- settings = {
- rootMarkers = {".git/"},
- languages = {
- javascript = tsserver_args,
- javascriptreact = tsserver_args,
- typescript = tsserver_args,
- typescriptreact = tsserver_args,
- html = {prettier},
- css = {prettier},
- json = {prettier},
- yaml = {prettier},
- markdown = {markdownPandocFormat}
- -- javascriptreact = {prettier, eslint},
- -- javascript = {prettier, eslint},
- -- markdown = {markdownPandocFormat, markdownlint},
- }
- }
-}
-
--- Also find way to toggle format on save
--- maybe this will help: https://superuser.com/questions/439078/how-to-disable-autocmd-or-augroup-in-vim
diff --git a/lua/lsp/ts-fmt-lint.lua b/lua/lsp/ts-fmt-lint.lua
new file mode 100644
index 00000000..3ca97d71
--- /dev/null
+++ b/lua/lsp/ts-fmt-lint.lua
@@ -0,0 +1,66 @@
+-- Example configuations here: https://github.com/mattn/efm-langserver
+-- You can look for project scope Prettier and Eslint with e.g. vim.fn.glob("node_modules/.bin/prettier") etc. If it is not found revert to global Prettier where needed.
+local M = {}
+
+M.setup = function()
+ local tsserver_args = {}
+
+ local prettier = {
+ formatCommand = "prettier --stdin-filepath ${INPUT}",
+ formatStdin = true
+ }
+
+ if vim.fn.glob("node_modules/.bin/prettier") then
+ prettier = {
+ formatCommand = "./node_modules/.bin/prettier --stdin-filepath ${INPUT}",
+ formatStdin = true
+ }
+ end
+
+ -- TODO global eslint?
+
+ local eslint = {
+ lintCommand = "./node_modules/.bin/eslint -f unix --stdin --stdin-filename ${INPUT}",
+ lintIgnoreExitCode = true,
+ lintStdin = true,
+ lintFormats = {"%f:%l:%c: %m"},
+ -- formatCommand = "./node_modules/.bin/eslint -f unix --fix --stdin-filename ${INPUT}", -- TODO check if eslint is the formatter then add this
+ formatStdin = true
+ }
+
+ if O.lang.tsserver.formatter == 'prettier' then
+ table.insert(tsserver_args, prettier)
+ end
+
+ if O.lang.tsserver.linter == 'eslint' then
+ table.insert(tsserver_args, eslint)
+ end
+
+ require"lspconfig".efm.setup {
+ -- init_options = {initializationOptions},
+ cmd = {DATA_PATH .. "/lspinstall/efm/efm-langserver"},
+ init_options = {documentFormatting = true, codeAction = false},
+ filetypes = {
+ "javascriptreact", "javascript", "typescript", "typescriptreact",
+ "html", "css", "yaml", "vue"
+ },
+ settings = {
+ rootMarkers = {".git/", "package.json"},
+ languages = {
+ javascript = tsserver_args,
+ javascriptreact = tsserver_args,
+ typescript = tsserver_args,
+ typescriptreact = tsserver_args,
+ html = {prettier},
+ css = {prettier},
+ json = {prettier},
+ yaml = {prettier}
+ -- javascriptreact = {prettier, eslint},
+ -- javascript = {prettier, eslint},
+ -- markdown = {markdownPandocFormat, markdownlint},
+ }
+ }
+ }
+end
+
+return M