@@ -30,7 +30,7 @@ func Format(ctx context.Context, f GoFile, rng span.Range) ([]TextEdit, error) {
30
30
return nil , err
31
31
}
32
32
pkg := f .GetPackage (ctx )
33
- if hasListErrors (pkg .GetErrors ()) || hasParseErrors (pkg . GetErrors ()) {
33
+ if hasListErrors (pkg .GetErrors ()) || hasParseErrors (pkg , f . URI ()) {
34
34
// Even if this package has list or parse errors, this file may not
35
35
// have any parse errors and can still be formatted. Using format.Node
36
36
// on an ast with errors may result in code being added or removed.
@@ -104,7 +104,6 @@ func Imports(ctx context.Context, view View, f GoFile, rng span.Range) ([]TextEd
104
104
if err != nil {
105
105
return nil , err
106
106
}
107
-
108
107
return computeTextEdits (ctx , f , string (formatted )), nil
109
108
}
110
109
@@ -174,9 +173,11 @@ func AllImportsFixes(ctx context.Context, view View, f GoFile, rng span.Range) (
174
173
return edits , editsPerFix , nil
175
174
}
176
175
177
- func hasParseErrors (errors []packages.Error ) bool {
178
- for _ , err := range errors {
179
- if err .Kind == packages .ParseError {
176
+ // hasParseErrors returns true if the given file has parse errors.
177
+ func hasParseErrors (pkg Package , uri span.URI ) bool {
178
+ for _ , err := range pkg .GetErrors () {
179
+ spn := packagesErrorSpan (err )
180
+ if spn .URI () == uri && err .Kind == packages .ParseError {
180
181
return true
181
182
}
182
183
}
0 commit comments