@@ -22,13 +22,18 @@ import { ChatWidget } from 'vs/workbench/contrib/chat/browser/chatWidget';
22
22
import { ChatModel } from 'vs/workbench/contrib/chat/common/chatModel' ;
23
23
import { IChatService } from 'vs/workbench/contrib/chat/common/chatService' ;
24
24
25
+ interface IChatQuickQuestionModeOptions {
26
+ renderInputOnTop : boolean ;
27
+ useDynamicMessageLayout : boolean ;
28
+ }
29
+
25
30
class BaseChatQuickQuestionMode implements IQuickQuestionMode {
26
31
private _currentTimer : any | undefined ;
27
32
private _input : IQuickPick < IQuickPickItem > | undefined ;
28
33
private _currentChat : QuickChat | undefined ;
29
34
30
35
constructor (
31
- private readonly renderInputOnTop : boolean
36
+ private readonly _options : IChatQuickQuestionModeOptions
32
37
) { }
33
38
34
39
run ( accessor : ServicesAccessor , query : string ) : void {
@@ -62,12 +67,17 @@ class BaseChatQuickQuestionMode implements IQuickQuestionMode {
62
67
this . _input . hideInput = true ;
63
68
64
69
65
- const containerList = dom . $ ( '.interactive-list' ) ;
66
- const containerSession = dom . $ ( '.interactive-session' , undefined , containerList ) ;
67
- containerSession . style . height = '500px' ;
68
- containerList . style . position = 'relative' ;
70
+ const containerSession = dom . $ ( '.interactive-session' ) ;
69
71
this . _input . widget = containerSession ;
70
72
73
+ this . _currentChat ??= instantiationService . createInstance ( QuickChat , {
74
+ providerId : providerInfo . id ,
75
+ ...this . _options
76
+ } ) ;
77
+ // show needs to come before the current chat rendering
78
+ this . _input . show ( ) ;
79
+ this . _currentChat . render ( containerSession ) ;
80
+
71
81
const clearButton = {
72
82
iconClass : ThemeIcon . asClassName ( Codicon . clearAll ) ,
73
83
tooltip : localize ( 'clear' , "Clear" ) ,
@@ -92,12 +102,6 @@ class BaseChatQuickQuestionMode implements IQuickQuestionMode {
92
102
93
103
//#endregion
94
104
95
- this . _currentChat ??= instantiationService . createInstance ( QuickChat , {
96
- providerId : providerInfo . id ,
97
- renderInputOnTop : this . renderInputOnTop ,
98
- } ) ;
99
- this . _currentChat . render ( containerSession ) ;
100
-
101
105
disposableStore . add ( this . _input . onDidAccept ( ( ) => {
102
106
this . _currentChat ?. acceptInput ( ) ;
103
107
} ) ) ;
@@ -110,7 +114,6 @@ class BaseChatQuickQuestionMode implements IQuickQuestionMode {
110
114
}
111
115
} ) ) ;
112
116
113
- this . _input . show ( ) ;
114
117
this . _currentChat . layout ( ) ;
115
118
this . _currentChat . focus ( ) ;
116
119
@@ -134,7 +137,7 @@ class QuickChat extends Disposable {
134
137
private _currentParentElement ?: HTMLElement ;
135
138
136
139
constructor (
137
- private readonly chatViewOptions : IChatViewOptions & { renderInputOnTop : boolean } ,
140
+ private readonly _options : IChatViewOptions & IChatQuickQuestionModeOptions ,
138
141
@IInstantiationService private readonly instantiationService : IInstantiationService ,
139
142
@IContextKeyService private readonly contextKeyService : IContextKeyService ,
140
143
@IChatService private readonly chatService : IChatService ,
@@ -157,14 +160,15 @@ class QuickChat extends Disposable {
157
160
}
158
161
159
162
render ( parent : HTMLElement ) : void {
160
- this . widget ?. dispose ( ) ;
161
163
this . _currentParentElement = parent ;
164
+ this . _scopedContextKeyService ?. dispose ( ) ;
162
165
this . _scopedContextKeyService = this . _register ( this . contextKeyService . createScoped ( parent ) ) ;
163
166
const scopedInstantiationService = this . instantiationService . createChild ( new ServiceCollection ( [ IContextKeyService , this . scopedContextKeyService ] ) ) ;
167
+ this . widget ?. dispose ( ) ;
164
168
this . widget = this . _register (
165
169
scopedInstantiationService . createInstance (
166
170
ChatWidget ,
167
- { resource : true , renderInputOnTop : this . chatViewOptions . renderInputOnTop } ,
171
+ { resource : true , renderInputOnTop : this . _options . renderInputOnTop } ,
168
172
{
169
173
listForeground : editorForeground ,
170
174
listBackground : editorBackground ,
@@ -173,6 +177,9 @@ class QuickChat extends Disposable {
173
177
} ) ) ;
174
178
this . widget . render ( parent ) ;
175
179
this . widget . setVisible ( true ) ;
180
+ if ( this . _options . useDynamicMessageLayout ) {
181
+ this . widget . setDynamicChatTreeItemLayout ( 2 , 600 ) ;
182
+ }
176
183
this . updateModel ( ) ;
177
184
if ( this . _currentQuery ) {
178
185
this . widget . inputEditor . setSelection ( {
@@ -203,7 +210,7 @@ class QuickChat extends Disposable {
203
210
}
204
211
205
212
async openChatView ( ) : Promise < void > {
206
- const widget = await this . _chatWidgetService . revealViewForProvider ( this . chatViewOptions . providerId ) ;
213
+ const widget = await this . _chatWidgetService . revealViewForProvider ( this . _options . providerId ) ;
207
214
if ( ! widget ?. viewModel || ! this . model ) {
208
215
return ;
209
216
}
@@ -233,13 +240,13 @@ class QuickChat extends Disposable {
233
240
}
234
241
235
242
layout ( ) : void {
236
- if ( this . _currentParentElement ) {
243
+ if ( ! this . _options . useDynamicMessageLayout && this . _currentParentElement ) {
237
244
this . widget . layout ( 500 , this . _currentParentElement . offsetWidth ) ;
238
245
}
239
246
}
240
247
241
248
private updateModel ( ) : void {
242
- this . model ??= this . chatService . startSession ( this . chatViewOptions . providerId , CancellationToken . None ) ;
249
+ this . model ??= this . chatService . startSession ( this . _options . providerId , CancellationToken . None ) ;
243
250
if ( ! this . model ) {
244
251
throw new Error ( 'Could not start chat session' ) ;
245
252
}
@@ -252,7 +259,10 @@ AskQuickQuestionAction.registerMode(
252
259
QuickQuestionMode . InputOnTopChat ,
253
260
class InputOnTopChatQuickQuestionMode extends BaseChatQuickQuestionMode {
254
261
constructor ( ) {
255
- super ( true ) ;
262
+ super ( {
263
+ renderInputOnTop : true ,
264
+ useDynamicMessageLayout : true
265
+ } ) ;
256
266
}
257
267
}
258
268
) ;
@@ -261,7 +271,10 @@ AskQuickQuestionAction.registerMode(
261
271
QuickQuestionMode . InputOnBottomChat ,
262
272
class InputOnBottomChatQuickQuestionMode extends BaseChatQuickQuestionMode {
263
273
constructor ( ) {
264
- super ( false ) ;
274
+ super ( {
275
+ renderInputOnTop : false ,
276
+ useDynamicMessageLayout : false
277
+ } ) ;
265
278
}
266
279
}
267
280
) ;
0 commit comments