Skip to content

Commit

Permalink
feat: dispose all diff previewer
Browse files Browse the repository at this point in the history
  • Loading branch information
bytemain committed Jul 5, 2024
1 parent bab2ec0 commit a86907e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class InlineChatController {

constructor(readonly options?: InlineChatControllerOptions) {}

public deffered: Deferred<void> = new Deferred();
public deferred: Deferred<void> = new Deferred();

private calculateCodeBlocks(content: string): string {
if (!this.options?.enableCodeblockRender) {
Expand Down Expand Up @@ -70,7 +70,7 @@ export class InlineChatController {
}

public async mountReadable(stream: SumiReadableStream<IChatProgress>): Promise<void> {
await this.deffered.promise;
await this.deferred.promise;
const reply = new ReplyResponse('');
let wholeContent = '';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
CancellationTokenSource,
ChatResponse,
Disposable,
Emitter,
ErrorResponse,
Event,
IAIReporter,
Expand Down Expand Up @@ -37,6 +38,7 @@ import {
} from '../inline-diff/inline-diff-previewer';
import { InlineDiffWidget } from '../inline-diff/inline-diff-widget';
import { InlineStreamDiffHandler } from '../inline-stream-diff/inline-stream-diff.handler';
import { IPartialEditEvent } from '../inline-stream-diff/live-preview.decoration';

import { InlineChatController } from './inline-chat-controller';
import { InlineChatFeatureRegistry } from './inline-chat.feature.registry';
Expand Down Expand Up @@ -72,6 +74,9 @@ export class InlineChatHandler extends Disposable {
@Autowired(CodeActionService)
private readonly codeActionService: CodeActionService;

private readonly _onPartialEditEvent = this.registerDispose(new Emitter<IPartialEditEvent>());
public readonly onPartialEditEvent: Event<IPartialEditEvent> = this._onPartialEditEvent.event;

private logger: ILogServiceClient;

private diffPreviewer: BaseInlineDiffPreviewer<InlineDiffWidget | InlineStreamDiffHandler>;
Expand Down Expand Up @@ -334,12 +339,21 @@ export class InlineChatHandler extends Disposable {
EInlineDiffPreviewMode.inlineLive,
);

if (!this.aiInlineChatDisposed.disposed) {
this.aiInlineChatDisposed.dispose();
}

if (inlineDiffMode === EInlineDiffPreviewMode.sideBySide) {
this.diffPreviewer = this.injector.get(SideBySideInlineDiffWidget, [monacoEditor, crossSelection]);
} else {
this.diffPreviewer = this.injector.get(LiveInlineDiffPreviewer, [monacoEditor, crossSelection]);
this.aiInlineChatDisposed.addDispose(
(this.diffPreviewer as LiveInlineDiffPreviewer).onPartialEditEvent((event) => {
this._onPartialEditEvent.fire(event);
}),
);
}

this.aiInlineChatDisposed.addDispose(this.diffPreviewer);
this.diffPreviewer.mount(this.aiInlineContentWidget);

this.diffPreviewer.show(
Expand All @@ -352,7 +366,7 @@ export class InlineChatHandler extends Disposable {

this.aiInlineChatOperationDisposed.addDispose(
this.diffPreviewer.onReady(() => {
controller.deffered.resolve();
controller.deferred.resolve();

this.aiInlineChatOperationDisposed.addDispose([
controller.onData((data) => {
Expand Down Expand Up @@ -444,10 +458,6 @@ export class InlineChatHandler extends Disposable {
);
}

get onPartialEditEvent() {
return (this.diffPreviewer as LiveInlineDiffPreviewer).onPartialEditEvent;
}

acceptAllPartialEdits() {
this.diffPreviewer.handleAction(EResultKind.ACCEPT);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export class InlineInputHandler extends Disposable {
if (InlineChatController.is(previewResponse)) {
const controller = previewResponse as InlineChatController;

controller.deffered.resolve();
controller.deferred.resolve();

inputDisposable.addDispose([
controller.onData(async (data) => {
Expand Down

0 comments on commit a86907e

Please sign in to comment.