-
Notifications
You must be signed in to change notification settings - Fork 881
Fix error spans for @satisfies
#3212
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2535,6 +2535,20 @@ func GetErrorRangeForNode(sourceFile *ast.SourceFile, node *ast.Node) core.TextR | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pos := SkipTrivia(sourceFile.Text(), node.Pos()) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return GetRangeOfTokenAtPosition(sourceFile, pos) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| case ast.KindSatisfiesExpression: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if node.AsSatisfiesExpression().Type.Flags&ast.NodeFlagsReparsed != 0 { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for current := node.Parent; current != nil; current = current.Parent { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for _, jsDoc := range current.JSDoc(nil) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if tags := jsDoc.AsJSDoc().Tags; tags != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for _, tag := range tags.Nodes { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if ast.IsJSDocSatisfiesTag(tag) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pos := SkipTrivia(sourceFile.Text(), tag.TagName().Pos()) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return GetRangeOfTokenAtPosition(sourceFile, pos) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+2539
to
+2550
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for current := node.Parent; current != nil; current = current.Parent { | |
| for _, jsDoc := range current.JSDoc(nil) { | |
| if tags := jsDoc.AsJSDoc().Tags; tags != nil { | |
| for _, tag := range tags.Nodes { | |
| if ast.IsJSDocSatisfiesTag(tag) { | |
| pos := SkipTrivia(sourceFile.Text(), tag.TagName().Pos()) | |
| return GetRangeOfTokenAtPosition(sourceFile, pos) | |
| } | |
| } | |
| } | |
| } | |
| } | |
| targetType := node.AsSatisfiesExpression().Type | |
| var firstSatisfiesTag *ast.Node | |
| for current := node.Parent; current != nil; current = current.Parent { | |
| for _, jsDoc := range current.JSDoc(nil) { | |
| if tags := jsDoc.AsJSDoc().Tags; tags != nil { | |
| for _, tag := range tags.Nodes { | |
| if ast.IsJSDocSatisfiesTag(tag) { | |
| if firstSatisfiesTag == nil { | |
| firstSatisfiesTag = tag | |
| } | |
| typeExpr := tag.AsJSDocSatisfiesTag().TypeExpression() | |
| if typeExpr != nil { | |
| if typeNode := typeExpr.Type(); typeNode != nil { | |
| if typeNode.Pos() == targetType.Pos() && typeNode.End() == targetType.End() { | |
| pos := SkipTrivia(sourceFile.Text(), tag.TagName().Pos()) | |
| return GetRangeOfTokenAtPosition(sourceFile, pos) | |
| } | |
| } | |
| } | |
| } | |
| } | |
| } | |
| } | |
| } | |
| if firstSatisfiesTag != nil { | |
| pos := SkipTrivia(sourceFile.Text(), firstSatisfiesTag.TagName().Pos()) | |
| return GetRangeOfTokenAtPosition(sourceFile, pos) | |
| } |
Copilot
AI
Mar 24, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
current.JSDoc(nil) triggers a GetSourceFileOfNode walk each time (since file is nil), and this code is already walking up the parent chain. This makes the reparsed-@satisfies path potentially O(depth^2). Consider computing sourceFile := ast.GetSourceFileOfNode(node) once and using current.JSDoc(sourceFile) inside the loop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not super fond of this but I couldn't find a better way to go from a reparsed node to the original JSDoc right now, and I tried a bunch. Am I missing something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure there's anything better, given we are in the scanner package and therefore if such a helper existed in
astnavit would be unavailable.But maybe @gabritto / @andrewbranch have a better thought on their minds.