sh.lua 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. }
  18. end
  19. M.format = function()
  20. O.formatters.filetype["sh"] = {
  21. function()
  22. return {
  23. exe = O.lang.sh.formatter.exe,
  24. args = O.lang.sh.formatter.args,
  25. stdin = not (O.lang.sh.formatter.stdin ~= nil),
  26. tempfile_prefix = ".formatter",
  27. }
  28. end,
  29. }
  30. require("formatter.config").set_defaults {
  31. logging = false,
  32. filetype = O.formatters.filetype,
  33. }
  34. end
  35. M.lint = function()
  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.linter == "shellcheck" then
  44. table.insert(sh_arguments, shellcheck)
  45. end
  46. if not require("lv-utils").check_lsp_client_active "efm" then
  47. require("lspconfig").efm.setup {
  48. -- init_options = {initializationOptions},
  49. cmd = { DATA_PATH .. "/lspinstall/efm/efm-langserver" },
  50. init_options = { documentFormatting = true, codeAction = false },
  51. root_dir = require("lspconfig").util.root_pattern ".git/",
  52. filetypes = { "sh" },
  53. settings = {
  54. rootMarkers = { ".git/" },
  55. languages = {
  56. sh = sh_arguments,
  57. },
  58. },
  59. }
  60. end
  61. end
  62. M.lsp = function()
  63. if not require("lv-utils").check_lsp_client_active "bashls" then
  64. -- npm i -g bash-language-server
  65. require("lspconfig").bashls.setup {
  66. cmd = { DATA_PATH .. "/lspinstall/bash/node_modules/.bin/bash-language-server", "start" },
  67. on_attach = require("lsp").common_on_attach,
  68. filetypes = { "sh", "zsh" },
  69. }
  70. end
  71. end
  72. M.dap = function()
  73. -- TODO: implement dap
  74. return "No DAP configured!"
  75. end
  76. return M