efm-general-ls.lua 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. -- Example configuations here: https://github.com/mattn/efm-langserver
  2. -- TODO this file needs to be refactored eache lang should be it's own file
  3. -- python
  4. local python_arguments = {}
  5. -- TODO replace with path argument
  6. local flake8 = {
  7. LintCommand = "flake8 --ignore=E501 --stdin-display-name ${INPUT} -",
  8. lintStdin = true,
  9. lintFormats = {"%f:%l:%c: %m"}
  10. }
  11. local isort = {formatCommand = "isort --quiet -", formatStdin = true}
  12. local yapf = {formatCommand = "yapf --quiet", formatStdin = true}
  13. if O.python.linter == 'flake8' then
  14. table.insert(python_arguments, flake8)
  15. end
  16. if O.python.formatter == 'yapf' then
  17. table.insert(python_arguments, yapf)
  18. end
  19. if O.python.isort then
  20. table.insert(python_arguments, isort)
  21. end
  22. -- lua
  23. local lua_arguments = {}
  24. local luaFormat = {
  25. formatCommand = "lua-format -i --no-keep-simple-function-one-line --column-limit=120",
  26. formatStdin = true
  27. }
  28. if O.lua.formatter == 'lua-format' then
  29. table.insert(lua_arguments, luaFormat)
  30. end
  31. -- sh
  32. local sh_arguments = {}
  33. local shfmt = {formatCommand = 'shfmt -ci -s -bn', formatStdin = true}
  34. local shellcheck = {
  35. LintCommand = 'shellcheck -f gcc -x',
  36. lintFormats = {'%f:%l:%c: %trror: %m', '%f:%l:%c: %tarning: %m', '%f:%l:%c: %tote: %m'}
  37. }
  38. if O.sh.formatter == 'shfmt' then
  39. table.insert(sh_arguments, shfmt)
  40. end
  41. if O.sh.linter == 'shellcheck' then
  42. table.insert(sh_arguments, shellcheck)
  43. end
  44. -- tsserver/web javascript react, vue, json, html, css, yaml
  45. local prettier = {formatCommand = "prettier --stdin-filepath ${INPUT}", formatStdin = true}
  46. -- 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.
  47. -- local prettier = {formatCommand = "./node_modules/.bin/prettier --stdin-filepath ${INPUT}", formatStdin = true}
  48. local eslint = {
  49. lintCommand = "./node_modules/.bin/eslint -f unix --stdin --stdin-filename ${INPUT}",
  50. lintIgnoreExitCode = true,
  51. lintStdin = true,
  52. lintFormats = {"%f:%l:%c: %m"},
  53. formatCommand = "./node_modules/.bin/eslint --fix-to-stdout --stdin --stdin-filename=${INPUT}",
  54. formatStdin = true
  55. }
  56. local tsserver_args = {}
  57. if O.tsserver.formatter == 'prettier' then
  58. table.insert(tsserver_args, prettier)
  59. end
  60. if O.tsserver.linter == 'eslint' then
  61. table.insert(tsserver_args, eslint)
  62. end
  63. -- local markdownlint = {
  64. -- -- TODO default to global lintrc
  65. -- -- lintcommand = 'markdownlint -s -c ./markdownlintrc',
  66. -- lintCommand = 'markdownlint -s',
  67. -- lintStdin = true,
  68. -- lintFormats = {'%f:%l %m', '%f:%l:%c %m', '%f: %l: %m'}
  69. -- }
  70. local markdownPandocFormat = {formatCommand = 'pandoc -f markdown -t gfm -sp --tab-stop=2', formatStdin = true}
  71. require"lspconfig".efm.setup {
  72. -- init_options = {initializationOptions},
  73. cmd = {DATA_PATH .. "/lspinstall/efm/efm-langserver"},
  74. init_options = {documentFormatting = true, codeAction = false},
  75. filetypes = {"lua", "python", "javascriptreact", "javascript", "sh", "html", "css", "json", "yaml", "markdown"},
  76. settings = {
  77. rootMarkers = {".git/"},
  78. languages = {
  79. python = python_arguments,
  80. lua = lua_arguments,
  81. sh = sh_arguments,
  82. javascript = tsserver_args,
  83. javascriptreact = tsserver_args,
  84. html = {prettier},
  85. css = {prettier},
  86. json = {prettier},
  87. yaml = {prettier},
  88. markdown = {markdownPandocFormat}
  89. -- javascriptreact = {prettier, eslint},
  90. -- javascript = {prettier, eslint},
  91. -- markdown = {markdownPandocFormat, markdownlint},
  92. }
  93. }
  94. }
  95. -- Also find way to toggle format on save
  96. -- maybe this will help: https://superuser.com/questions/439078/how-to-disable-autocmd-or-augroup-in-vim