-
Notifications
You must be signed in to change notification settings - Fork 34.7k
Terminal suggest: Support fig additionalSuggestions with proper insertValue handling #260696
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
d7d38d5
4c61017
daddb4d
2191351
961ff59
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
} | ||
} | ||
if (parsedArguments.suggestionFlags & SuggestionFlag.Options) { | ||
await addSuggestions(parsedArguments.completionObj.options, vscode.TerminalCompletionItemKind.Flag, parsedArguments); | ||
|
@@ -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'); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this causes a compile error
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed the compilation error in commit 2191351. Removed the invalid |
||
|
||
items.push(completionItem); | ||
} | ||
} | ||
} | ||
} | ||
|
||
function convertEnvRecordToArray(env: Record<string, string>): EnvironmentVariable[] { | ||
return Object.entries(env).map(([key, value]) => ({ key, value })); | ||
} | ||
|
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.