Skip to content

Terminal suggest: use absolute paths when relative input matches a CDPATH folder#314617

Open
yogeshwaran-c wants to merge 1 commit into
microsoft:mainfrom
yogeshwaran-c:fix/terminal-cdpath-zsh-completion-241858
Open

Terminal suggest: use absolute paths when relative input matches a CDPATH folder#314617
yogeshwaran-c wants to merge 1 commit into
microsoft:mainfrom
yogeshwaran-c:fix/terminal-cdpath-zsh-completion-241858

Conversation

@yogeshwaran-c
Copy link
Copy Markdown
Contributor

Summary

Fixes #241858.

When zsh's tab-completion replaces a partially-typed cd argument with the exact name of a folder reachable through $CDPATH (plus a trailing /), the typed prefix no longer resolves under cwd. Previously the suggest widget either bailed out or produced misleading ./<name>/... suggestions that did not match where cd would actually take the user.

This change adds a narrow fallback in TerminalCompletionService.resolveResources: when a relative cd argument cannot be resolved under cwd, it is resolved against each $CDPATH entry. 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, no cd prefix) and the existing CDPATH suggestion block are unchanged.

Test plan

  • New unit test cd folder1/ should suggest absolute paths under matching $CDPATH entry (#241858) in terminalCompletionService.test.ts covers the regression.
  • Manual: in zsh with CDPATH=$HOME/Work, type cd vsce, press Tab so zsh completes to vscode-vsce/, and confirm the suggest widget now offers absolute paths under $HOME/Work/vscode-vsce/.
  • Existing CDPATH suggestion tests still pass.

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
Copilot AI review requested due to automatic review settings May 6, 2026 01:46
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 $CDPATH fallback in TerminalCompletionService.resolveResources for unresolved relative cd folder arguments.
  • Switched fallback completions to emit absolute paths from the matched $CDPATH folder.
  • 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] });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CDPATH suggestions do not work well with ZSH auto completion

3 participants