Skip to content

Commit

Permalink
perf: lower 'go list' JSON payload size (#248)
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikaverpil authored Jan 2, 2025
1 parent e4b0770 commit 4244d8f
Show file tree
Hide file tree
Showing 6 changed files with 175 additions and 202 deletions.
19 changes: 18 additions & 1 deletion lua/neotest-golang/lib/cmd.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,24 @@ function M.golist_data(cwd)
end

function M.golist_command()
local cmd = { "go", "list", "-json" }
-- NOTE: original command can contain a lot of data:
-- local cmd = { "go", "list", "-json" }

-- NOTE: optimized command only outputs fields needed:
local cmd = {
"go",
"list",
"-f",
[[{
"Dir": "{{.Dir}}",
"ImportPath": "{{.ImportPath}}",
"Name": "{{.Name}}",
"TestGoFiles": [{{range $i, $f := .TestGoFiles}}{{if ne $i 0}},{{end}}"{{$f}}"{{end}}],
"XTestGoFiles": [{{range $i, $f := .XTestGoFiles}}{{if ne $i 0}},{{end}}"{{$f}}"{{end}}],
"Module": { "GoMod": "{{.Module.GoMod}}" }
}]],
}

local go_list_args = options.get().go_list_args
if type(go_list_args) == "function" then
go_list_args = go_list_args()
Expand Down
1 change: 1 addition & 0 deletions tests/go/internal/notest/notest.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package notest
5 changes: 5 additions & 0 deletions tests/go/internal/two/one_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package two

import "testing"

func TestOne(t *testing.T) {}
5 changes: 5 additions & 0 deletions tests/go/internal/two/two_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package two

import "testing"

func TestTwo(t *testing.T) {}
16 changes: 12 additions & 4 deletions tests/go/lookup_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@ describe("Lookup", function()
ExampleTestSuite2 = "TestExampleTestSuite2",
},
},
[folderpath .. "/internal/testname/testname_test.go"] = {
package = "testname",
replacements = {},
},
[folderpath .. "/internal/two/one_test.go"] = {
package = "two",
replacements = {},
},
[folderpath .. "/internal/two/two_test.go"] = {
package = "two",
replacements = {},
},
[folderpath .. "/internal/x/xtest_blackbox_test.go"] = {
package = "x_test",
replacements = {},
Expand All @@ -48,10 +60,6 @@ describe("Lookup", function()
package = "x",
replacements = {},
},
[folderpath .. "/internal/testname/testname_test.go"] = {
package = "testname",
replacements = {},
},
}

-- Act
Expand Down
Loading

0 comments on commit 4244d8f

Please sign in to comment.