fix(command): handle spaces in ClaudeCodeAdd file paths - #315
Draft
7A1T wants to merge 1 commit into
Draft
Conversation
Vim expands `%`/`#`/etc. in the Ex command line before the user-command callback runs, so `:ClaudeCodeAdd %` on a buffer whose path contains a space arrived as an already-expanded path string. The naive whitespace split then broke it into bogus path/line-number tokens, producing "Too many arguments" or "Invalid start line number" errors. Replace the split with a parser that treats trailing numeric tokens as line numbers and rejoins the rest as the path, and additionally supports a quoted path when a line range follows. Fixes coder#314
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.
Summary
:ClaudeCodeAdd %(the README-documented keybinding) broke for buffers whose path contains a space, because Vim expands%/#/etc. in the Ex command line before the user-command callback runs, so the naivevim.split(opts.args, "%s+")split the already-expanded path on its embedded spaces — producing "Too many arguments" or "Invalid start line number" errors.parse_add_command_args, which treats trailing numeric tokens (up to two) as line numbers and rejoins the rest as the path, so unquoted spaced paths resolve correctly. A quoted path ("my file.lua" 10 20) is also supported for when a line range follows.:ClaudeCodeAdd.Fixes #314
Test plan
tests/unit/claudecode_add_command_spec.luacovering unquoted spaced paths (with/without a line range), quoted paths, and unterminated-quote errors — 35/35 passing viabusted.vim.trimmock totests/mocks/vim.lua(was missing, needed by the new parser).mise run allnot run locally (mise/luajit unavailable in this environment) — pre-existing unrelated test failures (e.g.terminal_spec.lua,unpackglobal) were confirmed present on a cleanmaincheckout too, so they're an environment gap, not introduced by this change. Please run the fullmise run allin CI/a provisioned shell before merging.Marked as draft pending that full validation.