zig.lua 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. local M = {}
  2. M.config = function()
  3. O.lang.zig = {
  4. formatter = {
  5. exe = "zig",
  6. args = { "fmt" },
  7. stdin = false,
  8. },
  9. lsp = {
  10. path = "zls",
  11. },
  12. }
  13. end
  14. M.format = function()
  15. O.formatters.filetype["zig"] = {
  16. function()
  17. return {
  18. exe = O.lang.zig.formatter.exe,
  19. args = O.lang.zig.formatter.args,
  20. stdin = O.lang.zig.formatter.stdin,
  21. }
  22. end,
  23. }
  24. require("formatter.config").set_defaults {
  25. logging = false,
  26. filetype = O.formatters.filetype,
  27. }
  28. end
  29. M.lint = function()
  30. -- TODO: implement linters (if applicable)
  31. return "No linters configured!"
  32. end
  33. M.lsp = function()
  34. if require("lv-utils").check_lsp_client_active "zls" then
  35. return
  36. end
  37. -- Because lspinstall don't support zig yet,
  38. -- So we need zls preset in global lib
  39. -- Further custom install zls in
  40. -- https://github.com/zigtools/zls/wiki/Downloading-and-Building-ZLS
  41. require("lspconfig").zls.setup {
  42. cmd = { O.lang.zig.lsp.path },
  43. root_dir = require("lspconfig").util.root_pattern(".git", "build.zig", "zls.json"),
  44. on_attach = require("lsp").common_on_attach,
  45. }
  46. end
  47. M.dap = function()
  48. -- TODO: implement dap
  49. return "No DAP configured!"
  50. end
  51. return M