efm-general-ls.lua 3.9 KB

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