-
Notifications
You must be signed in to change notification settings - Fork 718
Full JSDoc support in LSP #1702
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
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 |
---|---|---|
|
@@ -2368,10 +2368,11 @@ func (c *Checker) checkJSDocComment(node *ast.Node, location *ast.Node) { | |
func (c *Checker) resolveJSDocMemberName(name *ast.Node, location *ast.Node) *ast.Symbol { | ||
if name != nil && ast.IsEntityName(name) { | ||
meaning := ast.SymbolFlagsType | ast.SymbolFlagsNamespace | ast.SymbolFlagsValue | ||
symbol := c.resolveEntityName(name, meaning, true /*ignoreErrors*/, true /*dontResolveAlias*/, location) | ||
if symbol == nil && ast.IsQualifiedName(name) { | ||
symbol := c.resolveJSDocMemberName(name.AsQualifiedName().Left, location) | ||
if symbol != nil { | ||
if symbol := c.resolveEntityName(name, meaning, true /*ignoreErrors*/, true /*dontResolveAlias*/, location); symbol != nil { | ||
return symbol | ||
} | ||
Comment on lines
+2371
to
+2373
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nitpick] The early return pattern introduced here removes the original variable assignment and changes the control flow. While functionally correct, this creates inconsistency with the original nested if-else structure that was handling the symbol resolution. Consider maintaining the original structure for better code readability and consistency. Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||
if ast.IsQualifiedName(name) { | ||
if symbol := c.resolveJSDocMemberName(name.AsQualifiedName().Left, location); symbol != nil { | ||
var t *Type | ||
if symbol.Flags&ast.SymbolFlagsValue != 0 { | ||
proto := c.getPropertyOfType(c.getTypeOfSymbol(symbol), "prototype") | ||
|
@@ -30203,19 +30204,15 @@ func (c *Checker) getSymbolAtLocation(node *ast.Node, ignoreErrors bool) *ast.Sy | |
return c.getSymbolOfDeclaration(grandParent) | ||
} | ||
|
||
if node.Kind == ast.KindIdentifier { | ||
if ast.IsIdentifier(node) { | ||
if isInRightSideOfImportOrExportAssignment(node) { | ||
return c.getSymbolOfNameOrPropertyAccessExpression(node) | ||
} else if parent.Kind == ast.KindBindingElement && | ||
grandParent.Kind == ast.KindObjectBindingPattern && | ||
node == parent.AsBindingElement().PropertyName { | ||
} else if ast.IsBindingElement(parent) && ast.IsObjectBindingPattern(grandParent) && node == parent.PropertyName() { | ||
typeOfPattern := c.getTypeOfNode(grandParent) | ||
propertyDeclaration := c.getPropertyOfType(typeOfPattern, node.Text()) | ||
|
||
if propertyDeclaration != nil { | ||
if propertyDeclaration := c.getPropertyOfType(typeOfPattern, node.Text()); propertyDeclaration != nil { | ||
return propertyDeclaration | ||
} | ||
} else if ast.IsMetaProperty(parent) && parent.AsMetaProperty().Name() == node { | ||
} else if ast.IsMetaProperty(parent) && parent.Name() == node { | ||
metaProp := parent.AsMetaProperty() | ||
if metaProp.KeywordToken == ast.KindNewKeyword && node.Text() == "target" { | ||
// `target` in `new.target` | ||
|
@@ -30230,6 +30227,14 @@ func (c *Checker) getSymbolAtLocation(node *ast.Node, ignoreErrors bool) *ast.Sy | |
} | ||
// no other meta properties are valid syntax, thus no others should have symbols | ||
return nil | ||
} else if ast.IsJSDocParameterTag(parent) && parent.Name() == node { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it odd to have this one special case here in the checker? I don't think we have any cases like this elsewhere after the reparser change. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We do have a few. We used to have logic in the binder that would bind declaration names in JSDoc nodes, but we don't do that anymore (which is good). The logic also can't be in |
||
if fn := ast.GetNodeAtPosition(ast.GetSourceFileOfNode(node), node.Pos(), false); fn != nil && ast.IsFunctionLike(fn) { | ||
for _, param := range fn.Parameters() { | ||
if param.Name().Text() == node.Text() { | ||
return c.getSymbolOfNode(param) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
@@ -30418,28 +30423,32 @@ func (c *Checker) getSymbolOfNameOrPropertyAccessExpression(name *ast.Node) *ast | |
// Missing entity name. | ||
return nil | ||
} | ||
|
||
if name.Kind == ast.KindIdentifier { | ||
isJSDoc := ast.IsJSDocNameReferenceContext(name) | ||
if ast.IsIdentifier(name) { | ||
jakebailey marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
if ast.IsJsxTagName(name) && isJsxIntrinsicTagName(name) { | ||
symbol := c.getIntrinsicTagSymbol(name.Parent) | ||
return core.IfElse(symbol == c.unknownSymbol, nil, symbol) | ||
} | ||
result := c.resolveEntityName( | ||
name, | ||
ast.SymbolFlagsValue, /*meaning*/ | ||
true, /*ignoreErrors*/ | ||
true, /*dontResolveAlias*/ | ||
nil /*location*/) | ||
meaning := core.IfElse(isJSDoc, ast.SymbolFlagsValue|ast.SymbolFlagsType|ast.SymbolFlagsNamespace, ast.SymbolFlagsValue) | ||
result := c.resolveEntityName(name, meaning, true /*ignoreErrors*/, true /*dontResolveAlias*/, nil /*location*/) | ||
if result == nil && isJSDoc { | ||
if container := ast.FindAncestor(name, ast.IsClassOrInterfaceLike); container != nil { | ||
symbol := c.getSymbolOfDeclaration(container) | ||
// Handle unqualified references to class static members and class or interface instance members | ||
if result = c.getMergedSymbol(c.getSymbol(c.getExportsOfSymbol(symbol), name.Text(), meaning)); result == nil { | ||
result = c.getPropertyOfType(c.getDeclaredTypeOfSymbol(symbol), name.Text()) | ||
} | ||
} | ||
} | ||
return result | ||
} else if ast.IsPrivateIdentifier(name) { | ||
return c.getSymbolForPrivateIdentifierExpression(name) | ||
} else if name.Kind == ast.KindPropertyAccessExpression || name.Kind == ast.KindQualifiedName { | ||
} else if ast.IsPropertyAccessExpression(name) || ast.IsQualifiedName(name) { | ||
links := c.symbolNodeLinks.Get(name) | ||
if links.resolvedSymbol != nil { | ||
return links.resolvedSymbol | ||
} | ||
|
||
if name.Kind == ast.KindPropertyAccessExpression { | ||
if ast.IsPropertyAccessExpression(name) { | ||
c.checkPropertyAccessExpression(name, CheckModeNormal, false /*writeOnly*/) | ||
if links.resolvedSymbol == nil { | ||
links.resolvedSymbol = c.getApplicableIndexSymbol( | ||
|
@@ -30450,7 +30459,9 @@ func (c *Checker) getSymbolOfNameOrPropertyAccessExpression(name *ast.Node) *ast | |
} else { | ||
c.checkQualifiedName(name, CheckModeNormal) | ||
} | ||
|
||
if links.resolvedSymbol == nil && isJSDoc && ast.IsQualifiedName(name) { | ||
return c.resolveJSDocMemberName(name, nil) | ||
} | ||
return links.resolvedSymbol | ||
} | ||
} else if ast.IsEntityName(name) && isTypeReferenceIdentifier(name) { | ||
|
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -191,7 +191,7 @@ func (p *Parser) reparseJSDocSignature(jsSignature *ast.Node, fun *ast.Node, jsD | |||||||||
if jsSignature.Type() != nil && jsSignature.Type().AsJSDocReturnTag().TypeExpression != nil { | ||||||||||
signature.FunctionLikeData().Type = p.factory.DeepCloneReparse(jsSignature.Type().AsJSDocReturnTag().TypeExpression.Type()) | ||||||||||
} | ||||||||||
loc := tag | ||||||||||
loc := jsSignature | ||||||||||
if tag.Kind == ast.KindJSDocOverloadTag { | ||||||||||
loc = tag.AsJSDocOverloadTag().TagName | ||||||||||
Comment on lines
195
to
196
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The variable assignment has changed from
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||||||
} | ||||||||||
|
@@ -213,7 +213,7 @@ func (p *Parser) reparseJSDocTypeLiteral(t *ast.TypeNode) *ast.Node { | |||||||||
if name.Kind == ast.KindQualifiedName { | ||||||||||
name = name.AsQualifiedName().Right | ||||||||||
} | ||||||||||
property := p.factory.NewPropertySignatureDeclaration(nil, name, p.makeQuestionIfOptional(jsprop), nil, nil) | ||||||||||
property := p.factory.NewPropertySignatureDeclaration(nil, p.factory.DeepCloneReparse(name), p.makeQuestionIfOptional(jsprop), nil, nil) | ||||||||||
if jsprop.TypeExpression != nil { | ||||||||||
property.AsPropertySignatureDeclaration().Type = p.reparseJSDocTypeLiteral(jsprop.TypeExpression.Type()) | ||||||||||
} | ||||||||||
|
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.
Is this a replacement for the bidirectional mapping plan we had originally conceived?
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.
Yeah, this is reasonably performant and not used in anything time critical. I haven't really seen a need for anything else.