Skip to content

Commit f60a608

Browse files
authored
Implement '/clear' slash command (microsoft#178095)
1 parent 400369e commit f60a608

File tree

3 files changed

+30
-9
lines changed

3 files changed

+30
-9
lines changed

src/vs/workbench/contrib/interactiveSession/browser/contrib/interactiveSessionInputEditorContrib.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService
1010
import { Position } from 'vs/editor/common/core/position';
1111
import { Range } from 'vs/editor/common/core/range';
1212
import { IDecorationOptions } from 'vs/editor/common/editorCommon';
13-
import { CompletionContext, CompletionItem, CompletionList } from 'vs/editor/common/languages';
13+
import { CompletionContext, CompletionItem, CompletionItemKind, CompletionList } from 'vs/editor/common/languages';
1414
import { ITextModel } from 'vs/editor/common/model';
1515
import { ILanguageFeaturesService } from 'vs/editor/common/services/languageFeatures';
1616
import { localize } from 'vs/nls';
@@ -164,7 +164,8 @@ class SlashCommandCompletions extends Disposable {
164164
insertText: `${withSlash} `,
165165
detail: c.detail,
166166
range: new Range(1, 1, 1, 1),
167-
kind: c.kind,
167+
sortText: c.sortText ?? c.command,
168+
kind: CompletionItemKind.Text // The icons are disabled here anyway
168169
};
169170
})
170171
};

src/vs/workbench/contrib/interactiveSession/browser/interactiveSessionWidget.ts

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,19 @@ export class InteractiveSessionWidget extends Disposable implements IInteractive
261261
}
262262

263263
if (!this.slashCommandsPromise) {
264-
this.slashCommandsPromise = this.interactiveSessionService.getSlashCommands(this.viewModel.sessionId, CancellationToken.None);
265-
this.slashCommandsPromise.then(commands => this.lastSlashCommands = commands);
264+
this.slashCommandsPromise = this.interactiveSessionService.getSlashCommands(this.viewModel.sessionId, CancellationToken.None).then(commands => {
265+
// If this becomes a repeated pattern, we should have a real internal slash command provider system
266+
const clearCommand: IInteractiveSlashCommand = {
267+
command: 'clear',
268+
sortText: 'z_clear',
269+
detail: localize('clear', "Clear the session"),
270+
};
271+
this.lastSlashCommands = [
272+
...(commands ?? []),
273+
clearCommand
274+
];
275+
return this.lastSlashCommands;
276+
});
266277
}
267278

268279
return this.slashCommandsPromise;
@@ -513,12 +524,21 @@ export class InteractiveSessionWidget extends Disposable implements IInteractive
513524
}
514525

515526
if (this.viewModel) {
516-
if (!query && this._inputEditor.getValue()) {
527+
const editorValue = this._inputEditor.getValue();
528+
if (!query && editorValue) {
517529
// Followups and programmatic messages don't go to history
518-
this.history.add(this._inputEditor.getValue());
530+
this.history.add(editorValue);
531+
}
532+
533+
// Shortcut for /clear command
534+
if (!query && editorValue.trim() === '/clear') {
535+
// If this becomes a repeated pattern, we should have a real internal slash command provider system
536+
this.clear();
537+
this._inputEditor.setValue('');
538+
return;
519539
}
520540

521-
const input = query ?? this._inputEditor.getValue();
541+
const input = query ?? editorValue;
522542
const result = this.interactiveSessionService.sendRequest(this.viewModel.sessionId, input);
523543
if (result) {
524544
this.requestInProgress.set(true);

src/vs/workbench/contrib/interactiveSession/common/interactiveSessionService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { CancellationToken } from 'vs/base/common/cancellation';
77
import { Event } from 'vs/base/common/event';
88
import { IDisposable } from 'vs/base/common/lifecycle';
99
import { URI } from 'vs/base/common/uri';
10-
import { CompletionItemKind, ProviderResult } from 'vs/editor/common/languages';
10+
import { ProviderResult } from 'vs/editor/common/languages';
1111
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
1212
import { InteractiveSessionModel } from 'vs/workbench/contrib/interactiveSession/common/interactiveSessionModel';
1313

@@ -60,7 +60,7 @@ export interface IInteractiveProvider {
6060

6161
export interface IInteractiveSlashCommand {
6262
command: string;
63-
kind: CompletionItemKind;
63+
sortText?: string;
6464
detail?: string;
6565
}
6666

0 commit comments

Comments
 (0)