-
Notifications
You must be signed in to change notification settings - Fork 664
Port isInComment
#1397
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
Port isInComment
#1397
Conversation
// `precedingToken` and `tokenAtPosition`. | ||
// It is the caller's responsibility to call `astnav.GetTokenAtPosition` to compute a default `tokenAtPosition`, | ||
// or `astnav.FindPrecedingToken` to compute a default `precedingToken`. | ||
func getRangeOfEnclosingComment( |
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.
This function in Strada used to differentiate between a null
precedingToken
(which would be left undefined) and an undefined
precedingToken
(which would get replaced with a default computed value). We can't easily do this in Go, so, I'm simply not doing anything to the parameters here.
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.
Maybe a separate shouldFindPrecedingToken bool
?
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 kinda dislike the original behavior, and there was only one place which needed it in Strada, so I'd rather leave it like this.
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.
Looks good, but I had a few nits. I am curious to hear what others say about needing an allocator for that method though.
// `precedingToken` and `tokenAtPosition`. | ||
// It is the caller's responsibility to call `astnav.GetTokenAtPosition` to compute a default `tokenAtPosition`, | ||
// or `astnav.FindPrecedingToken` to compute a default `precedingToken`. | ||
func getRangeOfEnclosingComment( |
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.
Maybe a separate shouldFindPrecedingToken bool
?
internal/ls/format.go
Outdated
tokenAtPosition *ast.Node, | ||
) *ast.CommentRange { | ||
jsdoc := ast.FindAncestor(tokenAtPosition, func(n *ast.Node) bool { | ||
return n.Kind == ast.KindJSDoc |
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.
We're probably missing an IsJSDoc
method, which you could just pass here as (*ast.Node).IsJSDoc`
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 could have sworn we had that already...
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 thought we could be avoiding adding it on purpose, to avoid confusion with isJSDocNode
, but I'll add it.
if node.Kind == ast.KindJsxText { | ||
return nil | ||
} | ||
return scanner.GetLeadingCommentRanges(&ast.NodeFactory{}, file.Text(), node.Pos()) |
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.
It's so weird that this needs a factory because we only ever really need to look at a single comment range at a time.
@@ -11,7 +11,7 @@ import ( | |||
|
|||
func TestCompletionsJSDocNoCrash3(t *testing.T) { | |||
t.Parallel() | |||
|
|||
t.Skip() |
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.
do we have an easy way to eyeball these Skip
tests for the future? Do we just assume every Skip
in fourslash is a bug?
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.
Some are bugs, some are missing features, e.g. JSDoc tests. The way to find out why they fail is to re-generate the tests without Skip
and look at the error messages.
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 just realized the comment range methods don't actually allocate and just return values - so it's even weirder that they need a factory! But I feel better about it because it's not just allocating slabs of memory needlessly.
Co-authored-by: Daniel Rosenwasser <[email protected]>
Co-authored-by: Daniel Rosenwasser <[email protected]>
Hopefully this will be the last reapproval needed. 🙁 |
Port
isInComment
/getRangeOfEnclosingComment
.This fixes some completion tests, but some tests now fail because JSDoc completions are unimplemented, and we always return
nil
for completions in a comment position.