sh.lua 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. }
  27. end,
  28. }
  29. require("formatter.config").set_defaults {
  30. logging = false,
  31. filetype = O.formatters.filetype,
  32. }
  33. end
  34. M.lint = function()
  35. -- sh
  36. local sh_arguments = {}
  37. local shfmt = { formatCommand = "shfmt -ci -s -bn", formatStdin = true }
  38. local shellcheck = {
  39. LintCommand = "shellcheck -f gcc -x",
  40. lintFormats = { "%f:%l:%c: %trror: %m", "%f:%l:%c: %tarning: %m", "%f:%l:%c: %tote: %m" },
  41. }
  42. if O.lang.sh.linter == "shellcheck" then
  43. table.insert(sh_arguments, shellcheck)
  44. end
  45. if not require("lv-utils").check_lsp_client_active "efm" then
  46. require("lspconfig").efm.setup {
  47. -- init_options = {initializationOptions},
  48. cmd = { DATA_PATH .. "/lspinstall/efm/efm-langserver" },
  49. init_options = { documentFormatting = true, codeAction = false },
  50. root_dir = require("lspconfig").util.root_pattern ".git/",
  51. filetypes = { "sh" },
  52. settings = {
  53. rootMarkers = { ".git/" },
  54. languages = {
  55. sh = sh_arguments,
  56. },
  57. },
  58. }
  59. end
  60. end
  61. M.lsp = function()
  62. if not require("lv-utils").check_lsp_client_active "bashls" then
  63. -- npm i -g bash-language-server
  64. require("lspconfig").bashls.setup {
  65. cmd = { DATA_PATH .. "/lspinstall/bash/node_modules/.bin/bash-language-server", "start" },
  66. on_attach = require("lsp").common_on_attach,
  67. filetypes = { "sh", "zsh" },
  68. }
  69. end
  70. end
  71. M.dap = function()
  72. -- TODO: implement dap
  73. return "No DAP configured!"
  74. end
  75. return M