efm-general-ls.lua 3.9 KB

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