Working on adding comment api

This commit is contained in:
Matt Bierner
2018-04-03 18:00:28 -07:00
parent b4195abe06
commit 094a469d51
65 changed files with 2031 additions and 29 deletions

View File

@@ -58,6 +58,7 @@ import { isFalsyOrEmpty } from 'vs/base/common/arrays';
import { OverviewRulerLane } from 'vs/editor/common/model';
import { ExtHostLogService } from 'vs/workbench/api/node/extHostLogService';
import { ExtHostWebviews } from 'vs/workbench/api/node/extHostWebview';
import { ExtHostComments } from './extHostComments';
export interface IExtensionApiFactory {
(extension: IExtensionDescription): typeof vscode;
@@ -119,6 +120,7 @@ export function createApiFactory(
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, extHostDocuments));
// Check that no named customers are missing
const expected: ProxyIdentifier<any>[] = Object.keys(ExtHostContext).map((key) => ExtHostContext[key]);
@@ -540,6 +542,9 @@ export function createApiFactory(
}),
registerSearchProvider: proposedApiFunction(extension, (scheme, provider) => {
return extHostFileSystem.registerSearchProvider(scheme, provider);
}),
registerCommentProvider: proposedApiFunction(extension, (provider: vscode.CommentProvider) => {
return exthostCommentProviders.registerCommentProvider(provider);
})
};

View File

@@ -104,6 +104,11 @@ export interface MainThreadCommandsShape extends IDisposable {
$getCommands(): Thenable<string[]>;
}
export interface MainThreadCommentsShape extends IDisposable {
$registerCommentProvider(handle: number): void;
$unregisterCommentProvider(handle: number): void;
}
export interface MainThreadConfigurationShape extends IDisposable {
$updateConfigurationOption(target: ConfigurationTarget, key: string, value: any, resource: UriComponents): TPromise<void>;
$removeConfigurationOption(target: ConfigurationTarget, key: string, resource: UriComponents): TPromise<void>;
@@ -813,10 +818,15 @@ export interface ExtHostProgressShape {
$acceptProgressCanceled(handle: number): void;
}
export interface ExtHostCommentsShape {
$providerComments(handle: number, document: UriComponents): TPromise<modes.CommentThread[]>;
}
// --- proxy identifiers
export const MainContext = {
MainThreadCommands: <ProxyIdentifier<MainThreadCommandsShape>>createMainId<MainThreadCommandsShape>('MainThreadCommands'),
MainThreadComments: createMainId<MainThreadCommentsShape>('MainThreadComments'),
MainThreadConfiguration: createMainId<MainThreadConfigurationShape>('MainThreadConfiguration'),
MainThreadDebugService: createMainId<MainThreadDebugServiceShape>('MainThreadDebugService'),
MainThreadDecorations: createMainId<MainThreadDecorationsShape>('MainThreadDecorations'),
@@ -871,5 +881,6 @@ export const ExtHostContext = {
ExtHostWorkspace: createExtId<ExtHostWorkspaceShape>('ExtHostWorkspace'),
ExtHostWindow: createExtId<ExtHostWindowShape>('ExtHostWindow'),
ExtHostWebviews: createExtId<ExtHostWebviewsShape>('ExtHostWebviews'),
ExtHostProgress: createMainId<ExtHostProgressShape>('ExtHostProgress')
ExtHostProgress: createMainId<ExtHostProgressShape>('ExtHostProgress'),
ExtHostComments: createMainId<ExtHostCommentsShape>('ExtHostComments')
};

View File

@@ -0,0 +1,76 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import { asWinJsPromise } from 'vs/base/common/async';
import { values } from 'vs/base/common/map';
import URI, { UriComponents } from 'vs/base/common/uri';
import { TPromise } from 'vs/base/common/winjs.base';
import * as modes from 'vs/editor/common/modes';
import { ExtHostDocuments } from 'vs/workbench/api/node/extHostDocuments';
import * as vscode from 'vscode';
import { flatten } from '../../../base/common/arrays';
import { ExtHostCommentsShape, IMainContext, MainContext, MainThreadCommentsShape } from './extHost.protocol';
import * as extHostTypeConverter from 'vs/workbench/api/node/extHostTypeConverters';
export class ExtHostComments implements ExtHostCommentsShape {
private static handlePool = 0;
private _proxy: MainThreadCommentsShape;
private _providers = new Map<number, vscode.CommentProvider>();
constructor(
mainContext: IMainContext,
private readonly _documents: ExtHostDocuments,
) {
this._proxy = mainContext.getProxy(MainContext.MainThreadComments);
}
registerCommentProvider(
provider: vscode.CommentProvider
): vscode.Disposable {
const handle = ExtHostComments.handlePool++;
this._providers.set(handle, provider);
this._proxy.$registerCommentProvider(handle);
return {
dispose: () => {
this._proxy.$unregisterCommentProvider(handle);
this._providers.delete(handle);
}
};
}
$providerComments(handle: number, uri: UriComponents): TPromise<modes.CommentThread[]> {
const data = this._documents.getDocumentData(URI.revive(uri));
if (!data || !data.document) {
return TPromise.as([]);
}
return asWinJsPromise(token => {
const allProviderResults = values(this._providers).map(provider => provider.provideComments(data.document, token));
return TPromise.join(allProviderResults);
})
.then(flatten)
.then(comments => comments.map(convertCommentThread));
}
}
function convertCommentThread(vscodeCommentThread: vscode.CommentThread): modes.CommentThread {
return {
range: extHostTypeConverter.fromRange(vscodeCommentThread.range),
comments: vscodeCommentThread.comments.map(convertComment)
};
}
function convertComment(vscodeComment: vscode.Comment): modes.Comment {
return {
body: extHostTypeConverter.MarkdownString.from(vscodeComment.body),
userName: vscodeComment.userName
};
}