refactor: treesitter utils (#91)
* refactor(ts_utils): i dont know why event it was here * fix: typos * fix(struct_tags)!: remove statement that i used for debug * refactor(ts_util): start from scratch * refactor(struct_tags): use new ts_util * fixup! refactor(struct_tags): use new ts_util * test(struct_tags): add support for multiple structs * fix(gotests): use new api * fix(impl): refactor some logic, use new api * docs(ts): add an explanation * refactor(_utils.ts): all public methods are just adapters * fix(comment): now it works * fixup! refactor(_utils.ts): all public methods are just adapters * fixup! fixup! refactor(_utils.ts): all public methods are just adapters * test(comment): e2e * tests(comment): fix * refactor(utils.ts): fix, docs * test(comment): fix tests again * fix(tests/comments): well, now i fell stupid * refactor(ts): add assert just to be sure that all elements are in the result * fix(ts): type annotations * fix(ts): pass bufnr to vim.treesitter.get_node * chore(ci): disable nightly * chore(ci): reorganize
This commit is contained in:
parent
f171953e43
commit
e9f2eef5e7
31 changed files with 346 additions and 409 deletions
0
spec/fixtures/comment/empty_input.go
vendored
Normal file
0
spec/fixtures/comment/empty_input.go
vendored
Normal file
2
spec/fixtures/comment/empty_output.go
vendored
Normal file
2
spec/fixtures/comment/empty_output.go
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
//
|
||||
|
||||
5
spec/fixtures/comment/func_input.go
vendored
Normal file
5
spec/fixtures/comment/func_input.go
vendored
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
package main
|
||||
|
||||
func Test(a int) bool {
|
||||
return false
|
||||
}
|
||||
6
spec/fixtures/comment/func_output.go
vendored
Normal file
6
spec/fixtures/comment/func_output.go
vendored
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
package main
|
||||
|
||||
// Test
|
||||
func Test(a int) bool {
|
||||
return false
|
||||
}
|
||||
3
spec/fixtures/comment/interface_input.go
vendored
Normal file
3
spec/fixtures/comment/interface_input.go
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
package main
|
||||
|
||||
type Testinger interface{}
|
||||
4
spec/fixtures/comment/interface_output.go
vendored
Normal file
4
spec/fixtures/comment/interface_output.go
vendored
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
package main
|
||||
|
||||
// Testinger
|
||||
type Testinger interface{}
|
||||
7
spec/fixtures/comment/method_input.go
vendored
Normal file
7
spec/fixtures/comment/method_input.go
vendored
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
package main
|
||||
|
||||
type Method struct{}
|
||||
|
||||
func (Method) Run() error {
|
||||
return nil
|
||||
}
|
||||
8
spec/fixtures/comment/method_output.go
vendored
Normal file
8
spec/fixtures/comment/method_output.go
vendored
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
package main
|
||||
|
||||
type Method struct{}
|
||||
|
||||
// Run
|
||||
func (Method) Run() error {
|
||||
return nil
|
||||
}
|
||||
2
spec/fixtures/comment/package_output.go
vendored
2
spec/fixtures/comment/package_output.go
vendored
|
|
@ -1,2 +1,2 @@
|
|||
// Package main provides main
|
||||
// Package main provides
|
||||
package main
|
||||
|
|
|
|||
3
spec/fixtures/comment/struct_input.go
vendored
Normal file
3
spec/fixtures/comment/struct_input.go
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
package main
|
||||
|
||||
type CommentStruct struct{}
|
||||
4
spec/fixtures/comment/struct_output.go
vendored
Normal file
4
spec/fixtures/comment/struct_output.go
vendored
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
package main
|
||||
|
||||
// CommentStruct
|
||||
type CommentStruct struct{}
|
||||
2
spec/fixtures/impl/reader_output.go
vendored
2
spec/fixtures/impl/reader_output.go
vendored
|
|
@ -1,6 +1,6 @@
|
|||
package main
|
||||
|
||||
func (r Read2) Read(p []byte) (n int, err error) {
|
||||
func (r *Read2) Read(p []byte) (n int, err error) {
|
||||
panic("not implemented") // TODO: Implement
|
||||
}
|
||||
|
||||
|
|
|
|||
18
spec/fixtures/tags/many_input.go
vendored
Normal file
18
spec/fixtures/tags/many_input.go
vendored
Normal file
|
|
@ -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
|
||||
}
|
||||
)
|
||||
18
spec/fixtures/tags/many_output.go
vendored
Normal file
18
spec/fixtures/tags/many_output.go
vendored
Normal file
|
|
@ -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
|
||||
}
|
||||
)
|
||||
|
|
@ -5,23 +5,50 @@ local T = MiniTest.new_set {
|
|||
hooks = {
|
||||
post_once = child.stop,
|
||||
pre_case = function()
|
||||
MiniTest.skip "This module should be fixed first"
|
||||
child.restart { "-u", t.mininit_path }
|
||||
end,
|
||||
},
|
||||
}
|
||||
|
||||
local function do_the_test(fixture, pos)
|
||||
local tmp = t.tmpfile()
|
||||
local fixtures = t.get_fixtures("comment/" .. fixture)
|
||||
t.writefile(tmp, fixtures.input)
|
||||
|
||||
child.cmd("silent edit " .. tmp)
|
||||
child.fn.setpos(".", { child.fn.bufnr "%", unpack(pos) })
|
||||
child.cmd "GoCmt"
|
||||
child.cmd "write"
|
||||
|
||||
t.eq(t.readfile(tmp), fixtures.output)
|
||||
|
||||
-- without it all other(not even from this module) tests are falling
|
||||
t.deletefile(tmp)
|
||||
end
|
||||
|
||||
T["comment"] = MiniTest.new_set {}
|
||||
T["comment"]["should add comment to package"] = function()
|
||||
do_the_test("package", { 1, 1 })
|
||||
end
|
||||
|
||||
T["comment"]["should add comment to package"] = function() end
|
||||
T["comment"]["should add comment to struct"] = function()
|
||||
do_the_test("struct", { 4, 1 })
|
||||
end
|
||||
|
||||
T["comment"]["should add comment to struct"] = function() end
|
||||
T["comment"]["should add comment to function"] = function()
|
||||
do_the_test("func", { 3, 1 })
|
||||
end
|
||||
|
||||
T["comment"]["should add comment to function"] = function() end
|
||||
T["comment"]["should add comment to method"] = function()
|
||||
do_the_test("method", { 5, 1 })
|
||||
end
|
||||
|
||||
T["comment"]["should add comment to method"] = function() end
|
||||
T["comment"]["should add comment to interface"] = function()
|
||||
do_the_test("interface", { 3, 6 })
|
||||
end
|
||||
|
||||
T["comment"]["should add comment to interface"] = function() end
|
||||
|
||||
T["comment"]["otherwise should add // above cursor"] = function() end
|
||||
T["comment"]["otherwise should add // above cursor"] = function()
|
||||
do_the_test("empty", { 1, 1 })
|
||||
end
|
||||
|
||||
return T
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ T["impl"]["works w io.Writer"] = function()
|
|||
t.writefile(tmp, fixtures.input)
|
||||
|
||||
child.cmd("silent edit " .. tmp)
|
||||
child.fn.setpos(".", { child.fn.bufnr(tmp), 3, 6 })
|
||||
child.fn.setpos(".", { child.fn.bufnr(tmp), 3, 0 })
|
||||
child.cmd "GoImpl w io.Writer"
|
||||
child.cmd "write"
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -31,6 +31,11 @@ function testutils.writefile(fpath, contents)
|
|||
vim.fn.writefile(vim.split(contents, "\n"), fpath)
|
||||
end
|
||||
|
||||
---@param fpath string
|
||||
function testutils.deletefile(fpath)
|
||||
vim.fn.delete(fpath)
|
||||
end
|
||||
|
||||
---@param fixture string
|
||||
---@return {input: string, output: string}
|
||||
function testutils.get_fixtures(fixture)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue