@@ -26,6 +26,7 @@ import { ChatModel, IChatResponseModel } from '../../../chat/common/chatModel.js
26
26
import { IChatService , IChatProgress } from '../../../chat/common/chatService.js' ;
27
27
import { CancellationTokenSource } from '../../../../../base/common/cancellation.js' ;
28
28
import { MenuId } from '../../../../../platform/actions/common/actions.js' ;
29
+ import type { IChatViewState } from '../../../chat/browser/chatWidget.js' ;
29
30
30
31
const enum Constants {
31
32
HorizontalMargin = 10 ,
@@ -65,7 +66,8 @@ export class TerminalChatWidget extends Disposable {
65
66
66
67
private _messages = this . _store . add ( new Emitter < Message > ( ) ) ;
67
68
68
- private _storageKey = 'terminal-inline-chat-history' ;
69
+ private _historyStorageKey = 'terminal-inline-chat-history' ;
70
+ private _viewStateStorageKey = 'terminal-inline-chat-view-state' ;
69
71
private _promptHistory : string [ ] = [ ] ;
70
72
71
73
private _lastResponseContent : string | undefined ;
@@ -137,6 +139,7 @@ export class TerminalChatWidget extends Disposable {
137
139
}
138
140
} ,
139
141
) ;
142
+ this . _register ( this . _inlineChatWidget . chatWidget . onDidChangeViewModel ( ( ) => this . _saveViewState ( ) ) ) ;
140
143
this . _register ( Event . any (
141
144
this . _inlineChatWidget . onDidChangeHeight ,
142
145
this . _instance . onDimensionsChanged ,
@@ -161,7 +164,7 @@ export class TerminalChatWidget extends Disposable {
161
164
this . _responseContainsCodeBlockContextKey = TerminalChatContextKeys . responseContainsCodeBlock . bindTo ( this . _contextKeyService ) ;
162
165
this . _responseContainsMulitpleCodeBlocksContextKey = TerminalChatContextKeys . responseContainsMultipleCodeBlocks . bindTo ( this . _contextKeyService ) ;
163
166
164
- this . _promptHistory = JSON . parse ( this . _storageService . get ( this . _storageKey , StorageScope . PROFILE , '[]' ) ) ;
167
+ this . _promptHistory = JSON . parse ( this . _storageService . get ( this . _historyStorageKey , StorageScope . PROFILE , '[]' ) ) ;
165
168
this . _historyUpdate = ( prompt : string ) => {
166
169
const idx = this . _promptHistory . indexOf ( prompt ) ;
167
170
if ( idx >= 0 ) {
@@ -170,7 +173,7 @@ export class TerminalChatWidget extends Disposable {
170
173
this . _promptHistory . unshift ( prompt ) ;
171
174
this . _historyOffset = - 1 ;
172
175
this . _historyCandidate = '' ;
173
- this . _storageService . store ( this . _storageKey , JSON . stringify ( this . _promptHistory ) , StorageScope . PROFILE , StorageTarget . USER ) ;
176
+ this . _storageService . store ( this . _historyStorageKey , JSON . stringify ( this . _promptHistory ) , StorageScope . PROFILE , StorageTarget . USER ) ;
174
177
} ;
175
178
}
176
179
@@ -217,8 +220,8 @@ export class TerminalChatWidget extends Disposable {
217
220
this . _inlineChatWidget . updateInfo ( localize ( 'welcome.1' , "AI-generated commands may be incorrect" ) ) ;
218
221
}
219
222
220
- async reveal ( ) : Promise < void > {
221
- await this . _createSession ( ) ;
223
+ async reveal ( viewState ?: IChatViewState ) : Promise < void > {
224
+ await this . _createSession ( viewState ) ;
222
225
this . _doLayout ( this . _inlineChatWidget . contentHeight ) ;
223
226
this . _container . classList . remove ( 'hide' ) ;
224
227
this . _visibleContextKey . set ( true ) ;
@@ -310,13 +313,13 @@ export class TerminalChatWidget extends Disposable {
310
313
return this . _focusTracker ;
311
314
}
312
315
313
- private async _createSession ( ) : Promise < void > {
316
+ private async _createSession ( viewState ?: IChatViewState ) : Promise < void > {
314
317
this . _sessionCtor = createCancelablePromise < void > ( async token => {
315
318
if ( ! this . _model . value ) {
316
319
this . _model . value = this . _chatService . startSession ( ChatAgentLocation . Terminal , token ) ;
317
320
const model = this . _model . value ;
318
321
if ( model ) {
319
- this . _inlineChatWidget . setChatModel ( model ) ;
322
+ this . _inlineChatWidget . setChatModel ( model , this . _loadViewState ( ) ) ;
320
323
}
321
324
if ( ! this . _model . value ) {
322
325
throw new Error ( 'Failed to start chat session' ) ;
@@ -326,6 +329,23 @@ export class TerminalChatWidget extends Disposable {
326
329
this . _register ( toDisposable ( ( ) => this . _sessionCtor ?. cancel ( ) ) ) ;
327
330
}
328
331
332
+ private _loadViewState ( ) {
333
+ const rawViewState = this . _storageService . get ( this . _viewStateStorageKey , StorageScope . PROFILE , undefined ) ;
334
+ let viewState : IChatViewState | undefined ;
335
+ if ( rawViewState ) {
336
+ try {
337
+ viewState = JSON . parse ( rawViewState ) ;
338
+ } catch {
339
+ viewState = undefined ;
340
+ }
341
+ }
342
+ return viewState ;
343
+ }
344
+
345
+ private _saveViewState ( ) {
346
+ this . _storageService . store ( this . _viewStateStorageKey , JSON . stringify ( this . _inlineChatWidget . chatWidget . getViewState ( ) ) , StorageScope . PROFILE , StorageTarget . USER ) ;
347
+ }
348
+
329
349
private _forcedPlaceholder : string | undefined = undefined ;
330
350
331
351
private _updatePlaceholder ( ) : void {
0 commit comments