[mirror] Make your go dev experience better
github.com/olexsmir/gopher.nvim
neovim
golang
1---@type gopher.Config
2---@dochide
3---@diagnostic disable-next-line: missing-fields .setup() gets injected later
4local config = {}
5
6---@tag gopher.nvim-config.ConfigGoTagTransform
7---@text Possible values for |gopher.Config|.gotag.transform:
8---
9---@dochide
10---@alias gopher.ConfigGoTagTransform
11---| "snakecase" "GopherUser" -> "gopher_user"
12---| "camelcase" "GopherUser" -> "gopherUser"
13---| "lispcase" "GopherUser" -> "gopher-user"
14---| "pascalcase" "GopherUser" -> "GopherUser"
15---| "titlecase" "GopherUser" -> "Gopher User"
16---| "keep" keeps the original field name
17
18---@toc_entry Config
19---@tag gopher.nvim-config
20---@eval return MiniDoc.afterlines_to_code(MiniDoc.current.eval_section)
21---@class gopher.Config
22---@field setup fun(user_config?: gopher.Config)
23local default_config = {
24 -- log level, you might consider using DEBUG or TRACE for debugging the plugin
25 ---@type number
26 log_level = vim.log.levels.INFO,
27
28 -- timeout for running internal commands
29 ---@type number
30 timeout = 2000,
31
32 -- timeout for running installer commands(e.g :GoDepsInstall, :GoDepsInstallSync)
33 ---@type number
34 installer_timeout = 999999,
35
36 -- user specified paths to binaries
37 ---@class gopher.ConfigCommand
38 commands = {
39 go = "go",
40 gomodifytags = "gomodifytags",
41 gotests = "gotests",
42 impl = "impl",
43 iferr = "iferr",
44 json2go = "json2go",
45 },
46 ---@class gopher.ConfigGotests
47 gotests = {
48 -- a default template that gotess will use.
49 -- gotets doesn't have template named `default`, we use it to represent absence of the provided template.
50 template = "default",
51
52 -- path to a directory containing custom test code templates
53 ---@type string|nil
54 template_dir = nil,
55
56 -- use named tests(map with test name as key) in table tests(slice of structs by default)
57 named = false,
58 },
59 ---@class gopher.ConfigGoTag
60 gotag = {
61 ---@type gopher.ConfigGoTagTransform
62 transform = "snakecase",
63
64 -- default tags to add to struct fields
65 default_tag = "json",
66
67 -- default tag option added struct fields, set to nil to disable
68 -- e.g: `option = "json=omitempty,xml=omitempty`
69 ---@type string|nil
70 option = nil,
71 },
72 ---@class gopher.ConfigIfErr
73 iferr = {
74 -- choose a custom error message, nil to use default
75 -- e.g: `message = 'fmt.Errorf("failed to %w", err)'`
76 ---@type string|nil
77 message = nil,
78 },
79 ---@class gopher.ConfigJson2Go
80 json2go = {
81 -- command used to open interactive input.
82 -- e.g: `split`, `botright split`, `tabnew`
83 interactive_cmd = "vsplit",
84
85 -- name of autogenerated struct, if nil none, will the default one of json2go.
86 -- e.g: "MySuperCoolName"
87 ---@type string|nil
88 type_name = nil,
89 },
90}
91--minidoc_afterlines_end
92
93---@type gopher.Config
94---@dochide
95local _config = default_config
96
97-- I am kinda secret so don't tell anyone about me even dont use me
98--
99-- if you don't believe me that i am secret see
100-- the line below it says @private
101---@private
102_config.___plugin_name = "gopher.nvim" ---@diagnostic disable-line: inject-field
103
104---@param user_config? gopher.Config
105---@dochide
106function config.setup(user_config)
107 vim.validate("user_config", user_config, "table", true)
108
109 _config = vim.tbl_deep_extend("force", vim.deepcopy(default_config), user_config or {})
110
111 vim.validate("log_level", _config.log_level, "number")
112 vim.validate("timeout", _config.timeout, "number")
113 vim.validate("installer_timeout", _config.timeout, "number")
114 vim.validate("commands", _config.commands, "table")
115 vim.validate("commands.go", _config.commands.go, "string")
116 vim.validate("commands.gomodifytags", _config.commands.gomodifytags, "string")
117 vim.validate("commands.gotests", _config.commands.gotests, "string")
118 vim.validate("commands.impl", _config.commands.impl, "string")
119 vim.validate("commands.iferr", _config.commands.iferr, "string")
120 vim.validate("commands.json2go", _config.commands.json2go, "string")
121 vim.validate("gotests", _config.gotests, "table")
122 vim.validate("gotests.template", _config.gotests.template, "string")
123 vim.validate("gotests.template_dir", _config.gotests.template_dir, { "string", "nil" })
124 vim.validate("gotests.named", _config.gotests.named, "boolean")
125 vim.validate("gotag", _config.gotag, "table")
126 vim.validate("gotag.transform", _config.gotag.transform, "string")
127 vim.validate("gotag.default_tag", _config.gotag.default_tag, "string")
128 vim.validate("gotag.option", _config.gotag.option, { "string", "nil" })
129 vim.validate("iferr", _config.iferr, "table")
130 vim.validate("iferr.message", _config.iferr.message, { "string", "nil" })
131 vim.validate("json2go.installer_timeout", _config.json2go.interactive_cmd, "string")
132 vim.validate("json2go.type_name", _config.json2go.type_name, { "string", "nil" })
133end
134
135setmetatable(config, {
136 __index = function(_, key)
137 return _config[key]
138 end,
139})
140
141---@dochide
142return config