summaryrefslogtreecommitdiff
path: root/lua/lsp/ts-fmt-lint.lua
diff options
context:
space:
mode:
authorchristianchiarulli <[email protected]>2021-07-03 18:50:21 -0400
committerchristianchiarulli <[email protected]>2021-07-03 18:50:21 -0400
commita8ccb55260accf241b7e061f1fd07f8e0a4dbbb6 (patch)
tree7409a728229119cb560cf8b786f937e2c3ffabf2 /lua/lsp/ts-fmt-lint.lua
parent7dc564c42727ac66dea1e9cb795a2568e00e4628 (diff)
eslint working (fixes) prettier working (with node modules)
Diffstat (limited to 'lua/lsp/ts-fmt-lint.lua')
-rw-r--r--lua/lsp/ts-fmt-lint.lua66
1 files changed, 66 insertions, 0 deletions
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