efm-general-ls.lua 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. -- Example configuations here: https://github.com/mattn/efm-langserver
  2. -- python
  3. local flake8 = {
  4. LintCommand = "flake8 --ignore=E501 --stdin-display-name ${INPUT} -",
  5. lintStdin = true,
  6. lintFormats = {"%f:%l:%c: %m"}
  7. }
  8. local isort = {formatCommand = "isort --quiet -", formatStdin = true}
  9. local yapf = {formatCommand = "yapf --quiet", formatStdin = true}
  10. -- lua
  11. local luaFormat = {
  12. formatCommand = "lua-format -i --no-keep-simple-function-one-line --column-limit=120",
  13. formatStdin = true
  14. }
  15. -- JavaScript/React/TypeScript
  16. local prettier = {formatCommand = "./node_modules/.bin/prettier --stdin-filepath ${INPUT}", formatStdin = true}
  17. local eslint = {
  18. lintCommand = "./node_modules/.bin/eslint -f unix --stdin --stdin-filename ${INPUT}",
  19. lintIgnoreExitCode = true,
  20. lintStdin = true,
  21. lintFormats = {"%f:%l:%c: %m"},
  22. formatCommand = "./node_modules/.bin/eslint --fix-to-stdout --stdin --stdin-filename=${INPUT}",
  23. formatStdin = true
  24. }
  25. local shellcheck = {
  26. LintCommand = 'shellcheck -f gcc -x',
  27. lintFormats = {'%f:%l:%c: %trror: %m', '%f:%l:%c: %tarning: %m', '%f:%l:%c: %tote: %m'}
  28. }
  29. local shfmt = {
  30. formatCommand = 'shfmt -ci -s -bn',
  31. formatStdin = true
  32. }
  33. require"lspconfig".efm.setup {
  34. -- init_options = {initializationOptions},
  35. init_options = {documentFormatting = true, codeAction = false},
  36. filetypes = {"lua", "python", "javascriptreact", "javascript", "sh"},
  37. settings = {
  38. rootMarkers = {".git/"},
  39. languages = {
  40. lua = {luaFormat},
  41. python = {isort, yapf},
  42. javascriptreact = {prettier, eslint},
  43. javascript = {prettier, eslint},
  44. sh = {shellcheck, shfmt}
  45. }
  46. }
  47. }
  48. -- TODO turn these eslint and prettier examples into something good
  49. -- TODO also shellcheck and shell formatting
  50. -- Also find way to toggle format on save
  51. -- maybe this will help: https://superuser.com/questions/439078/how-to-disable-autocmd-or-augroup-in-vim