fix: preserve directory locality for notebook cell paths in TS server#307796
Open
yogeshwaran-c wants to merge 1 commit intomicrosoft:mainfrom
Open
fix: preserve directory locality for notebook cell paths in TS server#307796yogeshwaran-c wants to merge 1 commit intomicrosoft:mainfrom
yogeshwaran-c wants to merge 1 commit intomicrosoft:mainfrom
Conversation
For notebook cell URIs on desktop, the TypeScript server receives file paths in a virtual format (^/vscode-notebook-cell/authority/path) that places the cell in a different directory than the actual notebook file. This breaks relative path resolution (e.g. import from './a.ts') because the TS server resolves relative paths based on the file's directory. This change encodes notebook cell URIs into the filename while keeping the path in the same directory as the notebook, so that path.dirname() returns the correct directory for relative path resolution. Closes microsoft#196172
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What kind of change does this PR introduce?
Bug fix
What is the current behavior?
When using TypeScript/JavaScript cells in VS Code notebooks (e.g., with the TypeScript Notebook extension), relative path imports like
import { a } from './a.ts'fail withTS(2307) Cannot find module, and "Go to Definition" navigates to a nonsensical path.This happens because the TypeScript language service client converts
vscode-notebook-cell://URIs into virtual file paths of the form^/vscode-notebook-cell/authority/path/to/notebook.ipynb#fragment. The TS server sees this virtual path and resolves relative imports against its directory (^/vscode-notebook-cell/authority/path/to/), which does not match the actual directory of the notebook file (/path/to/).Closes #196172
What is the new behavior?
For
vscode-notebook-cellURIs on desktop, the cell identity (authority + fragment) is now encoded into the filename while keeping the path in the same directory as the notebook file. This ensures thatpath.dirname()returns the actual notebook directory, so the TS server correctly resolves relative imports.Encoding format
Before (virtual path):
After (directory-preserving path):
The reverse conversion in
toResourcecorrectly parses these encoded paths back into propervscode-notebook-cell://URIs.Additional context
fsPathprovides a real filesystem path~vscode-notebook-cell~as a filename prefix, which is unlikely to collide with real filenames