ts-fmt-lint.lua 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. root_dir = require("lspconfig").util.root_pattern(".git/", "package.json"),
  22. filetypes = {
  23. "vue",
  24. "javascript",
  25. "javascriptreact",
  26. "typescript",
  27. "typescriptreact",
  28. "javascript.jsx",
  29. "typescript.tsx",
  30. },
  31. settings = {
  32. rootMarkers = { ".git/", "package.json" },
  33. languages = {
  34. vue = tsserver_args,
  35. javascript = tsserver_args,
  36. javascriptreact = tsserver_args,
  37. ["javascript.jsx"] = tsserver_args,
  38. typescript = tsserver_args,
  39. ["typescript.tsx"] = tsserver_args,
  40. typescriptreact = tsserver_args,
  41. },
  42. },
  43. }
  44. end
  45. return M