-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Add jsdoc member names: Class#method #44150
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
Conversation
A couple of mixed, nested references don't work yet. The scanner+parser interaction is wrong, the parser consumes one too many spaces, and the checker+services code needs a little cleanup.
1. I decided that correctly parsing a#b.c, an entity name containing an instance reference, is not worth the work. 2. I made the scanner, at least the jsdoc part, emit a # token, and provided a reScanPrivateIdentifier in order to convert #a to # a. 3. I cleaned up the code in the checker. 2. Unrelated: I added a missing space in linkPart display.
@DanielRosenwasser @amcasey I added you because you've had good opinions about usability in the past. Feel free to skip the implementation. @andrewbranch @elibarzilay I heard you like parsing.... |
const entityName = parseEntityName(/* allowReservedWords*/ false); | ||
const p2 = getNodePos(); | ||
let entityName: EntityName | JSDocInstanceReference = parseEntityName(/* allowReservedWords*/ false); | ||
while (token() === SyntaxKind.PrivateIdentifier) { |
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.
while
?
What does Foo#Bar#Baz
parse as?
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.
A left-deep JSDocInstanceReference tree: ((Foo#Bar)#Baz)
src/compiler/parser.ts
Outdated
? parseEntityName(/*allowReservedWords*/ true) | ||
: undefined; | ||
if (name) { | ||
while(token() === SyntaxKind.PrivateIdentifier) { |
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.
Huh, the linter really doesn’t make you do this?
while(token() === SyntaxKind.PrivateIdentifier) { | |
while (token() === SyntaxKind.PrivateIdentifier) { |
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.
Well, it used to. I'm not sure why it didn't complain this time.
src/compiler/scanner.ts
Outdated
@@ -2251,6 +2254,14 @@ namespace ts { | |||
return token; | |||
} | |||
|
|||
function reScanPrivateIdentifier(): SyntaxKind { |
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 know the various reScan
functions don’t all have perfectly comparable behavior, but it seems like the general naming convention is naming it for what you want, not what you currently have: “I currently have token X
, but have reason to believe that could be interpreted as token Y
, so to re-scan X
as Y
, I call reScanY
.”
The naming convention is clearly bad when read like that, but diverging from it is probably worse. I would either conform, naming this reScanHashToken
, or be totally explicit, naming it reScanPrivateIdentifierAsHashToken
.
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.
Nope, I just confused myself. I will reverse it.
This PR adds support for jsdoc instance references of the form
Class#method
. Right now, these are parsed only inside of@see
and@link
tags, but they could probably be allowed other places fairly simply.Additional fixes
@see {A.B.c}
, onlyc
worked. Now all 3 do.@link
quick info for links with unresolved entities. I think I was going to follow up with a general fix that proved too ambitious and forgot the ad-hoc fix until now.Implementation notes
rescanPrivateIdentifier
, which breaks up#id
into two tokens,# id
. This is the main way to get the newHashToken
out of the scanner, butscanJsDocToken
now also returnsHashToken
instead ofUnknown
. My first attempt just reused PrivateIdentifier, but this gave bad spans for find-all-refs. I also think that always scanning#
as part of a private identifier ties that token too tightly to private identifiers, so when#
gets used for other things, it'll probably make sense to invert the scanner's behaviour and provide arescanHash
function when private identifiers are desired.resolveJSDocInstanceReference
is recursive, then delegates toresolveEntityName
whenever it encounters a normal EntityName likeK.x
in, for example,K.x#m
. However, whenK.x
doesn't resolve, it also triesK.prototype.x
. That's because bothK#x
andK.x
are supported inside@see/@link
as synonyms ofK.prototype.x
. This fallback is inefficient, but only happens in services when find-all-refs is requested for@see/@link
, and only performs redundant work for chained entity names likeA.B.c
which should actually beA#B#c
.Fixes #43594