fix(cli): tab-complete paths with embedded spaces#26299
Open
0xDevNinja wants to merge 1 commit into
Open
Conversation
_extract_path_word() walked back only to the nearest space, so after prompt_toolkit autocompleted a directory whose name contained a space (e.g. `./My Documents/`), pressing Tab again extracted just `Documents/` — which does not exist in the cwd — and produced no completions. Find the rightmost anchored prefix (`./`, `../`, `~/`, `/`) that sits at the start of the line or directly after a space, and treat everything from there to the cursor as the path. Falls back to the last space-delimited token when no anchor is present, preserving the existing `open src/utils/x.py` mid-line behaviour. Avoids the over-consumption issue with the obvious "stop at any slash in tail" heuristic, which would walk all the way back through `tell me about ./My Documents/`. Fixes NousResearch#26223
Collaborator
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 does this PR do?
_extract_path_word()inhermes_cli/commands.pywalked back to thenearest space, so after prompt_toolkit autocompleted a directory whose
name contained a space (e.g.
./My Documents/), pressing Tab againextracted just
Documents/. That isn't a directory in cwd, so thelistdir returned nothing and tab completion silently stopped working
for everything inside that directory.
Fix
Find the rightmost anchored prefix (
./,../,~/,/) that sitsat the start of the line or directly after a space, and treat
everything from there to the cursor as the path. When no anchor is
present, fall back to the last space-delimited token (preserves the
existing mid-line
open src/utils/x.pybehaviour).Why not the heuristic proposed in the issue body
The "keep walking past a space if the tail contains a slash" rule
over-consumes in normal prose — for
tell me about ./My Documents/,every backwards chunk contains a slash, so the walk reaches the start
of the line and the resulting "word" can never be listdir'd. The
anchor-based approach stops as soon as the captured tail can stand on
its own as a path.
Related Issue
Fixes #26223
Type of Change
Changes Made
hermes_cli/commands.py— anchor-based_extract_path_word().tests/hermes_cli/test_path_completion.py— six new cases covering./My Documents/, mid-sentencelook at ./My Documents/,/etc/My Files/,~/My Notes/todo.md, deep./My Documents/Sub Folder/file.py,and the anchored-extension fallback for
./src/foo bar.py.Testing