-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Support a 'recommended' completion entry #20020
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
22123aa
Support a 'recommended' completion entry
4a757e9
Code review
d1abfbe
Merge branch 'master' into completionsRecommended
8918891
Merge branch 'master' into completionsRecommended
52a0b4b
Merge branch 'master' into completionsRecommended
c37427c
Restore duplicate comments
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -254,6 +254,7 @@ namespace ts { | |
return resolveName(location, escapeLeadingUnderscores(name), meaning, /*nameNotFoundMessage*/ undefined, /*nameArg*/ undefined, /*isUse*/ false); | ||
}, | ||
getJsxNamespace: () => unescapeLeadingUnderscores(getJsxNamespace()), | ||
getAccessibleSymbolChain, | ||
}; | ||
|
||
const tupleTypes: GenericType[] = []; | ||
|
@@ -759,10 +760,6 @@ namespace ts { | |
return nodeLinks[nodeId] || (nodeLinks[nodeId] = { flags: 0 }); | ||
} | ||
|
||
function getObjectFlags(type: Type): ObjectFlags { | ||
return type.flags & TypeFlags.Object ? (<ObjectType>type).objectFlags : 0; | ||
} | ||
|
||
function isGlobalSourceFile(node: Node) { | ||
return node.kind === SyntaxKind.SourceFile && !isExternalOrCommonJsModule(<SourceFile>node); | ||
} | ||
|
@@ -10430,20 +10427,6 @@ namespace ts { | |
!hasBaseType(checkClass, getDeclaringClass(p)) : false) ? undefined : checkClass; | ||
} | ||
|
||
// Return true if the given type is the constructor type for an abstract class | ||
function isAbstractConstructorType(type: Type) { | ||
if (getObjectFlags(type) & ObjectFlags.Anonymous) { | ||
const symbol = type.symbol; | ||
if (symbol && symbol.flags & SymbolFlags.Class) { | ||
const declaration = getClassLikeDeclarationOfSymbol(symbol); | ||
if (declaration && hasModifier(declaration, ModifierFlags.Abstract)) { | ||
return true; | ||
} | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
// Return true if the given type is deeply nested. We consider this to be the case when structural type comparisons | ||
// for 5 or more occurrences or instantiations of the type have been recorded on the given stack. It is possible, | ||
// though highly unlikely, for this test to be true in a situation where a chain of instantiations is not infinitely | ||
|
@@ -13744,7 +13727,7 @@ namespace ts { | |
// the contextual type of an initializer expression is the type annotation of the containing declaration, if present. | ||
function getContextualTypeForInitializerExpression(node: Expression): Type { | ||
const declaration = <VariableLikeDeclaration>node.parent; | ||
if (node === declaration.initializer) { | ||
if (node === declaration.initializer || node.kind === SyntaxKind.EqualsToken) { | ||
const typeNode = getEffectiveTypeAnnotationNode(declaration); | ||
if (typeNode) { | ||
return getTypeFromTypeNode(typeNode); | ||
|
@@ -13876,6 +13859,12 @@ namespace ts { | |
case SyntaxKind.AmpersandAmpersandToken: | ||
case SyntaxKind.CommaToken: | ||
return node === right ? getContextualType(binaryExpression) : undefined; | ||
case SyntaxKind.EqualsEqualsEqualsToken: | ||
case SyntaxKind.EqualsEqualsToken: | ||
case SyntaxKind.ExclamationEqualsEqualsToken: | ||
case SyntaxKind.ExclamationEqualsToken: | ||
// For completions after `x === ` | ||
return node === operatorToken ? getTypeOfExpression(binaryExpression.left) : undefined; | ||
default: | ||
return undefined; | ||
} | ||
|
@@ -14091,9 +14080,13 @@ namespace ts { | |
return getContextualTypeForReturnExpression(node); | ||
case SyntaxKind.YieldExpression: | ||
return getContextualTypeForYieldOperand(<YieldExpression>parent); | ||
case SyntaxKind.CallExpression: | ||
case SyntaxKind.NewExpression: | ||
return getContextualTypeForArgument(<CallExpression>parent, node); | ||
if (node.kind === SyntaxKind.NewKeyword) { // for completions after `new ` | ||
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. this one too |
||
return getContextualType(parent as NewExpression); | ||
} | ||
// falls through | ||
case SyntaxKind.CallExpression: | ||
return getContextualTypeForArgument(<CallExpression | NewExpression>parent, node); | ||
case SyntaxKind.TypeAssertionExpression: | ||
case SyntaxKind.AsExpression: | ||
return getTypeFromTypeNode((<AssertionExpression>parent).type); | ||
|
@@ -14127,6 +14120,12 @@ namespace ts { | |
case SyntaxKind.JsxOpeningElement: | ||
case SyntaxKind.JsxSelfClosingElement: | ||
return getAttributesTypeFromJsxOpeningLikeElement(<JsxOpeningLikeElement>parent); | ||
case SyntaxKind.CaseClause: { | ||
if (node.kind === SyntaxKind.CaseKeyword) { // for completions after `case ` | ||
const switchStatement = (parent as CaseClause).parent.parent; | ||
return getTypeOfExpression(switchStatement.expression); | ||
} | ||
} | ||
} | ||
return undefined; | ||
} | ||
|
@@ -22505,10 +22504,6 @@ namespace ts { | |
return getCheckFlags(s) & CheckFlags.Instantiated ? (<TransientSymbol>s).target : s; | ||
} | ||
|
||
function getClassLikeDeclarationOfSymbol(symbol: Symbol): Declaration { | ||
return forEach(symbol.declarations, d => isClassLike(d) ? d : undefined); | ||
} | ||
|
||
function getClassOrInterfaceDeclarationsOfSymbol(symbol: Symbol) { | ||
return filter(symbol.declarations, (d: Declaration): d is ClassDeclaration | InterfaceDeclaration => | ||
d.kind === SyntaxKind.ClassDeclaration || d.kind === SyntaxKind.InterfaceDeclaration); | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 changes what contextual type mean in the language. we should talk about this first