Skip to content

Fixed more ghost errors after LSP requests caching wrong contextual and parameter types#62184

Closed
Andarist wants to merge 5 commits intomicrosoft:mainfrom
Andarist:fix/ignore-cached-links-in-whole-source-files-during-lsp
Closed

Fixed more ghost errors after LSP requests caching wrong contextual and parameter types#62184
Andarist wants to merge 5 commits intomicrosoft:mainfrom
Andarist:fix/ignore-cached-links-in-whole-source-files-during-lsp

Conversation

@Andarist
Copy link
Copy Markdown
Contributor

@Andarist Andarist commented Aug 3, 2025

fixes #58351
fixes #62183
supersedes #58378

It's not enough to ignore cached types/signatures on the ancestry path of the location node of the LSP request. All nodes under that ancestry path can potentially cache wrong types and those types should not be carried over to regular checking scenarios.

This PR chooses a simple solution of ignoring node/symbol links on certain node kinds within the source file of the location node. It might ignore more caches than it has to but the implementation stays fairly straighforward thanks to that.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes ghost errors that occur after LSP requests (like signature help and completions) cache wrong contextual and parameter types. The fix ensures that cached types/signatures are not incorrectly carried over from LSP requests to regular type checking scenarios.

  • Replaces complex ancestry-based cache invalidation with simpler source file-based approach
  • Introduces separate cache arrays for nodes/symbols during LSP requests to avoid contaminating regular caches
  • Adds comprehensive test cases to verify the fix works for both signature help and completion scenarios

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
src/compiler/checker.ts Implements the core fix by using separate cache arrays for LSP requests and checking node types within the source file
tests/cases/fourslash/noErrorsAfterSignatureHelpRequestWithinGenericFunction1.ts Test case verifying no errors after signature help requests in complex generic scenarios
tests/cases/fourslash/noErrorsAfterCompletionsRequestWithinGenericFunction4.ts Test case verifying no errors after completion requests in generic function contexts

return symbolLinksWithoutResolvedSignatureCaching[id] ??= new SymbolLinks();
}
return symbolLinks[id] ??= new SymbolLinks();
}
Copy link

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.
}
return nodeLinks[nodeId] ??= new (NodeLinks as any)();
}

Copy link

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.
@Andarist
Copy link
Copy Markdown
Contributor Author

@jakebailey could you build a playground here?

@jakebailey
Copy link
Copy Markdown
Member

@typescript-bot pack this

@typescript-bot
Copy link
Copy Markdown
Collaborator

typescript-bot commented Aug 16, 2025

Starting jobs; this comment will be updated as builds start and complete.

Command Status Results
pack this ✅ Started ✅ Results

@typescript-bot
Copy link
Copy Markdown
Collaborator

typescript-bot commented Aug 16, 2025

Hey @jakebailey, I've packed this into an installable tgz. You can install it for testing by referencing it in your package.json like so:

{
    "devDependencies": {
        "typescript": "https://typescript.visualstudio.com/cf7ac146-d525-443c-b23c-0d58337efebc/_apis/build/builds/165902/artifacts?artifactName=tgz&fileId=8FE667DC2F0F93798F7AB64A0FC729B1860B4F7B98EF9536272DEF3DE523ED4D02&fileName=/typescript-6.0.0-insiders.20250816.tgz"
    }
}

and then running npm install.


There is also a playground for this build and an npm module you can use via "typescript": "npm:@typescript-deploys/pr-build@6.0.0-pr-62184-3".;

@typescript-bot typescript-bot added the For Backlog Bug PRs that fix a backlog bug label Aug 18, 2025
@jakebailey
Copy link
Copy Markdown
Member

I don't know if this is going to be portable to the new codebase; over there SymbolLinks has been split apart into 5 different maps and I don't know how we're going to replicate this sort of "save and restore" mechanism without pain...

@github-project-automation github-project-automation bot moved this from Not started to Done in PR Backlog Mar 24, 2026
@typescript-bot
Copy link
Copy Markdown
Collaborator

With 6.0 out as the final release vehicle for this codebase, we're closing all PRs that don't fit the merge criteria for post-6.0 patches. If you think this was a mistake and this PR fits the post-6.0 patch criteria, please post to the 6.0 iteration issue with details (specifically, which PR and which patch criteria it satisfies).

Next steps for PRs:

  • For crash bugfixes or language service improvements, PRs are currently accepted at the typescript-go repo
  • Changes to type system behavior should wait until after 7.0, at which point mainline TypeScript development will resume in this repository with the Go codebase
  • Library file updates (lib.d.ts etc) continue to live in this repo or the DOM Generator repo as appropriate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

For Backlog Bug PRs that fix a backlog bug

Projects

Status: Done

5 participants