ts-fmt-lint.lua 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. -- Example configuations here: https://github.com/mattn/efm-langserver
  2. -- 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.
  3. local M = {}
  4. M.setup = function()
  5. local tsserver_args = {}
  6. if O.lang.tsserver.linter == "eslint" or O.lang.tsserver.linter == "eslint_d" then
  7. local eslint = {
  8. lintCommand = O.lang.tsserver.linter .. " -f unix --stdin --stdin-filename {INPUT}",
  9. lintStdin = true,
  10. lintFormats = { "%f:%l:%c: %m" },
  11. lintIgnoreExitCode = true,
  12. formatCommand = O.lang.tsserver.linter .. " --fix-to-stdout --stdin --stdin-filename=${INPUT}",
  13. formatStdin = true,
  14. }
  15. table.insert(tsserver_args, eslint)
  16. end
  17. require("lspconfig").efm.setup {
  18. -- init_options = {initializationOptions},
  19. cmd = { DATA_PATH .. "/lspinstall/efm/efm-langserver" },
  20. init_options = { documentFormatting = true, codeAction = false },
  21. filetypes = {
  22. "vue",
  23. "javascript",
  24. "javascriptreact",
  25. "typescript",
  26. "typescriptreact",
  27. "javascript.jsx",
  28. "typescript.tsx",
  29. },
  30. settings = {
  31. rootMarkers = { ".git/", "package.json" },
  32. languages = {
  33. vue = tsserver_args,
  34. javascript = tsserver_args,
  35. javascriptreact = tsserver_args,
  36. ["javascript.jsx"] = tsserver_args,
  37. typescript = tsserver_args,
  38. ["typescript.tsx"] = tsserver_args,
  39. typescriptreact = tsserver_args,
  40. },
  41. },
  42. }
  43. end
  44. return M