Skip to content

Go shlex: fix completion position after trailing space and keep empty quoted strings - #10469

Merged
kovidgoyal merged 2 commits into
kovidgoyal:masterfrom
anandghegde:go-shlex-empty-quoted-strings
Sep 15, 2026
Merged

kovidgoyal merged 2 commits into
kovidgoyal:masterfrom
anandghegde:go-shlex-empty-quoted-strings

Conversation

@anandghegde

Copy link
Copy Markdown
Contributor

Two small fixes to the Go shlex package (tools/utils/shlex), in separate commits.

1. Tab completion after a space mangles the previous word in the kitty shell

SplitForCompletion worked out where the new empty word starts as if the word before it were one byte long. The readline completer then cuts before_cursor at that position, so part of the previous word gets replaced. To reproduce, run kitten @ and type launch --type , then press Tab twice:

  • before: the line becomes launch --window
  • after: the line becomes launch --type window

The new word always starts at the end of the input, so the fix sets the position to len(s).

2. Empty quoted strings are dropped

The Go lexer used an empty Value to mean EOF, so "" and '' never came out as arguments. launch --title '' vim split as ["launch", "--title", "vim"]. The C implementation already handles this (2093fb1). This commit ports that fix, allow_empty included, and signals EOF with Pos == -1. The empty-string test cases from kitty_tests/datatypes.py are now in the Go tests too.

Fix 1 has to land before fix 2. Otherwise a '' would put the completion position past the end of the input.

Tests: added cases to shlex_test.go, and both commits' new tests fail on the code before them. ./test.py passes on macOS (707 tests), and go vet is clean on the affected packages. I also checked the completion fix by hand in a locally built kitty.

I used Claude Code for this. I reviewed and tested the changes myself.

🤖 Generated with Claude Code

https://claude.ai/code/session_01MA8JGs7pCoXFL2W6jEJ8sD

anandghegde and others added 2 commits September 14, 2026 16:09
SplitForCompletion computed the position of the new empty word as if
the previous word were one byte long, so tab completing after a space
following a multi-character word replaced part of that word. For example,
completing "launch --type " in the kitten @ shell produced
"launch --window ". The new word starts at the end of the input.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01MA8JGs7pCoXFL2W6jEJ8sD
Port the fix from 2093fb1 in the C shlex implementation to the Go one.
Previously an argument such as "" or '' was silently dropped, since an
empty word was also used to signal EOF. So "launch --title '' vim" in the
kitty shell was parsed as "launch --title vim". EOF is now signalled with
a negative Pos.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01MA8JGs7pCoXFL2W6jEJ8sD
@kovidgoyal
kovidgoyal merged commit 784340a into kovidgoyal:master Sep 15, 2026
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.

2 participants