comment control. active thread, comment, input update.

This commit is contained in:
Peng Lyu
2019-02-15 17:48:03 -08:00
parent f7bfa34a67
commit 67ad526371
8 changed files with 403 additions and 4 deletions

View File

@@ -115,12 +115,12 @@ export function createApiFactory(
const extHostTerminalService = rpcProtocol.set(ExtHostContext.ExtHostTerminalService, new ExtHostTerminalService(rpcProtocol, extHostConfiguration, extHostLogService, extHostCommands));
const extHostDebugService = rpcProtocol.set(ExtHostContext.ExtHostDebugService, new ExtHostDebugService(rpcProtocol, extHostWorkspace, extensionService, extHostDocumentsAndEditors, extHostConfiguration, extHostTerminalService, extHostCommands));
const extHostSCM = rpcProtocol.set(ExtHostContext.ExtHostSCM, new ExtHostSCM(rpcProtocol, extHostCommands, extHostLogService));
const extHostComment = rpcProtocol.set(ExtHostContext.ExtHostComments, new ExtHostComments(rpcProtocol, extHostCommands.converter, extHostDocuments));
const extHostSearch = rpcProtocol.set(ExtHostContext.ExtHostSearch, new ExtHostSearch(rpcProtocol, schemeTransformer, extHostLogService));
const extHostTask = rpcProtocol.set(ExtHostContext.ExtHostTask, new ExtHostTask(rpcProtocol, extHostWorkspace, extHostDocumentsAndEditors, extHostConfiguration));
const extHostWindow = rpcProtocol.set(ExtHostContext.ExtHostWindow, new ExtHostWindow(rpcProtocol));
rpcProtocol.set(ExtHostContext.ExtHostExtensionService, extensionService);
const extHostProgress = rpcProtocol.set(ExtHostContext.ExtHostProgress, new ExtHostProgress(rpcProtocol.getProxy(MainContext.MainThreadProgress)));
const exthostCommentProviders = rpcProtocol.set(ExtHostContext.ExtHostComments, new ExtHostComments(rpcProtocol, extHostCommands.converter, extHostDocuments));
const extHostOutputService = rpcProtocol.set(ExtHostContext.ExtHostOutputService, new ExtHostOutputService(initData.logsLocation, rpcProtocol));
rpcProtocol.set(ExtHostContext.ExtHostStorage, extHostStorage);
@@ -640,10 +640,10 @@ export function createApiFactory(
return extHostSearch.registerFileIndexProvider(scheme, provider);
}),
registerDocumentCommentProvider: proposedApiFunction(extension, (provider: vscode.DocumentCommentProvider) => {
return exthostCommentProviders.registerDocumentCommentProvider(extension.identifier, provider);
return extHostComment.registerDocumentCommentProvider(extension.identifier, provider);
}),
registerWorkspaceCommentProvider: proposedApiFunction(extension, (provider: vscode.WorkspaceCommentProvider) => {
return exthostCommentProviders.registerWorkspaceCommentProvider(extension.identifier, provider);
return extHostComment.registerWorkspaceCommentProvider(extension.identifier, provider);
}),
registerRemoteAuthorityResolver: proposedApiFunction(extension, (authorityPrefix: string, resolver: vscode.RemoteAuthorityResolver) => {
return extensionService.registerRemoteAuthorityResolver(authorityPrefix, resolver);
@@ -666,6 +666,12 @@ export function createApiFactory(
}
};
const comment: typeof vscode.comment = {
createCommentControl(id: string, label: string) {
return extHostComment.createCommentControl(extension, id, label);
}
}
// namespace: debug
const debug: typeof vscode.debug = {
get activeDebugSession() {
@@ -748,6 +754,7 @@ export function createApiFactory(
extensions,
languages,
scm,
comment,
tasks,
window,
workspace,

View File

@@ -119,6 +119,8 @@ export interface CommentProviderFeatures {
}
export interface MainThreadCommentsShape extends IDisposable {
$registerCommentControl(handle: number, id: string, label: string): void;
$createCommentThread(handle: number, commentThreadHandle: number, threadId: string, resource: UriComponents, range: IRange, comments: modes.Comment[], collapseState: modes.CommentThreadCollapsibleState): modes.CommentThread | undefined;
$registerDocumentCommentProvider(handle: number, features: CommentProviderFeatures): void;
$unregisterDocumentCommentProvider(handle: number): void;
$registerWorkspaceCommentProvider(handle: number, extensionId: ExtensionIdentifier): void;
@@ -1091,6 +1093,8 @@ export interface ExtHostProgressShape {
export interface ExtHostCommentsShape {
$provideDocumentComments(handle: number, document: UriComponents): Promise<modes.CommentInfo>;
$createNewCommentThread(handle: number, document: UriComponents, range: IRange, text: string): Promise<modes.CommentThread>;
$onActiveCommentWidgetChange(commentControlhandle: number, commentThread: modes.CommentThread, comment: modes.Comment | undefined, input: string): Promise<void>;
$onCommentWidgetInputChange(commentControlhandle: number, value: string): Promise<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

@@ -14,6 +14,8 @@ import { CommandsConverter } from './extHostCommands';
import { IRange } from 'vs/editor/common/core/range';
import { CancellationToken } from 'vs/base/common/cancellation';
import { ExtensionIdentifier } from 'vs/platform/extensions/common/extensions';
import { IExtensionDescription } from 'vs/workbench/services/extensions/common/extensions';
import { Event, Emitter } from 'vs/base/common/event';
interface HandlerData<T> {
@@ -21,11 +23,17 @@ interface HandlerData<T> {
provider: T;
}
type ProviderHandle = number;
export class ExtHostComments implements ExtHostCommentsShape {
private static handlePool = 0;
private _proxy: MainThreadCommentsShape;
private _commentControls: Map<ProviderHandle, ExtHostCommentControl> = new Map<ProviderHandle, ExtHostCommentControl>();
private _commentControlsByExtension: Map<string, ExtHostCommentControl[]> = new Map<string, ExtHostCommentControl[]>();
private _documentProviders = new Map<number, HandlerData<vscode.DocumentCommentProvider>>();
private _workspaceProviders = new Map<number, HandlerData<vscode.WorkspaceCommentProvider>>();
@@ -37,6 +45,41 @@ export class ExtHostComments implements ExtHostCommentsShape {
this._proxy = mainContext.getProxy(MainContext.MainThreadComments);
}
createCommentControl(extension: IExtensionDescription, id: string, label: string): vscode.CommentControl {
const handle = ExtHostComments.handlePool++;
const commentControl = new ExtHostCommentControl(extension, this._proxy, id, label);
this._commentControls.set(handle, commentControl);
const commentControls = this._commentControlsByExtension.get(ExtensionIdentifier.toKey(extension.identifier)) || [];
commentControls.push(commentControl);
this._commentControlsByExtension.set(ExtensionIdentifier.toKey(extension.identifier), commentControls);
return commentControl;
}
$onActiveCommentWidgetChange(commentControlhandle: number, commentThread: modes.CommentThread, comment: modes.Comment | undefined, input: string): Promise<void> {
const commentControl = this._commentControls.get(commentControlhandle);
if (!commentControl) {
return Promise.resolve(undefined);
}
commentControl.$onActiveCommentWidgetChange(commentThread, comment, input);
return Promise.resolve(undefined);
}
$onCommentWidgetInputChange(commentControlhandle: number, value: string): Promise<void> {
const commentControl = this._commentControls.get(commentControlhandle);
if (!commentControl || !commentControl.widget) {
return Promise.resolve(undefined);
}
commentControl.widget.$onCommentWidgetInputChange(value);
return Promise.resolve(undefined);
}
registerWorkspaceCommentProvider(
extensionId: ExtensionIdentifier,
provider: vscode.WorkspaceCommentProvider
@@ -202,6 +245,134 @@ export class ExtHostComments implements ExtHostCommentsShape {
}
}
export class ExtHostCommentThread implements vscode.CommentThread {
private static _handlePool: number = 0;
readonly handle = ExtHostCommentThread._handlePool++;
get threadId(): string {
return this._threadId;
}
get resource(): vscode.Uri {
return this._resource;
}
get range(): vscode.Range {
return this._range;
}
get comments(): vscode.Comment[] {
return this._comments;
}
collapsibleState?: vscode.CommentThreadCollapsibleState;
constructor(
private _proxy: MainThreadCommentsShape,
private _commentControlHandle: number,
private _threadId: string,
private _resource: vscode.Uri,
private _range: vscode.Range,
private _comments: vscode.Comment[],
private _collapseState?: vscode.CommentThreadCollapsibleState
) {
this._proxy.$createCommentThread(
this._commentControlHandle,
this.handle,
this._threadId,
this._resource,
extHostTypeConverter.Range.from(this._range),
this._comments.map(convertToModeComment),
this._collapseState
);
}
getComment(commentId: string): vscode.Comment | undefined {
let comments = this._comments.filter(comment => comment.commentId === commentId);
if (comments && comments.length) {
return comments[0];
}
return;
}
}
export class ExtHostCommentWidget implements vscode.CommentWidget {
private _onDidChangeInput = new Emitter<string>();
get onDidChangeInput(): Event<string> {
return this._onDidChangeInput.event;
}
private _input: string = '';
get input(): string {
return this._input;
}
constructor(
public commentThread: vscode.CommentThread,
public comment: vscode.Comment | undefined,
input: string
) {
this._input = input;
}
$onCommentWidgetInputChange(value: string) {
this.updateValue(value);
}
private updateValue(value: string): void {
this._input = value;
this._onDidChangeInput.fire(value);
}
}
class ExtHostCommentControl implements vscode.CommentControl {
private static _handlePool: number = 0;
get id(): string {
return this._id;
}
get label(): string {
return this._label;
}
public widget?: ExtHostCommentWidget;
private handle: number = ExtHostCommentControl._handlePool++;
private _threads: Map<number, ExtHostCommentThread> = new Map<number, ExtHostCommentThread>();
constructor(
_extension: IExtensionDescription,
private _proxy: MainThreadCommentsShape,
private _id: string,
private _label: string
) {
this._proxy.$registerCommentControl(this.handle, _id, _label);
}
createCommentThread(id: string, resource: vscode.Uri, range: vscode.Range, comments: vscode.Comment[], collapsibleState?: vscode.CommentThreadCollapsibleState): vscode.CommentThread {
const commentThread = new ExtHostCommentThread(this._proxy, this.handle, id, resource, range, comments, collapsibleState);
this._threads.set(commentThread.handle, commentThread);
return commentThread;
}
$onActiveCommentWidgetChange(commentThread: modes.CommentThread, comment: modes.Comment | undefined, input: string) {
let extHostCommentThread = this._threads.get(commentThread.commentThreadHandle);
const extHostCommentWidget = new ExtHostCommentWidget(
extHostCommentThread,
comment ? extHostCommentThread.getComment(comment.commentId) : undefined,
input
);
this.widget = extHostCommentWidget;
}
dispose(): void {
throw new Error('Method not implemented.');
}
}
function convertCommentInfo(owner: number, extensionId: ExtensionIdentifier, provider: vscode.DocumentCommentProvider, vscodeCommentInfo: vscode.CommentInfo, commandsConverter: CommandsConverter): modes.CommentInfo {
return {
extensionId: extensionId.value,
@@ -260,6 +431,18 @@ function convertFromComment(comment: modes.Comment): vscode.Comment {
};
}
function convertToModeComment(vscodeComment: vscode.Comment): modes.Comment {
const iconPath = vscodeComment.userIconPath ? vscodeComment.userIconPath.toString() : vscodeComment.gravatar;
return {
commentId: vscodeComment.commentId,
body: extHostTypeConverter.MarkdownString.from(vscodeComment.body),
userName: vscodeComment.userName,
userIconPath: iconPath,
isDraft: vscodeComment.isDraft
};
}
function convertToComment(provider: vscode.DocumentCommentProvider | vscode.WorkspaceCommentProvider, vscodeComment: vscode.Comment, commandsConverter: CommandsConverter): modes.Comment {
const canEdit = !!(provider as vscode.DocumentCommentProvider).editComment && vscodeComment.canEdit;
const canDelete = !!(provider as vscode.DocumentCommentProvider).deleteComment && vscodeComment.canDelete;