Fix line navigation when opening files with line fragments#293733
Open
MrToph wants to merge 1 commit intomicrosoft:mainfrom
Open
Fix line navigation when opening files with line fragments#293733MrToph wants to merge 1 commit intomicrosoft:mainfrom
MrToph wants to merge 1 commit intomicrosoft:mainfrom
Conversation
📬 CODENOTIFYThe following users are being notified based on files changed in this PR: @bpaseroMatched files:
@deepak1556Matched files:
|
Author
|
@microsoft-github-policy-service agree |
MrToph
commented
Feb 8, 2026
| /** | ||
| * Resolve file links of the shape `file://./relativeFile.txt` against the model URI. | ||
| */ | ||
| export function resolveRelativeFileLink(uri: string | URI, modelUri: URI): string | URI { |
Author
There was a problem hiding this comment.
this is a refactor of the old code from src/vs/editor/contrib/links/browser/links.ts, I kept it functionally equivalent except the final with query + fragment.
MrToph
commented
Feb 8, 2026
| } | ||
|
|
||
| private async resolveOpenable(openable: IWindowOpenable, options: IPathResolveOptions = Object.create(null)): Promise<IPathToOpen | undefined> { | ||
| private async resolveOpenable(openable: IWindowOpenable, options: IPathResolveOptions = Object.create(null)): Promise<IPathToOpen<ITextEditorOptions> | undefined> { |
Author
There was a problem hiding this comment.
had to specify this because of a type error when using options.selection below.
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.
This PR fixes two line-navigation regressions for file links that include a fragment like
#L99.Related issue: #170405
Rationale
File deep-linking is increasingly important with external AI coding tools that use VS Code as the editor/diff viewer. In these workflows, opening a file at an exact location (and, in related scenarios, specific ranges) is core to review and iteration speed. Preserving URI fragments such as
#L99or#L99-L105avoids making users manually browse large files and lose the exact location being referenced.Problem summary
VS Code supports opening file links with line fragments (e.g.
#L99), but the fragment was getting dropped in two important paths:file://link.vscode://file/...#L99orcode-oss://file/...#L99).Reproduction matrix (with concrete paths)
Target file for all cases:
/tmp/vscode-link-repro/target.txtContents:
Source file used for in-editor link clicks:
/tmp/vscode-link-repro/source.txtContents:
Cases:
file://file://./target.txt#L99(from/tmp/vscode-link-repro/source.txt)file://file:///tmp/vscode-link-repro/target.txt#L99open) ×vscode://URLopen -b com.visualstudio.code.oss -u "code-oss://file/tmp/vscode-link-repro/target.txt#L99"open -b com.microsoft.VSCode -u "vscode://file/tmp/vscode-link-repro/target.txt#L99"open) ×file://URLopen -b com.visualstudio.code.oss -u "file:///tmp/vscode-link-repro/target.txt#L99"open-filewith a filesystem path and strips the URI fragment (#L99) before VS Code receives it.What changed
src/vs/editor/contrib/links/browser/links.ts)file://./...links against the active model URI.#L....src/vs/code/electron-main/app.ts)queryandfragmentwhen converting protocol file URLs intofileUriopenables.src/vs/platform/windows/electron-main/windowsMainService.ts)#L99) before resolving local file path.Tests
Added regression tests:
src/vs/editor/contrib/links/test/browser/linkDetectorUtils.test.tsValidated:
file://./...#L99now preserves fragment and resolves to line selection.