[mirror] Make your go dev experience better github.com/olexsmir/gopher.nvim
neovim golang
at v0.2.1 3.5 kB view raw
1local config = {} 2 3---@tag gopher.nvim-config.ConfigGoTagTransform 4---@text Possible values for |gopher.Config|.gotag.transform: 5--- 6---@dochide 7---@alias gopher.ConfigGoTagTransform 8---| "snakecase" "GopherUser" -> "gopher_user" 9---| "camelcase" "GopherUser" -> "gopherUser" 10---| "lispcase" "GopherUser" -> "gopher-user" 11---| "pascalcase" "GopherUser" -> "GopherUser" 12---| "titlecase" "GopherUser" -> "Gopher User" 13---| "keep" keeps the original field name 14 15---@toc_entry Config 16---@tag gopher.nvim-config 17---@eval return MiniDoc.afterlines_to_code(MiniDoc.current.eval_section) 18---@class gopher.Config 19local default_config = { 20 -- log level, you might consider using DEBUG or TRACE for debugging the plugin 21 ---@type number 22 log_level = vim.log.levels.INFO, 23 24 -- timeout for running internal commands 25 ---@type number 26 timeout = 2000, 27 28 -- user specified paths to binaries 29 ---@class gopher.ConfigCommand 30 commands = { 31 go = "go", 32 gomodifytags = "gomodifytags", 33 gotests = "gotests", 34 impl = "impl", 35 iferr = "iferr", 36 }, 37 ---@class gopher.ConfigGotests 38 gotests = { 39 -- gotests doesn't have template named "default" so this plugin uses "default" to set the default template 40 template = "default", 41 -- path to a directory containing custom test code templates 42 ---@type string|nil 43 template_dir = nil, 44 -- switch table tests from using slice to map (with test name for the key) 45 named = false, 46 }, 47 ---@class gopher.ConfigGoTag 48 gotag = { 49 ---@type gopher.ConfigGoTagTransform 50 transform = "snakecase", 51 52 -- default tags to add to struct fields 53 default_tag = "json", 54 }, 55 iferr = { 56 -- choose a custom error message 57 ---@type string|nil 58 message = nil, 59 }, 60} 61--minidoc_afterlines_end 62 63---@type gopher.Config 64---@dochide 65local _config = default_config 66 67-- I am kinda secret so don't tell anyone about me even dont use me 68-- 69-- if you don't believe me that i am secret see 70-- the line below it says @private 71---@private 72_config.___plugin_name = "gopher.nvim" ---@diagnostic disable-line: inject-field 73 74---@param user_config? gopher.Config 75---@dochide 76function config.setup(user_config) 77 vim.validate { user_config = { user_config, "table", true } } 78 79 _config = vim.tbl_deep_extend("force", vim.deepcopy(default_config), user_config or {}) 80 81 vim.validate { 82 log_level = { _config.log_level, "number" }, 83 timeout = { _config.timeout, "number" }, 84 ["commands"] = { _config.commands, "table" }, 85 ["commands.go"] = { _config.commands.go, "string" }, 86 ["commands.gomodifytags"] = { _config.commands.gomodifytags, "string" }, 87 ["commands.gotests"] = { _config.commands.gotests, "string" }, 88 ["commands.impl"] = { _config.commands.impl, "string" }, 89 ["commands.iferr"] = { _config.commands.iferr, "string" }, 90 ["gotests"] = { _config.gotests, "table" }, 91 ["gotests.template"] = { _config.gotests.template, "string" }, 92 ["gotests.template_dir"] = { _config.gotests.template, "string", true }, 93 ["gotests.named"] = { _config.gotests.named, "boolean" }, 94 ["gotag"] = { _config.gotag, "table" }, 95 ["gotag.transform"] = { _config.gotag.transform, "string" }, 96 ["gotag.default_tag"] = { _config.gotag.default_tag, "string" }, 97 ["iferr"] = { _config.iferr, "table" }, 98 ["iferr.message"] = { _config.iferr.message, "string", true }, 99 } 100end 101 102setmetatable(config, { 103 __index = function(_, key) 104 return _config[key] 105 end, 106}) 107 108---@dochide 109---@return gopher.Config 110return config