diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index a119fb6f8d70b..785aba5d2576a 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -1831,23 +1831,21 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { typeHasCallOrConstructSignatures, }; - function getCandidateSignaturesForStringLiteralCompletions(call: CallLikeExpression, editingArgument: Node, checkMode = CheckMode.IsForStringLiteralArgumentCompletions) { + function getCandidateSignaturesForStringLiteralCompletions(call: CallLikeExpression, editingArgument: Node) { const candidatesSet = new Set(); const candidates: Signature[] = []; - if (checkMode & CheckMode.IsForStringLiteralArgumentCompletions) { - // first, get candidates when inference is blocked from the source node. - runWithInferenceBlockedFromSourceNode(editingArgument, () => getResolvedSignatureWorker(call, candidates, /*argumentCount*/ undefined, checkMode)); - for (const candidate of candidates) { - candidatesSet.add(candidate); - } - - // reset candidates for second pass - candidates.length = 0; + // first, get candidates when inference is blocked from the source node. + runWithInferenceBlockedFromSourceNode(editingArgument, () => getResolvedSignatureWorker(call, candidates, /*argumentCount*/ undefined, CheckMode.IsForStringLiteralArgumentCompletions)); + for (const candidate of candidates) { + candidatesSet.add(candidate); } + // reset candidates for second pass + candidates.length = 0; + // next, get candidates where the source node is considered for inference. - runWithoutResolvedSignatureCaching(editingArgument, () => getResolvedSignatureWorker(call, candidates, /*argumentCount*/ undefined, checkMode & ~CheckMode.IsForStringLiteralArgumentCompletions)); + runWithoutResolvedSignatureCaching(editingArgument, () => getResolvedSignatureWorker(call, candidates, /*argumentCount*/ undefined, CheckMode.Normal)); for (const candidate of candidates) { candidatesSet.add(candidate); } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 00ca1e79ee999..33fd0ba2a4c28 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1,6 +1,5 @@ import { BaseNodeFactory, - CheckMode, CreateSourceFileOptions, EmitHelperFactory, GetCanonicalFileName, @@ -4992,7 +4991,7 @@ export interface TypeChecker { */ getResolvedSignature(node: CallLikeExpression, candidatesOutArray?: Signature[], argumentCount?: number): Signature | undefined; /** @internal */ getResolvedSignatureForSignatureHelp(node: CallLikeExpression, candidatesOutArray?: Signature[], argumentCount?: number): Signature | undefined; - /** @internal */ getCandidateSignaturesForStringLiteralCompletions(call: CallLikeExpression, editingArgument: Node, checkMode?: CheckMode): Signature[]; + /** @internal */ getCandidateSignaturesForStringLiteralCompletions(call: CallLikeExpression, editingArgument: Node): Signature[]; /** @internal */ getExpandedParameters(sig: Signature): readonly (readonly Symbol[])[]; /** @internal */ hasEffectiveRestParameter(sig: Signature): boolean; /** @internal */ containsArgumentsReference(declaration: SignatureDeclaration): boolean; diff --git a/src/services/stringCompletions.ts b/src/services/stringCompletions.ts index 89486ca2baa7b..3f8bc5fa0861b 100644 --- a/src/services/stringCompletions.ts +++ b/src/services/stringCompletions.ts @@ -7,7 +7,6 @@ import { CaseClause, changeExtension, CharacterCodes, - CheckMode, combinePaths, comparePaths, comparePatternKeys, @@ -406,7 +405,7 @@ function getStringLiteralCompletionEntries(sourceFile: SourceFile, node: StringL // Get string literal completions from specialized signatures of the target // i.e. declare function f(a: 'A'); // f("/*completion position*/") - return argumentInfo && (getStringLiteralCompletionsFromSignature(argumentInfo.invocation, node, argumentInfo, typeChecker) || getStringLiteralCompletionsFromSignature(argumentInfo.invocation, node, argumentInfo, typeChecker, CheckMode.Normal)) || fromContextualType(ContextFlags.None); + return argumentInfo && getStringLiteralCompletionsFromSignature(argumentInfo.invocation, node, argumentInfo, typeChecker) || fromContextualType(ContextFlags.None); } // falls through (is `require("")` or `require(""` or `import("")`) @@ -496,11 +495,11 @@ function getAlreadyUsedTypesInStringLiteralUnion(union: UnionTypeNode, current: return mapDefined(union.types, type => type !== current && isLiteralTypeNode(type) && isStringLiteral(type.literal) ? type.literal.text : undefined); } -function getStringLiteralCompletionsFromSignature(call: CallLikeExpression, arg: StringLiteralLike, argumentInfo: SignatureHelp.ArgumentInfoForCompletions, checker: TypeChecker, checkMode = CheckMode.IsForStringLiteralArgumentCompletions): StringLiteralCompletionsFromTypes | undefined { +function getStringLiteralCompletionsFromSignature(call: CallLikeExpression, arg: StringLiteralLike, argumentInfo: SignatureHelp.ArgumentInfoForCompletions, checker: TypeChecker): StringLiteralCompletionsFromTypes | undefined { let isNewIdentifier = false; const uniques = new Map(); const editingArgument = isJsxOpeningLikeElement(call) ? Debug.checkDefined(findAncestor(arg.parent, isJsxAttribute)) : arg; - const candidates = checker.getCandidateSignaturesForStringLiteralCompletions(call, editingArgument, checkMode); + const candidates = checker.getCandidateSignaturesForStringLiteralCompletions(call, editingArgument); const types = flatMap(candidates, candidate => { if (!signatureHasRestParameter(candidate) && argumentInfo.argumentCount > candidate.parameters.length) return; let type = candidate.getTypeParameterAtPosition(argumentInfo.argumentIndex);