From 59a0e961c4bc849ac5877e374cb16fc10046aa78 Mon Sep 17 00:00:00 2001 From: Oleksandr Smirnov Date: Tue, 18 Mar 2025 21:21:14 +0200 Subject: [PATCH] test(struct_tags): add support for multiple structs --- lua/gopher/_utils/ts/init.lua | 2 +- spec/fixtures/tags/many_input.go | 18 ++++++++++++++++++ spec/fixtures/tags/many_output.go | 18 ++++++++++++++++++ spec/integration/struct_tags_test.lua | 12 ++++++++++++ 4 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 spec/fixtures/tags/many_input.go create mode 100644 spec/fixtures/tags/many_output.go diff --git a/lua/gopher/_utils/ts/init.lua b/lua/gopher/_utils/ts/init.lua index 64c948f..90fc899 100644 --- a/lua/gopher/_utils/ts/init.lua +++ b/lua/gopher/_utils/ts/init.lua @@ -45,7 +45,7 @@ function ts.get_struct_node_at_pos(bufnr) end local res = {} - local r = get_parrent_node("type_declaration", node) + local r = get_parrent_node("type_spec", node) if not r then error "No struct found under cursor" end diff --git a/spec/fixtures/tags/many_input.go b/spec/fixtures/tags/many_input.go new file mode 100644 index 0000000..f5c6367 --- /dev/null +++ b/spec/fixtures/tags/many_input.go @@ -0,0 +1,18 @@ +package main + +type ( + TestOne struct { + Asdf string + ID int + } + + TestTwo struct { + Fesa int + A bool + } + + TestThree struct { + Asufj int + Fs string + } +) diff --git a/spec/fixtures/tags/many_output.go b/spec/fixtures/tags/many_output.go new file mode 100644 index 0000000..36877b8 --- /dev/null +++ b/spec/fixtures/tags/many_output.go @@ -0,0 +1,18 @@ +package main + +type ( + TestOne struct { + Asdf string + ID int + } + + TestTwo struct { + Fesa int `testing:"fesa"` + A bool `testing:"a"` + } + + TestThree struct { + Asufj int + Fs string + } +) diff --git a/spec/integration/struct_tags_test.lua b/spec/integration/struct_tags_test.lua index 8fb4aa3..e8f8606 100644 --- a/spec/integration/struct_tags_test.lua +++ b/spec/integration/struct_tags_test.lua @@ -34,4 +34,16 @@ T["struct_tags"]["works remove"] = function() t.eq(t.readfile(tmp), fixtures.output) end +T["struct_tags"]["works many structs"] = function() + local tmp = t.tmpfile() + local fixtures = t.get_fixtures "tags/many" + t.writefile(tmp, fixtures.input) + + child.cmd("silent edit " .. tmp) + child.fn.setpos(".", { child.fn.bufnr "%", 10, 3, 0 }) + child.cmd "GoTagAdd testing" + + t.eq(t.readfile(tmp), fixtures.output) +end + return T