Skip to content

Commit

Permalink
Show global slash commands under @ (#229471)
Browse files Browse the repository at this point in the history
  • Loading branch information
roblourens authored Sep 24, 2024
1 parent 09fe7cb commit 2a88ead
Showing 1 changed file with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,42 @@ class SlashCommandCompletions extends Disposable {
};
}
}));
this._register(this.languageFeaturesService.completionProvider.register({ scheme: ChatInputPart.INPUT_SCHEME, hasAccessToAllModels: true }, {
_debugDisplayName: 'globalSlashCommandsAt',
triggerCharacters: ['@'],
provideCompletionItems: async (model: ITextModel, position: Position, _context: CompletionContext, _token: CancellationToken) => {
const widget = this.chatWidgetService.getWidgetByInputUri(model.uri);
if (!widget || !widget.viewModel) {
return null;
}

const range = computeCompletionRanges(model, position, /@\w*/g);
if (!range) {
return null;
}

const slashCommands = this.chatSlashCommandService.getCommands(widget.location);
if (!slashCommands) {
return null;
}

return {
suggestions: slashCommands.map((c, i): CompletionItem => {
const withSlash = `${chatSubcommandLeader}${c.command}`;
return {
label: withSlash,
insertText: c.executeImmediately ? '' : `${withSlash} `,
detail: c.detail,
range: new Range(1, 1, 1, 1),
filterText: `${chatAgentLeader}${c.command}`,
sortText: c.sortText ?? 'z'.repeat(i + 1),
kind: CompletionItemKind.Text, // The icons are disabled here anyway,
command: c.executeImmediately ? { id: SubmitAction.ID, title: withSlash, arguments: [{ widget, inputValue: `${withSlash} ` }] } : undefined,
};
})
};
}
}));
}
}

Expand Down

0 comments on commit 2a88ead

Please sign in to comment.