sh.lua 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. on_attach = require("lsp").common_on_attach,
  51. init_options = { documentFormatting = true, codeAction = false },
  52. root_dir = require("lspconfig").util.root_pattern ".git/",
  53. filetypes = { "sh" },
  54. settings = {
  55. rootMarkers = { ".git/" },
  56. languages = {
  57. sh = sh_arguments,
  58. },
  59. },
  60. }
  61. end
  62. end
  63. M.lsp = function()
  64. if not require("lv-utils").check_lsp_client_active "bashls" then
  65. -- npm i -g bash-language-server
  66. require("lspconfig").bashls.setup {
  67. cmd = { DATA_PATH .. "/lspinstall/bash/node_modules/.bin/bash-language-server", "start" },
  68. on_attach = require("lsp").common_on_attach,
  69. filetypes = { "sh", "zsh" },
  70. }
  71. end
  72. end
  73. M.dap = function()
  74. -- TODO: implement dap
  75. return "No DAP configured!"
  76. end
  77. return M