sh.lua 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. local M = {}
  2. M.config = function()
  3. O.lang.sh = {
  4. -- @usage can be 'shellcheck'
  5. linter = "",
  6. -- @usage can be 'shfmt'
  7. diagnostics = {
  8. virtual_text = { spacing = 0, prefix = "" },
  9. signs = true,
  10. underline = true,
  11. },
  12. formatter = {
  13. exe = "shfmt",
  14. args = { "-w" },
  15. stdin = false,
  16. },
  17. linters = { "shellcheck" },
  18. }
  19. end
  20. M.format = function()
  21. O.formatters.filetype["sh"] = {
  22. function()
  23. return {
  24. exe = O.lang.sh.formatter.exe,
  25. args = O.lang.sh.formatter.args,
  26. stdin = O.lang.sh.formatter.stdin,
  27. tempfile_prefix = ".formatter",
  28. }
  29. end,
  30. }
  31. require("formatter.config").set_defaults {
  32. logging = false,
  33. filetype = O.formatters.filetype,
  34. }
  35. end
  36. M.lint = function()
  37. require("lint").linters_by_ft = {
  38. sh = O.lang.sh.linters,
  39. }
  40. end
  41. M.lsp = function()
  42. if not require("lv-utils").check_lsp_client_active "bashls" then
  43. -- npm i -g bash-language-server
  44. require("lspconfig").bashls.setup {
  45. cmd = { DATA_PATH .. "/lspinstall/bash/node_modules/.bin/bash-language-server", "start" },
  46. on_attach = require("lsp").common_on_attach,
  47. filetypes = { "sh", "zsh" },
  48. }
  49. end
  50. end
  51. M.dap = function()
  52. -- TODO: implement dap
  53. return "No DAP configured!"
  54. end
  55. return M