Skip to content

Commit

Permalink
Merge pull request microsoft#235510 from microsoft/joh/irrelevant-worm
Browse files Browse the repository at this point in the history
chore - remove `IChatEditingService#onDidCreateEditingSession` in favor of `currentEditingSessionObs`
  • Loading branch information
jrieken authored Dec 6, 2024
2 parents 17f6bcb + 2ccf448 commit bf96ce3
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
*--------------------------------------------------------------------------------------------*/

import { Codicon } from '../../../../../base/common/codicons.js';
import { Event } from '../../../../../base/common/event.js';
import { KeyCode, KeyMod } from '../../../../../base/common/keyCodes.js';
import { DisposableStore } from '../../../../../base/common/lifecycle.js';
import { ResourceSet } from '../../../../../base/common/map.js';
import { marked } from '../../../../../base/common/marked/marked.js';
import { waitForState } from '../../../../../base/common/observable.js';
import { basename } from '../../../../../base/common/resources.js';
import { URI } from '../../../../../base/common/uri.js';
import { ServicesAccessor } from '../../../../../editor/browser/editorExtensions.js';
Expand Down Expand Up @@ -465,9 +465,7 @@ export function registerChatTitleActions() {

let editingSession = chatEditingService.currentEditingSessionObs.get();
if (!editingSession) {
await Event.toPromise(chatEditingService.onDidCreateEditingSession);
editingSession = chatEditingService.currentEditingSessionObs.get();
return;
editingSession = await waitForState(chatEditingService.currentEditingSessionObs);
}

if (!editingSession) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,6 @@ export class ChatEditingService extends Disposable implements IChatEditingServic
return this._currentSessionObs;
}

private readonly _onDidCreateEditingSession = this._register(new Emitter<IChatEditingSession>());
get onDidCreateEditingSession() {
return this._onDidCreateEditingSession.event;
}

private readonly _onDidChangeEditingSession = this._register(new Emitter<void>());
public readonly onDidChangeEditingSession = this._onDidChangeEditingSession.event;

Expand Down Expand Up @@ -220,7 +215,6 @@ export class ChatEditingService extends Disposable implements IChatEditingServic
}));

this._currentSessionObs.set(session, undefined);
this._onDidCreateEditingSession.fire(session);
this._onDidChangeEditingSession.fire();
return session;
}
Expand Down
7 changes: 6 additions & 1 deletion src/vs/workbench/contrib/chat/browser/chatWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { MarkdownString } from '../../../../base/common/htmlContent.js';
import { Disposable, DisposableStore, IDisposable, MutableDisposable, combinedDisposable, toDisposable } from '../../../../base/common/lifecycle.js';
import { ResourceSet } from '../../../../base/common/map.js';
import { Schemas } from '../../../../base/common/network.js';
import { autorun } from '../../../../base/common/observable.js';
import { extUri, isEqual } from '../../../../base/common/resources.js';
import { isDefined } from '../../../../base/common/types.js';
import { URI } from '../../../../base/common/uri.js';
Expand Down Expand Up @@ -250,7 +251,11 @@ export class ChatWidget extends Disposable implements IChatWidget {

const chatEditingSessionDisposables = this._register(new DisposableStore());

this._register(this.chatEditingService.onDidCreateEditingSession((session) => {
this._register(autorun(r => {
const session = this.chatEditingService.currentEditingSessionObs.read(r);
if (!session) {
return;
}
if (session.chatSessionId !== this.viewModel?.sessionId) {
// this chat editing session is for a different chat widget
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ import { CancellationToken } from '../../../../../base/common/cancellation.js';
import { Event } from '../../../../../base/common/event.js';
import { Disposable, DisposableStore } from '../../../../../base/common/lifecycle.js';
import { ResourceMap } from '../../../../../base/common/map.js';
import { autorun } from '../../../../../base/common/observable.js';
import { URI } from '../../../../../base/common/uri.js';
import { localize } from '../../../../../nls.js';
import { IWorkbenchContribution } from '../../../../common/contributions.js';
import { ChatEditingSessionChangeType, IChatEditingService, WorkingSetEntryRemovalReason, WorkingSetEntryState } from '../../common/chatEditingService.js';
import { ChatEditingSessionChangeType, IChatEditingService, IChatEditingSession, WorkingSetEntryRemovalReason, WorkingSetEntryState } from '../../common/chatEditingService.js';
import { IChatWidgetService } from '../chat.js';

export class ChatRelatedFilesContribution extends Disposable implements IWorkbenchContribution {
Expand All @@ -25,10 +26,12 @@ export class ChatRelatedFilesContribution extends Disposable implements IWorkben
) {
super();

this._handleNewEditingSession();
this._register(this.chatEditingService.onDidCreateEditingSession(() => {
this._register(autorun(r => {
this.chatEditingSessionDisposables.clear();
this._handleNewEditingSession();
const session = this.chatEditingService.currentEditingSessionObs.read(r);
if (session) {
this._handleNewEditingSession(session);
}
}));
}

Expand Down Expand Up @@ -95,11 +98,8 @@ export class ChatRelatedFilesContribution extends Disposable implements IWorkben

}

private _handleNewEditingSession() {
const currentEditingSession = this.chatEditingService.currentEditingSessionObs.get();
if (!currentEditingSession) {
return;
}
private _handleNewEditingSession(currentEditingSession: IChatEditingSession) {

const widget = this.chatWidgetService.getWidgetBySessionId(currentEditingSession.chatSessionId);
if (!widget || widget.viewModel?.sessionId !== currentEditingSession.chatSessionId) {
return;
Expand Down
1 change: 0 additions & 1 deletion src/vs/workbench/contrib/chat/common/chatEditingService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export interface IChatEditingService {

_serviceBrand: undefined;

readonly onDidCreateEditingSession: Event<IChatEditingSession>;
/**
* emitted when a session is created, changed or disposed
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ import { IChatEditingService, IChatEditingSession } from '../../../chat/common/c
import { ITextModelService } from '../../../../../editor/common/services/resolverService.js';
import { TextModelResolverService } from '../../../../services/textmodelResolver/common/textModelResolverService.js';
import { ChatInputBoxContentProvider } from '../../../chat/browser/chatEdinputInputContentProvider.js';
import { IObservable, observableValue } from '../../../../../base/common/observable.js';

suite('InlineChatController', function () {

Expand Down Expand Up @@ -162,7 +163,7 @@ suite('InlineChatController', function () {
[IInlineChatSessionService, new SyncDescriptor(InlineChatSessionServiceImpl)],
[ICommandService, new SyncDescriptor(TestCommandService)],
[IChatEditingService, new class extends mock<IChatEditingService>() {
override onDidCreateEditingSession: Event<IChatEditingSession> = Event.None;
override currentEditingSessionObs: IObservable<IChatEditingSession | null> = observableValue(this, null);
}],
[IInlineChatSavingService, new class extends mock<IInlineChatSavingService>() {
override markChanged(session: Session): void {
Expand Down

0 comments on commit bf96ce3

Please sign in to comment.