go.lua 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. lsp = {
  14. path = DATA_PATH .. "/lspinstall/go/gopls",
  15. },
  16. }
  17. end
  18. M.format = function()
  19. O.formatters.filetype["go"] = {
  20. function()
  21. return {
  22. exe = O.lang.go.formatter.exe,
  23. args = O.lang.go.formatter.args,
  24. stdin = O.lang.go.formatter.stdin,
  25. }
  26. end,
  27. }
  28. require("formatter.config").set_defaults {
  29. logging = false,
  30. filetype = O.formatters.filetype,
  31. }
  32. end
  33. M.lint = function()
  34. require("lint").linters_by_ft = {
  35. go = O.lang.go.linters,
  36. }
  37. end
  38. M.lsp = function()
  39. if not require("lv-utils").check_lsp_client_active "gopls" then
  40. require("lspconfig").gopls.setup {
  41. cmd = { O.lang.go.lsp.path },
  42. settings = { gopls = { analyses = { unusedparams = true }, staticcheck = true } },
  43. root_dir = require("lspconfig").util.root_pattern(".git", "go.mod"),
  44. init_options = { usePlaceholders = true, completeUnimported = true },
  45. on_attach = require("lsp").common_on_attach,
  46. }
  47. end
  48. end
  49. M.dap = function()
  50. -- TODO: implement dap
  51. return "No DAP configured!"
  52. end
  53. return M