Skip to content

Commit fdde488

Browse files
committed
Disable agent/command completions for none-panel locations. Add temp workaround for editor location
1 parent 7406bce commit fdde488

File tree

2 files changed

+55
-10
lines changed

2 files changed

+55
-10
lines changed

src/vs/workbench/contrib/chat/browser/contrib/chatInputEditorContrib.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ class SlashCommandCompletions extends Disposable {
276276
triggerCharacters: ['/'],
277277
provideCompletionItems: async (model: ITextModel, position: Position, _context: CompletionContext, _token: CancellationToken) => {
278278
const widget = this.chatWidgetService.getWidgetByInputUri(model.uri);
279-
if (!widget || !widget.viewModel) {
279+
if (!widget || !widget.viewModel || widget.location !== ChatAgentLocation.Panel /* TODO@jrieken - enable when agents are adopted*/) {
280280
return null;
281281
}
282282

@@ -331,7 +331,7 @@ class AgentCompletions extends Disposable {
331331
triggerCharacters: ['@'],
332332
provideCompletionItems: async (model: ITextModel, position: Position, _context: CompletionContext, _token: CancellationToken) => {
333333
const widget = this.chatWidgetService.getWidgetByInputUri(model.uri);
334-
if (!widget || !widget.viewModel) {
334+
if (!widget || !widget.viewModel || widget.location !== ChatAgentLocation.Panel /* TODO@jrieken - enable when agents are adopted*/) {
335335
return null;
336336
}
337337

@@ -376,7 +376,7 @@ class AgentCompletions extends Disposable {
376376
triggerCharacters: ['/'],
377377
provideCompletionItems: async (model: ITextModel, position: Position, _context: CompletionContext, token: CancellationToken) => {
378378
const widget = this.chatWidgetService.getWidgetByInputUri(model.uri);
379-
if (!widget || !widget.viewModel) {
379+
if (!widget || !widget.viewModel || widget.location !== ChatAgentLocation.Panel /* TODO@jrieken - enable when agents are adopted*/) {
380380
return;
381381
}
382382

@@ -428,7 +428,7 @@ class AgentCompletions extends Disposable {
428428
provideCompletionItems: async (model: ITextModel, position: Position, _context: CompletionContext, token: CancellationToken) => {
429429
const widget = this.chatWidgetService.getWidgetByInputUri(model.uri);
430430
const viewModel = widget?.viewModel;
431-
if (!widget || !viewModel) {
431+
if (!widget || !viewModel || widget.location !== ChatAgentLocation.Panel /* TODO@jrieken - enable when agents are adopted*/) {
432432
return;
433433
}
434434

@@ -523,7 +523,7 @@ class BuiltinDynamicCompletions extends Disposable {
523523
triggerCharacters: [chatVariableLeader],
524524
provideCompletionItems: async (model: ITextModel, position: Position, _context: CompletionContext, _token: CancellationToken) => {
525525
const widget = this.chatWidgetService.getWidgetByInputUri(model.uri);
526-
if (!widget || !widget.supportsFileReferences) {
526+
if (!widget || !widget.supportsFileReferences || widget.location !== ChatAgentLocation.Panel /* TODO@jrieken - enable when agents are adopted*/) {
527527
return null;
528528
}
529529

@@ -589,7 +589,7 @@ class VariableCompletions extends Disposable {
589589
provideCompletionItems: async (model: ITextModel, position: Position, _context: CompletionContext, _token: CancellationToken) => {
590590

591591
const widget = this.chatWidgetService.getWidgetByInputUri(model.uri);
592-
if (!widget) {
592+
if (!widget || widget.location !== ChatAgentLocation.Panel /* TODO@jrieken - enable when agents are adopted*/) {
593593
return null;
594594
}
595595

src/vs/workbench/contrib/inlineChat/browser/inlineChatController.ts

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { IPosition, Position } from 'vs/editor/common/core/position';
2020
import { IRange, Range } from 'vs/editor/common/core/range';
2121
import { ISelection, Selection } from 'vs/editor/common/core/selection';
2222
import { IEditorContribution } from 'vs/editor/common/editorCommon';
23-
import { TextEdit } from 'vs/editor/common/languages';
23+
import { CompletionItemKind, CompletionList, TextEdit } from 'vs/editor/common/languages';
2424
import { IEditorWorkerService } from 'vs/editor/common/services/editorWorker';
2525
import { InlineCompletionsController } from 'vs/editor/contrib/inlineCompletions/browser/inlineCompletionsController';
2626
import { localize } from 'vs/nls';
@@ -47,6 +47,9 @@ import { MessageController } from 'vs/editor/contrib/message/browser/messageCont
4747
import { tail } from 'vs/base/common/arrays';
4848
import { IChatRequestModel } from 'vs/workbench/contrib/chat/common/chatModel';
4949
import { InlineChatError } from 'vs/workbench/contrib/inlineChat/browser/inlineChatSessionServiceImpl';
50+
import { ILanguageFeaturesService } from 'vs/editor/common/services/languageFeatures';
51+
import { ChatInputPart } from 'vs/workbench/contrib/chat/browser/chatInputPart';
52+
import { OffsetRange } from 'vs/editor/common/core/offsetRange';
5053

5154
export const enum State {
5255
CREATE_SESSION = 'CREATE_SESSION',
@@ -144,6 +147,8 @@ export class InlineChatController implements IEditorContribution {
144147
@IChatService private readonly _chatService: IChatService,
145148
@IBulkEditService private readonly _bulkEditService: IBulkEditService,
146149
@ICommandService private readonly _commandService: ICommandService,
150+
@ILanguageFeaturesService private readonly _languageFeatureService: ILanguageFeaturesService,
151+
@IChatWidgetService private readonly _chatWidgetService: IChatWidgetService,
147152
) {
148153
this._ctxVisible = CTX_INLINE_CHAT_VISIBLE.bindTo(contextKeyService);
149154
this._ctxDidEdit = CTX_INLINE_CHAT_DID_EDIT.bindTo(contextKeyService);
@@ -427,6 +432,35 @@ export class InlineChatController implements IEditorContribution {
427432
}
428433
}));
429434

435+
// TODO@jrieken
436+
// REMOVE when agents are adopted
437+
this._sessionStore.add(this._languageFeatureService.completionProvider.register({ scheme: ChatInputPart.INPUT_SCHEME, hasAccessToAllModels: true }, {
438+
_debugDisplayName: 'inline chat commands',
439+
triggerCharacters: ['/'],
440+
provideCompletionItems: (model, position, context, token) => {
441+
442+
if (!this._session || !this._session.session.slashCommands) {
443+
return undefined;
444+
}
445+
const widget = this._chatWidgetService.getWidgetByInputUri(model.uri);
446+
if (widget !== this._zone.value.widget.chatWidget && widget !== this._input.value.chatWidget) {
447+
return undefined;
448+
}
449+
450+
const result: CompletionList = { suggestions: [], incomplete: false };
451+
for (const command of this._session.session.slashCommands) {
452+
const withSlash = `/${command.command}`;
453+
result.suggestions.push({
454+
label: { label: withSlash, description: command.detail ?? '' },
455+
kind: CompletionItemKind.Text,
456+
insertText: withSlash,
457+
range: Range.fromPositions(new Position(1, 1), position),
458+
});
459+
}
460+
461+
return result;
462+
}
463+
}));
430464
// Update context key
431465
this._ctxSupportIssueReporting.set(this._session.provider.supportIssueReporting ?? false);
432466

@@ -504,9 +538,20 @@ export class InlineChatController implements IEditorContribution {
504538
this._zone.value.widget.value = input;
505539

506540
// slash command referring
507-
const slashCommandLike = request.message.parts.find(part => part instanceof ChatRequestAgentSubcommandPart || part instanceof ChatRequestSlashCommandPart);
508-
const refer = slashCommandLike && this._session.session.slashCommands?.some(value => value.refer && slashCommandLike.text === `/${value.command}`);
509-
if (refer) {
541+
let slashCommandLike = request.message.parts.find(part => part instanceof ChatRequestAgentSubcommandPart || part instanceof ChatRequestSlashCommandPart);
542+
const refer = this._session.session.slashCommands?.some(value => {
543+
if (value.refer) {
544+
if (slashCommandLike?.text === `/${value.command}`) {
545+
return true;
546+
}
547+
if (request?.message.text.startsWith(`/${value.command}`)) {
548+
slashCommandLike = new ChatRequestSlashCommandPart(new OffsetRange(0, 1), new Range(1, 1, 1, 1), { command: value.command, detail: value.detail ?? '' });
549+
return true;
550+
}
551+
}
552+
return false;
553+
});
554+
if (refer && slashCommandLike) {
510555
this._log('[IE] seeing refer command, continuing outside editor', this._session.provider.extensionId);
511556

512557
// cancel this request

0 commit comments

Comments
 (0)