efm-general-ls.lua 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. -- Example configuations here: https://github.com/mattn/efm-langserver
  2. -- tsserver/web javascript react, vue, json, html, css, yaml
  3. local prettier = {formatCommand = "prettier --stdin-filepath ${INPUT}", formatStdin = true}
  4. -- 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.
  5. -- local prettier = {formatCommand = "./node_modules/.bin/prettier --stdin-filepath ${INPUT}", formatStdin = true}
  6. local eslint = {
  7. lintCommand = "./node_modules/.bin/eslint -f unix --stdin --stdin-filename ${INPUT}",
  8. lintIgnoreExitCode = true,
  9. lintStdin = true,
  10. lintFormats = {"%f:%l:%c: %m"},
  11. formatCommand = "./node_modules/.bin/eslint --fix-to-stdout --stdin --stdin-filename=${INPUT}",
  12. formatStdin = true
  13. }
  14. local tsserver_args = {}
  15. if O.lang.tsserver.formatter == 'prettier' then table.insert(tsserver_args, prettier) end
  16. if O.lang.tsserver.linter == 'eslint' then table.insert(tsserver_args, eslint) end
  17. -- local markdownlint = {
  18. -- -- TODO default to global lintrc
  19. -- -- lintcommand = 'markdownlint -s -c ./markdownlintrc',
  20. -- lintCommand = 'markdownlint -s',
  21. -- lintStdin = true,
  22. -- lintFormats = {'%f:%l %m', '%f:%l:%c %m', '%f: %l: %m'}
  23. -- }
  24. local markdownPandocFormat = {formatCommand = 'pandoc -f markdown -t gfm -sp --tab-stop=2', formatStdin = true}
  25. require"lspconfig".efm.setup {
  26. -- init_options = {initializationOptions},
  27. cmd = {DATA_PATH .. "/lspinstall/efm/efm-langserver"},
  28. init_options = {documentFormatting = true, codeAction = false},
  29. filetypes = {"lua", "python", "javascriptreact", "javascript", "typescript","typescriptreact","sh", "html", "css", "yaml", "markdown", "vue"},
  30. settings = {
  31. rootMarkers = {".git/"},
  32. languages = {
  33. javascript = tsserver_args,
  34. javascriptreact = tsserver_args,
  35. typescript = tsserver_args,
  36. typescriptreact = tsserver_args,
  37. html = {prettier},
  38. css = {prettier},
  39. json = {prettier},
  40. yaml = {prettier},
  41. markdown = {markdownPandocFormat}
  42. -- javascriptreact = {prettier, eslint},
  43. -- javascript = {prettier, eslint},
  44. -- markdown = {markdownPandocFormat, markdownlint},
  45. }
  46. }
  47. }
  48. -- Also find way to toggle format on save
  49. -- maybe this will help: https://superuser.com/questions/439078/how-to-disable-autocmd-or-augroup-in-vim