I simply began working with goimports immediately right now, as an alternative of counting on editor (Zed) extensions/gopls. Within the editor, an import is accurately resolved, however on the command line it’s not.
I loosely have this file construction, and I need goimports to look at rename.go (bundle rename) and add an import for bundle subcmd:
+ subcmd
- inference.go
- inference_test.go
+ rename
- rename.go
- rename_test.go
- subcmd.go
- subcmd_test.go
goimports -d rename.go
offers me nothing, however goimports -d rename_test.go
does what I’d anticipate:
diff -u ./subcmd/rename/rename_test.go.orig ./subcmd/rename/rename_test.go
--- ./subcmd/rename/rename_test.go.orig 2024-05-14 04:09:21
+++ ./subcmd/rename/rename_test.go 2024-05-14 04:09:21
@@ -5,7 +5,8 @@
"replicate"
"testing"
- )
+ "github.com/zacharysyoung/gocsv/subcmd"
+)
func TestRename(t *testing.T) {
kind cg subcmd.ColGroup
rename_test.go is part of bundle rename, additionally.
Once I run goimports -d -v rename.go
I can see a message about fixing rename.go, nevertheless it comes on the very starting, and from what I can inform, earlier than goimports has discovered something to export:
% goimports -d -v ./subcmd/rename/rename.go
2024/05/14 04:10:57.587385 fixImports(filename="./subcmd/rename/rename.go"), abs="/Customers/zyoung/develop/go/Private/gocsv/subcmd/rename/rename.go", srcDir="/Customers/zyoung/develop/go/Private/gocsv/subcmd/rename" ...
...
2024/05/14 04:10:58.416946 subcmd candidate 1/1: github.com/zacharysyoung/gocsv/subcmd in /Customers/zyoung/develop/go/Private/gocsv/subcmd
2024/05/14 04:10:58.416955 loading exports in dir /Customers/zyoung/develop/go/Private/gocsv/subcmd (searching for bundle subcmd)
2024/05/14 04:10:58.417430 loaded exports in dir /Customers/zyoung/develop/go/Private/gocsv/subcmd (bundle subcmd): [{Base0Cols func go1.0} {Base1Cols func go1.0} {Bool const go1.0} {ColGroup type go1.0} {CompareBools func go1.0} {FinalizeCols func go1.0} {Infer func go1.0} {InferCols func go1.0} {InferredType type go1.0} {NewTestdataRunner func go1.0} {Number const go1.0} {Runner type go1.0} {String const go1.0} {TestdataRunner type go1.0} {Time const go1.0} {ToBool func go1.0} {ToNumber func go1.0} {ToTime func go1.0} {UnmarshalFunc type go1.0}]
Can anybody see what’s occurring, what I is perhaps doing fallacious? Thanks.
I figured it out. My challenge is in a foul state after manually making an attempt to shift some packages round.
rename.go wants subcmd.ErrNoData, however subcmd doesn’t export that var; it does have errNoData, although. So, must undergo and repair some exports.
1 Like