Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 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
53 changes: 53 additions & 0 deletions extensions/terminal-suggest/src/fig/figInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,11 @@ export async function collectCompletionItemResult(
}
if (parsedArguments.suggestionFlags & SuggestionFlag.Subcommands) {
await addSuggestions(parsedArguments.completionObj.subcommands, vscode.TerminalCompletionItemKind.Method);

// Add support for additionalSuggestions
if (parsedArguments.completionObj.additionalSuggestions) {
await addAdditionalSuggestions(parsedArguments.completionObj.additionalSuggestions, terminalContext, prefix, items);
}
}
Comment on lines +343 to 346
Copy link
Member

Choose a reason for hiding this comment

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

the cursor replacement doesn't work

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed the cursor replacement in commit 2191351. Now properly handles the insertValue property and replaces {cursor} placeholder with empty string. For example, insertValue: "commit -m '{cursor}'" now correctly becomes "commit -m ''" in the completion.

if (parsedArguments.suggestionFlags & SuggestionFlag.Options) {
await addSuggestions(parsedArguments.completionObj.options, vscode.TerminalCompletionItemKind.Flag, parsedArguments);
Expand All @@ -346,6 +351,54 @@ export async function collectCompletionItemResult(
return { filesRequested, foldersRequested, fileExtensions };
}

async function addAdditionalSuggestions(
additionalSuggestions: (string | Fig.Suggestion)[],
terminalContext: { commandLine: string; cursorPosition: number },
prefix: string,
items: vscode.TerminalCompletionItem[]
) {
for (const suggestion of additionalSuggestions) {
if (typeof suggestion === 'string') {
// Simple string suggestion
items.push(createCompletionItem(
terminalContext.cursorPosition,
prefix,
{ label: suggestion },
undefined,
undefined,
vscode.TerminalCompletionItemKind.Method
));
} else {
// Full suggestion object
const suggestionLabels = getFigSuggestionLabel(suggestion);
if (!suggestionLabels?.length) {
continue;
}

for (const label of suggestionLabels) {
const completionItem = createCompletionItem(
terminalContext.cursorPosition,
prefix,
{ label },
undefined,
suggestion.description,
vscode.TerminalCompletionItemKind.Method
);

// Handle icon property (fig://... icons are not directly supported yet,
// but we can use a lightbulb icon for additionalSuggestions)
if (suggestion.icon) {
// Note: Custom icons from fig (fig://...) are not yet supported.
// Using lightbulb outline icon as mentioned in issue #239706
completionItem.icon = new vscode.ThemeIcon('lightbulb');
}
Copy link
Member

Choose a reason for hiding this comment

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

this causes a compile error

Property 'icon' does not exist on type 'TerminalCompletionItem'.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed the compilation error in commit 2191351. Removed the invalid icon property assignment since TerminalCompletionItem doesn't have an icon property. Instead, I use TerminalCompletionItemKind.Alias for suggestions with icons to provide visual differentiation.


items.push(completionItem);
}
}
}
}

function convertEnvRecordToArray(env: Record<string, string>): EnvironmentVariable[] {
return Object.entries(env).map(([key, value]) => ({ key, value }));
}
Expand Down
26 changes: 26 additions & 0 deletions extensions/terminal-suggest/src/test/fig.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,32 @@ export const figGenericTestSuites: ISuiteSpec[] = [
{ input: 'foo b|', expectedCompletions: ['b', 'foo'] },
{ input: 'foo c|', expectedCompletions: ['c', 'foo'] },
]
},
{
name: 'Fig additionalSuggestions support',
completionSpecs: [
{
name: 'git',
description: 'Git version control',
subcommands: [
{ name: 'commit', description: 'Commit changes' },
{ name: 'add', description: 'Add files' }
],
additionalSuggestions: [
{
name: "commit -m 'msg'",
description: "Git commit shortcut",
insertValue: "commit -m '{cursor}'",
icon: "fig://template?color=2ecc71&badge=🔥",
},
"quick-commit"
]
}
],
availableCommands: 'git',
testSpecs: [
{ input: 'git |', expectedCompletions: ["commit -m 'msg'", 'quick-commit', 'commit', 'add'] },
]
}
];

Loading