-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Avoid caching resolved signatures for language service requests like signature help #52679
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 |
|---|---|---|
|
|
@@ -1636,9 +1636,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { | |
| getResolvedSignature: (node, candidatesOutArray, argumentCount) => | ||
| getResolvedSignatureWorker(node, candidatesOutArray, argumentCount, CheckMode.Normal), | ||
| getResolvedSignatureForStringLiteralCompletions: (call, editingArgument, candidatesOutArray) => | ||
| getResolvedSignatureWorker(call, candidatesOutArray, /*argumentCount*/ undefined, CheckMode.IsForStringLiteralArgumentCompletions, editingArgument), | ||
| runWithInferenceBlockedFromSourceNode(editingArgument, () => getResolvedSignatureWorker(call, candidatesOutArray, /*argumentCount*/ undefined, CheckMode.IsForStringLiteralArgumentCompletions)), | ||
|
||
| getResolvedSignatureForSignatureHelp: (node, candidatesOutArray, argumentCount) => | ||
| getResolvedSignatureWorker(node, candidatesOutArray, argumentCount, CheckMode.IsForSignatureHelp), | ||
| runWithoutResolvedSignatureCaching(node, () => getResolvedSignatureWorker(node, candidatesOutArray, argumentCount, CheckMode.IsForSignatureHelp)), | ||
| getExpandedParameters, | ||
| hasEffectiveRestParameter, | ||
| containsArgumentsReference, | ||
|
|
@@ -1813,36 +1813,43 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { | |
| isTypeParameterPossiblyReferenced, | ||
| }; | ||
|
|
||
| function runWithInferenceBlockedFromSourceNode<T>(node: Node | undefined, fn: () => T): T { | ||
| function runWithoutResolvedSignatureCaching<T>(node: Node | undefined, fn: () => T): T { | ||
| const containingCall = findAncestor(node, isCallLikeExpression); | ||
DanielRosenwasser marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const containingCallResolvedSignature = containingCall && getNodeLinks(containingCall).resolvedSignature; | ||
| if (containingCall) { | ||
| getNodeLinks(containingCall).resolvedSignature = undefined; | ||
| } | ||
| const result = fn(); | ||
| if (containingCall) { | ||
| getNodeLinks(containingCall).resolvedSignature = containingCallResolvedSignature; | ||
| } | ||
| return result; | ||
| } | ||
|
|
||
| function runWithInferenceBlockedFromSourceNode<T>(node: Node | undefined, fn: () => T): T { | ||
| const containingCall = findAncestor(node, isCallLikeExpression); | ||
| if (containingCall) { | ||
| let toMarkSkip = node!; | ||
| do { | ||
| getNodeLinks(toMarkSkip).skipDirectInference = true; | ||
| toMarkSkip = toMarkSkip.parent; | ||
| } while (toMarkSkip && toMarkSkip !== containingCall); | ||
| getNodeLinks(containingCall).resolvedSignature = undefined; | ||
| } | ||
| const result = fn(); | ||
| const result = runWithoutResolvedSignatureCaching(node, fn); | ||
| if (containingCall) { | ||
| let toMarkSkip = node!; | ||
| do { | ||
| getNodeLinks(toMarkSkip).skipDirectInference = undefined; | ||
| toMarkSkip = toMarkSkip.parent; | ||
| } while (toMarkSkip && toMarkSkip !== containingCall); | ||
| getNodeLinks(containingCall).resolvedSignature = containingCallResolvedSignature; | ||
| } | ||
| return result; | ||
| } | ||
|
|
||
| function getResolvedSignatureWorker(nodeIn: CallLikeExpression, candidatesOutArray: Signature[] | undefined, argumentCount: number | undefined, checkMode: CheckMode, editingArgument?: Node): Signature | undefined { | ||
| function getResolvedSignatureWorker(nodeIn: CallLikeExpression, candidatesOutArray: Signature[] | undefined, argumentCount: number | undefined, checkMode: CheckMode): Signature | undefined { | ||
| const node = getParseTreeNode(nodeIn, isCallLikeExpression); | ||
| apparentArgumentCount = argumentCount; | ||
| const res = | ||
| !node ? undefined : | ||
| editingArgument ? runWithInferenceBlockedFromSourceNode(editingArgument, () => getResolvedSignature(node, candidatesOutArray, checkMode)) : | ||
| getResolvedSignature(node, candidatesOutArray, checkMode); | ||
| const res = !node ? undefined : getResolvedSignature(node, candidatesOutArray, checkMode); | ||
| apparentArgumentCount = undefined; | ||
| return res; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| ///<reference path="fourslash.ts"/> | ||
| // @strict: true | ||
| //// | ||
| //// declare function f(x: string, y: number): any; | ||
| //// | ||
| //// /*1*/f(/*2*/)/*3*/ | ||
|
|
||
| goTo.marker("2"); | ||
| verify.signatureHelp({ | ||
| triggerReason: { | ||
| kind: "invoked" | ||
| } | ||
| }) | ||
| edit.insert(`"`) | ||
| edit.insert(`"`) | ||
| verify.signatureHelp({ | ||
| triggerReason: { | ||
| kind: "retrigger" | ||
| } | ||
| }) | ||
| verify.not.codeFixAvailable() // trigger typecheck | ||
| verify.errorExistsBetweenMarkers("1", "3"); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| ///<reference path="fourslash.ts"/> | ||
| // @strict: true | ||
| //// | ||
| //// interface Events { | ||
| //// click: any; | ||
| //// drag: any; | ||
| //// } | ||
| //// | ||
| //// declare function addListener<K extends keyof Events>(type: K, listener: (ev: Events[K]) => any): void; | ||
| //// | ||
| //// /*1*/addListener("/*2*/")/*3*/ | ||
|
|
||
| verify.completions({ marker: ["2"], exact: ["click", "drag"] }); | ||
| verify.errorExistsBetweenMarkers("1", "3"); |
Uh oh!
There was an error while loading. Please reload this page.