-
Notifications
You must be signed in to change notification settings - Fork 17.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
go/ast: record start and end of file in File.FileStart, File.FileEnd #53202
Comments
@adonovan Thanks for reporting. Do you think this API addition needs to go through the proposal process or it small enough to be a normal issue with a FeatureRequest label? |
No, I don't think it needs the proposal process as the field addition is harmless. The question for @griesemer is whether any behavior change to File.Pos/End is acceptable. The patch below caused some gopls tests to fail, for example.
|
I agree that this is harmless, but new public API should always go through the proposal process. |
This proposal has been added to the active column of the proposals project |
I don't think we can change the behavior of (values returned by) I'm ok with adding two new fields ( |
It sounds like the answer is to add two fields to ast.File - Start and EOF, or else FileStart and FileEnd - but not change the results of Pos and End. Both @adonovan and @griesemer will be away off and on for a while so let's put this on hold. |
Placed on hold. |
Ok, let's leave Pos/End as they are. |
CL implementing proposed changes: https://go-review.googlesource.com/c/go/+/427955 |
Change https://go.dev/cl/427955 mentions this issue: |
Taking off hold. It's a little surprising that End() and EndPos are different values: the names don't make clear which is which (both are Pos). Maybe File.FileStart and File.FileEnd? It's a bit repetitive but it at least tells a bit more. |
This proposal has been added to the active column of the proposals project |
Retitled for the fields being FileStart and FileEnd. People seem happy with that. |
Based on the discussion above, this proposal seems like a likely accept. |
No change in consensus, so accepted. 🎉 |
This change causes the parser to record the positions of the first and last character in the file in new ast.File fields FileStart and FileEnd. The behavior of the existing Pos() and End() methods, which record the span of declarations, must remain unchanged for compatibility. Fixes golang/go#53202 Change-Id: I250b19e69f41e3590292c3fe6dea1943ec98f629 Reviewed-on: https://go-review.googlesource.com/c/go/+/427955 TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Robert Griesemer <[email protected]> Run-TryBot: Alan Donovan <[email protected]> Auto-Submit: Alan Donovan <[email protected]> Reviewed-by: Robert Findley <[email protected]>
The Pos/End methods on ast.Node are supposed to report the extent of the syntax node, but ast.File has always been an exception: its Pos reports the position of the start of the Package token, which is typically not the start of the file, since the package declaration is usually preceded by one or more of a copyright header comment, a build tag comment, and a package doc comment, all of which are subjects of interest to developer tools.
I propose that ast.File be augmented with a new field,
Start token.Pos
, and that the parser set this field. Furthermore I propose that(*File).Pos()
returnf.Start
instead off.Package
. This change is slightly higher risk since it may break workarounds for the bug, but it is a bug nonetheless.See https://cs.opensource.google/go/x/tools/+/master:go/ast/astutil/enclosing.go;l=57-61 for an example of the nuisance.
The text was updated successfully, but these errors were encountered: