Skip to content

Commit 0284236

Browse files
author
Rachel Macfarlane
authored
Fix #74668, old comment API not adding comments
1 parent d89187e commit 0284236

File tree

5 files changed

+49
-0
lines changed

5 files changed

+49
-0
lines changed

src/vs/workbench/api/browser/mainThreadComments.ts

+23
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,9 @@ export class MainThreadComments extends Disposable implements MainThreadComments
469469
private _handlers = new Map<number, string>();
470470
private _commentControllers = new Map<number, MainThreadCommentController>();
471471

472+
private _activeCommentThread?: MainThreadCommentThread;
473+
private _input?: modes.CommentInput;
474+
472475
private _openPanelListener: IDisposable | null;
473476

474477
constructor(
@@ -483,6 +486,26 @@ export class MainThreadComments extends Disposable implements MainThreadComments
483486
this._disposables = [];
484487
this._activeCommentThreadDisposables = [];
485488
this._proxy = extHostContext.getProxy(ExtHostContext.ExtHostComments);
489+
490+
this._disposables.push(this._commentService.onDidChangeActiveCommentThread(async thread => {
491+
let handle = (thread as MainThreadCommentThread).controllerHandle;
492+
let controller = this._commentControllers.get(handle);
493+
494+
if (!controller) {
495+
return;
496+
}
497+
498+
this._activeCommentThreadDisposables = dispose(this._activeCommentThreadDisposables);
499+
this._activeCommentThread = thread as MainThreadCommentThread;
500+
controller.activeCommentThread = this._activeCommentThread;
501+
502+
this._activeCommentThreadDisposables.push(this._activeCommentThread.onDidChangeInput(input => { // todo, dispose
503+
this._input = input;
504+
this._proxy.$onCommentWidgetInputChange(handle, URI.parse(this._activeCommentThread!.resource), this._activeCommentThread!.range, this._input ? this._input.value : undefined);
505+
}));
506+
507+
await this._proxy.$onCommentWidgetInputChange(controller.handle, URI.parse(this._activeCommentThread!.resource), this._activeCommentThread.range, this._input ? this._input.value : undefined);
508+
}));
486509
}
487510

488511
$registerCommentController(handle: number, id: string, label: string): void {

src/vs/workbench/browser/web.simpleservices.ts

+2
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,7 @@ export class SimpleCommentService implements ICommentService {
619619
onDidSetAllCommentThreads: Event<IWorkspaceCommentThreadsEvent> = Event.None;
620620
onDidUpdateCommentThreads: Event<ICommentThreadChangedEvent> = Event.None;
621621
onDidChangeActiveCommentingRange: Event<{ range: Range; commentingRangesInfo: CommentingRanges; }> = Event.None;
622+
onDidChangeActiveCommentThread: Event<any> = Event.None;
622623
onDidSetDataProvider: Event<void> = Event.None;
623624
onDidDeleteDataProvider: Event<string> = Event.None;
624625
setDocumentComments: any;
@@ -649,6 +650,7 @@ export class SimpleCommentService implements ICommentService {
649650
deleteReaction: any;
650651
getReactionGroup: any;
651652
toggleReaction: any;
653+
setActiveCommentThread: any;
652654
}
653655
registerSingleton(ICommentService, SimpleCommentService, true);
654656
//#endregion

src/vs/workbench/contrib/comments/browser/commentNode.ts

+5
Original file line numberDiff line numberDiff line change
@@ -424,12 +424,14 @@ export class CommentNode extends Disposable {
424424
uri: this._commentEditor.getModel()!.uri,
425425
value: this.comment.body.value
426426
};
427+
this.commentService.setActiveCommentThread(commentThread);
427428

428429
this._commentEditorDisposables.push(this._commentEditor.onDidFocusEditorWidget(() => {
429430
commentThread.input = {
430431
uri: this._commentEditor!.getModel()!.uri,
431432
value: this.comment.body.value
432433
};
434+
this.commentService.setActiveCommentThread(commentThread);
433435
}));
434436

435437
this._commentEditorDisposables.push(this._commentEditor.onDidChangeModelContent(e => {
@@ -439,6 +441,7 @@ export class CommentNode extends Disposable {
439441
let input = commentThread.input;
440442
input.value = newVal;
441443
commentThread.input = input;
444+
this.commentService.setActiveCommentThread(commentThread);
442445
}
443446
}
444447
}));
@@ -486,6 +489,7 @@ export class CommentNode extends Disposable {
486489
uri: this._commentEditor.getModel()!.uri,
487490
value: newBody
488491
};
492+
this.commentService.setActiveCommentThread(commentThread);
489493
let commandId = this.comment.editCommand.id;
490494
let args = this.comment.editCommand.arguments || [];
491495

@@ -523,6 +527,7 @@ export class CommentNode extends Disposable {
523527
if (result.confirmed) {
524528
try {
525529
if (this.comment.deleteCommand) {
530+
this.commentService.setActiveCommentThread(this.commentThread);
526531
let commandId = this.comment.deleteCommand.id;
527532
let args = this.comment.deleteCommand.arguments || [];
528533

src/vs/workbench/contrib/comments/browser/commentService.ts

+9
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export interface ICommentService {
3838
readonly onDidSetResourceCommentInfos: Event<IResourceCommentThreadEvent>;
3939
readonly onDidSetAllCommentThreads: Event<IWorkspaceCommentThreadsEvent>;
4040
readonly onDidUpdateCommentThreads: Event<ICommentThreadChangedEvent>;
41+
readonly onDidChangeActiveCommentThread: Event<CommentThread | null>;
4142
readonly onDidChangeActiveCommentingRange: Event<{ range: Range, commentingRangesInfo: CommentingRanges }>;
4243
readonly onDidSetDataProvider: Event<void>;
4344
readonly onDidDeleteDataProvider: Event<string>;
@@ -69,6 +70,7 @@ export interface ICommentService {
6970
deleteReaction(owner: string, resource: URI, comment: Comment, reaction: CommentReaction): Promise<void>;
7071
getReactionGroup(owner: string): CommentReaction[] | undefined;
7172
toggleReaction(owner: string, resource: URI, thread: CommentThread2, comment: Comment, reaction: CommentReaction): Promise<void>;
73+
setActiveCommentThread(commentThread: CommentThread | null): void;
7274
}
7375

7476
export class CommentService extends Disposable implements ICommentService {
@@ -89,6 +91,9 @@ export class CommentService extends Disposable implements ICommentService {
8991
private readonly _onDidUpdateCommentThreads: Emitter<ICommentThreadChangedEvent> = this._register(new Emitter<ICommentThreadChangedEvent>());
9092
readonly onDidUpdateCommentThreads: Event<ICommentThreadChangedEvent> = this._onDidUpdateCommentThreads.event;
9193

94+
private readonly _onDidChangeActiveCommentThread = this._register(new Emitter<CommentThread | null>());
95+
readonly onDidChangeActiveCommentThread = this._onDidChangeActiveCommentThread.event;
96+
9297
private readonly _onDidChangeActiveCommentingRange: Emitter<{
9398
range: Range, commentingRangesInfo:
9499
CommentingRanges
@@ -109,6 +114,10 @@ export class CommentService extends Disposable implements ICommentService {
109114
super();
110115
}
111116

117+
setActiveCommentThread(commentThread: CommentThread | null) {
118+
this._onDidChangeActiveCommentThread.fire(commentThread);
119+
}
120+
112121
setDocumentComments(resource: URI, commentInfos: ICommentInfo[]): void {
113122
this._onDidSetResourceCommentInfos.fire({ resource, commentInfos });
114123
}

src/vs/workbench/contrib/comments/browser/commentThreadWidget.ts

+10
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,10 @@ export class ReviewZoneWidget extends ZoneWidget implements ICommentThreadWidget
211211

212212
this._bodyElement = <HTMLDivElement>dom.$('.body');
213213
container.appendChild(this._bodyElement);
214+
215+
dom.addDisposableListener(this._bodyElement, dom.EventType.FOCUS_IN, e => {
216+
this.commentService.setActiveCommentThread(this._commentThread);
217+
});
214218
}
215219

216220
protected _fillHead(container: HTMLElement): void {
@@ -265,6 +269,7 @@ export class ReviewZoneWidget extends ZoneWidget implements ICommentThreadWidget
265269
} else {
266270
const deleteCommand = (this._commentThread as modes.CommentThread2).deleteCommand;
267271
if (deleteCommand) {
272+
this.commentService.setActiveCommentThread(this._commentThread);
268273
return this.commandService.executeCommand(deleteCommand.id, ...(deleteCommand.arguments || []));
269274
} else if (this._commentEditor.getValue() === '') {
270275
this.commentService.disposeCommentThread(this._owner, this._commentThread.threadId!);
@@ -516,6 +521,7 @@ export class ReviewZoneWidget extends ZoneWidget implements ICommentThreadWidget
516521
uri: this._commentEditor.getModel()!.uri,
517522
value: this._commentEditor.getValue()
518523
};
524+
this.commentService.setActiveCommentThread(this._commentThread);
519525
}));
520526

521527
this._commentThreadDisposables.push(this._commentEditor.getModel()!.onDidChangeContent(() => {
@@ -526,6 +532,7 @@ export class ReviewZoneWidget extends ZoneWidget implements ICommentThreadWidget
526532
newInput.value = modelContent;
527533
thread.input = newInput;
528534
}
535+
this.commentService.setActiveCommentThread(this._commentThread);
529536
}));
530537

531538
this._commentThreadDisposables.push((this._commentThread as modes.CommentThread2).onDidChangeInput(input => {
@@ -727,6 +734,7 @@ export class ReviewZoneWidget extends ZoneWidget implements ICommentThreadWidget
727734
uri: this._commentEditor.getModel()!.uri,
728735
value: this._commentEditor.getValue()
729736
};
737+
this.commentService.setActiveCommentThread(this._commentThread);
730738
await this.commandService.executeCommand(acceptInputCommand.id, ...(acceptInputCommand.arguments || []));
731739
}));
732740

@@ -751,6 +759,7 @@ export class ReviewZoneWidget extends ZoneWidget implements ICommentThreadWidget
751759
uri: this._commentEditor.getModel()!.uri,
752760
value: this._commentEditor.getValue()
753761
};
762+
this.commentService.setActiveCommentThread(this._commentThread);
754763
await this.commandService.executeCommand(command.id, ...(command.arguments || []));
755764
}));
756765
});
@@ -821,6 +830,7 @@ export class ReviewZoneWidget extends ZoneWidget implements ICommentThreadWidget
821830
uri: this._commentEditor.getModel()!.uri,
822831
value: this._commentEditor.getValue()
823832
};
833+
this.commentService.setActiveCommentThread(this._commentThread);
824834
let commandId = commentThread.acceptInputCommand.id;
825835
let args = commentThread.acceptInputCommand.arguments || [];
826836

0 commit comments

Comments
 (0)