Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,21 +337,24 @@ export class Completion {
previousArgs: string[],
toComplete: string
) {
const commandParts = [...previousArgs];
const commandParts = [...previousArgs].filter(Boolean);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does this do?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixes the vite autocompletion issue because when you type vite , the shell might pass something like "vite", "" as the arguments array to the completion function (where the empty string represents the position where TAB was pressed) without this, those empty strings would be treated as actual command parts causing the matching logic to fail when comparing against available commands since no match would be found, no subcommands would be shown here! this cleans up the arguments array to only contain actual command parts like "vite" to make the matching logic to work correctly

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes total sense!


for (const [k, command] of this.commands) {
if (k === '') continue;

const parts = k.split(' ');
let match = true;

let match = true;
let i = 0;

while (i < commandParts.length) {
if (parts[i] !== commandParts[i]) {
match = false;
break;
}
i++;
}

if (match && parts[i]?.startsWith(toComplete)) {
this.completions.push({
value: parts[i],
Expand Down