-
Notifications
You must be signed in to change notification settings - Fork 13k
Fixed more ghost errors after LSP requests caching wrong contextual and parameter types #62184
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
Open
Andarist
wants to merge
1
commit into
microsoft:main
Choose a base branch
from
Andarist:fix/ignore-cached-links-in-whole-source-files-during-lsp
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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 |
---|---|---|
|
@@ -1971,27 +1971,11 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { | |
function runWithoutResolvedSignatureCaching<T>(node: Node | undefined, fn: () => T): T { | ||
node = findAncestor(node, isCallLikeOrFunctionLikeExpression); | ||
if (node) { | ||
const cachedResolvedSignatures = []; | ||
const cachedTypes = []; | ||
while (node) { | ||
const nodeLinks = getNodeLinks(node); | ||
cachedResolvedSignatures.push([nodeLinks, nodeLinks.resolvedSignature] as const); | ||
nodeLinks.resolvedSignature = undefined; | ||
if (isFunctionExpressionOrArrowFunction(node)) { | ||
const symbolLinks = getSymbolLinks(getSymbolOfDeclaration(node)); | ||
const type = symbolLinks.type; | ||
cachedTypes.push([symbolLinks, type] as const); | ||
symbolLinks.type = undefined; | ||
} | ||
node = findAncestor(node.parent, isCallLikeOrFunctionLikeExpression); | ||
} | ||
sourceFileWithoutResolvedSignatureCaching = getSourceFileOfNode(node); | ||
const result = fn(); | ||
for (const [nodeLinks, resolvedSignature] of cachedResolvedSignatures) { | ||
nodeLinks.resolvedSignature = resolvedSignature; | ||
} | ||
for (const [symbolLinks, type] of cachedTypes) { | ||
symbolLinks.type = type; | ||
} | ||
sourceFileWithoutResolvedSignatureCaching = undefined; | ||
symbolLinksWithoutResolvedSignatureCaching = undefined; | ||
nodeLinksWithoutResolvedSignatureCaching = undefined; | ||
return result; | ||
} | ||
return fn(); | ||
|
@@ -2342,7 +2326,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { | |
var maximumSuggestionCount = 10; | ||
var mergedSymbols: Symbol[] = []; | ||
var symbolLinks: SymbolLinks[] = []; | ||
var symbolLinksWithoutResolvedSignatureCaching: SymbolLinks[] | undefined; | ||
var nodeLinks: NodeLinks[] = []; | ||
var nodeLinksWithoutResolvedSignatureCaching: NodeLinks[] | undefined; | ||
var sourceFileWithoutResolvedSignatureCaching: SourceFile | undefined; | ||
var flowLoopCaches: Map<string, Type>[] = []; | ||
var flowLoopNodes: FlowNode[] = []; | ||
var flowLoopKeys: string[] = []; | ||
|
@@ -2917,12 +2904,20 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { | |
function getSymbolLinks(symbol: Symbol): SymbolLinks { | ||
if (symbol.flags & SymbolFlags.Transient) return (symbol as TransientSymbol).links; | ||
const id = getSymbolId(symbol); | ||
if (sourceFileWithoutResolvedSignatureCaching && symbol.valueDeclaration && (isFunctionExpressionOrArrowFunction(symbol.valueDeclaration) || tryGetRootParameterDeclaration(symbol.valueDeclaration)) && getSourceFileOfNode(symbol.valueDeclaration) === sourceFileWithoutResolvedSignatureCaching) { | ||
symbolLinksWithoutResolvedSignatureCaching ??= []; | ||
return symbolLinksWithoutResolvedSignatureCaching[id] ??= new SymbolLinks(); | ||
} | ||
return symbolLinks[id] ??= new SymbolLinks(); | ||
} | ||
|
||
function getNodeLinks(node: Node): NodeLinks { | ||
const nodeId = getNodeId(node); | ||
return nodeLinks[nodeId] || (nodeLinks[nodeId] = new (NodeLinks as any)()); | ||
if (sourceFileWithoutResolvedSignatureCaching && (isCallLikeOrFunctionLikeExpression(node) || tryGetRootParameterDeclaration(node)) && getSourceFileOfNode(node) === sourceFileWithoutResolvedSignatureCaching) { | ||
nodeLinksWithoutResolvedSignatureCaching ??= []; | ||
return nodeLinksWithoutResolvedSignatureCaching[nodeId] ??= new (NodeLinks as any)(); | ||
} | ||
return nodeLinks[nodeId] ??= new (NodeLinks as any)(); | ||
} | ||
|
||
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 condition is also complex and nearly identical to the one in Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||
function getSymbol(symbols: SymbolTable, name: __String, meaning: SymbolFlags): Symbol | undefined { | ||
|
32 changes: 32 additions & 0 deletions
32
tests/cases/fourslash/noErrorsAfterCompletionsRequestWithinGenericFunction4.ts
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/// <reference path="fourslash.ts" /> | ||
|
||
// @strict: true | ||
// @target: esnext | ||
// @lib: esnext | ||
|
||
//// type ObjectFromEntries<T> = T extends readonly [ | ||
//// infer Key extends string | number | symbol, | ||
//// infer Value, | ||
//// ][] | ||
//// ? { [key in Key]: Value } | ||
//// : never; | ||
//// | ||
//// type KeyValuePairs<T> = { | ||
//// [K in keyof T]: [K, T[K]]; | ||
//// }[keyof T]; | ||
//// | ||
//// declare function mapObjectEntries< | ||
//// const T extends object, | ||
//// const TMapped extends [string | number | symbol, unknown], | ||
//// >( | ||
//// obj: T, | ||
//// mapper: ([a, b]: KeyValuePairs<T>) => TMapped, | ||
//// ): ObjectFromEntries<TMapped[]>; | ||
//// | ||
//// mapObjectEntries({ a: 1, b: 2 }, ([x, y]) => ["a/*1*/", y]); | ||
|
||
verify.completions({ | ||
marker: "1", | ||
exact: ["a"], | ||
}); | ||
verify.noErrors(); |
118 changes: 118 additions & 0 deletions
118
tests/cases/fourslash/noErrorsAfterSignatureHelpRequestWithinGenericFunction1.ts
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 |
---|---|---|
@@ -0,0 +1,118 @@ | ||
/// <reference path="fourslash.ts" /> | ||
|
||
// @strict: true | ||
// @target: esnext | ||
// @lib: esnext | ||
|
||
//// export interface Pipeable { | ||
//// pipe<A, B = never>(this: A, ab: (_: A) => B): B; | ||
//// } | ||
//// | ||
//// type Covariant<A> = (_: never) => A; | ||
//// | ||
//// interface VarianceStruct<out A, out E, out R> { | ||
//// readonly _V: string; | ||
//// readonly _A: Covariant<A>; | ||
//// readonly _E: Covariant<E>; | ||
//// readonly _R: Covariant<R>; | ||
//// } | ||
//// | ||
//// declare const EffectTypeId: unique symbol; | ||
//// | ||
//// interface Variance<out A, out E, out R> { | ||
//// readonly [EffectTypeId]: VarianceStruct<A, E, R>; | ||
//// } | ||
//// | ||
//// interface Effect<out A, out E = never, out R = never> | ||
//// extends Variance<A, E, R>, | ||
//// Pipeable {} | ||
//// | ||
//// interface Class<Fields> extends Pipeable { | ||
//// new (): Fields; | ||
//// } | ||
//// | ||
//// interface TaggedErrorClass<Tag extends string, Fields> extends Class<Fields> { | ||
//// readonly _tag: Tag; | ||
//// } | ||
//// | ||
//// declare const TaggedError: (identifier?: string) => < | ||
//// Tag extends string, | ||
//// Fields | ||
//// >( | ||
//// tag: Tag, | ||
//// fieldsOr: Fields | ||
//// ) => TaggedErrorClass< | ||
//// Tag, | ||
//// { | ||
//// readonly _tag: Tag; | ||
//// } | ||
//// >; | ||
//// | ||
//// declare const log: ( | ||
//// ...message: ReadonlyArray<any> | ||
//// ) => Effect<void, never, never>; | ||
//// | ||
//// export const categoriesKey = "@effect/error/categories"; | ||
//// | ||
//// export declare const withCategory: <Categories extends Array<PropertyKey>>( | ||
//// ...categories: Categories | ||
//// ) => <Args extends Array<any>, Ret, C extends { new (...args: Args): Ret }>( | ||
//// C: C | ||
//// ) => C & { | ||
//// new (...args: Args): Ret & { | ||
//// [categoriesKey]: { [Cat in Categories[number]]: true }; | ||
//// }; | ||
//// }; | ||
//// | ||
//// export type AllKeys<E> = E extends { [categoriesKey]: infer Q } | ||
//// ? keyof Q | ||
//// : never; | ||
//// export type ExtractAll<E, Cats extends PropertyKey> = Cats extends any | ||
//// ? Extract<E, { [categoriesKey]: { [K in Cats]: any } }> | ||
//// : never; | ||
//// | ||
//// export declare const catchCategory: < | ||
//// E, | ||
//// const Categories extends Array<AllKeys<E>>, | ||
//// A2, | ||
//// E2, | ||
//// R2 | ||
//// >( | ||
//// ...args: [ | ||
//// ...Categories, | ||
//// f: (err: ExtractAll<E, Categories[number]>) => Effect<A2, E2, R2> | ||
//// ] | ||
//// ) => <A, R>( | ||
//// effect: Effect<A, E, R> | ||
//// ) => Effect<A | A2, E2 | Exclude<E, ExtractAll<E, Categories[number]>>, R | R2>; | ||
//// | ||
//// class FooError extends TaggedError()("FooError", {}).pipe( | ||
//// withCategory("domain") | ||
//// ) {} | ||
//// | ||
//// class BarError extends TaggedError()("BarError", {}).pipe( | ||
//// withCategory("system", "domain") | ||
//// ) {} | ||
//// | ||
//// class BazError extends TaggedError()("BazError", {}).pipe( | ||
//// withCategory("system") | ||
//// ) {} | ||
//// | ||
//// declare const baz: ( | ||
//// x: number | ||
//// ) => Effect<never, FooError | BarError | BazError, never>; | ||
//// | ||
//// export const program = baz(1).pipe(catchCategory("domain",/*1*/ (_) => log(_._tag))); | ||
|
||
verify.noErrors(); | ||
goTo.marker("1"); | ||
edit.insert(","); | ||
verify.signatureHelpPresentForTriggerReason({ | ||
kind: "characterTyped", | ||
triggerCharacter: ",", | ||
}); | ||
edit.backspace(1); | ||
verify.signatureHelpPresentForTriggerReason({ | ||
kind: "retrigger", | ||
}); | ||
verify.noErrors(); |
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 condition is complex and difficult to read. Consider extracting it into a well-named helper function like
shouldUseSeparateSymbolLinks
to improve readability and maintainability.Copilot uses AI. Check for mistakes.