Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Oct 9, 2025

Fixes a panic that occurred during completion requests when the language service tried to rehydrate cached export information but couldn't find the symbol or module anymore.

Issue

The language service was panicking with errors like:

panic handling request textDocument/completion Could not find symbol 'sourceMapsEnabled' by key 'sourceMapsEnabled' in module "/home/jabaile/.cache/typescript/7.0/node_modules/@types/graceful-fs/index"

This happened when:

  • Cached export info referenced a symbol or module that was no longer available
  • Module resolution changed (e.g., due to null export conditions in package.json)
  • Symbols were removed or renamed in a module

Solution

Changed rehydrateCachedInfo to return (*SymbolExportInfo, bool) instead of panicking when symbols or modules cannot be found. Updated callers to use core.MapFiltered to gracefully skip entries that can't be rehydrated, allowing completions to continue with the remaining valid entries.

Changes

  • Modified exportInfoMap.rehydrateCachedInfo to return a success boolean
  • Replaced two panic() calls with graceful return nil, false error handling
  • Updated get() and search() methods to handle rehydration failures
  • Added regression test TestCompletionNullExportCondition

The fix maintains robustness by handling transient cache state gracefully rather than crashing the language service.

Original prompt

This section details on the original issue you should resolve

<issue_title>textDocument/completion Could not find symbol</issue_title>
<issue_description>This panicked while I was typing out a new test case.


panic handling request textDocument/completion Could not find symbol 'sourceMapsEnabled' by key 'sourceMapsEnabled' in module "/home/jabaile/.cache/typescript/7.0/node_modules/@types/graceful-fs/index" goroutine 2147 [running]:
runtime/debug.Stack()
	runtime/debug/stack.go:26 +0x5e
github.com/microsoft/typescript-go/internal/lsp.(*Server).recover(0xc0000f8dc0, 0xc00d1abd70)
	github.com/microsoft/typescript-go/internal/lsp/server.go:532 +0x58
panic({0xae6b60?, 0xc00f93e140?})
	runtime/panic.go:783 +0x132
github.com/microsoft/typescript-go/internal/ls.(*exportInfoMap).rehydrateCachedInfo(0xc000329090, 0xc0015c2c08, {0x1, {0xc006a77e4c, 0x11}, {0xc006a77e4c, 0x11}, {0x0, 0x0}, {0xc00027e161, ...}, ...})
	github.com/microsoft/typescript-go/internal/ls/autoimports.go:302 +0x494
github.com/microsoft/typescript-go/internal/ls.(*exportInfoMap).search.func1(...)
	github.com/microsoft/typescript-go/internal/ls/autoimports.go:231
github.com/microsoft/typescript-go/internal/core.Map[...](...)
	github.com/microsoft/typescript-go/internal/core/core.go:57
github.com/microsoft/typescript-go/internal/ls.(*exportInfoMap).search(0xc000329090, 0xc0015c2c08, {0xc0002401e7?, 0x47769f?}, 0x0, 0xc0003291f8, 0xc000329338)
	github.com/microsoft/typescript-go/internal/ls/autoimports.go:230 +0x3d4
github.com/microsoft/typescript-go/internal/ls.(*LanguageService).searchExportInfosForCompletions(0xc00e564de0, {0xe66270, 0xc0094bb9f0}, 0xc0015c2c08, 0xc00946b608, 0xc00e604090, 0x0, 0x0, 0x0, {0xe885c8, ...}, ...)
	github.com/microsoft/typescript-go/internal/ls/autoimportsexportinfo.go:172 +0x3da
github.com/microsoft/typescript-go/internal/ls.(*LanguageService).getCompletionData.func9()
	github.com/microsoft/typescript-go/internal/ls/completions.go:1269 +0x26c
github.com/microsoft/typescript-go/internal/ls.(*LanguageService).getCompletionData.func17()
	github.com/microsoft/typescript-go/internal/ls/completions.go:1685 +0x5f6
github.com/microsoft/typescript-go/internal/ls.(*LanguageService).getCompletionData.func18(...)
	github.com/microsoft/typescript-go/internal/ls/completions.go:1712
github.com/microsoft/typescript-go/internal/ls.(*LanguageService).getCompletionData(0xc00e564de0, {0xe66270, 0xc0094bb9f0}, 0xc0015c2c08, 0xc00946b608, 0x1, 0xc00e604090)
	github.com/microsoft/typescript-go/internal/ls/completions.go:1740 +0x1ee2
github.com/microsoft/typescript-go/internal/ls.(*LanguageService).getCompletionsAtPosition(0xc00e564de0, {0xe66270, 0xc0094bb9f0}, 0xc00946b608, 0x1, 0x0, 0xc00e604090, 0xc00026d2c0)
	github.com/microsoft/typescript-go/internal/ls/completions.go:397 +0x2dd
github.com/microsoft/typescript-go/internal/ls.(*LanguageService).ProvideCompletion(0xc00e564de0, {0xe66270, 0xc0094bb9f0}, {0xc00b59bda0?, 0x1?}, {0x1?, 0x0?}, 0xc00d141210, 0xc00026d2c0, 0xc00e604090)
	github.com/microsoft/typescript-go/internal/ls/completions.go:48 +0xe7
github.com/microsoft/typescript-go/internal/lsp.(*Server).handleCompletion(0xc0003581c0?, {0xe66270, 0xc0094bb9f0}, 0xc00e564de0, 0xc00d1abd40)
	github.com/microsoft/typescript-go/internal/lsp/server.go:754 +0xff
github.com/microsoft/typescript-go/internal/lsp.init.func1.registerLanguageServiceDocumentRequestHandler[...].15({0xe66270, 0xc0094bb9f0}, 0xc00d1abd70)
	github.com/microsoft/typescript-go/internal/lsp/server.go:518 +0x130
github.com/microsoft/typescript-go/internal/lsp.(*Server).handleRequestOrNotification(0xc0000f8dc0, {0xe66270, 0xc0094bb9f0}, 0xc00d1abd70)
	github.com/microsoft/typescript-go/internal/lsp/server.go:424 +0x10d
github.com/microsoft/typescript-go/internal/lsp.(*Server).dispatchLoop.func1()
	github.com/microsoft/typescript-go/internal/lsp/server.go:329 +0x3a
created by github.com/microsoft/typescript-go/internal/lsp.(*Server).dispatchLoop in goroutine 35
	github.com/microsoft/typescript-go/internal/lsp/server.go:349 +0x8aa

[Error - 10:14:47 AM] Request textDocument/completion failed.
  Message: InternalError: panic handling request textDocument/completion: Could not find symbol 'sourceMapsEnabled' by key 'sourceMapsEnabled' in module "/home/jabaile/.cache/typescript/7.0/node_modules/@types/graceful-fs/index"
  Code: -32603 
[10:14:47.980] Processed 1 file changes in 30.405µs
======== Cloning snapshot 8 ========
[10:14:47.980] Reason: RequestedLanguageService (pending file changes) - [file:///home/jabaile/work/TypeScript-go/testdata/tests/cases/compiler/tsgo1701.ts]
[10:14:47.980] DidChangeFiles
	[10:14:47.980] Checking for changes affecting config files
		[10:14:47.980] Summarizing file changes
		[10:14:47.980] Checking if any changed files are config files
	[10:14:47.980] Marking project /dev/null/inferred as dirty due to changes in /home/jabaile/work/TypeScript-go/testdata/tests/cases/compiler/tsgo1701.ts
[10:14:47.980] DidRequestFile
	[10:14:...

</details>

Fixes microsoft/typescript-go#1704

<!-- START COPILOT CODING AGENT TIPS -->
---

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more [Copilot coding agent tips](https://gh.io/copilot-coding-agent-tips) in the docs.

Copilot AI and others added 3 commits October 9, 2025 11:29
Changed rehydrateCachedInfo to return (info, bool) instead of panicking when symbols or modules cannot be found. Updated callers to use MapFiltered to skip entries that can't be rehydrated.

Co-authored-by: jakebailey <[email protected]>
@Copilot Copilot AI changed the title [WIP] Fix textDocument/completion symbol not found panic Fix panic in textDocument/completion when cached symbols cannot be rehydrated Oct 9, 2025
@Copilot Copilot AI requested a review from jakebailey October 9, 2025 11:40
Copilot finished work on behalf of jakebailey October 9, 2025 11:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants