Skip to content

Commit 90d7435

Browse files
committed
go/expect: account for the offset from the file.base for modfiles
Since parsing modfiles does not give us positions relative to the fileset, we need to account for this by adding the file's offset within the fileset to the positions of the markers within the file. Change-Id: I826cec05cd77d37900d32bce2fb6e5edcbfea936 Reviewed-on: https://go-review.googlesource.com/c/tools/+/217341 Run-TryBot: Rohan Challa <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Rebecca Stambler <[email protected]>
1 parent 6682176 commit 90d7435

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

go/expect/extract.go

+12-2
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,18 @@ func Parse(fset *token.FileSet, filename string, content []byte) ([]*Note, error
5252
if err != nil {
5353
return nil, err
5454
}
55-
fset.AddFile(filename, -1, len(content)).SetLinesForContent(content)
56-
return extractMod(fset, file)
55+
f := fset.AddFile(filename, -1, len(content))
56+
f.SetLinesForContent(content)
57+
notes, err := extractMod(fset, file)
58+
if err != nil {
59+
return nil, err
60+
}
61+
// Since modfile.Parse does not return an *ast, we need to add the offset
62+
// within the file's contents to the file's base relative to the fileset.
63+
for _, note := range notes {
64+
note.Pos += token.Pos(f.Base())
65+
}
66+
return notes, nil
5767
}
5868
return nil, nil
5969
}

0 commit comments

Comments
 (0)