Callback for creating new comments

This commit is contained in:
Peng Lyu
2019-03-06 10:15:51 -08:00
parent 20dfc77b84
commit 42194d82a1
7 changed files with 67 additions and 217 deletions

View File

@@ -136,6 +136,7 @@ export class MainThreadCommentThread implements modes.CommentThread2 {
set collapsibleState(newState: modes.CommentThreadCollapsibleState) {
this._collapsibleState = newState;
this._onDidChangeCollasibleState.fire(this._collapsibleState);
}
@@ -170,41 +171,6 @@ export class MainThreadCommentThread implements modes.CommentThread2 {
}
}
export class MainThreadCommentingRanges implements modes.CommentingRanges {
get ranges(): IRange[] {
return this._ranges;
}
set ranges(newRanges: IRange[]) {
this._ranges = newRanges;
}
set newCommentThreadCommand(newCommand: modes.Command) {
this._newCommentThreadCommand = newCommand;
this._onDidChangeNewCommentThreadCommand.fire(this._newCommentThreadCommand);
}
get newCommentThreadCommand(): modes.Command {
return this._newCommentThreadCommand;
}
private _onDidChangeNewCommentThreadCommand = new Emitter<modes.Command>();
get onDidChangeNewCommentThreadCommand(): Event<modes.Command> { return this._onDidChangeNewCommentThreadCommand.event; }
constructor(
public commentingRangesHandle: number,
public controller: MainThreadCommentController,
public resource: URI,
private _ranges: IRange[],
private _newCommentThreadCommand: modes.Command,
) {
}
dispose() {
}
}
export class MainThreadCommentController {
get handle(): number {
return this._handle;
@@ -224,7 +190,6 @@ export class MainThreadCommentController {
private _threads: Map<number, MainThreadCommentThread> = new Map<number, MainThreadCommentThread>();
public activeCommentThread?: MainThreadCommentThread;
private _commentingRanges: Map<number, MainThreadCommentingRanges> = new Map<number, MainThreadCommentingRanges>();
constructor(
private _proxy: ExtHostCommentsShape,
private _commentService: ICommentService,
@@ -276,38 +241,6 @@ export class MainThreadCommentController {
thread.comments = comments;
}
createCommentingRanges(commentingRangesHandle: number, resource: UriComponents, ranges: IRange[], command: modes.Command) {
let commentingRange = new MainThreadCommentingRanges(
commentingRangesHandle,
this,
URI.revive(resource),
ranges,
command
);
this._commentingRanges.set(commentingRangesHandle, commentingRange);
return commentingRange;
}
deleteCommentingRanges(commentingRangesHandle: number) {
let commentingRanges = this._commentingRanges.get(commentingRangesHandle);
this._commentingRanges.delete(commentingRangesHandle);
commentingRanges.dispose();
}
updateCommentingRanges(commentingRangesHandle: number, newRanges: IRange[]) {
let commentingRanges = this._commentingRanges.get(commentingRangesHandle);
commentingRanges.ranges = newRanges;
}
updateCommentingRangesCommands(commentingRangesHandle: number, command: modes.Command) {
let commentingRanges = this._commentingRanges.get(commentingRangesHandle);
commentingRanges.newCommentThreadCommand = command;
}
updateAcceptInputCommands(commentThreadHandle: number, acceptInputCommands: modes.Command[]) {
let thread = this._threads.get(commentThreadHandle);
thread.acceptInputCommands = acceptInputCommands;
@@ -333,7 +266,7 @@ export class MainThreadCommentController {
}
}
getDocumentComments(resource: URI) {
async getDocumentComments(resource: URI, token) {
let ret = [];
for (let thread of keys(this._threads)) {
if (this._threads.get(thread).resource === resource.toString()) {
@@ -341,17 +274,17 @@ export class MainThreadCommentController {
}
}
let commentingRanges: modes.CommentingRanges;
for (let key of keys(this._commentingRanges)) {
if (this._commentingRanges.get(key).resource.toString() === resource.toString()) {
commentingRanges = this._commentingRanges.get(key);
}
}
let commentingRanges = await this._proxy.$provideCommentingRanges(this.handle, resource, token);
return <ICommentInfo>{
owner: String(this.handle),
threads: ret,
commentingRanges: commentingRanges || [],
commentingRanges: commentingRanges ?
{
resource: resource, ranges: commentingRanges, newCommentThreadCallback: (uri: UriComponents, range: IRange) => {
this._proxy.$createNewCommentWidgetCallback(this.handle, uri, range, token);
}
} : [],
draftMode: modes.DraftMode.NotSupported
};
}
@@ -408,15 +341,6 @@ export class MainThreadComments extends Disposable implements MainThreadComments
await this._proxy.$onCommentWidgetInputChange(controller.handle, this._input ? this._input.value : undefined);
}));
this._disposables.push(this._commentService.onDidChangeActiveCommentingRange(value => {
let controller = (value.commentingRangesInfo as MainThreadCommentingRanges).controller;
if (!controller) {
return;
}
this._proxy.$onActiveCommentingRangeChange(controller.handle, value.range);
}));
}
$registerCommentController(handle: number, id: string, label: string): void {
@@ -451,46 +375,6 @@ export class MainThreadComments extends Disposable implements MainThreadComments
return provider.deleteCommentThread(commentThreadHandle);
}
$createCommentingRanges(handle: number, commentingRangesHandle: number, resource: UriComponents, ranges: IRange[], command: modes.Command) {
let provider = this._commentControllers.get(handle);
if (!provider) {
return undefined;
}
return provider.createCommentingRanges(commentingRangesHandle, resource, ranges, command);
}
$deleteCommentingRanges(handle: number, commentingRangesHandle: number) {
let provider = this._commentControllers.get(handle);
if (!provider) {
return undefined;
}
return provider.deleteCommentingRanges(commentingRangesHandle);
}
$updateCommentingRanges(handle: number, commentingRangesHandle: number, newRanges: IRange[]): void {
let provider = this._commentControllers.get(handle);
if (!provider) {
return;
}
provider.updateCommentingRanges(commentingRangesHandle, newRanges);
}
$updateCommentingRangesCommands(handle: number, commentingRangesHandle: number, command: modes.Command): void {
let provider = this._commentControllers.get(handle);
if (!provider) {
return;
}
provider.updateCommentingRangesCommands(commentingRangesHandle, command);
}
$updateComments(handle: number, commentThreadHandle: number, comments: modes.Comment[]) {
let provider = this._commentControllers.get(handle);

View File

@@ -123,10 +123,6 @@ export interface MainThreadCommentsShape extends IDisposable {
$createCommentThread(handle: number, commentThreadHandle: number, threadId: string, resource: UriComponents, range: IRange, comments: modes.Comment[], commands: modes.Command[], collapseState: modes.CommentThreadCollapsibleState): modes.CommentThread2 | undefined;
$deleteCommentThread(handle: number, commentThreadHandle: number): void;
$updateComments(handle: number, commentThreadHandle: number, comments: modes.Comment[]): void;
$createCommentingRanges(handle: number, commentingRangesHandle: number, resource: UriComponents, ranges: IRange[], commands: modes.Command): void;
$deleteCommentingRanges(handle: number, commentingRangesHandle: number): void;
$updateCommentingRanges(handle: number, commentingRangesHandle: number, newRanges: IRange[]): void;
$updateCommentingRangesCommands(handle: number, commentingRangesHandle: number, command: modes.Command): void;
$setInputValue(handle: number, input: string): void;
$updateCommentThreadCommands(handle: number, commentThreadHandle: number, acceptInputCommands: modes.Command[]): void;
$updateCommentThreadCollapsibleState(handle: number, commentThreadHandle: number, collapseState: modes.CommentThreadCollapsibleState): void;
@@ -1107,7 +1103,8 @@ export interface ExtHostCommentsShape {
$provideDocumentComments(handle: number, document: UriComponents): Promise<modes.CommentInfo>;
$createNewCommentThread(handle: number, document: UriComponents, range: IRange, text: string): Promise<modes.CommentThread>;
$onCommentWidgetInputChange(commentControllerHandle: number, input: string): Promise<number | undefined>;
$onActiveCommentingRangeChange(commentControllerHandle: number, range: IRange): void;
$provideCommentingRanges(commentControllerHandle: number, uriComponents: UriComponents, token: CancellationToken): Promise<IRange[] | undefined>;
$createNewCommentWidgetCallback(commentControllerHandle: number, uriComponents: UriComponents, range: IRange, token: CancellationToken): void;
$replyToCommentThread(handle: number, document: UriComponents, range: IRange, commentThread: modes.CommentThread, text: string): Promise<modes.CommentThread>;
$editComment(handle: number, document: UriComponents, comment: modes.Comment, text: string): Promise<void>;
$deleteComment(handle: number, document: UriComponents, comment: modes.Comment): Promise<void>;

View File

@@ -99,14 +99,26 @@ export class ExtHostComments implements ExtHostCommentsShape {
return Promise.resolve(commentControllerHandle);
}
$onActiveCommentingRangeChange(commentControllerHandle: number, range: IRange) {
$provideCommentingRanges(commentControllerHandle: number, uriComponents: UriComponents, token: CancellationToken): Promise<IRange[] | undefined> {
const commentController = this._commentControllers.get(commentControllerHandle);
if (!commentController) {
if (!commentController || !commentController.commentingRangeProvider) {
return Promise.resolve(undefined);
}
return asPromise(() => {
return commentController.commentingRangeProvider.provider(URI.revive(uriComponents), token);
}).then(ranges => ranges.map(extHostTypeConverter.Range.from));
}
$createNewCommentWidgetCallback(commentControllerHandle: number, uriComponents: UriComponents, range: IRange, token: CancellationToken): void {
const commentController = this._commentControllers.get(commentControllerHandle);
if (!commentController || !commentController.commentingRangeProvider) {
return;
}
commentController.setActiveCommentingRange(extHostTypeConverter.Range.to(range));
commentController.commentingRangeProvider.callback(URI.revive(uriComponents), extHostTypeConverter.Range.to(range));
}
registerWorkspaceCommentProvider(
@@ -398,53 +410,12 @@ export class ExtHostCommentInputBox implements vscode.CommentInputBox {
}
}
export class ExtHostCommentingRanges implements vscode.CommentingRanges {
private static _handlePool: number = 0;
readonly handle = ExtHostCommentingRanges._handlePool++;
get resource(): vscode.Uri {
return this._resource;
}
get ranges(): vscode.Range[] {
return this._ranges;
}
set ranges(newRanges: vscode.Range[]) {
this._ranges = newRanges;
this._proxy.$updateCommentingRanges(this._commentControllerHandle, this.handle, this._ranges.map(extHostTypeConverter.Range.from));
}
get newCommentThreadCommand(): vscode.Command {
return this._command;
}
set newCommentThreadCommand(command: vscode.Command) {
this._command = command;
const internal = this._commandsConverter.toInternal(command);
this._proxy.$updateCommentingRangesCommands(this._commentControllerHandle, this.handle, internal);
}
class ExtHostCommentingRangeProvider {
constructor(
private _proxy: MainThreadCommentsShape,
private readonly _commandsConverter: CommandsConverter,
private _commentControllerHandle: number,
private _resource: vscode.Uri,
private _ranges: vscode.Range[],
private _command: vscode.Command,
public provider: (uri: vscode.Uri, token: vscode.CancellationToken) => vscode.ProviderResult<vscode.Range[]>,
public callback: (uri: vscode.Uri, range: vscode.Range) => void
) {
this._proxy.$createCommentingRanges(
this._commentControllerHandle,
this.handle,
this._resource,
this._ranges.map(extHostTypeConverter.Range.from),
this._commandsConverter.toInternal(this._command)
);
}
dispose() {
this._proxy.$deleteCommentingRanges(this._commentControllerHandle, this.handle);
}
}
@@ -465,7 +436,16 @@ class ExtHostCommentController implements vscode.CommentController {
}
private _threads: Map<number, ExtHostCommentThread> = new Map<number, ExtHostCommentThread>();
private _commentingRanges: Map<number, ExtHostCommentingRanges> = new Map<number, ExtHostCommentingRanges>();
private _commentingRangeProvider: ExtHostCommentingRangeProvider | undefined = undefined;
get commentingRangeProvider(): ExtHostCommentingRangeProvider | undefined {
return this._commentingRangeProvider;
}
set commentingRangeProvider(commentingRangeProvider: ExtHostCommentingRangeProvider | undefined) {
this._commentingRangeProvider = commentingRangeProvider;
}
constructor(
_extension: IExtensionDescription,
@@ -484,6 +464,10 @@ class ExtHostCommentController implements vscode.CommentController {
return commentThread;
}
registerCommentingRangeProvider(provider: (uri: vscode.Uri, token: vscode.CancellationToken) => vscode.ProviderResult<vscode.Range[]>, callback: (uri: vscode.Uri, range: vscode.Range) => void) {
this._commentingRangeProvider = new ExtHostCommentingRangeProvider(provider, callback);
}
$onCommentWidgetInputChange(input: string) {
if (!this.inputBox) {
this.inputBox = new ExtHostCommentInputBox(this._proxy, this.handle, input);
@@ -492,16 +476,6 @@ class ExtHostCommentController implements vscode.CommentController {
}
}
createCommentingRanges(resource: vscode.Uri, ranges: vscode.Range[], newCommentThreadCommand: vscode.Command): vscode.CommentingRanges {
const commentingRange = new ExtHostCommentingRanges(this._proxy, this._commandsConverter, this.handle, resource, ranges, newCommentThreadCommand);
this._commentingRanges.set(commentingRange.handle, commentingRange);
return commentingRange;
}
setActiveCommentingRange(range: vscode.Range) {
this.activeCommentingRange = range;
}
getCommentThread(handle: number) {
return this._threads.get(handle);
}
@@ -510,9 +484,6 @@ class ExtHostCommentController implements vscode.CommentController {
this._threads.forEach(value => {
value.dispose();
});
this._commentingRanges.forEach(value => {
value.dispose();
});
}
}