Skip to content

feat: add directory/file path completion for terminal input - #74

Open
BingqingLyu wants to merge 8 commits into
mainfrom
fork-pr-2879-feat-path-completion
Open

feat: add directory/file path completion for terminal input#74
BingqingLyu wants to merge 8 commits into
mainfrom
fork-pr-2879-feat-path-completion

Conversation

@BingqingLyu

@BingqingLyu BingqingLyu commented Apr 27, 2026

Copy link
Copy Markdown
Owner

Background

Users frequently need to reference file paths in prompts (e.g. src/components/auth/LoginForm.tsx). Currently they must type full paths manually, which is error-prone and slow in large projects with deep directory structures.

Related: Item-18: Directory/File Path Completion

Before / After

Before After
File referencing Only @ prefix triggers file completion Also supports /, ./, ../, ~/ as path prefixes
Absolute paths /home/user/... misidentified as a slash command — no suggestions shown Recognized as a path, shows filesystem suggestions
Workflow Must remember and type full paths manually Shell-like Tab completion — browse directories level by level

Implementation

  • directoryCompletion.ts — Directory scanning with LRU cache (500 entries, 5min TTL), .gitignore-aware filtering
  • usePathCompletion.ts — React hook with 100ms debounce + AbortController to cancel stale requests
  • useCommandCompletion.tsx — New CompletionMode.PATH; resolves SLASH/PATH conflict so /home is no longer treated as a slash command

Changes

Type File Description
New utils/directoryCompletion.ts (+348) Core completion logic
New hooks/usePathCompletion.ts (+167) Path completion hook
Modified hooks/useCommandCompletion.tsx (+57/-8) Integrate PATH mode
Tests 3 test files (+530) 48 test cases covering path parsing, Unicode, mode disambiguation, etc.

Tests

 ✓ directoryCompletion.test.ts  (24 tests)
 ✓ usePathCompletion.test.ts     (2 tests)
 ✓ useCommandCompletion.test.ts (22 tests)
 ✓ InputPrompt.test.tsx        (105 tests | 1 skipped)
 0 new TypeScript errors

Manual verification: Launch the CLI, type ./sr — you should see suggestions like src/. Press Tab to accept and continue completing the next directory level.

wenshao and others added 8 commits April 4, 2026 18:23
Implement path auto-completion inspired by Claude Code's directoryCompletion.ts.
When user types a path-like token (/, ./, ../, ~/), trigger file/directory
completion with LRU-cached directory scanning and .gitignore filtering.

- New module: utils/directoryCompletion.ts with SimpleLRUCache, path parsing,
  directory scanning, and completion generation
- New hook: usePathCompletion.ts with 100ms debounce and abort controller
- Modified: useCommandCompletion.tsx to add PATH completion mode with
  SLASH/PATH disambiguation for absolute paths
- 21 unit tests covering all path completion scenarios

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
- Use os.homedir() instead of process.env for home directory expansion
- Extract magic number 100 to named constant MAX_SCAN_RESULTS
- Remove redundant 'enabled' field from UsePathCompletionReturn
- Add comment explaining cursorRow === 0 restriction for PATH mode

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
- Preserve ./ prefix in completion values (was incorrectly stripped)
- Remove bare ~, ., .. from path-like token detection (produced wrong results)
- Fix bare / falling into PATH mode instead of SLASH mode when commands exist
- Include symlinks in scanDirectoryForPaths results
- Simplify usePathCompletion to return void (align with useAtCompletion pattern)
- Strengthen tests to verify actual mode selection via mock call assertions

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Verify that path completion does not add trailing space after
autocomplete (unlike AT/SLASH mode), which allows users to continue
navigating deeper into directories.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Add Windows backslash path support to isPathLikeToken (~\, .\, ..\)
- Clear suggestions/loading state when usePathCompletion is disabled
  to prevent stale UI state

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Resolve symlink target type via stat() so symlinks to directories
  show as directories with trailing / and allow continued navigation
- Use toCodePoints() instead of [...str].length for consistency with
  existing ASCII fast path
- Fix test: use vi.spyOn(process, 'cwd') instead of direct assignment
- Add tests for symlink-to-directory and broken symlink handling

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Map.set() on an existing key preserves its original insertion position,
which would cause frequently-updated entries to be evicted prematurely.
Delete-then-reinsert to maintain correct LRU ordering.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Add completionMode to UseCommandCompletionReturn so consumers
  (e.g., InputPrompt) can distinguish PATH vs SLASH mode for
  correct SuggestionsDisplay layout
- Fix Windows path regex to accept both C:\ and C:/ separators

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@BingqingLyu BingqingLyu added conflicting-group-1 conflicting-group-1 Conflicting PR group 1 — review as a batch conflicting-pr Shares at least one cross-PR dependency with other PRs and removed conflicting-pr labels May 7, 2026
@BingqingLyu

BingqingLyu commented May 7, 2026

Copy link
Copy Markdown
Owner Author

Conflict Group 1

This PR shares modified functions with 2 other PR(s): #62, #9.

These PRs should be reviewed as a batch — merging one may affect the others.

Function File Also modified by
useCommandCompletion useCommandCompletion.tsx #62, #9
graph LR
    PR74["PR #74"]
    FuseCommandCompletion_8197["useCommandCompletion<br>useCommandCompletion.tsx"]
    PR74 -->|modifies| FuseCommandCompletion_8197
    PR62["PR #62"]
    PR62 -->|modifies| FuseCommandCompletion_8197
    PR9["PR #9"]
    PR9 -->|modifies| FuseCommandCompletion_8197
Loading

Posted by codegraph-ai conflict detection.

@github-actions

Copy link
Copy Markdown

This pull request has had no activity for 60 days and is being marked as stale. It will be closed in another 30 days if no further activity occurs. To keep it open, push a new commit or leave a comment. Maintainers may apply pinned, status/blocked, status/on-hold, or status/ready-for-merge to exempt it from auto-close.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

conflicting-group-1 Conflicting PR group 1 — review as a batch conflicting-pr Shares at least one cross-PR dependency with other PRs status/stale

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants