[mirror] Make your go dev experience better github.com/olexsmir/gopher.nvim
neovim golang

feat(struct_tags): set default tag (#87)

* feat(struct_tags): add config option for default tag

* docs: docgen

* fix(struct_tags): as it turns out it didnt work as i supposed to before, but now it does

authored by olexsmir.xyz and committed by GitHub 57b5dbf6 c2f64db4

Changed files
+19 -13
doc
lua
+7
doc/gopher.nvim.txt
··· 55 55 ---@type number 56 56 log_level = vim.log.levels.INFO, 57 57 58 + -- timeout for running commands 59 + ---@type number 60 + timeout = 2000, 61 + 58 62 -- user specified paths to binaries 59 63 ---@class gopher.ConfigCommand 60 64 commands = { ··· 80 84 gotag = { 81 85 ---@type gopher.ConfigGoTagTransform 82 86 transform = "snakecase", 87 + 88 + -- default tags to add to struct fields 89 + default_tag = "json", 83 90 }, 84 91 } 85 92 <
+3
lua/gopher/config.lua
··· 62 62 gotag = { 63 63 ---@type gopher.ConfigGoTagTransform 64 64 transform = "snakecase", 65 + 66 + -- default tags to add to struct fields 67 + default_tag = "json", 65 68 }, 66 69 } 67 70 --minidoc_afterlines_end
+9 -13
lua/gopher/struct_tags.lua
··· 55 55 table.insert(cmd_args, v) 56 56 end 57 57 58 - -- set default tag for "clear tags" 59 - if #arg == 1 and arg[1] ~= "-clear-tags" then 60 - table.insert(cmd_args, "json") 61 - end 62 - 63 58 local rs = r.sync { 64 59 c.commands.gomodifytags, 65 60 "-transform", ··· 99 94 100 95 -- add tags to struct under cursor 101 96 function struct_tags.add(...) 102 - local arg = { ... } 103 - if #arg == nil or arg == "" then 104 - arg = { "json" } 97 + local user_tags = { ... } 98 + if #user_tags == 0 then 99 + vim.print("c.gotag.default_tag", c.gotag.default_tag) 100 + user_tags = { c.gotag.default_tag } 105 101 end 106 102 107 103 local cmd_args = { "-add-tags" } 108 - for _, v in ipairs(arg) do 104 + for _, v in ipairs(user_tags) do 109 105 table.insert(cmd_args, v) 110 106 end 111 107 ··· 114 110 115 111 -- remove tags to struct under cursor 116 112 function struct_tags.remove(...) 117 - local arg = { ... } 118 - if #arg == nil or arg == "" then 119 - arg = { "json" } 113 + local user_tags = { ... } 114 + if #user_tags == 0 then 115 + user_tags = { c.gotag.default_tag } 120 116 end 121 117 122 118 local cmd_args = { "-remove-tags" } 123 - for _, v in ipairs(arg) do 119 + for _, v in ipairs(user_tags) do 124 120 table.insert(cmd_args, v) 125 121 end 126 122