Skip to content

Support Windows paths and directory separators in path tab completion - #1212

Open
nordicnode wants to merge 1 commit into
CodebuffAI:mainfrom
nordicnode:fix-windows-path-tab-completion
Open

Support Windows paths and directory separators in path tab completion#1212
nordicnode wants to merge 1 commit into
CodebuffAI:mainfrom
nordicnode:fix-windows-path-tab-completion

Conversation

@nordicnode

Copy link
Copy Markdown

Support Windows paths and directory separators in path tab completion

Summary

• In cli/src/hooks/use-path-tab-completion.ts, fix path tab completion and automatic directory navigation on Windows.
• Previously, usePathTabCompletion checked searchQuery.startsWith('/') || searchQuery.startsWith('~') for absolute paths. On Windows, drive paths (C:\...) and UNC paths were not matched, causing them to fall through to the relative path branch (path.join(currentPath, searchQuery)).
• Furthermore, completed.endsWith('/') was used to detect full directory completions. On Windows, path-completion.ts appends path.sep (\), so completed.endsWith('/') was always false, breaking automatic directory navigation when pressing Tab.
• Exports pure helpers isAbsolutePath, isCompleteDirectory, and toRelativePath from use-path-tab-completion.ts to handle both POSIX and Windows path styles.
• In cli/src/hooks/__tests__/use-path-tab-completion.test.ts, uses the exported implementations and adds test cases for Windows drive paths and backslash directory completions.

Test plan

[✓] bun test --config=/dev/null src/hooks/__tests__/use-path-tab-completion.test.ts — 35 pass, 0 fail
[✓] bun run --cwd cli typecheck — 0 errors
[✓] PR hygiene check passed

@codebuff-team

Copy link
Copy Markdown
Contributor

Good catch and a clean fix. The core bug is real: usePathTabCompletion only recognized POSIX-style absolute paths (/, ~), so Windows drive paths (C:\...) fell into the relative-path branch and got mangled via path.join(currentPath, searchQuery). Likewise, checking only completed.endsWith('/') broke auto-navigation on Windows since path-completion.ts appends path.sep (\) there.

Extracting isAbsolutePath, isCompleteDirectory, and toRelativePath as exported pure functions is the right move — it lets the test file exercise the actual implementation instead of a hand-duplicated copy (the previous tests were testing dead code, not the hook). That's a meaningful improvement on its own.

A couple of things worth double-checking before porting:

  • isCompleteDirectory now treats a trailing \ as a directory marker unconditionally, even on POSIX, where a filename literally ending in \ is legal (rare, but possible). Probably fine, just flag it.
  • isAbsolutePath calls both path.isAbsolute and path.win32.isAbsolute regardless of platform — intentional per the PR description, and reasonable since you want Windows-style paths recognized even if the CLI happens to run under WSL/POSIX, but worth a comment noting this is deliberate cross-platform detection, not a mistake.

Small, in-scope, tested, addresses a real cross-platform bug. This is the kind of PR worth porting by hand.

@codebuff-team codebuff-team added bot:triaged Classified by the community triage bot pr:port-candidate Worth porting into the private source tree labels Sep 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:triaged Classified by the community triage bot pr:port-candidate Worth porting into the private source tree

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants