Skip to content

Commit 219b7f6

Browse files
author
Stephen Gutekanst
committed
langserver/internal/refs: use per-file best-effort approach
Previously `langserver/internal/refs` would abort on the first error found in a package. After this change, we make a best-effort approach to finding references on a per-file level instead of only at the per-package level at the callsite in `workspace_refs.go`. This is useful because while not all Go packages can be built, e.g. this one that I ran into in the wild which imports a broken-path `ntoolkit/component` package: https://github.com/shadowmint/go-component/blob/master/src/ntoolkit/component/component_fake_component_test.go We can still find useful information from them, e.g. references to `testing.T` above. This also occurs in e.g. this kubernetes staging directory: https://github.com/kubernetes/kubernetes/tree/master/staging So the use cases for this change are real, and there is no real harm in making this change.
1 parent 9a7c3b2 commit 219b7f6

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

langserver/internal/refs/refs.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,19 +67,19 @@ func (c *Config) Refs(emit func(*Ref)) error {
6767
return nil
6868
}
6969

70-
var firstErr error
70+
var errs []string
7171
for _, file := range c.PkgFiles {
7272
ast.Inspect(file, func(n ast.Node) bool {
7373
switch n := n.(type) {
7474
case *ast.ImportSpec:
7575
if err := ref(file, n.Pos(), n.End()); err != nil {
76-
firstErr = err
76+
errs = append(errs, err.Error())
7777
return false
7878
}
7979

8080
case *ast.SelectorExpr:
8181
if err := ref(file, n.Sel.Pos(), n.Sel.End()); err != nil {
82-
firstErr = err
82+
errs = append(errs, err.Error())
8383
return false
8484
}
8585

@@ -101,17 +101,17 @@ func (c *Config) Refs(emit func(*Ref)) error {
101101
// since these fall into an edge case (do not represent
102102
// real errors for us).
103103
if _, ok := err.(*notPackageLevelDef); !ok {
104-
firstErr = err
104+
errs = append(errs, err.Error())
105105
return false
106106
}
107107
}
108108
}
109109
}
110110
return true
111111
})
112-
if firstErr != nil {
113-
return firstErr
114-
}
112+
}
113+
if len(errs) > 0 {
114+
return errors.New(strings.Join(errs, "\n"))
115115
}
116116
return nil
117117
}

0 commit comments

Comments
 (0)