Merge from vscode 071a5cf16fc999727acc31c790d78f750fa4b166 (#5261)

This commit is contained in:
Anthony Dresser
2019-04-30 07:54:56 -07:00
committed by GitHub
parent 02916aeffa
commit aacc0eca67
24 changed files with 564 additions and 238 deletions

View File

@@ -121,11 +121,19 @@ export interface MainThreadCommandsShape extends IDisposable {
$getCommands(): Promise<string[]>;
}
export interface CommentThreadTemplate {
label: string;
acceptInputCommand?: modes.Command;
additionalCommands?: modes.Command[];
deleteCommand?: modes.Command;
}
export interface CommentProviderFeatures {
startDraftLabel?: string;
deleteDraftLabel?: string;
finishDraftLabel?: string;
reactionGroup?: modes.CommentReaction[];
commentThreadTemplate?: CommentThreadTemplate;
}
export interface MainThreadCommentsShape extends IDisposable {
@@ -1206,10 +1214,11 @@ export interface ExtHostCommentsShape {
$provideDocumentComments(handle: number, document: UriComponents): Promise<modes.CommentInfo | null>;
$createNewCommentThread(handle: number, document: UriComponents, range: IRange, text: string): Promise<modes.CommentThread | null>;
$onCommentWidgetInputChange(commentControllerHandle: number, input: string | undefined): Promise<number | undefined>;
$onActiveCommentThreadChange(commentControllerHandle: number, threadHandle: number | undefined): Promise<number | undefined>;
$provideCommentingRanges(commentControllerHandle: number, uriComponents: UriComponents, token: CancellationToken): Promise<IRange[] | undefined>;
$provideReactionGroup(commentControllerHandle: number): Promise<modes.CommentReaction[] | undefined>;
$toggleReaction(commentControllerHandle: number, threadHandle: number, uri: UriComponents, comment: modes.Comment, reaction: modes.CommentReaction): Promise<void>;
$createNewCommentWidgetCallback(commentControllerHandle: number, uriComponents: UriComponents, range: IRange, token: CancellationToken): Promise<void>;
$createNewCommentWidgetCallback(commentControllerHandle: number, uriComponents: UriComponents, range: IRange, token: CancellationToken): Promise<number | undefined>;
$replyToCommentThread(handle: number, document: UriComponents, range: IRange, commentThread: modes.CommentThread, text: string): Promise<modes.CommentThread | null>;
$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,6 +99,17 @@ export class ExtHostComments implements ExtHostCommentsShape {
return Promise.resolve(commentControllerHandle);
}
$onActiveCommentThreadChange(commentControllerHandle: number, threadHandle: number): Promise<number | undefined> {
const commentController = this._commentControllers.get(commentControllerHandle);
if (!commentController) {
return Promise.resolve(undefined);
}
commentController.$onActiveCommentThreadChange(threadHandle);
return Promise.resolve(threadHandle);
}
$provideCommentingRanges(commentControllerHandle: number, uriComponents: UriComponents, token: CancellationToken): Promise<IRange[] | undefined> {
const commentController = this._commentControllers.get(commentControllerHandle);
@@ -146,28 +157,34 @@ export class ExtHostComments implements ExtHostCommentsShape {
});
}
$createNewCommentWidgetCallback(commentControllerHandle: number, uriComponents: UriComponents, range: IRange, token: CancellationToken): Promise<void> {
$createNewCommentWidgetCallback(commentControllerHandle: number, uriComponents: UriComponents, range: IRange, token: CancellationToken): Promise<number | undefined> {
const commentController = this._commentControllers.get(commentControllerHandle);
if (!commentController) {
return Promise.resolve();
return Promise.resolve(undefined);
}
if (!(commentController as any).emptyCommentThreadFactory && !(commentController.commentingRangeProvider && commentController.commentingRangeProvider.createEmptyCommentThread)) {
return Promise.resolve();
if (!(commentController as any).emptyCommentThreadFactory && !(commentController.commentingRangeProvider && commentController.commentingRangeProvider.createEmptyCommentThread) && !(commentController.emptyCommentThreadFactory && commentController.emptyCommentThreadFactory.createEmptyCommentThread)) {
return Promise.resolve(undefined);
}
const document = this._documents.getDocument(URI.revive(uriComponents));
return asPromise(() => {
// TODO, remove this once GH PR stable deprecates `emptyCommentThreadFactory`.
if ((commentController as any).emptyCommentThreadFactory) {
return (commentController as any).emptyCommentThreadFactory!.createEmptyCommentThread(document, extHostTypeConverter.Range.to(range));
if (commentController.emptyCommentThreadFactory) {
return commentController.emptyCommentThreadFactory!.createEmptyCommentThread(document, extHostTypeConverter.Range.to(range));
}
if (commentController.commentingRangeProvider && commentController.commentingRangeProvider.createEmptyCommentThread) {
return commentController.commentingRangeProvider.createEmptyCommentThread(document, extHostTypeConverter.Range.to(range));
}
}).then(() => Promise.resolve());
return undefined; // {{SQL CARBON EDIT}} @anthonydresser revert back after strict-null-check
}).then((commentThread: ExtHostCommentThread | undefined) => {
if (commentThread) {
return Promise.resolve(commentThread.handle);
}
return Promise.resolve(undefined);
});
}
registerWorkspaceCommentProvider(
@@ -451,6 +468,12 @@ export class ExtHostCommentThread implements vscode.CommentThread {
private _localDisposables: types.Disposable[];
private _isDiposed: boolean;
public get isDisposed(): boolean {
return this._isDiposed;
}
constructor(
private _proxy: MainThreadCommentsShape,
private readonly _commandsConverter: CommandsConverter,
@@ -469,6 +492,7 @@ export class ExtHostCommentThread implements vscode.CommentThread {
);
this._localDisposables = [];
this._isDiposed = false;
this._localDisposables.push(this.onDidUpdateCommentThread(() => {
this.eventuallyUpdateCommentThread();
@@ -519,6 +543,7 @@ export class ExtHostCommentThread implements vscode.CommentThread {
this._commentController.handle,
this.handle
);
this._isDiposed = true;
}
}
@@ -562,7 +587,17 @@ class ExtHostCommentController implements vscode.CommentController {
return this._label;
}
public inputBox?: ExtHostCommentInputBox;
public inputBox: ExtHostCommentInputBox | undefined;
private _activeCommentThread: ExtHostCommentThread | undefined;
public get activeCommentThread(): ExtHostCommentThread | undefined {
if (this._activeCommentThread && this._activeCommentThread.isDisposed) {
this._activeCommentThread = undefined;
}
return this._activeCommentThread;
}
public activeCommentingRange?: vscode.Range;
public get handle(): number {
@@ -570,7 +605,31 @@ class ExtHostCommentController implements vscode.CommentController {
}
private _threads: Map<number, ExtHostCommentThread> = new Map<number, ExtHostCommentThread>();
commentingRangeProvider?: vscode.CommentingRangeProvider;
commentingRangeProvider?: vscode.CommentingRangeProvider & { createEmptyCommentThread: (document: vscode.TextDocument, range: types.Range) => Promise<vscode.CommentThread>; };
private _emptyCommentThreadFactory: vscode.EmptyCommentThreadFactory | undefined;
get emptyCommentThreadFactory(): vscode.EmptyCommentThreadFactory | undefined {
return this._emptyCommentThreadFactory;
}
set emptyCommentThreadFactory(newEmptyCommentThreadFactory: vscode.EmptyCommentThreadFactory | undefined) {
this._emptyCommentThreadFactory = newEmptyCommentThreadFactory;
if (this._emptyCommentThreadFactory && this._emptyCommentThreadFactory.template) {
let template = this._emptyCommentThreadFactory.template;
const acceptInputCommand = template.acceptInputCommand ? this._commandsConverter.toInternal(template.acceptInputCommand) : undefined;
const additionalCommands = template.additionalCommands ? template.additionalCommands.map(x => this._commandsConverter.toInternal(x)) : [];
const deleteCommand = template.deleteCommand ? this._commandsConverter.toInternal(template.deleteCommand) : undefined;
this._proxy.$updateCommentControllerFeatures(this.handle, {
commentThreadTemplate: {
label: template.label,
acceptInputCommand,
additionalCommands,
deleteCommand
}
});
}
}
private _commentReactionProvider?: vscode.CommentReactionProvider;
@@ -610,6 +669,10 @@ class ExtHostCommentController implements vscode.CommentController {
}
}
$onActiveCommentThreadChange(threadHandle: number) {
this._activeCommentThread = this.getCommentThread(threadHandle);
}
getCommentThread(handle: number) {
return this._threads.get(handle);
}
@@ -664,6 +727,7 @@ function convertFromComment(comment: modes.Comment): vscode.Comment {
}
return {
id: comment.commentId,
commentId: comment.commentId,
body: extHostTypeConverter.MarkdownString.to(comment.body),
userName: comment.userName,
@@ -685,7 +749,7 @@ function convertToModeComment(commentController: ExtHostCommentController, vscod
const iconPath = vscodeComment.userIconPath ? vscodeComment.userIconPath.toString() : vscodeComment.gravatar;
return {
commentId: vscodeComment.commentId,
commentId: vscodeComment.id || vscodeComment.commentId,
body: extHostTypeConverter.MarkdownString.from(vscodeComment.body),
userName: vscodeComment.userName,
userIconPath: iconPath,

View File

@@ -2287,6 +2287,61 @@ export enum FoldingRangeKind {
//#endregion
//#region Comment
@es5ClassCompat
export class Comment {
id: string;
body: MarkdownString;
userName: string;
label?: string;
userIconPath?: URI;
selectCommand?: vscode.Command;
editCommand?: vscode.Command;
deleteCommand?: vscode.Command;
/**
* The id of the comment
*
* @deprecated Use Id instead
*/
commentId: string;
/**
* @deprecated Use userIconPath instead. The avatar src of the user who created the comment
*/
gravatar?: string;
/**
* @deprecated, use editCommand
*/
canEdit?: boolean;
/**
* @deprecated, use deleteCommand
*/
canDelete?: boolean;
/**
* @deprecated
*/
command?: vscode.Command;
/**
* @deprecated
*/
isDraft?: boolean;
/**
* Proposed Comment Reaction
*/
commentReactions?: vscode.CommentReaction[];
constructor(id: string, body: MarkdownString, userName: string) {
this.id = id;
this.body = body;
this.userName = userName;
}
}
export enum CommentThreadCollapsibleState {
/**
@@ -2298,6 +2353,7 @@ export enum CommentThreadCollapsibleState {
*/
Expanded = 1
}
//#endregion
@es5ClassCompat
export class QuickInputButtons {