sh.lua 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. local M = {}
  2. M.config = function()
  3. -- TODO: implement config for language
  4. return "No config available!"
  5. end
  6. M.format = function()
  7. O.formatters.filetype["sh"] = {
  8. function()
  9. return {
  10. exe = O.lang.sh.formatter.exe,
  11. args = O.lang.sh.formatter.args,
  12. stdin = not (O.lang.sh.formatter.stdin ~= nil),
  13. }
  14. end,
  15. }
  16. require("formatter.config").set_defaults {
  17. logging = false,
  18. filetype = O.formatters.filetype,
  19. }
  20. end
  21. M.lint = function()
  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
  47. end
  48. M.lsp = function()
  49. if not require("lv-utils").check_lsp_client_active "bashls" then
  50. -- npm i -g bash-language-server
  51. require("lspconfig").bashls.setup {
  52. cmd = { DATA_PATH .. "/lspinstall/bash/node_modules/.bin/bash-language-server", "start" },
  53. on_attach = require("lsp").common_on_attach,
  54. filetypes = { "sh", "zsh" },
  55. }
  56. end
  57. end
  58. M.dap = function()
  59. -- TODO: implement dap
  60. return "No DAP configured!"
  61. end
  62. return M