Merge remote-tracking branch 'upstream/master' into treeExplorerAPI

This commit is contained in:
Pine Wu
2016-11-08 23:13:32 -08:00
174 changed files with 6613 additions and 5230 deletions

View File

@@ -9,6 +9,7 @@ import { TrieMap } from 'vs/base/common/map';
import { score } from 'vs/editor/common/modes/languageSelector';
import * as Platform from 'vs/base/common/platform';
import { IThreadService } from 'vs/workbench/services/thread/common/threadService';
import { WorkspaceConfigurationNode } from 'vs/workbench/services/configuration/common/configuration';
import * as errors from 'vs/base/common/errors';
import product from 'vs/platform/product';
import pkg from 'vs/platform/package';
@@ -43,16 +44,16 @@ import * as vscode from 'vscode';
import * as paths from 'vs/base/common/paths';
import { realpathSync } from 'fs';
import { ITelemetryInfo } from 'vs/platform/telemetry/common/telemetry';
import { MainContext, ExtHostContext, InstanceCollection, IInitConfiguration } from './extHost.protocol';
import { MainContext, ExtHostContext, InstanceCollection } from './extHost.protocol';
import * as languageConfiguration from 'vs/editor/common/modes/languageConfiguration';
export interface IExtensionApiFactory {
(extension?: IExtensionDescription): typeof vscode;
(extension: IExtensionDescription): typeof vscode;
}
function proposedApiFunction<T>(extension: IExtensionDescription, fn: T): T {
if (extension && extension.enableProposedApi) {
if (extension.enableProposedApi) {
return fn;
} else {
return <any>(() => {
@@ -64,7 +65,7 @@ function proposedApiFunction<T>(extension: IExtensionDescription, fn: T): T {
/**
* This method instantiates and returns the extension API surface
*/
export function createApiFactory(initDataConfiguration: IInitConfiguration, initTelemetryInfo: ITelemetryInfo, threadService: IThreadService, extensionService: ExtHostExtensionService, contextService: IWorkspaceContextService): IExtensionApiFactory {
export function createApiFactory(initDataConfiguration: WorkspaceConfigurationNode, initTelemetryInfo: ITelemetryInfo, threadService: IThreadService, extensionService: ExtHostExtensionService, contextService: IWorkspaceContextService): IExtensionApiFactory {
// Addressable instances
const col = new InstanceCollection();
@@ -94,9 +95,9 @@ export function createApiFactory(initDataConfiguration: IInitConfiguration, init
// Register API-ish commands
ExtHostApiCommands.register(extHostCommands);
return function (extension?: IExtensionDescription): typeof vscode {
return function (extension: IExtensionDescription): typeof vscode {
if (extension && extension.enableProposedApi) {
if (extension.enableProposedApi) {
console.warn(`${extension.name} (${extension.id}) uses PROPOSED API which is subject to change and removal without notice`);
}
@@ -206,7 +207,7 @@ export function createApiFactory(initDataConfiguration: IInitConfiguration, init
return languageFeatures.registerSignatureHelpProvider(selector, provider, triggerCharacters);
},
registerCompletionItemProvider(selector: vscode.DocumentSelector, provider: vscode.CompletionItemProvider, ...triggerCharacters: string[]): vscode.Disposable {
return languageFeatures.registerCompletionItemProvider(selector, provider, triggerCharacters);
return languageFeatures.registerCompletionItemProvider(selector, provider, triggerCharacters, extension.id);
},
registerDocumentLinkProvider(selector: vscode.DocumentSelector, provider: vscode.DocumentLinkProvider): vscode.Disposable {
return languageFeatures.registerDocumentLinkProvider(selector, provider);
@@ -465,8 +466,23 @@ export function defineAPI(factory: IExtensionApiFactory, extensionService: ExtHo
// fall back to a default implementation
if (!defaultApiImpl) {
defaultApiImpl = factory(undefined);
defaultApiImpl = factory(nullExtensionDescription);
}
return defaultApiImpl;
};
}
const nullExtensionDescription: IExtensionDescription = {
id: 'nullExtensionDescription',
name: 'Null Extension Description',
publisher: 'vscode',
activationEvents: undefined,
contributes: undefined,
enableProposedApi: false,
engines: undefined,
extensionDependencies: undefined,
extensionFolderPath: undefined,
isBuiltin: false,
main: undefined,
version: undefined
};

View File

@@ -29,6 +29,7 @@ import * as modes from 'vs/editor/common/modes';
import { IResourceEdit } from 'vs/editor/common/services/bulkEdit';
import { ConfigurationTarget } from 'vs/workbench/services/configuration/common/configurationEditing';
import { WorkspaceConfigurationNode } from 'vs/workbench/services/configuration/common/configuration';
import { IPickOpenEntry, IPickOptions } from 'vs/workbench/services/quickopen/common/quickOpenService';
import { SaveReason } from 'vs/workbench/services/textfile/common/textfiles';
@@ -45,10 +46,6 @@ export interface IEnvironment {
extensionTestsPath: string;
}
export interface IInitConfiguration {
_initConfigurationBrand: void;
}
export interface IInitData {
parentPid: number;
environment: IEnvironment;
@@ -56,7 +53,7 @@ export interface IInitData {
workspace: IWorkspace;
};
extensions: IExtensionDescription[];
configuration: IInitConfiguration;
configuration: WorkspaceConfigurationNode;
telemetryInfo: ITelemetryInfo;
}
@@ -238,7 +235,7 @@ export abstract class ExtHostCommandsShape {
}
export abstract class ExtHostConfigurationShape {
$acceptConfigurationChanged(config: any) { throw ni(); }
$acceptConfigurationChanged(config: WorkspaceConfigurationNode) { throw ni(); }
}
export abstract class ExtHostDiagnosticsShape {

View File

@@ -9,24 +9,25 @@ import Event, { Emitter } from 'vs/base/common/event';
import { WorkspaceConfiguration } from 'vscode';
import { ExtHostConfigurationShape, MainThreadConfigurationShape } from './extHost.protocol';
import { ConfigurationTarget } from 'vs/workbench/services/configuration/common/configurationEditing';
import { WorkspaceConfigurationNode, IWorkspaceConfigurationValue } from 'vs/workbench/services/configuration/common/configuration';
export class ExtHostConfiguration extends ExtHostConfigurationShape {
private _proxy: MainThreadConfigurationShape;
private _config: any;
private _config: WorkspaceConfigurationNode;
private _onDidChangeConfiguration = new Emitter<void>();
constructor(proxy: MainThreadConfigurationShape, configuration: any) {
constructor(proxy: MainThreadConfigurationShape, config: WorkspaceConfigurationNode) {
super();
this._proxy = proxy;
this._config = configuration;
this._config = config;
}
get onDidChangeConfiguration(): Event<void> {
return this._onDidChangeConfiguration && this._onDidChangeConfiguration.event;
}
public $acceptConfigurationChanged(config: any) {
public $acceptConfigurationChanged(config: WorkspaceConfigurationNode) {
this._config = config;
this._onDidChangeConfiguration.fire(undefined);
}
@@ -39,14 +40,17 @@ export class ExtHostConfiguration extends ExtHostConfigurationShape {
const result: WorkspaceConfiguration = {
has(key: string): boolean {
return typeof ExtHostConfiguration._lookUp(key, config) !== 'undefined';
return typeof ExtHostConfiguration._lookUp(key, <WorkspaceConfigurationNode>config) !== 'undefined';
},
get<T>(key: string, defaultValue?: T): T {
let result = ExtHostConfiguration._lookUp(key, config);
get<T>(key: string, defaultValue?: T): any {
let result = ExtHostConfiguration._lookUp(key, <WorkspaceConfigurationNode>config);
if (typeof result === 'undefined') {
result = defaultValue;
return defaultValue;
} else if (isConfigurationValue(result)) {
return result.value;
} else {
return ExtHostConfiguration._values(result);
}
return result;
},
update: (key: string, value: any, global: boolean = false) => {
key = section ? `${section}.${key}` : key;
@@ -56,26 +60,66 @@ export class ExtHostConfiguration extends ExtHostConfigurationShape {
} else {
return this._proxy.$removeConfigurationOption(target, key);
}
},
inspect(key: string) {
let result = ExtHostConfiguration._lookUp(key, <WorkspaceConfigurationNode>config);
if (isConfigurationValue(result)) {
return {
key: section ? `${section}.${key}` : key,
defaultValue: result.default,
globalValue: result.user,
workspaceValue: result.workspace
};
}
}
};
if (typeof config === 'object') {
mixin(result, config, false);
if (!isConfigurationValue(config)) {
mixin(result, ExtHostConfiguration._values(config), false);
}
return Object.freeze(result);
}
private static _lookUp(section: string, config: any) {
private static _lookUp(section: string, config: WorkspaceConfigurationNode): WorkspaceConfigurationNode | IWorkspaceConfigurationValue<any> {
if (!section) {
return;
}
let parts = section.split('.');
let node = config;
while (node && parts.length) {
node = node[parts.shift()];
let child = node[parts.shift()];
if (isConfigurationValue(child)) {
return child;
} else {
node = child;
}
}
return node;
}
private static _values(node: WorkspaceConfigurationNode): any {
let target = Object.create(null);
for (let key in node) {
let child = node[key];
if (isConfigurationValue(child)) {
target[key] = child.value;
} else {
target[key] = ExtHostConfiguration._values(child);
}
}
return target;
}
}
function isConfigurationValue(thing: any): thing is IWorkspaceConfigurationValue<any> {
return typeof thing === 'object'
// must have 'value'
&& typeof (<IWorkspaceConfigurationValue<any>>thing).value !== 'undefined'
// and at least one source 'default', 'user', or 'workspace'
&& (typeof (<IWorkspaceConfigurationValue<any>>thing).default !== 'undefined'
|| typeof (<IWorkspaceConfigurationValue<any>>thing).user !== 'undefined'
|| typeof (<IWorkspaceConfigurationValue<any>>thing).workspace !== 'undefined');
}

View File

@@ -412,12 +412,14 @@ class SuggestAdapter {
private _commands: CommandsConverter;
private _heapService: ExtHostHeapService;
private _provider: vscode.CompletionItemProvider;
private _extensionId: string;
constructor(documents: ExtHostDocuments, commands: CommandsConverter, heapService: ExtHostHeapService, provider: vscode.CompletionItemProvider) {
constructor(documents: ExtHostDocuments, commands: CommandsConverter, heapService: ExtHostHeapService, provider: vscode.CompletionItemProvider, extensionId?: string) {
this._documents = documents;
this._commands = commands;
this._heapService = heapService;
this._provider = provider;
this._extensionId = extensionId;
}
provideCompletionItems(resource: URI, position: IPosition): TPromise<modes.ISuggestResult> {
@@ -477,6 +479,10 @@ class SuggestAdapter {
suggestion.overwriteAfter = 0;
}
if (this._extensionId) {
suggestion._extensionId = this._extensionId;
}
// store suggestion
result.suggestions.push(suggestion);
}
@@ -771,9 +777,9 @@ export class ExtHostLanguageFeatures extends ExtHostLanguageFeaturesShape {
// --- suggestion
registerCompletionItemProvider(selector: vscode.DocumentSelector, provider: vscode.CompletionItemProvider, triggerCharacters: string[]): vscode.Disposable {
registerCompletionItemProvider(selector: vscode.DocumentSelector, provider: vscode.CompletionItemProvider, triggerCharacters: string[], extensionId?: string): vscode.Disposable {
const handle = this._nextHandle();
this._adapter[handle] = new SuggestAdapter(this._documents, this._commands.converter, this._heapService, provider);
this._adapter[handle] = new SuggestAdapter(this._documents, this._commands.converter, this._heapService, provider, extensionId);
this._proxy.$registerSuggestSupport(handle, selector, triggerCharacters);
return this._createDisposable(handle);
}

View File

@@ -7,7 +7,7 @@
import { TPromise } from 'vs/base/common/winjs.base';
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { IThreadService } from 'vs/workbench/services/thread/common/threadService';
import { IWorkspaceConfigurationService } from 'vs/workbench/services/configuration/common/configuration';
import { IWorkspaceConfigurationService, getWorkspaceConfigurationTree } from 'vs/workbench/services/configuration/common/configuration';
import { IConfigurationEditingService, ConfigurationTarget } from 'vs/workbench/services/configuration/common/configurationEditing';
import { MainThreadConfigurationShape, ExtHostContext } from './extHost.protocol';
@@ -24,7 +24,11 @@ export class MainThreadConfiguration extends MainThreadConfigurationShape {
super();
this._configurationEditingService = configurationEditingService;
const proxy = threadService.get(ExtHostContext.ExtHostConfiguration);
this._toDispose = configurationService.onDidUpdateConfiguration(event => proxy.$acceptConfigurationChanged(event.config));
this._toDispose = configurationService.onDidUpdateConfiguration(() => {
const tree = getWorkspaceConfigurationTree(configurationService);
proxy.$acceptConfigurationChanged(tree);
});
}
public dispose(): void {