@@ -20,7 +20,7 @@ import { IPosition, Position } from 'vs/editor/common/core/position';
20
20
import { IRange , Range } from 'vs/editor/common/core/range' ;
21
21
import { ISelection , Selection } from 'vs/editor/common/core/selection' ;
22
22
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' ;
24
24
import { IEditorWorkerService } from 'vs/editor/common/services/editorWorker' ;
25
25
import { InlineCompletionsController } from 'vs/editor/contrib/inlineCompletions/browser/inlineCompletionsController' ;
26
26
import { localize } from 'vs/nls' ;
@@ -47,6 +47,9 @@ import { MessageController } from 'vs/editor/contrib/message/browser/messageCont
47
47
import { tail } from 'vs/base/common/arrays' ;
48
48
import { IChatRequestModel } from 'vs/workbench/contrib/chat/common/chatModel' ;
49
49
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' ;
50
53
51
54
export const enum State {
52
55
CREATE_SESSION = 'CREATE_SESSION' ,
@@ -144,6 +147,8 @@ export class InlineChatController implements IEditorContribution {
144
147
@IChatService private readonly _chatService : IChatService ,
145
148
@IBulkEditService private readonly _bulkEditService : IBulkEditService ,
146
149
@ICommandService private readonly _commandService : ICommandService ,
150
+ @ILanguageFeaturesService private readonly _languageFeatureService : ILanguageFeaturesService ,
151
+ @IChatWidgetService private readonly _chatWidgetService : IChatWidgetService ,
147
152
) {
148
153
this . _ctxVisible = CTX_INLINE_CHAT_VISIBLE . bindTo ( contextKeyService ) ;
149
154
this . _ctxDidEdit = CTX_INLINE_CHAT_DID_EDIT . bindTo ( contextKeyService ) ;
@@ -427,6 +432,35 @@ export class InlineChatController implements IEditorContribution {
427
432
}
428
433
} ) ) ;
429
434
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
+ } ) ) ;
430
464
// Update context key
431
465
this . _ctxSupportIssueReporting . set ( this . _session . provider . supportIssueReporting ?? false ) ;
432
466
@@ -504,9 +538,20 @@ export class InlineChatController implements IEditorContribution {
504
538
this . _zone . value . widget . value = input ;
505
539
506
540
// 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 ) {
510
555
this . _log ( '[IE] seeing refer command, continuing outside editor' , this . _session . provider . extensionId ) ;
511
556
512
557
// cancel this request
0 commit comments