Skip to content

Commit 3e76cae

Browse files
adonovangopherbot
authored andcommitted
internal/analysisinternal: ValidateFix: more specific errors
These details help us diagnose errors in gopls especially relating to synthezized End() positions beyond EOF. Change-Id: Iff36f5c4e01f2256f2cbf8cc03b27d7b3aa74b11 Reviewed-on: https://go-review.googlesource.com/c/tools/+/651097 Reviewed-by: Robert Findley <[email protected]> Commit-Queue: Alan Donovan <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Auto-Submit: Alan Donovan <[email protected]>
1 parent d2fcd36 commit 3e76cae

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

go/analysis/internal/checker/fix_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func TestReportInvalidDiagnostic(t *testing.T) {
9393
// TextEdit has invalid Pos.
9494
{
9595
"bad Pos",
96-
`analyzer "a" suggests invalid fix .*: missing file info for pos`,
96+
`analyzer "a" suggests invalid fix .*: no token.File for TextEdit.Pos .0.`,
9797
func(pos token.Pos) analysis.Diagnostic {
9898
return analysis.Diagnostic{
9999
Pos: pos,
@@ -110,7 +110,7 @@ func TestReportInvalidDiagnostic(t *testing.T) {
110110
// TextEdit has invalid End.
111111
{
112112
"End < Pos",
113-
`analyzer "a" suggests invalid fix .*: pos .* > end`,
113+
`analyzer "a" suggests invalid fix .*: TextEdit.Pos .* > TextEdit.End .*`,
114114
func(pos token.Pos) analysis.Diagnostic {
115115
return analysis.Diagnostic{
116116
Pos: pos,

internal/analysisinternal/analysis.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -419,18 +419,19 @@ func validateFix(fset *token.FileSet, fix *analysis.SuggestedFix) error {
419419
start := edit.Pos
420420
file := fset.File(start)
421421
if file == nil {
422-
return fmt.Errorf("missing file info for pos (%v)", edit.Pos)
422+
return fmt.Errorf("no token.File for TextEdit.Pos (%v)", edit.Pos)
423423
}
424424
if end := edit.End; end.IsValid() {
425425
if end < start {
426-
return fmt.Errorf("pos (%v) > end (%v)", edit.Pos, edit.End)
426+
return fmt.Errorf("TextEdit.Pos (%v) > TextEdit.End (%v)", edit.Pos, edit.End)
427427
}
428428
endFile := fset.File(end)
429429
if endFile == nil {
430-
return fmt.Errorf("malformed end position %v", end)
430+
return fmt.Errorf("no token.File for TextEdit.End (%v; File(start).FileEnd is %d)", end, file.Base()+file.Size())
431431
}
432432
if endFile != file {
433-
return fmt.Errorf("edit spans files %v and %v", file.Name(), endFile.Name())
433+
return fmt.Errorf("edit #%d spans files (%v and %v)",
434+
i, file.Position(edit.Pos), endFile.Position(edit.End))
434435
}
435436
} else {
436437
edit.End = start // update the SuggestedFix

0 commit comments

Comments
 (0)