@@ -22,13 +22,18 @@ import { ChatWidget } from 'vs/workbench/contrib/chat/browser/chatWidget';
2222import { ChatModel } from 'vs/workbench/contrib/chat/common/chatModel' ;
2323import { IChatService } from 'vs/workbench/contrib/chat/common/chatService' ;
2424
25+ interface IChatQuickQuestionModeOptions {
26+ renderInputOnTop : boolean ;
27+ useDynamicMessageLayout : boolean ;
28+ }
29+
2530class BaseChatQuickQuestionMode implements IQuickQuestionMode {
2631 private _currentTimer : any | undefined ;
2732 private _input : IQuickPick < IQuickPickItem > | undefined ;
2833 private _currentChat : QuickChat | undefined ;
2934
3035 constructor (
31- private readonly renderInputOnTop : boolean
36+ private readonly _options : IChatQuickQuestionModeOptions
3237 ) { }
3338
3439 run ( accessor : ServicesAccessor , query : string ) : void {
@@ -62,12 +67,17 @@ class BaseChatQuickQuestionMode implements IQuickQuestionMode {
6267 this . _input . hideInput = true ;
6368
6469
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' ) ;
6971 this . _input . widget = containerSession ;
7072
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+
7181 const clearButton = {
7282 iconClass : ThemeIcon . asClassName ( Codicon . clearAll ) ,
7383 tooltip : localize ( 'clear' , "Clear" ) ,
@@ -92,12 +102,6 @@ class BaseChatQuickQuestionMode implements IQuickQuestionMode {
92102
93103 //#endregion
94104
95- this . _currentChat ??= instantiationService . createInstance ( QuickChat , {
96- providerId : providerInfo . id ,
97- renderInputOnTop : this . renderInputOnTop ,
98- } ) ;
99- this . _currentChat . render ( containerSession ) ;
100-
101105 disposableStore . add ( this . _input . onDidAccept ( ( ) => {
102106 this . _currentChat ?. acceptInput ( ) ;
103107 } ) ) ;
@@ -110,7 +114,6 @@ class BaseChatQuickQuestionMode implements IQuickQuestionMode {
110114 }
111115 } ) ) ;
112116
113- this . _input . show ( ) ;
114117 this . _currentChat . layout ( ) ;
115118 this . _currentChat . focus ( ) ;
116119
@@ -134,7 +137,7 @@ class QuickChat extends Disposable {
134137 private _currentParentElement ?: HTMLElement ;
135138
136139 constructor (
137- private readonly chatViewOptions : IChatViewOptions & { renderInputOnTop : boolean } ,
140+ private readonly _options : IChatViewOptions & IChatQuickQuestionModeOptions ,
138141 @IInstantiationService private readonly instantiationService : IInstantiationService ,
139142 @IContextKeyService private readonly contextKeyService : IContextKeyService ,
140143 @IChatService private readonly chatService : IChatService ,
@@ -157,14 +160,15 @@ class QuickChat extends Disposable {
157160 }
158161
159162 render ( parent : HTMLElement ) : void {
160- this . widget ?. dispose ( ) ;
161163 this . _currentParentElement = parent ;
164+ this . _scopedContextKeyService ?. dispose ( ) ;
162165 this . _scopedContextKeyService = this . _register ( this . contextKeyService . createScoped ( parent ) ) ;
163166 const scopedInstantiationService = this . instantiationService . createChild ( new ServiceCollection ( [ IContextKeyService , this . scopedContextKeyService ] ) ) ;
167+ this . widget ?. dispose ( ) ;
164168 this . widget = this . _register (
165169 scopedInstantiationService . createInstance (
166170 ChatWidget ,
167- { resource : true , renderInputOnTop : this . chatViewOptions . renderInputOnTop } ,
171+ { resource : true , renderInputOnTop : this . _options . renderInputOnTop } ,
168172 {
169173 listForeground : editorForeground ,
170174 listBackground : editorBackground ,
@@ -173,6 +177,9 @@ class QuickChat extends Disposable {
173177 } ) ) ;
174178 this . widget . render ( parent ) ;
175179 this . widget . setVisible ( true ) ;
180+ if ( this . _options . useDynamicMessageLayout ) {
181+ this . widget . setDynamicChatTreeItemLayout ( 2 , 600 ) ;
182+ }
176183 this . updateModel ( ) ;
177184 if ( this . _currentQuery ) {
178185 this . widget . inputEditor . setSelection ( {
@@ -203,7 +210,7 @@ class QuickChat extends Disposable {
203210 }
204211
205212 async openChatView ( ) : Promise < void > {
206- const widget = await this . _chatWidgetService . revealViewForProvider ( this . chatViewOptions . providerId ) ;
213+ const widget = await this . _chatWidgetService . revealViewForProvider ( this . _options . providerId ) ;
207214 if ( ! widget ?. viewModel || ! this . model ) {
208215 return ;
209216 }
@@ -233,13 +240,13 @@ class QuickChat extends Disposable {
233240 }
234241
235242 layout ( ) : void {
236- if ( this . _currentParentElement ) {
243+ if ( ! this . _options . useDynamicMessageLayout && this . _currentParentElement ) {
237244 this . widget . layout ( 500 , this . _currentParentElement . offsetWidth ) ;
238245 }
239246 }
240247
241248 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 ) ;
243250 if ( ! this . model ) {
244251 throw new Error ( 'Could not start chat session' ) ;
245252 }
@@ -252,7 +259,10 @@ AskQuickQuestionAction.registerMode(
252259 QuickQuestionMode . InputOnTopChat ,
253260 class InputOnTopChatQuickQuestionMode extends BaseChatQuickQuestionMode {
254261 constructor ( ) {
255- super ( true ) ;
262+ super ( {
263+ renderInputOnTop : true ,
264+ useDynamicMessageLayout : true
265+ } ) ;
256266 }
257267 }
258268) ;
@@ -261,7 +271,10 @@ AskQuickQuestionAction.registerMode(
261271 QuickQuestionMode . InputOnBottomChat ,
262272 class InputOnBottomChatQuickQuestionMode extends BaseChatQuickQuestionMode {
263273 constructor ( ) {
264- super ( false ) ;
274+ super ( {
275+ renderInputOnTop : false ,
276+ useDynamicMessageLayout : false
277+ } ) ;
265278 }
266279 }
267280) ;
0 commit comments