Skip to content

Commit 70cd43b

Browse files
committed
revert
1 parent 1be9924 commit 70cd43b

File tree

2 files changed

+5
-45
lines changed

2 files changed

+5
-45
lines changed

src/t.ts

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -217,20 +217,6 @@ export class RootCommand extends Command {
217217
}
218218
}
219219

220-
// Fallback: if nothing matched yet, try to match any single-token command
221-
// later in the args (helps when the executable name or runner is included,
222-
// e.g., `pnpm nuxt dev` where `nuxt` is not a registered command).
223-
if (!matchedCommand) {
224-
for (let i = 0; i < args.length; i++) {
225-
const potential = this.commands.get(args[i]);
226-
if (potential) {
227-
matchedCommand = potential;
228-
remaining = args.slice(i + 1);
229-
break;
230-
}
231-
}
232-
}
233-
234220
// If no command was matched, use the root command (this)
235221
return [matchedCommand || this, remaining];
236222
}
@@ -273,12 +259,9 @@ export class RootCommand extends Command {
273259
// Determine if we should complete commands
274260
private shouldCompleteCommands(
275261
toComplete: string,
276-
endsWithSpace: boolean,
277-
isRootCommandContext: boolean
262+
endsWithSpace: boolean
278263
): boolean {
279-
// Only suggest commands when we're still completing at the root context.
280-
// Once a command is matched, we should move on to its arguments/flags.
281-
return isRootCommandContext && !toComplete.startsWith('-');
264+
return !toComplete.startsWith('-');
282265
}
283266

284267
// Handle flag completion (names and values)
@@ -474,7 +457,6 @@ export class RootCommand extends Command {
474457
}
475458

476459
const [matchedCommand] = this.matchCommand(previousArgs);
477-
const isRootContext = matchedCommand === this;
478460
const lastPrevArg = previousArgs[previousArgs.length - 1];
479461

480462
// 1. Handle flag/option completion
@@ -508,9 +490,7 @@ export class RootCommand extends Command {
508490
}
509491

510492
// 2. Handle command/subcommand completion
511-
if (
512-
this.shouldCompleteCommands(toComplete, endsWithSpace, isRootContext)
513-
) {
493+
if (this.shouldCompleteCommands(toComplete, endsWithSpace)) {
514494
this.handleCommandCompletion(previousArgs, toComplete);
515495
}
516496
// 3. Handle positional arguments - always check for root command arguments

src/zsh.ts

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,32 +21,12 @@ _${name}() {
2121
local shellCompDirectiveFilterDirs=${ShellCompDirective.ShellCompDirectiveFilterDirs}
2222
local shellCompDirectiveKeepOrder=${ShellCompDirective.ShellCompDirectiveKeepOrder}
2323
24-
local lastParam lastChar flagPrefix requestComp out directive comp lastComp noSpace keepOrder isNewWord
24+
local lastParam lastChar flagPrefix requestComp out directive comp lastComp noSpace keepOrder
2525
local -a completions
2626
2727
__${name}_debug "\\n========= starting completion logic =========="
2828
__${name}_debug "CURRENT: \${CURRENT}, words[*]: \${words[*]}"
2929
30-
# Track whether the cursor is positioned on a new (empty) word so we can
31-
# pass an empty argument to the CLI when the user has already completed
32-
# the previous token (e.g. after typing a space).
33-
isNewWord=0
34-
if [ \${#words[@]} -ge \${CURRENT} ] && [ -z "\${words[\${CURRENT}]}" ]; then
35-
isNewWord=1
36-
__${name}_debug "Detected empty current word via words[\${CURRENT}]"
37-
elif [ -n "\${BUFFER}" ] && [ "\${BUFFER[-1]}" = " " ]; then
38-
isNewWord=1
39-
__${name}_debug "Detected trailing space in buffer"
40-
fi
41-
42-
# When completing a brand-new (empty) word, CURRENT can point past the end
43-
# of the words array. Pad with an empty element so downstream logic keeps
44-
# the last typed argument (avoids replaying the prior completion).
45-
if [ $isNewWord -eq 1 ] && [ \${#words[@]} -lt \${CURRENT} ]; then
46-
__${name}_debug "Padding words to CURRENT with empty element"
47-
words+=("")
48-
fi
49-
5030
# The user could have moved the cursor backwards on the command-line.
5131
# We need to trigger completion from the $CURRENT location, so we need
5232
# to truncate the command-line ($words) up to the $CURRENT location.
@@ -68,7 +48,7 @@ _${name}() {
6848
6949
# Prepare the command to obtain completions, ensuring arguments are quoted for eval
7050
local -a args_to_quote=("\${(@)words[2,-1]}")
71-
if [ "\${lastChar}" = "" ] || [ $isNewWord -eq 1 ]; then
51+
if [ "\${lastChar}" = "" ]; then
7252
# If the last parameter is complete (there is a space following it)
7353
# We add an extra empty parameter so we can indicate this to the go completion code.
7454
__${name}_debug "Adding extra empty parameter"

0 commit comments

Comments
 (0)