mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-23 01:58:53 +01:00
edits fixes (#238826)
one inline chat session per file, fix revealing for 1+n requests
This commit is contained in:
@@ -51,6 +51,8 @@ export class InlineChatController2 implements IEditorContribution {
|
||||
|
||||
|
||||
private readonly _showWidgetOverrideObs = observableValue(this, false);
|
||||
private readonly _isActiveController = observableValue(this, false);
|
||||
|
||||
|
||||
constructor(
|
||||
private readonly _editor: ICodeEditor,
|
||||
@@ -114,7 +116,7 @@ export class InlineChatController2 implements IEditorContribution {
|
||||
const sessionObs = derived(r => {
|
||||
sessionsSignal.read(r);
|
||||
const model = editorObs.model.read(r);
|
||||
const value = model && inlineChatSessions.getSession2(_editor, model.uri);
|
||||
const value = model && inlineChatSessions.getSession2(model.uri);
|
||||
return value ?? undefined;
|
||||
});
|
||||
|
||||
@@ -124,6 +126,7 @@ export class InlineChatController2 implements IEditorContribution {
|
||||
|
||||
if (!session) {
|
||||
ctxHasSession.set(undefined);
|
||||
this._isActiveController.set(false, undefined);
|
||||
} else {
|
||||
const checkRequests = () => ctxHasSession.set(session.chatModel.getRequests().length === 0 ? 'empty' : 'active');
|
||||
store.add(session.chatModel.onDidChange(checkRequests));
|
||||
@@ -136,8 +139,9 @@ export class InlineChatController2 implements IEditorContribution {
|
||||
this._store.add(autorunWithStore((r, store) => {
|
||||
|
||||
const session = sessionObs.read(r);
|
||||
const isActive = this._isActiveController.read(r);
|
||||
|
||||
if (!session) {
|
||||
if (!session || !isActive) {
|
||||
visibleSessionObs.set(undefined, undefined);
|
||||
return;
|
||||
}
|
||||
@@ -214,6 +218,10 @@ export class InlineChatController2 implements IEditorContribution {
|
||||
const value = this._showWidgetOverrideObs.get();
|
||||
this._showWidgetOverrideObs.set(!value, undefined);
|
||||
}
|
||||
|
||||
markActiveController() {
|
||||
this._isActiveController.set(true, undefined);
|
||||
}
|
||||
}
|
||||
|
||||
export class StartSessionAction2 extends EditorAction2 {
|
||||
@@ -251,6 +259,7 @@ export class StartSessionAction2 extends EditorAction2 {
|
||||
}
|
||||
const textModel = editor.getModel();
|
||||
await inlineChatSessions.createSession2(editor, textModel.uri, CancellationToken.None);
|
||||
InlineChatController2.get(editor)?.markActiveController();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -326,7 +335,7 @@ export class StopSessionAction2 extends AbstractInlineChatAction {
|
||||
return;
|
||||
}
|
||||
const textModel = editor.getModel();
|
||||
inlineChatSessions.getSession2(editor, textModel.uri)?.dispose();
|
||||
inlineChatSessions.getSession2(textModel.uri)?.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -356,8 +365,9 @@ class RevealWidget extends AbstractInlineChatAction {
|
||||
});
|
||||
}
|
||||
|
||||
runInlineChatCommand(accessor: ServicesAccessor, ctrl: InlineChatController2, editor: ICodeEditor, ...args: any[]): void {
|
||||
runInlineChatCommand(_accessor: ServicesAccessor, ctrl: InlineChatController2, _editor: ICodeEditor): void {
|
||||
ctrl.toggleWidgetUntilNextRequest();
|
||||
ctrl.markActiveController();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -64,6 +64,6 @@ export interface IInlineChatSessionService {
|
||||
|
||||
|
||||
createSession2(editor: ICodeEditor, uri: URI, token: CancellationToken): Promise<IInlineChatSession2>;
|
||||
getSession2(editor: ICodeEditor, uri: URI): IInlineChatSession2 | undefined;
|
||||
getSession2(uri: URI): IInlineChatSession2 | undefined;
|
||||
onDidChangeSessions: Event<this>;
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ import { ITextFileService } from '../../../services/textfile/common/textfiles.js
|
||||
import { IChatEditingService, WorkingSetEntryState } from '../../chat/common/chatEditingService.js';
|
||||
import { assertType } from '../../../../base/common/types.js';
|
||||
import { autorun } from '../../../../base/common/observable.js';
|
||||
import { ResourceMap } from '../../../../base/common/map.js';
|
||||
|
||||
|
||||
type SessionData = {
|
||||
@@ -318,7 +319,7 @@ export class InlineChatSessionServiceImpl implements IInlineChatSessionService {
|
||||
|
||||
// ---- NEW
|
||||
|
||||
private readonly _sessions2 = new Map<string, IInlineChatSession2>();
|
||||
private readonly _sessions2 = new ResourceMap<IInlineChatSession2>();
|
||||
|
||||
private readonly _onDidChangeSessions = this._store.add(new Emitter<this>());
|
||||
readonly onDidChangeSessions: Event<this> = this._onDidChangeSessions.event;
|
||||
@@ -328,8 +329,7 @@ export class InlineChatSessionServiceImpl implements IInlineChatSessionService {
|
||||
|
||||
assertType(editor.hasModel());
|
||||
|
||||
const key = this._key(editor, uri);
|
||||
if (this._sessions2.has(key)) {
|
||||
if (this._sessions2.has(uri)) {
|
||||
throw new Error('Session already exists');
|
||||
}
|
||||
|
||||
@@ -343,7 +343,7 @@ export class InlineChatSessionServiceImpl implements IInlineChatSessionService {
|
||||
const store = new DisposableStore();
|
||||
store.add(toDisposable(() => {
|
||||
editingSession.reject();
|
||||
this._sessions2.delete(key);
|
||||
this._sessions2.delete(uri);
|
||||
this._onDidChangeSessions.fire(this);
|
||||
}));
|
||||
store.add(editingSession);
|
||||
@@ -365,14 +365,13 @@ export class InlineChatSessionServiceImpl implements IInlineChatSessionService {
|
||||
editingSession,
|
||||
dispose: store.dispose.bind(store)
|
||||
};
|
||||
this._sessions2.set(key, result);
|
||||
this._sessions2.set(uri, result);
|
||||
this._onDidChangeSessions.fire(this);
|
||||
return result;
|
||||
}
|
||||
|
||||
getSession2(editor: ICodeEditor, uri: URI): IInlineChatSession2 | undefined {
|
||||
const key = this._key(editor, uri);
|
||||
return this._sessions2.get(key);
|
||||
getSession2(uri: URI): IInlineChatSession2 | undefined {
|
||||
return this._sessions2.get(uri);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user