Skip to content

Commit

Permalink
Fix #74668, old comment API not adding comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Rachel Macfarlane committed May 31, 2019
1 parent d89187e commit 0284236
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/vs/workbench/api/browser/mainThreadComments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,9 @@ export class MainThreadComments extends Disposable implements MainThreadComments
private _handlers = new Map<number, string>();
private _commentControllers = new Map<number, MainThreadCommentController>();

private _activeCommentThread?: MainThreadCommentThread;
private _input?: modes.CommentInput;

private _openPanelListener: IDisposable | null;

constructor(
Expand All @@ -483,6 +486,26 @@ export class MainThreadComments extends Disposable implements MainThreadComments
this._disposables = [];
this._activeCommentThreadDisposables = [];
this._proxy = extHostContext.getProxy(ExtHostContext.ExtHostComments);

this._disposables.push(this._commentService.onDidChangeActiveCommentThread(async thread => {
let handle = (thread as MainThreadCommentThread).controllerHandle;
let controller = this._commentControllers.get(handle);

if (!controller) {
return;
}

this._activeCommentThreadDisposables = dispose(this._activeCommentThreadDisposables);
this._activeCommentThread = thread as MainThreadCommentThread;
controller.activeCommentThread = this._activeCommentThread;

this._activeCommentThreadDisposables.push(this._activeCommentThread.onDidChangeInput(input => { // todo, dispose
this._input = input;
this._proxy.$onCommentWidgetInputChange(handle, URI.parse(this._activeCommentThread!.resource), this._activeCommentThread!.range, this._input ? this._input.value : undefined);
}));

await this._proxy.$onCommentWidgetInputChange(controller.handle, URI.parse(this._activeCommentThread!.resource), this._activeCommentThread.range, this._input ? this._input.value : undefined);
}));
}

$registerCommentController(handle: number, id: string, label: string): void {
Expand Down
2 changes: 2 additions & 0 deletions src/vs/workbench/browser/web.simpleservices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,7 @@ export class SimpleCommentService implements ICommentService {
onDidSetAllCommentThreads: Event<IWorkspaceCommentThreadsEvent> = Event.None;
onDidUpdateCommentThreads: Event<ICommentThreadChangedEvent> = Event.None;
onDidChangeActiveCommentingRange: Event<{ range: Range; commentingRangesInfo: CommentingRanges; }> = Event.None;
onDidChangeActiveCommentThread: Event<any> = Event.None;
onDidSetDataProvider: Event<void> = Event.None;
onDidDeleteDataProvider: Event<string> = Event.None;
setDocumentComments: any;
Expand Down Expand Up @@ -649,6 +650,7 @@ export class SimpleCommentService implements ICommentService {
deleteReaction: any;
getReactionGroup: any;
toggleReaction: any;
setActiveCommentThread: any;
}
registerSingleton(ICommentService, SimpleCommentService, true);
//#endregion
Expand Down
5 changes: 5 additions & 0 deletions src/vs/workbench/contrib/comments/browser/commentNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -424,12 +424,14 @@ export class CommentNode extends Disposable {
uri: this._commentEditor.getModel()!.uri,
value: this.comment.body.value
};
this.commentService.setActiveCommentThread(commentThread);

this._commentEditorDisposables.push(this._commentEditor.onDidFocusEditorWidget(() => {
commentThread.input = {
uri: this._commentEditor!.getModel()!.uri,
value: this.comment.body.value
};
this.commentService.setActiveCommentThread(commentThread);
}));

this._commentEditorDisposables.push(this._commentEditor.onDidChangeModelContent(e => {
Expand All @@ -439,6 +441,7 @@ export class CommentNode extends Disposable {
let input = commentThread.input;
input.value = newVal;
commentThread.input = input;
this.commentService.setActiveCommentThread(commentThread);
}
}
}));
Expand Down Expand Up @@ -486,6 +489,7 @@ export class CommentNode extends Disposable {
uri: this._commentEditor.getModel()!.uri,
value: newBody
};
this.commentService.setActiveCommentThread(commentThread);
let commandId = this.comment.editCommand.id;
let args = this.comment.editCommand.arguments || [];

Expand Down Expand Up @@ -523,6 +527,7 @@ export class CommentNode extends Disposable {
if (result.confirmed) {
try {
if (this.comment.deleteCommand) {
this.commentService.setActiveCommentThread(this.commentThread);
let commandId = this.comment.deleteCommand.id;
let args = this.comment.deleteCommand.arguments || [];

Expand Down
9 changes: 9 additions & 0 deletions src/vs/workbench/contrib/comments/browser/commentService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export interface ICommentService {
readonly onDidSetResourceCommentInfos: Event<IResourceCommentThreadEvent>;
readonly onDidSetAllCommentThreads: Event<IWorkspaceCommentThreadsEvent>;
readonly onDidUpdateCommentThreads: Event<ICommentThreadChangedEvent>;
readonly onDidChangeActiveCommentThread: Event<CommentThread | null>;
readonly onDidChangeActiveCommentingRange: Event<{ range: Range, commentingRangesInfo: CommentingRanges }>;
readonly onDidSetDataProvider: Event<void>;
readonly onDidDeleteDataProvider: Event<string>;
Expand Down Expand Up @@ -69,6 +70,7 @@ export interface ICommentService {
deleteReaction(owner: string, resource: URI, comment: Comment, reaction: CommentReaction): Promise<void>;
getReactionGroup(owner: string): CommentReaction[] | undefined;
toggleReaction(owner: string, resource: URI, thread: CommentThread2, comment: Comment, reaction: CommentReaction): Promise<void>;
setActiveCommentThread(commentThread: CommentThread | null): void;
}

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

private readonly _onDidChangeActiveCommentThread = this._register(new Emitter<CommentThread | null>());
readonly onDidChangeActiveCommentThread = this._onDidChangeActiveCommentThread.event;

private readonly _onDidChangeActiveCommentingRange: Emitter<{
range: Range, commentingRangesInfo:
CommentingRanges
Expand All @@ -109,6 +114,10 @@ export class CommentService extends Disposable implements ICommentService {
super();
}

setActiveCommentThread(commentThread: CommentThread | null) {
this._onDidChangeActiveCommentThread.fire(commentThread);
}

setDocumentComments(resource: URI, commentInfos: ICommentInfo[]): void {
this._onDidSetResourceCommentInfos.fire({ resource, commentInfos });
}
Expand Down
10 changes: 10 additions & 0 deletions src/vs/workbench/contrib/comments/browser/commentThreadWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,10 @@ export class ReviewZoneWidget extends ZoneWidget implements ICommentThreadWidget

this._bodyElement = <HTMLDivElement>dom.$('.body');
container.appendChild(this._bodyElement);

dom.addDisposableListener(this._bodyElement, dom.EventType.FOCUS_IN, e => {
this.commentService.setActiveCommentThread(this._commentThread);
});
}

protected _fillHead(container: HTMLElement): void {
Expand Down Expand Up @@ -265,6 +269,7 @@ export class ReviewZoneWidget extends ZoneWidget implements ICommentThreadWidget
} else {
const deleteCommand = (this._commentThread as modes.CommentThread2).deleteCommand;
if (deleteCommand) {
this.commentService.setActiveCommentThread(this._commentThread);
return this.commandService.executeCommand(deleteCommand.id, ...(deleteCommand.arguments || []));
} else if (this._commentEditor.getValue() === '') {
this.commentService.disposeCommentThread(this._owner, this._commentThread.threadId!);
Expand Down Expand Up @@ -516,6 +521,7 @@ export class ReviewZoneWidget extends ZoneWidget implements ICommentThreadWidget
uri: this._commentEditor.getModel()!.uri,
value: this._commentEditor.getValue()
};
this.commentService.setActiveCommentThread(this._commentThread);
}));

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

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

Expand All @@ -751,6 +759,7 @@ export class ReviewZoneWidget extends ZoneWidget implements ICommentThreadWidget
uri: this._commentEditor.getModel()!.uri,
value: this._commentEditor.getValue()
};
this.commentService.setActiveCommentThread(this._commentThread);
await this.commandService.executeCommand(command.id, ...(command.arguments || []));
}));
});
Expand Down Expand Up @@ -821,6 +830,7 @@ export class ReviewZoneWidget extends ZoneWidget implements ICommentThreadWidget
uri: this._commentEditor.getModel()!.uri,
value: this._commentEditor.getValue()
};
this.commentService.setActiveCommentThread(this._commentThread);
let commandId = commentThread.acceptInputCommand.id;
let args = commentThread.acceptInputCommand.arguments || [];

Expand Down

0 comments on commit 0284236

Please sign in to comment.