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