go.lua 1.2 KB

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