Skip to content

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
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 16 additions & 21 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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[] = [];
Expand Down Expand Up @@ -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();
}
Copy link
Preview

Copilot AI Aug 3, 2025

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.

Suggested change
}
function getSymbolLinks(symbol: Symbol): SymbolLinks {
if (symbol.flags & SymbolFlags.Transient) return (symbol as TransientSymbol).links;
const id = getSymbolId(symbol);
if (shouldUseSeparateSymbolLinksForSymbol(symbol, sourceFileWithoutResolvedSignatureCaching)) {
symbolLinksWithoutResolvedSignatureCaching ??= [];
return symbolLinksWithoutResolvedSignatureCaching[id] ??= new SymbolLinks();
}
return symbolLinks[id] ??= new SymbolLinks();
}
function shouldUseSeparateSymbolLinksForSymbol(symbol: Symbol, sourceFileWithoutResolvedSignatureCaching: SourceFile | undefined): boolean {
return !!(sourceFileWithoutResolvedSignatureCaching &&
symbol.valueDeclaration &&
(isFunctionExpressionOrArrowFunction(symbol.valueDeclaration) || tryGetRootParameterDeclaration(symbol.valueDeclaration)) &&
getSourceFileOfNode(symbol.valueDeclaration) === sourceFileWithoutResolvedSignatureCaching);
}

Copilot uses AI. Check for mistakes.


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)();
}

Copy link
Preview

Copilot AI Aug 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This condition is also complex and nearly identical to the one in getSymbolLinks. Consider extracting both conditions into shared helper functions to reduce duplication and improve maintainability.

Copilot uses AI. Check for mistakes.

function getSymbol(symbols: SymbolTable, name: __String, meaning: SymbolFlags): Symbol | undefined {
Expand Down
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();
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();
Loading