-
Notifications
You must be signed in to change notification settings - Fork 657
Fix invalid URI for untitled references/definitions #1344
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
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: DanielRosenwasser <972891+DanielRosenwasser@users.noreply.github.com>
The issue was that untitled filenames (^/untitled/ts-nul-authority/...) were being treated as relative paths and resolved against the current working directory, corrupting their format. - Modified GetEncodedRootLength to recognize ^/ as a rooted path prefix - Added comprehensive tests for untitled path handling - Verified fix resolves the URI conversion round-trip issue Co-authored-by: DanielRosenwasser <972891+DanielRosenwasser@users.noreply.github.com>
This test simulates the exact issue scenario: - VS Code sends untitled:Untitled-2 URI - Verifies the path is not corrupted by current directory resolution - Confirms round-trip URI conversion works correctly - Proves references/definitions will return correct untitled URIs Co-authored-by: DanielRosenwasser <972891+DanielRosenwasser@users.noreply.github.com>
uri
for untitled references/definitions
internal/tspath/path.go
Outdated
// Untitled paths (e.g., "^/untitled/ts-nul-authority/Untitled-1") | ||
if ch0 == '^' && ln > 1 && path[1] == '/' { | ||
return 2 // Untitled: "^/" | ||
} | ||
|
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.
This is uncommon, so move it right before the URL checks.
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.
Moved the untitled path check to before the URL checks as requested. This improves performance by checking common cases (POSIX/DOS paths) first before the uncommon untitled paths. Fixed in 0fd6461.
Co-authored-by: DanielRosenwasser <972891+DanielRosenwasser@users.noreply.github.com>
There's a check for |
Co-authored-by: DanielRosenwasser <972891+DanielRosenwasser@users.noreply.github.com>
Removed the redundant check as requested. Since |
This PR addresses the issue where find references and go-to-definition operations on untitled files return incorrect URIs that cannot be linked back to the original location.
Root Cause Analysis
The issue was in the path handling logic in
internal/tspath/path.go
. When VS Code sends requests with untitled URIs likeuntitled:Untitled-2
, the following sequence occurs:DocumentURIToFileName
correctly convertsuntitled:Untitled-2
to^/untitled/ts-nul-authority/Untitled-2
GetEncodedRootLength
did not recognize^/
as a rooted path, returning 0ToPath
treated the untitled filename as relative and resolved it against current directory^/untitled/ts-nul-authority/Untitled-2
into/home/user/project/^/untitled/ts-nul-authority/Untitled-2
FileNameToDocumentURI
was called, it couldn't recognize the corrupted path as untitled and returned a regular file URISolution
Modified
GetEncodedRootLength
to recognize paths starting with^/
as rooted paths (similar to how/
andc:
are handled). This prevents untitled filenames from being resolved against the current directory.Implementation
^/
prefix inGetEncodedRootLength
function^/
)Before Fix
After Fix
The integration test confirms the complete flow works correctly, simulating the exact scenario from the original issue where references and definitions on untitled files now return proper
untitled:
URIs instead of brokenfile://
URIs.Fixes #1343.
💡 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 in the docs.