signatureHelp: Factor out 'isSyntacticOwner' function (#25518)
This commit is contained in:
parent
49468e7eb6
commit
1e8a5bf2f1
|
@ -30,14 +30,12 @@ namespace ts.SignatureHelp {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only need to be careful if the user typed a character and signature help wasn't showing.
|
// Only need to be careful if the user typed a character and signature help wasn't showing.
|
||||||
const shouldCarefullyCheckContext = !!triggerReason && triggerReason.kind === "characterTyped";
|
const onlyUseSyntacticOwners = !!triggerReason && triggerReason.kind === "characterTyped";
|
||||||
|
|
||||||
// Bail out quickly in the middle of a string or comment, don't provide signature help unless the user explicitly requested it.
|
// Bail out quickly in the middle of a string or comment, don't provide signature help unless the user explicitly requested it.
|
||||||
if (shouldCarefullyCheckContext) {
|
if (onlyUseSyntacticOwners && (isInString(sourceFile, position, startingToken) || isInComment(sourceFile, position))) {
|
||||||
if (isInString(sourceFile, position, startingToken) || isInComment(sourceFile, position)) {
|
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
const argumentInfo = getContainingArgumentInfo(startingToken, position, sourceFile);
|
const argumentInfo = getContainingArgumentInfo(startingToken, position, sourceFile);
|
||||||
if (!argumentInfo) return undefined;
|
if (!argumentInfo) return undefined;
|
||||||
|
@ -45,7 +43,7 @@ namespace ts.SignatureHelp {
|
||||||
cancellationToken.throwIfCancellationRequested();
|
cancellationToken.throwIfCancellationRequested();
|
||||||
|
|
||||||
// Extra syntactic and semantic filtering of signature help
|
// Extra syntactic and semantic filtering of signature help
|
||||||
const candidateInfo = getCandidateInfo(argumentInfo, typeChecker, sourceFile, startingToken, shouldCarefullyCheckContext);
|
const candidateInfo = getCandidateInfo(argumentInfo, typeChecker, sourceFile, startingToken, onlyUseSyntacticOwners);
|
||||||
cancellationToken.throwIfCancellationRequested();
|
cancellationToken.throwIfCancellationRequested();
|
||||||
|
|
||||||
if (!candidateInfo) {
|
if (!candidateInfo) {
|
||||||
|
@ -66,35 +64,9 @@ namespace ts.SignatureHelp {
|
||||||
|
|
||||||
const { invocation } = argumentInfo;
|
const { invocation } = argumentInfo;
|
||||||
if (invocation.kind === InvocationKind.Call) {
|
if (invocation.kind === InvocationKind.Call) {
|
||||||
if (onlyUseSyntacticOwners) {
|
if (onlyUseSyntacticOwners && !isSyntacticOwner(startingToken, invocation.node, sourceFile)) {
|
||||||
if (isCallOrNewExpression(invocation.node)) {
|
|
||||||
const invocationChildren = invocation.node.getChildren(sourceFile);
|
|
||||||
switch (startingToken.kind) {
|
|
||||||
case SyntaxKind.OpenParenToken:
|
|
||||||
if (!contains(invocationChildren, startingToken)) {
|
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
case SyntaxKind.CommaToken:
|
|
||||||
const containingList = findContainingList(startingToken);
|
|
||||||
if (!containingList || !contains(invocationChildren, findContainingList(startingToken))) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case SyntaxKind.LessThanToken:
|
|
||||||
if (!lessThanFollowsCalledExpression(startingToken, sourceFile, invocation.node.expression)) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const candidates: Signature[] = [];
|
const candidates: Signature[] = [];
|
||||||
const resolvedSignature = checker.getResolvedSignature(invocation.node, candidates, argumentInfo.argumentCount)!; // TODO: GH#18217
|
const resolvedSignature = checker.getResolvedSignature(invocation.node, candidates, argumentInfo.argumentCount)!; // TODO: GH#18217
|
||||||
return candidates.length === 0 ? undefined : { candidates, resolvedSignature };
|
return candidates.length === 0 ? undefined : { candidates, resolvedSignature };
|
||||||
|
@ -111,6 +83,23 @@ namespace ts.SignatureHelp {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isSyntacticOwner(startingToken: Node, node: CallLikeExpression, sourceFile: SourceFile): boolean {
|
||||||
|
if (!isCallOrNewExpression(node)) return false;
|
||||||
|
const invocationChildren = node.getChildren(sourceFile);
|
||||||
|
switch (startingToken.kind) {
|
||||||
|
case SyntaxKind.OpenParenToken:
|
||||||
|
return contains(invocationChildren, startingToken);
|
||||||
|
case SyntaxKind.CommaToken: {
|
||||||
|
const containingList = findContainingList(startingToken);
|
||||||
|
return !!containingList && contains(invocationChildren, containingList);
|
||||||
|
}
|
||||||
|
case SyntaxKind.LessThanToken:
|
||||||
|
return lessThanFollowsCalledExpression(startingToken, sourceFile, node.expression);
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function createJavaScriptSignatureHelpItems(argumentInfo: ArgumentListInfo, program: Program, cancellationToken: CancellationToken): SignatureHelpItems | undefined {
|
function createJavaScriptSignatureHelpItems(argumentInfo: ArgumentListInfo, program: Program, cancellationToken: CancellationToken): SignatureHelpItems | undefined {
|
||||||
// See if we can find some symbol with the call expression name that has call signatures.
|
// See if we can find some symbol with the call expression name that has call signatures.
|
||||||
const expression = getExpressionFromInvocation(argumentInfo.invocation);
|
const expression = getExpressionFromInvocation(argumentInfo.invocation);
|
||||||
|
|
Loading…
Reference in a new issue