mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-24 10:38:59 +01:00
Refactor and put id as property of TreeContentProvider
This commit is contained in:
@@ -12,11 +12,13 @@ import { IThreadService } from 'vs/workbench/services/thread/common/threadServic
|
||||
import * as errors from 'vs/base/common/errors';
|
||||
import product from 'vs/platform/product';
|
||||
import pkg from 'vs/platform/package';
|
||||
|
||||
import { ExtHostFileSystemEventService } from 'vs/workbench/api/node/extHostFileSystemEventService';
|
||||
import { ExtHostDocuments } from 'vs/workbench/api/node/extHostDocuments';
|
||||
import { ExtHostDocumentSaveParticipant } from 'vs/workbench/api/node/extHostDocumentSaveParticipant';
|
||||
import { ExtHostConfiguration } from 'vs/workbench/api/node/extHostConfiguration';
|
||||
import { ExtHostDiagnostics } from 'vs/workbench/api/node/extHostDiagnostics';
|
||||
import { ExtHostExplorers } from 'vs/workbench/api/node/extHostExplorers';
|
||||
import { ExtHostWorkspace } from 'vs/workbench/api/node/extHostWorkspace';
|
||||
import { ExtHostQuickOpen } from 'vs/workbench/api/node/extHostQuickOpen';
|
||||
import { ExtHostHeapService } from 'vs/workbench/api/node/extHostHeapService';
|
||||
@@ -64,6 +66,7 @@ export function createApiFactory(threadService: IThreadService, extensionService
|
||||
const extHostDocuments = col.define(ExtHostContext.ExtHostDocuments).set<ExtHostDocuments>(new ExtHostDocuments(threadService));
|
||||
const extHostDocumentSaveParticipant = col.define(ExtHostContext.ExtHostDocumentSaveParticipant).set<ExtHostDocumentSaveParticipant>(new ExtHostDocumentSaveParticipant(extHostDocuments, threadService.get(MainContext.MainThreadWorkspace)));
|
||||
const extHostEditors = col.define(ExtHostContext.ExtHostEditors).set<ExtHostEditors>(new ExtHostEditors(threadService, extHostDocuments));
|
||||
const extHostExplorers = col.define(ExtHostContext.ExtHostExplorers).set<ExtHostExplorers>(new ExtHostExplorers(threadService));
|
||||
const extHostCommands = col.define(ExtHostContext.ExtHostCommands).set<ExtHostCommands>(new ExtHostCommands(threadService, extHostEditors, extHostHeapService));
|
||||
const extHostConfiguration = col.define(ExtHostContext.ExtHostConfiguration).set<ExtHostConfiguration>(new ExtHostConfiguration(threadService.get(MainContext.MainThreadConfiguration)));
|
||||
const extHostDiagnostics = col.define(ExtHostContext.ExtHostDiagnostics).set<ExtHostDiagnostics>(new ExtHostDiagnostics(threadService));
|
||||
|
||||
@@ -20,6 +20,7 @@ import { MainThreadDiagnostics } from './mainThreadDiagnostics';
|
||||
import { MainThreadDocuments } from './mainThreadDocuments';
|
||||
import { MainThreadEditors } from './mainThreadEditors';
|
||||
import { MainThreadErrors } from './mainThreadErrors';
|
||||
import { MainThreadExplorers } from './mainThreadExplorers';
|
||||
import { MainThreadLanguageFeatures } from './mainThreadLanguageFeatures';
|
||||
import { MainThreadLanguages } from './mainThreadLanguages';
|
||||
import { MainThreadMessageService } from './mainThreadMessageService';
|
||||
@@ -70,6 +71,7 @@ export class ExtHostContribution implements IWorkbenchContribution {
|
||||
col.define(MainContext.MainThreadDocuments).set(create(MainThreadDocuments));
|
||||
col.define(MainContext.MainThreadEditors).set(create(MainThreadEditors));
|
||||
col.define(MainContext.MainThreadErrors).set(create(MainThreadErrors));
|
||||
col.define(MainContext.MainThreadExplorers).set(create(MainThreadExplorers));
|
||||
col.define(MainContext.MainThreadLanguageFeatures).set(create(MainThreadLanguageFeatures));
|
||||
col.define(MainContext.MainThreadLanguages).set(create(MainThreadLanguages));
|
||||
col.define(MainContext.MainThreadMessageService).set(create(MainThreadMessageService));
|
||||
|
||||
@@ -115,6 +115,11 @@ export abstract class MainThreadEditorsShape {
|
||||
$tryApplyEdits(id: string, modelVersionId: number, edits: editorCommon.ISingleEditOperation[], opts: IApplyEditsOptions): TPromise<boolean> { throw ni(); }
|
||||
}
|
||||
|
||||
export abstract class MainThreadExplorersShape {
|
||||
$registerTreeContentProvider(treeContentProviderId: string): void { throw ni(); }
|
||||
$unregisterTreeContentProvider(treeContentProviderId: string): void { throw ni(); }
|
||||
}
|
||||
|
||||
export abstract class MainThreadErrorsShape {
|
||||
onUnexpectedExtHostError(err: any): void { throw ni(); }
|
||||
}
|
||||
@@ -257,6 +262,10 @@ export abstract class ExtHostEditorsShape {
|
||||
$acceptTextEditorRemove(id: string): void { throw ni(); }
|
||||
}
|
||||
|
||||
export abstract class ExtHostExplorersShape {
|
||||
$provideTextDocumentContent(treeContentProviderId: string): vscode.ITree { throw ni(); };
|
||||
}
|
||||
|
||||
export abstract class ExtHostExtensionServiceShape {
|
||||
$localShowMessage(severity: Severity, msg: string): void { throw ni(); }
|
||||
$activateExtension(extensionDescription: IExtensionDescription): TPromise<void> { throw ni(); }
|
||||
@@ -331,6 +340,7 @@ export const MainContext = {
|
||||
MainThreadDocuments: createMainId<MainThreadDocumentsShape>('MainThreadDocuments', MainThreadDocumentsShape),
|
||||
MainThreadEditors: createMainId<MainThreadEditorsShape>('MainThreadEditors', MainThreadEditorsShape),
|
||||
MainThreadErrors: createMainId<MainThreadErrorsShape>('MainThreadErrors', MainThreadErrorsShape),
|
||||
MainThreadExplorers: createMainId<MainThreadExplorersShape>('MainThreadExplorers', MainThreadExplorersShape),
|
||||
MainThreadLanguageFeatures: createMainId<MainThreadLanguageFeaturesShape>('MainThreadLanguageFeatures', MainThreadLanguageFeaturesShape),
|
||||
MainThreadLanguages: createMainId<MainThreadLanguagesShape>('MainThreadLanguages', MainThreadLanguagesShape),
|
||||
MainThreadMessageService: createMainId<MainThreadMessageServiceShape>('MainThreadMessageService', MainThreadMessageServiceShape),
|
||||
@@ -351,6 +361,7 @@ export const ExtHostContext = {
|
||||
ExtHostDocuments: createExtId<ExtHostDocumentsShape>('ExtHostDocuments', ExtHostDocumentsShape),
|
||||
ExtHostDocumentSaveParticipant: createExtId<ExtHostDocumentSaveParticipantShape>('ExtHostDocumentSaveParticipant', ExtHostDocumentSaveParticipantShape),
|
||||
ExtHostEditors: createExtId<ExtHostEditorsShape>('ExtHostEditors', ExtHostEditorsShape),
|
||||
ExtHostExplorers: createExtId<ExtHostExplorersShape>('ExtHostExplorers',ExtHostExplorersShape),
|
||||
ExtHostFileSystemEventService: createExtId<ExtHostFileSystemEventServiceShape>('ExtHostFileSystemEventService', ExtHostFileSystemEventServiceShape),
|
||||
ExtHostHeapService: createExtId<ExtHostHeapServiceShape>('ExtHostHeapMonitor', ExtHostHeapServiceShape),
|
||||
ExtHostLanguageFeatures: createExtId<ExtHostLanguageFeaturesShape>('ExtHostLanguageFeatures', ExtHostLanguageFeaturesShape),
|
||||
|
||||
51
src/vs/workbench/api/node/extHostExplorers.ts
Normal file
51
src/vs/workbench/api/node/extHostExplorers.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* 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 * as vscode from 'vscode';
|
||||
import {TPromise} from 'vs/base/common/winjs.base';
|
||||
import {Disposable} from 'vs/workbench/api/node/extHostTypes';
|
||||
import {IThreadService} from 'vs/workbench/services/thread/common/threadService';
|
||||
import {MainContext, ExtHostExplorersShape, MainThreadExplorersShape} from './extHost.protocol';
|
||||
|
||||
export class ExtHostExplorers extends ExtHostExplorersShape {
|
||||
private _proxy: MainThreadExplorersShape;
|
||||
|
||||
private _treeContentProviders: { [treeContentProviderId: string]: vscode.TreeContentProvider; };
|
||||
|
||||
constructor(threadService: IThreadService) {
|
||||
super();
|
||||
|
||||
this._proxy = threadService.get(MainContext.MainThreadExplorers);
|
||||
|
||||
this._treeContentProviders = Object.create(null);
|
||||
}
|
||||
|
||||
public registerTreeContentProvider(provider: vscode.TreeContentProvider): vscode.Disposable {
|
||||
const treeContentProviderId = provider.id;
|
||||
|
||||
if (this._treeContentProviders[treeContentProviderId]) {
|
||||
throw new Error(`TreeContentProvider with id '${provider.id} already registered`);
|
||||
}
|
||||
|
||||
this._treeContentProviders[treeContentProviderId] = provider;
|
||||
this._proxy.$registerTreeContentProvider(treeContentProviderId);
|
||||
|
||||
return new Disposable(() => {
|
||||
if (delete this._treeContentProviders[treeContentProviderId]) {
|
||||
this._proxy.$unregisterTreeContentProvider(treeContentProviderId);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
$provideTextDocumentContent(treeContentProviderId: string): vscode.ITree {
|
||||
const provider = this._treeContentProviders[treeContentProviderId];
|
||||
if (!provider) {
|
||||
throw new Error(`no TreeContentProvider registered with id '${treeContentProviderId}'`);
|
||||
}
|
||||
|
||||
return provider.provideTreeContent();
|
||||
}
|
||||
}
|
||||
@@ -264,4 +264,5 @@ export class MainThreadDocuments extends MainThreadDocumentsShape {
|
||||
}
|
||||
}, onUnexpectedError);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
22
src/vs/workbench/api/node/mainThreadExplorers.ts
Normal file
22
src/vs/workbench/api/node/mainThreadExplorers.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import {IThreadService} from 'vs/workbench/services/thread/common/threadService';
|
||||
import {ExtHostContext, MainThreadExplorersShape, ExtHostExplorersShape} from './extHost.protocol';
|
||||
|
||||
export class MainThreadExplorers extends MainThreadExplorersShape {
|
||||
private _proxy: ExtHostExplorersShape;
|
||||
|
||||
constructor(
|
||||
@IThreadService threadService: IThreadService
|
||||
) {
|
||||
super();
|
||||
|
||||
this._proxy = threadService.get(ExtHostContext.ExtHostExplorers);
|
||||
}
|
||||
|
||||
$registerTreeContentProvider(treeContentProviderId: string): void {
|
||||
const tree = this._proxy.$provideTextDocumentContent(treeContentProviderId);
|
||||
}
|
||||
|
||||
$unregisterTreeContentProvider(treeContentProviderId: string): void {
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user