Skip to content

fix(autocomplete): respect cursor position in zsh completion - #205

Open
Tmwakalasya wants to merge 2 commits into
openai:mainfrom
Tmwakalasya:fix/zsh-completion-cursor
Open

Tmwakalasya wants to merge 2 commits into
openai:mainfrom
Tmwakalasya:fix/zsh-completion-cursor

Conversation

@Tmwakalasya

Copy link
Copy Markdown
Contributor

Summary

Zsh completion forwards every word after the executable, including words after the cursor. The backend treats the last supplied argument as the word being completed.

For example, with the cursor immediately after li in openai models li --format json, completing li returns no suggestion because the backend receives json as its current word.

Limit the quoted array slice to CURRENT - 1 arguments after the executable. This includes the cursor's word, excludes trailing arguments, and preserves spaces and empty arguments. No backend or generated-code changes are needed.

Regression coverage

Add 14 cases using the real rendered Zsh script and the existing Go completion helper, with Zsh's UI functions stubbed:

  • Commands and flags completed before trailing arguments, plus end-of-line controls.
  • Empty current/preceding words and values containing spaces.
  • File-completion routing, including @, @file://, and @data:// prefixes.
  • Non-file flag values that should offer no completion.

Assertions check exact NUL-delimited forwarded arguments, suggestions or file-completion dispatch, and exit status. Tests skip when Zsh is unavailable.

Validation

The new mid-line-command regression failed before the fix; end-of-line controls passed. After the fix, all of these passed:

env CGO_ENABLED=0 GOPROXY=off go test -buildvcs=false ./internal/autocomplete -count=1
env CGO_ENABLED=0 GOPROXY=off go test -buildvcs=false ./internal/autocomplete -run '^TestZshCompletionRespectsCursor$' -count=25 -shuffle=on
env CGO_ENABLED=0 GOPROXY=off go vet -buildvcs=false ./internal/autocomplete
zsh -n internal/autocomplete/shellscripts/zsh_autocomplete.zsh
go mod verify
git diff --check

No live API calls were made. A live interactive Tab session, the full mock-server integration suite, and the race-detector suite were not run.

@Tmwakalasya
Tmwakalasya requested a review from a team as a code owner September 19, 2026 16:01
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.

1 participant