-
Notifications
You must be signed in to change notification settings - Fork 722
Fix panic in textDocument/completion when cached symbols cannot be rehydrated #1844
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
Closed
Closed
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
4ca857d
Initial plan
Copilot 911d4dc
Add reproduction test for completion panic with null export conditions
Copilot 1af301c
Fix panic by handling symbol rehydration failures gracefully
Copilot 6a9e3be
Add documentation for rehydration fix and test
Copilot 90fe17e
Use MapNonNil and rename to tryRehydrateCachedInfo
Copilot f276270
Replace inaccurate comments with TODO markers for original panics
Copilot 9411842
Remove test that doesn't reproduce the crash
Copilot 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
69 changes: 69 additions & 0 deletions
69
internal/fourslash/tests/completionNullExportCondition_test.go
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,69 @@ | ||
package fourslash_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/microsoft/typescript-go/internal/core" | ||
"github.com/microsoft/typescript-go/internal/fourslash" | ||
. "github.com/microsoft/typescript-go/internal/fourslash/tests/util" | ||
"github.com/microsoft/typescript-go/internal/ls" | ||
"github.com/microsoft/typescript-go/internal/testutil" | ||
) | ||
|
||
// Regression test for panic when rehydrating cached export info fails. | ||
// This can happen when: | ||
// - Module resolution changes (e.g., null export conditions) | ||
// - Symbols are removed/renamed in a module | ||
// - Modules become unavailable | ||
// The language service should handle this gracefully instead of panicking. | ||
func TestCompletionNullExportCondition(t *testing.T) { | ||
t.Parallel() | ||
defer testutil.RecoverAndFail(t, "Panic on fourslash test") | ||
const content = `// @module: esnext | ||
// @moduleResolution: node16 | ||
// @allowJs: true | ||
// @noTypesAndSymbols: true | ||
// @noEmit: true | ||
|
||
// @Filename: /node_modules/dep/package.json | ||
{ | ||
"name": "dep", | ||
"version": "1.0.0", | ||
"exports": { | ||
".": { | ||
"import": null, | ||
"require": "./dist/index.js", | ||
"types": "./dist/index.d.ts" | ||
} | ||
} | ||
} | ||
|
||
// @Filename: /node_modules/dep/dist/index.d.ts | ||
export const sourceMapsEnabled = true; | ||
export const someOtherExport = "value"; | ||
|
||
// @Filename: /node_modules/dep/dist/index.mjs | ||
export const sourceMapsEnabled = true; | ||
export const someOtherExport = "value"; | ||
|
||
// @Filename: /index.mts | ||
// Trigger auto-import completion - should work without panicking | ||
source/**/ | ||
` | ||
f := fourslash.NewFourslash(t, nil /*capabilities*/, content) | ||
// This should not panic when requesting completions | ||
f.VerifyCompletions(t, "", &fourslash.CompletionsExpectedList{ | ||
UserPreferences: &ls.UserPreferences{ | ||
IncludeCompletionsForModuleExports: core.TSTrue, | ||
IncludeCompletionsForImportStatements: core.TSTrue, | ||
}, | ||
IsIncomplete: false, | ||
ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ | ||
CommitCharacters: &DefaultCommitCharacters, | ||
EditRange: Ignored, | ||
}, | ||
Items: &fourslash.CompletionsExpectedItems{ | ||
// The exact items don't matter - we're just testing it doesn't panic | ||
}, | ||
}) | ||
} |
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
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.
Just make these
MapNonNil
- everyfalse
condition is alsonil
anyway.I don't know if
tryRehydrateCachedInfo
would be a better name to indicate that it might returnnil
now.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.
Done in commit f4e7b5e. Changed to use
MapNonNil
and renamed the function totryRehydrateCachedInfo
to better indicate it may return nil.