go.lua 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. local M = {}
  2. M.config = function()
  3. O.lang.go = {
  4. formatter = {
  5. exe = "gofmt",
  6. args = {},
  7. stdin = true,
  8. },
  9. linters = {
  10. "golangcilint",
  11. "revive",
  12. },
  13. }
  14. end
  15. M.format = function()
  16. O.formatters.filetype["go"] = {
  17. function()
  18. return {
  19. exe = O.lang.go.formatter.exe,
  20. args = O.lang.go.formatter.args,
  21. stdin = O.lang.go.formatter.stdin,
  22. }
  23. end,
  24. }
  25. require("formatter.config").set_defaults {
  26. logging = false,
  27. filetype = O.formatters.filetype,
  28. }
  29. end
  30. M.lint = function()
  31. require("lint").linters_by_ft = {
  32. go = O.lang.go.linters,
  33. }
  34. end
  35. M.lsp = function()
  36. if not require("lv-utils").check_lsp_client_active "gopls" then
  37. require("lspconfig").gopls.setup {
  38. cmd = { DATA_PATH .. "/lspinstall/go/gopls" },
  39. settings = { gopls = { analyses = { unusedparams = true }, staticcheck = true } },
  40. root_dir = require("lspconfig").util.root_pattern(".git", "go.mod"),
  41. init_options = { usePlaceholders = true, completeUnimported = true },
  42. on_attach = require("lsp").common_on_attach,
  43. }
  44. end
  45. end
  46. M.dap = function()
  47. -- TODO: implement dap
  48. return "No DAP configured!"
  49. end
  50. return M