Batch comment thread properties update event (#71569)

This commit is contained in:
Peng Lyu
2019-04-02 01:00:03 +02:00
committed by GitHub
parent 615d53e1d3
commit 260442f574
8 changed files with 226 additions and 246 deletions

View File

@@ -16,6 +16,7 @@ import { IRange } from 'vs/editor/common/core/range';
import { CancellationToken } from 'vs/base/common/cancellation';
import { ExtensionIdentifier, IExtensionDescription } from 'vs/platform/extensions/common/extensions';
import { Event, Emitter } from 'vs/base/common/event';
import { debounce } from 'vs/base/common/decorators';
interface HandlerData<T> {
@@ -360,10 +361,13 @@ export class ExtHostCommentThread implements vscode.CommentThread {
return this._resource;
}
private _onDidUpdateCommentThread = new Emitter<void>();
readonly onDidUpdateCommentThread = this._onDidUpdateCommentThread.event;
set range(range: vscode.Range) {
if (range.isEqual(this._range)) {
this._range = range;
this._proxy.$updateCommentThreadRange(this._commentController.handle, this.handle, extHostTypeConverter.Range.from(this._range));
this._onDidUpdateCommentThread.fire();
}
}
@@ -379,7 +383,7 @@ export class ExtHostCommentThread implements vscode.CommentThread {
set label(label: string) {
this._label = label;
this._proxy.$updateCommentThreadLabel(this._commentController.handle, this.handle, this._label);
this._onDidUpdateCommentThread.fire();
}
get comments(): vscode.Comment[] {
@@ -387,8 +391,8 @@ export class ExtHostCommentThread implements vscode.CommentThread {
}
set comments(newComments: vscode.Comment[]) {
this._proxy.$updateComments(this._commentController.handle, this.handle, newComments.map(cmt => { return convertToModeComment(this._commentController, cmt, this._commandsConverter); }));
this._comments = newComments;
this._onDidUpdateCommentThread.fire();
}
private _acceptInputCommand: vscode.Command;
@@ -398,9 +402,7 @@ export class ExtHostCommentThread implements vscode.CommentThread {
set acceptInputCommand(acceptInputCommand: vscode.Command) {
this._acceptInputCommand = acceptInputCommand;
const internal = this._commandsConverter.toInternal(acceptInputCommand);
this._proxy.$updateCommentThreadAcceptInputCommand(this._commentController.handle, this.handle, internal);
this._onDidUpdateCommentThread.fire();
}
private _additionalCommands: vscode.Command[] = [];
@@ -410,9 +412,7 @@ export class ExtHostCommentThread implements vscode.CommentThread {
set additionalCommands(additionalCommands: vscode.Command[]) {
this._additionalCommands = additionalCommands;
const internals = additionalCommands.map(x => this._commandsConverter.toInternal(x));
this._proxy.$updateCommentThreadAdditionalCommands(this._commentController.handle, this.handle, internals);
this._onDidUpdateCommentThread.fire();
}
private _deleteCommand?: vscode.Command;
@@ -422,9 +422,7 @@ export class ExtHostCommentThread implements vscode.CommentThread {
set deleteCommand(deleteCommand: vscode.Command) {
this._deleteCommand = deleteCommand;
const internal = this._commandsConverter.toInternal(deleteCommand);
this._proxy.$updateCommentThreadDeleteCommand(this._commentController.handle, this.handle, internal);
this._onDidUpdateCommentThread.fire();
}
private _collapseState?: vscode.CommentThreadCollapsibleState;
@@ -435,9 +433,11 @@ export class ExtHostCommentThread implements vscode.CommentThread {
set collapsibleState(newState: vscode.CommentThreadCollapsibleState) {
this._collapseState = newState;
this._proxy.$updateCommentThreadCollapsibleState(this._commentController.handle, this.handle, convertToCollapsibleState(newState));
this._onDidUpdateCommentThread.fire();
}
private _localDisposables: types.Disposable[];
constructor(
private _proxy: MainThreadCommentsShape,
private readonly _commandsConverter: CommandsConverter,
@@ -452,12 +452,41 @@ export class ExtHostCommentThread implements vscode.CommentThread {
this.handle,
this._threadId,
this._resource,
extHostTypeConverter.Range.from(this._range),
this._comments.map(comment => { return convertToModeComment(this._commentController, comment, this._commandsConverter); }),
this._acceptInputCommand ? this._commandsConverter.toInternal(this._acceptInputCommand) : undefined,
this._additionalCommands ? this._additionalCommands.map(x => this._commandsConverter.toInternal(x)) : [],
this._deleteCommand ? this._commandsConverter.toInternal(this._deleteCommand) : undefined,
this._collapseState!
extHostTypeConverter.Range.from(this._range)
);
this._localDisposables = [];
this._localDisposables.push(this.onDidUpdateCommentThread(() => {
this.eventuallyUpdateCommentThread();
}));
// set up comments after ctor to batch update events.
this.comments = _comments;
}
@debounce(100)
eventuallyUpdateCommentThread(): void {
const commentThreadRange = extHostTypeConverter.Range.from(this._range);
const label = this.label;
const comments = this._comments.map(cmt => { return convertToModeComment(this._commentController, cmt, this._commandsConverter); });
const acceptInputCommand = this._acceptInputCommand ? this._commandsConverter.toInternal(this._acceptInputCommand) : undefined;
const additionalCommands = this._additionalCommands ? this._additionalCommands.map(x => this._commandsConverter.toInternal(x)) : [];
const deleteCommand = this._deleteCommand ? this._commandsConverter.toInternal(this._deleteCommand) : undefined;
const collapsibleState = convertToCollapsibleState(this._collapseState);
this._proxy.$updateCommentThread(
this._commentController.handle,
this.handle,
this._threadId,
this._resource,
commentThreadRange,
label,
comments,
acceptInputCommand,
additionalCommands,
deleteCommand,
collapsibleState
);
}
@@ -472,6 +501,7 @@ export class ExtHostCommentThread implements vscode.CommentThread {
}
dispose() {
this._localDisposables.forEach(disposable => disposable.dispose());
this._proxy.$deleteCommentThread(
this._commentController.handle,
this.handle
@@ -607,7 +637,7 @@ function convertFromCommentThread(commentThread: modes.CommentThread): vscode.Co
threadId: commentThread.threadId!,
resource: URI.parse(commentThread.resource!),
range: extHostTypeConverter.Range.to(commentThread.range),
comments: commentThread.comments.map(convertFromComment),
comments: commentThread.comments ? commentThread.comments.map(convertFromComment) : [],
collapsibleState: commentThread.collapsibleState
};
}