Skip to content

Commit e2c5a90

Browse files
authored
Disable signature help on unresolved bare identifiers; add more declaration info on other unresolved calls (microsoft#39352)
* Disable signature help on unresolved bare identifiers; add more declaration info on unresolvedproperty access * Remove stray ts-ignore
1 parent ff1f449 commit e2c5a90

File tree

3 files changed

+41
-4
lines changed

3 files changed

+41
-4
lines changed

src/services/signatureHelp.ts

+13-4
Original file line numberDiff line numberDiff line change
@@ -120,14 +120,22 @@ namespace ts.SignatureHelp {
120120
if (argumentInfo.invocation.kind === InvocationKind.Contextual) return undefined;
121121
// See if we can find some symbol with the call expression name that has call signatures.
122122
const expression = getExpressionFromInvocation(argumentInfo.invocation);
123-
const name = isIdentifier(expression) ? expression.text : isPropertyAccessExpression(expression) ? expression.name.text : undefined;
123+
const name = isPropertyAccessExpression(expression) ? expression.name.text : undefined;
124124
const typeChecker = program.getTypeChecker();
125125
return name === undefined ? undefined : firstDefined(program.getSourceFiles(), sourceFile =>
126126
firstDefined(sourceFile.getNamedDeclarations().get(name), declaration => {
127127
const type = declaration.symbol && typeChecker.getTypeOfSymbolAtLocation(declaration.symbol, declaration);
128128
const callSignatures = type && type.getCallSignatures();
129129
if (callSignatures && callSignatures.length) {
130-
return typeChecker.runWithCancellationToken(cancellationToken, typeChecker => createSignatureHelpItems(callSignatures, callSignatures[0], argumentInfo, sourceFile, typeChecker));
130+
return typeChecker.runWithCancellationToken(
131+
cancellationToken,
132+
typeChecker => createSignatureHelpItems(
133+
callSignatures,
134+
callSignatures[0],
135+
argumentInfo,
136+
sourceFile,
137+
typeChecker,
138+
/*useFullPrefix*/ true));
131139
}
132140
}));
133141
}
@@ -496,10 +504,11 @@ namespace ts.SignatureHelp {
496504
{ isTypeParameterList, argumentCount, argumentsSpan: applicableSpan, invocation, argumentIndex }: ArgumentListInfo,
497505
sourceFile: SourceFile,
498506
typeChecker: TypeChecker,
507+
useFullPrefix?: boolean,
499508
): SignatureHelpItems {
500509
const enclosingDeclaration = getEnclosingDeclarationFromInvocation(invocation);
501-
const callTargetSymbol = invocation.kind === InvocationKind.Contextual ? invocation.symbol : typeChecker.getSymbolAtLocation(getExpressionFromInvocation(invocation));
502-
const callTargetDisplayParts = callTargetSymbol ? symbolToDisplayParts(typeChecker, callTargetSymbol, /*enclosingDeclaration*/ undefined, /*meaning*/ undefined) : emptyArray;
510+
const callTargetSymbol = invocation.kind === InvocationKind.Contextual ? invocation.symbol : (typeChecker.getSymbolAtLocation(getExpressionFromInvocation(invocation)) || useFullPrefix && resolvedSignature.declaration?.symbol);
511+
const callTargetDisplayParts = callTargetSymbol ? symbolToDisplayParts(typeChecker, callTargetSymbol, useFullPrefix ? sourceFile : undefined, /*meaning*/ undefined) : emptyArray;
503512
const items = map(candidates, candidateSignature => getSignatureHelpItem(candidateSignature, callTargetDisplayParts, isTypeParameterList, typeChecker, enclosingDeclaration, sourceFile));
504513

505514
if (argumentIndex !== 0) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
// @allowJs: true
4+
// @checkJs: true
5+
6+
// @Filename: test.js
7+
////log(/**/)
8+
9+
verify.noSignatureHelp("");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
// @allowJs: true
4+
// @checkJs: true
5+
6+
// @Filename: test.js
7+
////foo.filter(/**/)
8+
9+
goTo.marker("");
10+
verify.signatureHelp({
11+
text: "ReadonlyArray.filter<S extends T>(predicate: (value: T, index: number, array: readonly T[]) => value is S, thisArg?: any): S[]",
12+
overloadsCount: 2,
13+
docComment: "Returns the elements of an array that meet the condition specified in a callback function.",
14+
parameterDocComment: "A function that accepts up to three arguments. The filter method calls the predicate function one time for each element in the array.",
15+
tags: [
16+
{ name: "param", text: "predicate A function that accepts up to three arguments. The filter method calls the predicate function one time for each element in the array." },
17+
{ name: "param", text: "thisArg An object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value." }
18+
]
19+
});

0 commit comments

Comments
 (0)