feat(struct_tags): add :GoTagClear
This commit is contained in:
parent
10abcb661e
commit
07f86d669b
6 changed files with 50 additions and 5 deletions
|
|
@ -43,6 +43,7 @@ gopher.comment = require("gopher.comment").comment
|
|||
gopher.tags = {
|
||||
add = tags.add,
|
||||
rm = tags.remove,
|
||||
clear = tags.clear,
|
||||
}
|
||||
|
||||
gopher.test = {
|
||||
|
|
|
|||
|
|
@ -89,7 +89,8 @@ local function handler_user_args(args)
|
|||
return res
|
||||
end
|
||||
|
||||
-- add tags to struct under cursor
|
||||
---Adds tags to a struct under the cursor
|
||||
---@param ... string Tags to add to the struct fields. If not provided, it will use [config.tag.default_tag]
|
||||
function struct_tags.add(...)
|
||||
local args = { ... }
|
||||
local fpath = vim.fn.expand "%"
|
||||
|
|
@ -101,7 +102,8 @@ function struct_tags.add(...)
|
|||
handle_tags(fpath, bufnr, user_args)
|
||||
end
|
||||
|
||||
-- remove tags to struct under cursor
|
||||
---Removes tags from a struct under the cursor
|
||||
---@param ... string Tags to add to the struct fields. If not provided, it will use [config.tag.default_tag]
|
||||
function struct_tags.remove(...)
|
||||
local args = { ... }
|
||||
local fpath = vim.fn.expand "%"
|
||||
|
|
@ -113,4 +115,11 @@ function struct_tags.remove(...)
|
|||
handle_tags(fpath, bufnr, user_args)
|
||||
end
|
||||
|
||||
---Removes all tags from a struct under the cursor
|
||||
function struct_tags.clear()
|
||||
local fpath = vim.fn.expand "%"
|
||||
local bufnr = vim.api.nvim_get_current_buf()
|
||||
handle_tags(fpath, bufnr, { "-clear-tags" })
|
||||
end
|
||||
|
||||
return struct_tags
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
command! -nargs=* GoTagAdd :lua require"gopher".tags.add(<f-args>)
|
||||
command! -nargs=* GoTagRm :lua require"gopher".tags.rm(<f-args>)
|
||||
command! GoTagClear :lua require"gopher".tags.clear()
|
||||
command! GoTestAdd :lua require"gopher".test.add()
|
||||
command! GoTestsAll :lua require"gopher".test.all()
|
||||
command! GoTestsExp :lua require"gopher".test.exported()
|
||||
|
|
|
|||
11
spec/fixtures/tags/clear_input.go
vendored
Normal file
11
spec/fixtures/tags/clear_input.go
vendored
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
package main
|
||||
|
||||
type Test struct {
|
||||
ID int `json:"id" yaml:"id" xml:"id" db:"id"`
|
||||
Name string `json:"name" yaml:"name" xml:"name" db:"name"`
|
||||
Num int64 `json:"num" yaml:"num" xml:"num" db:"num"`
|
||||
Another struct {
|
||||
First int `json:"first" yaml:"first" xml:"first" db:"first"`
|
||||
Second string `json:"second" yaml:"second" xml:"second" db:"second"`
|
||||
} `json:"another" yaml:"another" xml:"another" db:"another"`
|
||||
}
|
||||
11
spec/fixtures/tags/clear_output.go
vendored
Normal file
11
spec/fixtures/tags/clear_output.go
vendored
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
package main
|
||||
|
||||
type Test struct {
|
||||
ID int
|
||||
Name string
|
||||
Num int64
|
||||
Another struct {
|
||||
First int
|
||||
Second string
|
||||
}
|
||||
}
|
||||
|
|
@ -10,7 +10,7 @@ local T = MiniTest.new_set {
|
|||
},
|
||||
}
|
||||
T["struct_tags"] = MiniTest.new_set {}
|
||||
T["struct_tags"]["works add"] = function()
|
||||
T["struct_tags"]["should add tag"] = function()
|
||||
local tmp = t.tmpfile()
|
||||
local fixtures = t.get_fixtures "tags/add"
|
||||
t.writefile(tmp, fixtures.input)
|
||||
|
|
@ -22,7 +22,7 @@ T["struct_tags"]["works add"] = function()
|
|||
t.eq(t.readfile(tmp), fixtures.output)
|
||||
end
|
||||
|
||||
T["struct_tags"]["works remove"] = function()
|
||||
T["struct_tags"]["should remove tag"] = function()
|
||||
local tmp = t.tmpfile()
|
||||
local fixtures = t.get_fixtures "tags/remove"
|
||||
t.writefile(tmp, fixtures.input)
|
||||
|
|
@ -34,7 +34,7 @@ T["struct_tags"]["works remove"] = function()
|
|||
t.eq(t.readfile(tmp), fixtures.output)
|
||||
end
|
||||
|
||||
T["struct_tags"]["works many structs"] = function()
|
||||
T["struct_tags"]["should be able to handle many structs"] = function()
|
||||
local tmp = t.tmpfile()
|
||||
local fixtures = t.get_fixtures "tags/many"
|
||||
t.writefile(tmp, fixtures.input)
|
||||
|
|
@ -46,4 +46,16 @@ T["struct_tags"]["works many structs"] = function()
|
|||
t.eq(t.readfile(tmp), fixtures.output)
|
||||
end
|
||||
|
||||
T["struct_tags"]["should clear struct"] = function()
|
||||
local tmp = t.tmpfile()
|
||||
local fixtures = t.get_fixtures "tags/clear"
|
||||
t.writefile(tmp, fixtures.input)
|
||||
|
||||
child.cmd("silent edit " .. tmp)
|
||||
child.fn.setpos(".", { child.fn.bufnr "%", 3, 1, 0 })
|
||||
child.cmd "GoTagClear"
|
||||
|
||||
t.eq(t.readfile(tmp), fixtures.output)
|
||||
end
|
||||
|
||||
return T
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue