Terminal suggest: use absolute paths when relative input matches a CDPATH folder#314617
Open
yogeshwaran-c wants to merge 1 commit into
Open
Terminal suggest: use absolute paths when relative input matches a CDPATH folder#314617yogeshwaran-c wants to merge 1 commit into
yogeshwaran-c wants to merge 1 commit into
Conversation
When zsh tab-completes `cd <prefix>` to an exact CDPATH folder name plus a trailing slash, the resulting path doesn't exist under cwd, so the suggest widget previously either bailed out or produced misleading `./<name>/...` suggestions. Resolve the typed prefix against $CDPATH entries when it fails to resolve under cwd and emit absolute path completions, matching where `cd` would actually take the user. Fixes microsoft#241858
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates terminal path completion so cd <folder>/ can fall back to $CDPATH when the partially completed folder does not exist under the current working directory, which fixes the zsh tab-completion scenario described in #241858.
Changes:
- Added a
$CDPATHfallback inTerminalCompletionService.resolveResourcesfor unresolved relativecdfolder arguments. - Switched fallback completions to emit absolute paths from the matched
$CDPATHfolder. - Added a regression test covering the zsh-style
cd folder1/completion flow.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/vs/workbench/contrib/terminalContrib/suggest/browser/terminalCompletionService.ts |
Adds the new $CDPATH resolution fallback and absolute-path completion behavior in terminal resource completion. |
src/vs/workbench/contrib/terminalContrib/suggest/test/browser/terminalCompletionService.test.ts |
Adds a unit test for the zsh/CDPATH regression scenario. |
| if (!absolutePath.endsWith(resourceOptions.pathSeparator)) { | ||
| absolutePath += resourceOptions.pathSeparator; | ||
| } | ||
| lastWordFolder = absolutePath; |
Comment on lines
+694
to
+697
| assertPartialCompletionsExist(result, [ | ||
| { label: '/cdpath_value/folder1/inner1/', detail: '/cdpath_value/folder1/inner1/' }, | ||
| { label: '/cdpath_value/folder1/inner2/', detail: '/cdpath_value/folder1/inner2/' }, | ||
| ], { replacementRange: [3, 11] }); |
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.
Summary
Fixes #241858.
When zsh's tab-completion replaces a partially-typed
cdargument with the exact name of a folder reachable through$CDPATH(plus a trailing/), the typed prefix no longer resolves undercwd. Previously the suggest widget either bailed out or produced misleading./<name>/...suggestions that did not match wherecdwould actually take the user.This change adds a narrow fallback in
TerminalCompletionService.resolveResources: when a relativecdargument cannot be resolved undercwd, it is resolved against each$CDPATHentry. If a match is found, the completions are emitted as absolute paths under that CDPATH-resolved folder, which is what Tyriar described as the expected behavior in the issue.Other input shapes (
./foo/, no trailing slash, nocdprefix) and the existing CDPATH suggestion block are unchanged.Test plan
cd folder1/ should suggest absolute paths under matching $CDPATH entry (#241858)interminalCompletionService.test.tscovers the regression.CDPATH=$HOME/Work, typecd vsce, press Tab so zsh completes tovscode-vsce/, and confirm the suggest widget now offers absolute paths under$HOME/Work/vscode-vsce/.