sh.lua 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. O.formatters.filetype["sh"] = {
  2. function()
  3. return {
  4. exe = O.lang.sh.formatter.exe,
  5. args = O.lang.sh.formatter.args,
  6. stdin = not (O.lang.sh.formatter.stdin ~= nil),
  7. }
  8. end,
  9. }
  10. require("formatter.config").set_defaults {
  11. logging = false,
  12. filetype = O.formatters.filetype,
  13. }
  14. if not require("lv-utils").check_lsp_client_active "bashls" then
  15. -- npm i -g bash-language-server
  16. require("lspconfig").bashls.setup {
  17. cmd = { DATA_PATH .. "/lspinstall/bash/node_modules/.bin/bash-language-server", "start" },
  18. on_attach = require("lsp").common_on_attach,
  19. filetypes = { "sh", "zsh" },
  20. }
  21. end
  22. -- sh
  23. local sh_arguments = {}
  24. local shfmt = { formatCommand = "shfmt -ci -s -bn", formatStdin = true }
  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. if O.lang.sh.linter == "shellcheck" then
  30. table.insert(sh_arguments, shellcheck)
  31. end
  32. if not require("lv-utils").check_lsp_client_active "efm" then
  33. require("lspconfig").efm.setup {
  34. -- init_options = {initializationOptions},
  35. cmd = { DATA_PATH .. "/lspinstall/efm/efm-langserver" },
  36. init_options = { documentFormatting = true, codeAction = false },
  37. root_dir = require("lspconfig").util.root_pattern ".git/",
  38. filetypes = { "sh" },
  39. settings = {
  40. rootMarkers = { ".git/" },
  41. languages = {
  42. sh = sh_arguments,
  43. },
  44. },
  45. }
  46. end