mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-22 17:22:59 -05:00
Merge from vscode 1ce89e2cb720d69c496c2815c4696ee4fd4429a6 (#6779)
* Merge from vscode 1ce89e2cb720d69c496c2815c4696ee4fd4429a6 * redisable accounts because of issues
This commit is contained in:
@@ -90,7 +90,6 @@ export class MainThreadEditorInsets implements MainThreadEditorInsetsShape {
|
||||
|
||||
const webview = this._webviewService.createWebview('' + handle, {
|
||||
enableFindWidget: false,
|
||||
allowSvgs: false,
|
||||
extension: { id: extensionId, location: URI.revive(extensionLocation) }
|
||||
}, {
|
||||
allowScripts: options.enableScripts,
|
||||
|
||||
@@ -15,7 +15,6 @@ export class MainThreadCommands implements MainThreadCommandsShape {
|
||||
private readonly _commandRegistrations = new Map<string, IDisposable>();
|
||||
private readonly _generateCommandsDocumentationRegistration: IDisposable;
|
||||
private readonly _proxy: ExtHostCommandsShape;
|
||||
private _onDidExecuteCommandListener?: IDisposable;
|
||||
|
||||
constructor(
|
||||
extHostContext: IExtHostContext,
|
||||
@@ -78,19 +77,6 @@ export class MainThreadCommands implements MainThreadCommandsShape {
|
||||
return this._commandService.executeCommand<T>(id, ...args);
|
||||
}
|
||||
|
||||
$registerCommandListener() {
|
||||
if (!this._onDidExecuteCommandListener) {
|
||||
this._onDidExecuteCommandListener = this._commandService.onDidExecuteCommand(command => this._proxy.$handleDidExecuteCommand(command));
|
||||
}
|
||||
}
|
||||
|
||||
$unregisterCommandListener() {
|
||||
if (this._onDidExecuteCommandListener) {
|
||||
this._onDidExecuteCommandListener.dispose();
|
||||
this._onDidExecuteCommandListener = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
$getCommands(): Promise<string[]> {
|
||||
return Promise.resolve([...CommandsRegistry.getCommands().keys()]);
|
||||
}
|
||||
|
||||
@@ -5,49 +5,33 @@
|
||||
|
||||
import { extHostNamedCustomer } from 'vs/workbench/api/common/extHostCustomers';
|
||||
import { MainContext, MainThreadKeytarShape, IExtHostContext } from 'vs/workbench/api/common/extHost.protocol';
|
||||
import { ICredentialsService } from 'vs/platform/credentials/common/credentials';
|
||||
import { optional } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { ICredentialsService } from 'vs/workbench/services/credentials/common/credentials';
|
||||
|
||||
@extHostNamedCustomer(MainContext.MainThreadKeytar)
|
||||
export class MainThreadKeytar implements MainThreadKeytarShape {
|
||||
|
||||
private readonly _credentialsService?: ICredentialsService;
|
||||
|
||||
constructor(
|
||||
_extHostContext: IExtHostContext,
|
||||
@optional(ICredentialsService) credentialsService: ICredentialsService,
|
||||
) {
|
||||
this._credentialsService = credentialsService;
|
||||
@ICredentialsService private readonly _credentialsService: ICredentialsService,
|
||||
) { }
|
||||
|
||||
async $getPassword(service: string, account: string): Promise<string | null> {
|
||||
return this._credentialsService.getPassword(service, account);
|
||||
}
|
||||
|
||||
async $setPassword(service: string, account: string, password: string): Promise<void> {
|
||||
return this._credentialsService.setPassword(service, account, password);
|
||||
}
|
||||
|
||||
async $deletePassword(service: string, account: string): Promise<boolean> {
|
||||
return this._credentialsService.deletePassword(service, account);
|
||||
}
|
||||
|
||||
async $findPassword(service: string): Promise<string | null> {
|
||||
return this._credentialsService.findPassword(service);
|
||||
}
|
||||
|
||||
dispose(): void {
|
||||
//
|
||||
}
|
||||
|
||||
async $getPassword(service: string, account: string): Promise<string | null> {
|
||||
if (this._credentialsService) {
|
||||
return this._credentialsService.getPassword(service, account);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
async $setPassword(service: string, account: string, password: string): Promise<void> {
|
||||
if (this._credentialsService) {
|
||||
return this._credentialsService.setPassword(service, account, password);
|
||||
}
|
||||
}
|
||||
|
||||
async $deletePassword(service: string, account: string): Promise<boolean> {
|
||||
if (this._credentialsService) {
|
||||
return this._credentialsService.deletePassword(service, account);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
async $findPassword(service: string): Promise<string | null> {
|
||||
if (this._credentialsService) {
|
||||
return this._credentialsService.findPassword(service);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,13 +27,14 @@ export class MainThreadTreeViews extends Disposable implements MainThreadTreeVie
|
||||
this._proxy = extHostContext.getProxy(ExtHostContext.ExtHostTreeViews);
|
||||
}
|
||||
|
||||
$registerTreeViewDataProvider(treeViewId: string, options: { showCollapseAll: boolean }): void {
|
||||
$registerTreeViewDataProvider(treeViewId: string, options: { showCollapseAll: boolean, canSelectMany: boolean }): void {
|
||||
const dataProvider = new TreeViewDataProvider(treeViewId, this._proxy, this.notificationService);
|
||||
this._dataProviders.set(treeViewId, dataProvider);
|
||||
const viewer = this.getTreeView(treeViewId);
|
||||
if (viewer) {
|
||||
viewer.dataProvider = dataProvider;
|
||||
viewer.showCollapseAllAction = !!options.showCollapseAll;
|
||||
viewer.canSelectMany = !!options.canSelectMany;
|
||||
this.registerListeners(treeViewId, viewer);
|
||||
this._proxy.$setVisible(treeViewId, viewer.visible);
|
||||
} else {
|
||||
|
||||
@@ -327,7 +327,7 @@ export class MainThreadWebviews extends Disposable implements MainThreadWebviews
|
||||
if (MainThreadWebviews.standardSupportedLinkSchemes.has(link.scheme)) {
|
||||
return true;
|
||||
}
|
||||
if (this._productService.productConfiguration.urlProtocol === link.scheme) {
|
||||
if (this._productService.urlProtocol === link.scheme) {
|
||||
return true;
|
||||
}
|
||||
return !!webview.webview.contentOptions.enableCommandUris && link.scheme === 'command';
|
||||
|
||||
@@ -151,7 +151,7 @@ const viewsContribution: IJSONSchema = {
|
||||
default: []
|
||||
},
|
||||
'remote': {
|
||||
description: localize('views.remote', "Contributes views to Remote container in the Activity bar"),
|
||||
description: localize('views.remote', "Contributes views to Remote container in the Activity bar. To contribute to this container, enableProposedApi needs to be turned on"),
|
||||
type: 'array',
|
||||
items: nestableViewDescriptor,
|
||||
default: []
|
||||
@@ -387,6 +387,11 @@ class ViewsExtensionHandler implements IWorkbenchContribution {
|
||||
return;
|
||||
}
|
||||
|
||||
if (entry.key === 'remote' && !extension.description.enableProposedApi) {
|
||||
collector.warn(localize('ViewContainerRequiresProposedAPI', "View container '{0}' requires 'enableProposedApi' turned on to be added to 'Remote'.", entry.key));
|
||||
return;
|
||||
}
|
||||
|
||||
const viewContainer = this.getViewContainer(entry.key);
|
||||
if (!viewContainer) {
|
||||
collector.warn(localize('ViewContainerDoesnotExist', "View container '{0}' does not exist and all views registered to it will be added to 'Explorer'.", entry.key));
|
||||
|
||||
@@ -225,11 +225,7 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
|
||||
},
|
||||
getCommands(filterInternal: boolean = false): Thenable<string[]> {
|
||||
return extHostCommands.getCommands(filterInternal);
|
||||
},
|
||||
onDidExecuteCommand: proposedApiFunction(extension, (listener, thisArgs?, disposables?) => {
|
||||
checkProposedApiEnabled(extension);
|
||||
return extHostCommands.onDidExecuteCommand(listener, thisArgs, disposables);
|
||||
}),
|
||||
}
|
||||
};
|
||||
|
||||
// namespace: env
|
||||
|
||||
@@ -21,7 +21,7 @@ import { EndOfLineSequence, ISingleEditOperation } from 'vs/editor/common/model'
|
||||
import { IModelChangedEvent } from 'vs/editor/common/model/mirrorTextModel';
|
||||
import * as modes from 'vs/editor/common/modes';
|
||||
import { CharacterPair, CommentRule, EnterAction } from 'vs/editor/common/modes/languageConfiguration';
|
||||
import { ICommandHandlerDescription, ICommandEvent } from 'vs/platform/commands/common/commands';
|
||||
import { ICommandHandlerDescription } from 'vs/platform/commands/common/commands';
|
||||
import { ConfigurationTarget, IConfigurationData, IConfigurationModel } from 'vs/platform/configuration/common/configuration';
|
||||
import { ConfigurationScope } from 'vs/platform/configuration/common/configurationRegistry';
|
||||
import { ExtensionIdentifier, IExtensionDescription } from 'vs/platform/extensions/common/extensions';
|
||||
@@ -119,8 +119,6 @@ export interface MainThreadClipboardShape extends IDisposable {
|
||||
|
||||
export interface MainThreadCommandsShape extends IDisposable {
|
||||
$registerCommand(id: string): void;
|
||||
$registerCommandListener(): void;
|
||||
$unregisterCommandListener(): void;
|
||||
$unregisterCommand(id: string): void;
|
||||
$executeCommand<T>(id: string, args: any[]): Promise<T | undefined>;
|
||||
$getCommands(): Promise<string[]>;
|
||||
@@ -246,7 +244,7 @@ export interface MainThreadTextEditorsShape extends IDisposable {
|
||||
}
|
||||
|
||||
export interface MainThreadTreeViewsShape extends IDisposable {
|
||||
$registerTreeViewDataProvider(treeViewId: string, options: { showCollapseAll: boolean }): void;
|
||||
$registerTreeViewDataProvider(treeViewId: string, options: { showCollapseAll: boolean, canSelectMany: boolean }): void;
|
||||
$refresh(treeViewId: string, itemsToRefresh?: { [treeItemHandle: string]: ITreeItem }): Promise<void>;
|
||||
$reveal(treeViewId: string, treeItem: ITreeItem, parentChain: ITreeItem[], options: IRevealOptions): Promise<void>;
|
||||
$setMessage(treeViewId: string, message: string): void;
|
||||
@@ -739,7 +737,6 @@ export interface MainThreadWindowShape extends IDisposable {
|
||||
export interface ExtHostCommandsShape {
|
||||
$executeContributedCommand<T>(id: string, ...args: any[]): Promise<T>;
|
||||
$getContributedCommandHandlerDescriptions(): Promise<{ [id: string]: string | ICommandHandlerDescription }>;
|
||||
$handleDidExecuteCommand(command: ICommandEvent): void;
|
||||
}
|
||||
|
||||
export interface ExtHostConfigurationShape {
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { validateConstraint } from 'vs/base/common/types';
|
||||
import { ICommandHandlerDescription, ICommandEvent } from 'vs/platform/commands/common/commands';
|
||||
import { ICommandHandlerDescription } from 'vs/platform/commands/common/commands';
|
||||
import * as extHostTypes from 'vs/workbench/api/common/extHostTypes';
|
||||
import * as extHostTypeConverter from 'vs/workbench/api/common/extHostTypeConverters';
|
||||
import { cloneAndChange } from 'vs/base/common/objects';
|
||||
@@ -17,7 +17,6 @@ import { revive } from 'vs/base/common/marshalling';
|
||||
import { Range } from 'vs/editor/common/core/range';
|
||||
import { Position } from 'vs/editor/common/core/position';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { Event, Emitter } from 'vs/base/common/event';
|
||||
import { DisposableStore, toDisposable } from 'vs/base/common/lifecycle';
|
||||
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { IExtHostRpcService } from 'vs/workbench/api/common/extHostRpcService';
|
||||
@@ -36,9 +35,6 @@ export class ExtHostCommands implements ExtHostCommandsShape {
|
||||
|
||||
readonly _serviceBrand: any;
|
||||
|
||||
private readonly _onDidExecuteCommand: Emitter<vscode.CommandExecutionEvent>;
|
||||
readonly onDidExecuteCommand: Event<vscode.CommandExecutionEvent>;
|
||||
|
||||
private readonly _commands = new Map<string, CommandHandler>();
|
||||
private readonly _proxy: MainThreadCommandsShape;
|
||||
private readonly _converter: CommandsConverter;
|
||||
@@ -50,11 +46,6 @@ export class ExtHostCommands implements ExtHostCommandsShape {
|
||||
@ILogService logService: ILogService
|
||||
) {
|
||||
this._proxy = extHostRpc.getProxy(MainContext.MainThreadCommands);
|
||||
this._onDidExecuteCommand = new Emitter<vscode.CommandExecutionEvent>({
|
||||
onFirstListenerDidAdd: () => this._proxy.$registerCommandListener(),
|
||||
onLastListenerRemove: () => this._proxy.$unregisterCommandListener(),
|
||||
});
|
||||
this.onDidExecuteCommand = Event.filter(this._onDidExecuteCommand.event, e => e.command[0] !== '_'); // filter 'private' commands
|
||||
this._logService = logService;
|
||||
this._converter = new CommandsConverter(this);
|
||||
this._argumentProcessors = [
|
||||
@@ -119,22 +110,13 @@ export class ExtHostCommands implements ExtHostCommandsShape {
|
||||
});
|
||||
}
|
||||
|
||||
$handleDidExecuteCommand(command: ICommandEvent): void {
|
||||
this._onDidExecuteCommand.fire({
|
||||
command: command.commandId,
|
||||
arguments: command.args.map(arg => this._argumentProcessors.reduce((r, p) => p.processArgument(r), arg))
|
||||
});
|
||||
}
|
||||
|
||||
executeCommand<T>(id: string, ...args: any[]): Promise<T> {
|
||||
this._logService.trace('ExtHostCommands#executeCommand', id);
|
||||
|
||||
if (this._commands.has(id)) {
|
||||
// we stay inside the extension host and support
|
||||
// to pass any kind of parameters around
|
||||
const res = this._executeContributedCommand<T>(id, args);
|
||||
this._onDidExecuteCommand.fire({ command: id, arguments: args });
|
||||
return res;
|
||||
return this._executeContributedCommand<T>(id, args);
|
||||
|
||||
} else {
|
||||
// automagically convert some argument types
|
||||
|
||||
@@ -5,14 +5,22 @@
|
||||
|
||||
import { TernarySearchTree } from 'vs/base/common/map';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { MainThreadKeytarShape, IEnvironment, MainThreadWindowShape, MainThreadTelemetryShape } from 'vs/workbench/api/common/extHost.protocol';
|
||||
import { ExtHostConfigProvider } from 'vs/workbench/api/common/extHostConfiguration';
|
||||
import { MainThreadTelemetryShape, MainContext } from 'vs/workbench/api/common/extHost.protocol';
|
||||
import { ExtHostConfigProvider, IExtHostConfiguration } from 'vs/workbench/api/common/extHostConfiguration';
|
||||
import { nullExtensionDescription } from 'vs/workbench/services/extensions/common/extensions';
|
||||
import { ExtensionDescriptionRegistry } from 'vs/workbench/services/extensions/common/extensionDescriptionRegistry';
|
||||
import * as vscode from 'vscode';
|
||||
import { ExtensionIdentifier, IExtensionDescription } from 'vs/platform/extensions/common/extensions';
|
||||
import { endsWith } from 'vs/base/common/strings';
|
||||
import { IExtensionApiFactory } from 'vs/workbench/api/common/extHost.api.impl';
|
||||
import { IExtHostRpcService } from 'vs/workbench/api/common/extHostRpcService';
|
||||
import { IExtHostInitDataService } from 'vs/workbench/api/common/extHostInitDataService';
|
||||
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { IExtHostExtensionService } from 'vs/workbench/api/common/extHostExtensionService';
|
||||
import { platform } from 'vs/base/common/process';
|
||||
|
||||
import { AzdataNodeModuleFactory, SqlopsNodeModuleFactory } from 'sql/workbench/api/common/extHostRequireInterceptor'; // {{SQL CARBON EDIT}}
|
||||
import { IExtensionApiFactory as sqlIApiFactory } from 'sql/workbench/api/common/sqlExtHost.api.impl'; // {{SQL CARBON EDIT}}
|
||||
|
||||
|
||||
interface LoadFunction {
|
||||
@@ -21,40 +29,45 @@ interface LoadFunction {
|
||||
|
||||
export interface INodeModuleFactory { //{{SQL CARBON EDIT}} export interface
|
||||
readonly nodeModuleName: string | string[];
|
||||
load(request: string, parent: { filename: string; }, isMain: any, original: LoadFunction): any;
|
||||
alternaiveModuleName?(name: string): string | undefined;
|
||||
load(request: string, parent: URI, isMain: any, original: LoadFunction): any;
|
||||
alternativeModuleName?(name: string): string | undefined;
|
||||
}
|
||||
|
||||
export class NodeModuleRequireInterceptor {
|
||||
public static INSTANCE = new NodeModuleRequireInterceptor();
|
||||
export abstract class RequireInterceptor {
|
||||
|
||||
private readonly _factories: Map<string, INodeModuleFactory>;
|
||||
private readonly _alternatives: ((moduleName: string) => string | undefined)[];
|
||||
protected readonly _factories: Map<string, INodeModuleFactory>;
|
||||
protected readonly _alternatives: ((moduleName: string) => string | undefined)[];
|
||||
|
||||
constructor() {
|
||||
constructor(
|
||||
private _apiFactory: sqlIApiFactory, // {{SQL CARBON EDIT}} replace with ours
|
||||
private _extensionRegistry: ExtensionDescriptionRegistry,
|
||||
@IInstantiationService private readonly _instaService: IInstantiationService,
|
||||
@IExtHostConfiguration private readonly _extHostConfiguration: IExtHostConfiguration,
|
||||
@IExtHostExtensionService private readonly _extHostExtensionService: IExtHostExtensionService,
|
||||
@IExtHostInitDataService private readonly _initData: IExtHostInitDataService
|
||||
) {
|
||||
this._factories = new Map<string, INodeModuleFactory>();
|
||||
this._alternatives = [];
|
||||
this._installInterceptor(this._factories, this._alternatives);
|
||||
}
|
||||
|
||||
private _installInterceptor(factories: Map<string, INodeModuleFactory>, alternatives: ((moduleName: string) => string | undefined)[]): void {
|
||||
const node_module = <any>require.__$__nodeRequire('module');
|
||||
const original = node_module._load;
|
||||
node_module._load = function load(request: string, parent: { filename: string; }, isMain: any) {
|
||||
for (let alternativeModuleName of alternatives) {
|
||||
let alternative = alternativeModuleName(request);
|
||||
if (alternative) {
|
||||
request = alternative;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!factories.has(request)) {
|
||||
return original.apply(this, arguments);
|
||||
}
|
||||
return factories.get(request)!.load(request, parent, isMain, original);
|
||||
};
|
||||
async install(): Promise<void> {
|
||||
|
||||
this._installInterceptor();
|
||||
|
||||
const configProvider = await this._extHostConfiguration.getConfigProvider();
|
||||
const extensionPaths = await this._extHostExtensionService.getExtensionPathIndex();
|
||||
|
||||
this.register(new VSCodeNodeModuleFactory(this._apiFactory.vscode, extensionPaths, this._extensionRegistry, configProvider)); // {{SQL CARBON EDIT}} // add node module
|
||||
this.register(new AzdataNodeModuleFactory(this._apiFactory.azdata, extensionPaths)); // {{SQL CARBON EDIT}} // add node module
|
||||
this.register(new SqlopsNodeModuleFactory(this._apiFactory.sqlops, extensionPaths)); // {{SQL CARBON EDIT}} // add node module
|
||||
this.register(this._instaService.createInstance(KeytarNodeModuleFactory));
|
||||
if (this._initData.remote.isRemote) {
|
||||
this.register(this._instaService.createInstance(OpenNodeModuleFactory, extensionPaths));
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract _installInterceptor(): void;
|
||||
|
||||
public register(interceptor: INodeModuleFactory): void {
|
||||
if (Array.isArray(interceptor.nodeModuleName)) {
|
||||
for (let moduleName of interceptor.nodeModuleName) {
|
||||
@@ -63,15 +76,17 @@ export class NodeModuleRequireInterceptor {
|
||||
} else {
|
||||
this._factories.set(interceptor.nodeModuleName, interceptor);
|
||||
}
|
||||
if (typeof interceptor.alternaiveModuleName === 'function') {
|
||||
if (typeof interceptor.alternativeModuleName === 'function') {
|
||||
this._alternatives.push((moduleName) => {
|
||||
return interceptor.alternaiveModuleName!(moduleName);
|
||||
return interceptor.alternativeModuleName!(moduleName);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export class VSCodeNodeModuleFactory implements INodeModuleFactory {
|
||||
//#region --- vscode-module
|
||||
|
||||
class VSCodeNodeModuleFactory implements INodeModuleFactory {
|
||||
public readonly nodeModuleName = 'vscode';
|
||||
|
||||
private readonly _extApiImpl = new Map<string, typeof vscode>();
|
||||
@@ -85,10 +100,10 @@ export class VSCodeNodeModuleFactory implements INodeModuleFactory {
|
||||
) {
|
||||
}
|
||||
|
||||
public load(request: string, parent: { filename: string; }): any {
|
||||
public load(_request: string, parent: URI): any {
|
||||
|
||||
// get extension id from filename and api for extension
|
||||
const ext = this._extensionPaths.findSubstr(URI.file(parent.filename).fsPath);
|
||||
const ext = this._extensionPaths.findSubstr(parent.fsPath);
|
||||
if (ext) {
|
||||
let apiImpl = this._extApiImpl.get(ExtensionIdentifier.toKey(ext.identifier));
|
||||
if (!apiImpl) {
|
||||
@@ -102,13 +117,18 @@ export class VSCodeNodeModuleFactory implements INodeModuleFactory {
|
||||
if (!this._defaultApiImpl) {
|
||||
let extensionPathsPretty = '';
|
||||
this._extensionPaths.forEach((value, index) => extensionPathsPretty += `\t${index} -> ${value.identifier.value}\n`);
|
||||
console.warn(`Could not identify extension for 'vscode' require call from ${parent.filename}. These are the extension path mappings: \n${extensionPathsPretty}`);
|
||||
console.warn(`Could not identify extension for 'vscode' require call from ${parent.fsPath}. These are the extension path mappings: \n${extensionPathsPretty}`);
|
||||
this._defaultApiImpl = this._apiFactory(nullExtensionDescription, this._extensionRegistry, this._configProvider);
|
||||
}
|
||||
return this._defaultApiImpl;
|
||||
}
|
||||
}
|
||||
|
||||
//#endregion
|
||||
|
||||
|
||||
//#region --- keytar-module
|
||||
|
||||
interface IKeytarModule {
|
||||
getPassword(service: string, account: string): Promise<string | null>;
|
||||
setPassword(service: string, account: string, password: string): Promise<void>;
|
||||
@@ -116,16 +136,23 @@ interface IKeytarModule {
|
||||
findPassword(service: string): Promise<string | null>;
|
||||
}
|
||||
|
||||
export class KeytarNodeModuleFactory implements INodeModuleFactory {
|
||||
class KeytarNodeModuleFactory implements INodeModuleFactory {
|
||||
public readonly nodeModuleName: string = 'keytar';
|
||||
|
||||
private alternativeNames: Set<string> | undefined;
|
||||
private _impl: IKeytarModule;
|
||||
|
||||
constructor(mainThreadKeytar: MainThreadKeytarShape, environment: IEnvironment) {
|
||||
constructor(
|
||||
@IExtHostRpcService rpcService: IExtHostRpcService,
|
||||
@IExtHostInitDataService initData: IExtHostInitDataService,
|
||||
|
||||
) {
|
||||
const { environment } = initData;
|
||||
const mainThreadKeytar = rpcService.getProxy(MainContext.MainThreadKeytar);
|
||||
|
||||
if (environment.appRoot) {
|
||||
let appRoot = environment.appRoot.fsPath;
|
||||
if (process.platform === 'win32') {
|
||||
if (platform === 'win32') {
|
||||
appRoot = appRoot.replace(/\\/g, '/');
|
||||
}
|
||||
if (appRoot[appRoot.length - 1] === '/') {
|
||||
@@ -151,11 +178,11 @@ export class KeytarNodeModuleFactory implements INodeModuleFactory {
|
||||
};
|
||||
}
|
||||
|
||||
public load(request: string, parent: { filename: string; }): any {
|
||||
public load(_request: string, _parent: URI): any {
|
||||
return this._impl;
|
||||
}
|
||||
|
||||
public alternaiveModuleName(name: string): string | undefined {
|
||||
public alternativeModuleName(name: string): string | undefined {
|
||||
const length = name.length;
|
||||
// We need at least something like: `?/keytar` which requires
|
||||
// more than 7 characters.
|
||||
@@ -173,6 +200,11 @@ export class KeytarNodeModuleFactory implements INodeModuleFactory {
|
||||
}
|
||||
}
|
||||
|
||||
//#endregion
|
||||
|
||||
|
||||
//#region --- opn/open-module
|
||||
|
||||
interface OpenOptions {
|
||||
wait: boolean;
|
||||
app: string | string[];
|
||||
@@ -186,15 +218,23 @@ interface IOpenModule {
|
||||
(target: string, options?: OpenOptions): Thenable<void>;
|
||||
}
|
||||
|
||||
export class OpenNodeModuleFactory implements INodeModuleFactory {
|
||||
class OpenNodeModuleFactory implements INodeModuleFactory {
|
||||
|
||||
public readonly nodeModuleName: string[] = ['open', 'opn'];
|
||||
|
||||
private _extensionId: string | undefined;
|
||||
private _original?: IOriginalOpen;
|
||||
private _impl: IOpenModule;
|
||||
private _mainThreadTelemetry: MainThreadTelemetryShape;
|
||||
|
||||
constructor(
|
||||
private readonly _extensionPaths: TernarySearchTree<IExtensionDescription>,
|
||||
@IExtHostRpcService rpcService: IExtHostRpcService,
|
||||
) {
|
||||
|
||||
this._mainThreadTelemetry = rpcService.getProxy(MainContext.MainThreadTelemetry);
|
||||
const mainThreadWindow = rpcService.getProxy(MainContext.MainThreadWindow);
|
||||
|
||||
constructor(mainThreadWindow: MainThreadWindowShape, private _mainThreadTelemerty: MainThreadTelemetryShape, private readonly _extensionPaths: TernarySearchTree<IExtensionDescription>) {
|
||||
this._impl = (target, options) => {
|
||||
const uri: URI = URI.parse(target);
|
||||
// If we have options use the original method.
|
||||
@@ -210,15 +250,15 @@ export class OpenNodeModuleFactory implements INodeModuleFactory {
|
||||
};
|
||||
}
|
||||
|
||||
public load(request: string, parent: { filename: string; }, isMain: any, original: LoadFunction): any {
|
||||
public load(request: string, parent: URI, isMain: any, original: LoadFunction): any {
|
||||
// get extension id from filename and api for extension
|
||||
const extension = this._extensionPaths.findSubstr(URI.file(parent.filename).fsPath);
|
||||
const extension = this._extensionPaths.findSubstr(parent.fsPath);
|
||||
if (extension) {
|
||||
this._extensionId = extension.identifier.value;
|
||||
this.sendShimmingTelemetry();
|
||||
}
|
||||
|
||||
this._original = original(request, parent, isMain);
|
||||
this._original = original(request, { filename: parent.fsPath }, isMain);
|
||||
return this._impl;
|
||||
}
|
||||
|
||||
@@ -234,7 +274,7 @@ export class OpenNodeModuleFactory implements INodeModuleFactory {
|
||||
type ShimmingOpenClassification = {
|
||||
extension: { classification: 'SystemMetaData', purpose: 'FeatureInsight' };
|
||||
};
|
||||
this._mainThreadTelemerty.$publicLog2<{ extension: string }, ShimmingOpenClassification>('shimming.open', { extension: this._extensionId });
|
||||
this._mainThreadTelemetry.$publicLog2<{ extension: string }, ShimmingOpenClassification>('shimming.open', { extension: this._extensionId });
|
||||
}
|
||||
|
||||
private sendNoForwardTelemetry(): void {
|
||||
@@ -244,6 +284,8 @@ export class OpenNodeModuleFactory implements INodeModuleFactory {
|
||||
type ShimmingOpenCallNoForwardClassification = {
|
||||
extension: { classification: 'SystemMetaData', purpose: 'FeatureInsight' };
|
||||
};
|
||||
this._mainThreadTelemerty.$publicLog2<{ extension: string }, ShimmingOpenCallNoForwardClassification>('shimming.open.call.noForward', { extension: this._extensionId });
|
||||
this._mainThreadTelemetry.$publicLog2<{ extension: string }, ShimmingOpenCallNoForwardClassification>('shimming.open.call.noForward', { extension: this._extensionId });
|
||||
}
|
||||
}
|
||||
|
||||
//#endregion
|
||||
@@ -55,10 +55,21 @@ export class ExtHostTreeViews implements ExtHostTreeViewsShape {
|
||||
private commands: ExtHostCommands,
|
||||
private logService: ILogService
|
||||
) {
|
||||
|
||||
function isTreeViewItemHandleArg(arg: any): boolean {
|
||||
return arg && arg.$treeViewId && arg.$treeItemHandle;
|
||||
}
|
||||
commands.registerArgumentProcessor({
|
||||
processArgument: arg => {
|
||||
if (arg && arg.$treeViewId && arg.$treeItemHandle) {
|
||||
if (isTreeViewItemHandleArg(arg)) {
|
||||
return this.convertArgument(arg);
|
||||
} else if (Array.isArray(arg) && (arg.length > 0)) {
|
||||
return arg.map(item => {
|
||||
if (isTreeViewItemHandleArg(item)) {
|
||||
return this.convertArgument(item);
|
||||
}
|
||||
return item;
|
||||
});
|
||||
}
|
||||
return arg;
|
||||
}
|
||||
@@ -187,13 +198,10 @@ export class ExtHostTreeView<T> extends Disposable {
|
||||
private refreshPromise: Promise<void> = Promise.resolve();
|
||||
private refreshQueue: Promise<void> = Promise.resolve();
|
||||
|
||||
constructor(private viewId: string, options: vscode.TreeViewOptions<T>, private proxy: MainThreadTreeViewsShape, private commands: CommandsConverter, private logService: ILogService, private extension: IExtensionDescription) {
|
||||
constructor(private viewId: string, options: vscode.TreeViewOptions2<T>, private proxy: MainThreadTreeViewsShape, private commands: CommandsConverter, private logService: ILogService, private extension: IExtensionDescription) {
|
||||
super();
|
||||
this.dataProvider = options.treeDataProvider;
|
||||
// {{SQL CARBON EDIT}}
|
||||
if (this.proxy) {
|
||||
this.proxy.$registerTreeViewDataProvider(viewId, { showCollapseAll: !!options.showCollapseAll });
|
||||
}
|
||||
this.proxy.$registerTreeViewDataProvider(viewId, { showCollapseAll: !!options.showCollapseAll, canSelectMany: !!options.canSelectMany });
|
||||
if (this.dataProvider.onDidChangeTreeData) {
|
||||
this._register(this.dataProvider.onDidChangeTreeData(element => this._onDidChangeData.fire({ message: false, element })));
|
||||
}
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { createApiFactoryAndRegisterActors } from 'vs/workbench/api/common/extHost.api.impl';
|
||||
import { NodeModuleRequireInterceptor, VSCodeNodeModuleFactory, KeytarNodeModuleFactory, OpenNodeModuleFactory } from 'vs/workbench/api/node/extHostRequireInterceptor';
|
||||
import { createApiFactoryAndRegisterActors } from 'sql/workbench/api/common/sqlExtHost.api.impl'; // {{SQL CARBON EDIT}} replace with ours
|
||||
import { RequireInterceptor } from 'vs/workbench/api/common/extHostRequireInterceptor';
|
||||
import { MainContext } from 'vs/workbench/api/common/extHost.protocol';
|
||||
import { ExtensionActivationTimesBuilder } from 'vs/workbench/api/common/extHostExtensionActivator';
|
||||
import { connectProxyResolver } from 'vs/workbench/services/extensions/node/proxyResolver';
|
||||
@@ -14,15 +14,33 @@ import { CLIServer } from 'vs/workbench/api/node/extHostCLIServer';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { Schemas } from 'vs/base/common/network';
|
||||
|
||||
import { createAdsApiFactory } from 'sql/workbench/api/common/sqlExtHost.api.impl'; // {{SQL CARBON EDIT}} use our extension initalizer
|
||||
import { AzdataNodeModuleFactory, SqlopsNodeModuleFactory } from 'sql/workbench/api/node/extHostRequireInterceptor'; // {{SQL CARBON EDIT}} use our extension initalizer
|
||||
class NodeModuleRequireInterceptor extends RequireInterceptor {
|
||||
|
||||
protected _installInterceptor(): void {
|
||||
const that = this;
|
||||
const node_module = <any>require.__$__nodeRequire('module');
|
||||
const original = node_module._load;
|
||||
node_module._load = function load(request: string, parent: { filename: string; }, isMain: any) {
|
||||
for (let alternativeModuleName of that._alternatives) {
|
||||
let alternative = alternativeModuleName(request);
|
||||
if (alternative) {
|
||||
request = alternative;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!that._factories.has(request)) {
|
||||
return original.apply(this, arguments);
|
||||
}
|
||||
return that._factories.get(request)!.load(request, URI.file(parent.filename), isMain, original);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export class ExtHostExtensionService extends AbstractExtHostExtensionService {
|
||||
|
||||
protected async _beforeAlmostReadyToRunExtensions(): Promise<void> {
|
||||
// initialize API and register actors
|
||||
const extensionApiFactory = this._instaService.invokeFunction(createApiFactoryAndRegisterActors);
|
||||
const adsExtensionApiFactory = this._instaService.invokeFunction(createAdsApiFactory); // {{SQL CARBON EDIT}} // add factory
|
||||
|
||||
// Register Download command
|
||||
this._instaService.createInstance(ExtHostDownloadService);
|
||||
@@ -34,21 +52,11 @@ export class ExtHostExtensionService extends AbstractExtHostExtensionService {
|
||||
}
|
||||
|
||||
// Module loading tricks
|
||||
const configProvider = await this._extHostConfiguration.getConfigProvider();
|
||||
const extensionPaths = await this.getExtensionPathIndex();
|
||||
NodeModuleRequireInterceptor.INSTANCE.register(new AzdataNodeModuleFactory(adsExtensionApiFactory.azdata, extensionPaths)); // {{SQL CARBON EDIT}} // add node module
|
||||
NodeModuleRequireInterceptor.INSTANCE.register(new SqlopsNodeModuleFactory(adsExtensionApiFactory.sqlops, extensionPaths)); // {{SQL CARBON EDIT}} // add node module
|
||||
NodeModuleRequireInterceptor.INSTANCE.register(new VSCodeNodeModuleFactory(extensionApiFactory, extensionPaths, this._registry, configProvider));
|
||||
NodeModuleRequireInterceptor.INSTANCE.register(new KeytarNodeModuleFactory(this._extHostContext.getProxy(MainContext.MainThreadKeytar), this._initData.environment));
|
||||
if (this._initData.remote.isRemote) {
|
||||
NodeModuleRequireInterceptor.INSTANCE.register(new OpenNodeModuleFactory(
|
||||
this._extHostContext.getProxy(MainContext.MainThreadWindow),
|
||||
this._extHostContext.getProxy(MainContext.MainThreadTelemetry),
|
||||
extensionPaths
|
||||
));
|
||||
}
|
||||
const interceptor = this._instaService.createInstance(NodeModuleRequireInterceptor, extensionApiFactory, this._registry);
|
||||
await interceptor.install();
|
||||
|
||||
// Do this when extension service exists, but extensions are not being activated yet.
|
||||
const configProvider = await this._extHostConfiguration.getConfigProvider();
|
||||
await connectProxyResolver(this._extHostWorkspace, configProvider, this, this._logService, this._mainThreadTelemetryProxy);
|
||||
|
||||
// Use IPC messages to forward console-calls, note that the console is
|
||||
|
||||
@@ -444,6 +444,14 @@ export class ExtHostTask implements ExtHostTaskShape {
|
||||
if (dto === undefined) {
|
||||
return Promise.reject(new Error('Task is not valid'));
|
||||
}
|
||||
|
||||
// If this task is a custom execution, then we need to save it away
|
||||
// in the provided custom execution map that is cleaned up after the
|
||||
// task is executed.
|
||||
if (CustomExecution2DTO.is(dto.execution)) {
|
||||
await this.addCustomExecution2(dto, <vscode.Task2>task);
|
||||
}
|
||||
|
||||
return this._proxy.$executeTask(dto).then(value => this.getTaskExecution(value, task));
|
||||
}
|
||||
}
|
||||
@@ -529,11 +537,6 @@ export class ExtHostTask implements ExtHostTaskShape {
|
||||
return Promise.reject(new Error('no handler found'));
|
||||
}
|
||||
|
||||
// For custom execution tasks, we need to store the execution objects locally
|
||||
// since we obviously cannot send callback functions through the proxy.
|
||||
// So, clear out any existing ones.
|
||||
this._providedCustomExecutions2.clear();
|
||||
|
||||
// Set up a list of task ID promises that we can wait on
|
||||
// before returning the provided tasks. The ensures that
|
||||
// our task IDs are calculated for any custom execution tasks.
|
||||
@@ -695,5 +698,17 @@ export class ExtHostTask implements ExtHostTaskShape {
|
||||
if (extensionCallback2) {
|
||||
this._activeCustomExecutions2.delete(execution.id);
|
||||
}
|
||||
|
||||
const lastCustomExecution = this._providedCustomExecutions2.get(execution.id);
|
||||
// Technically we don't really need to do this, however, if an extension
|
||||
// is executing a task through "executeTask" over and over again
|
||||
// with different properties in the task definition, then this list
|
||||
// could grow indefinitely, something we don't want.
|
||||
this._providedCustomExecutions2.clear();
|
||||
// We do still need to hang on to the last custom execution so that the
|
||||
// Rerun Task command doesn't choke when it tries to rerun a custom execution
|
||||
if (lastCustomExecution) {
|
||||
this._providedCustomExecutions2.set(execution.id, lastCustomExecution);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,118 +3,152 @@
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { createApiFactoryAndRegisterActors, IExtensionApiFactory } from 'vs/workbench/api/common/extHost.api.impl';
|
||||
import { createApiFactoryAndRegisterActors } from 'sql/workbench/api/common/sqlExtHost.api.impl'; // {{SQL CARBON EDIT}} replace with ours
|
||||
import { ExtensionActivationTimesBuilder } from 'vs/workbench/api/common/extHostExtensionActivator';
|
||||
import { AbstractExtHostExtensionService } from 'vs/workbench/api/common/extHostExtensionService';
|
||||
import { endsWith, startsWith } from 'vs/base/common/strings';
|
||||
import { IExtensionDescription, ExtensionIdentifier } from 'vs/platform/extensions/common/extensions';
|
||||
import { ExtHostConfigProvider } from 'vs/workbench/api/common/extHostConfiguration';
|
||||
import * as vscode from 'vscode';
|
||||
import { TernarySearchTree } from 'vs/base/common/map';
|
||||
import { nullExtensionDescription } from 'vs/workbench/services/extensions/common/extensions';
|
||||
import { ExtensionDescriptionRegistry } from 'vs/workbench/services/extensions/common/extensionDescriptionRegistry';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { Schemas } from 'vs/base/common/network';
|
||||
import { joinPath } from 'vs/base/common/resources';
|
||||
import { RequireInterceptor } from 'vs/workbench/api/common/extHostRequireInterceptor';
|
||||
|
||||
class ApiInstances {
|
||||
class ExportsTrap {
|
||||
|
||||
private readonly _apiInstances = new Map<string, typeof vscode>();
|
||||
static readonly Instance = new ExportsTrap();
|
||||
|
||||
constructor(
|
||||
private readonly _apiFactory: IExtensionApiFactory,
|
||||
private readonly _extensionPaths: TernarySearchTree<IExtensionDescription>,
|
||||
private readonly _extensionRegistry: ExtensionDescriptionRegistry,
|
||||
private readonly _configProvider: ExtHostConfigProvider,
|
||||
) {
|
||||
//
|
||||
private readonly _names: string[] = [];
|
||||
private readonly _exports = new Map<string, any>();
|
||||
|
||||
private constructor() {
|
||||
|
||||
const exportsProxy = new Proxy({}, {
|
||||
set: (target: any, p: PropertyKey, value: any) => {
|
||||
// store in target
|
||||
target[p] = value;
|
||||
// store in named-bucket
|
||||
const name = this._names[this._names.length - 1];
|
||||
this._exports.get(name)![p] = value;
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
const moduleProxy = new Proxy({}, {
|
||||
|
||||
get: (target: any, p: PropertyKey) => {
|
||||
if (p === 'exports') {
|
||||
return exportsProxy;
|
||||
}
|
||||
|
||||
return target[p];
|
||||
},
|
||||
|
||||
set: (target: any, p: PropertyKey, value: any) => {
|
||||
// store in target
|
||||
target[p] = value;
|
||||
|
||||
// override bucket
|
||||
if (p === 'exports') {
|
||||
const name = this._names[this._names.length - 1];
|
||||
this._exports.set(name, value);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
(<any>self).exports = exportsProxy;
|
||||
(<any>self).module = moduleProxy;
|
||||
}
|
||||
|
||||
get(modulePath: string): typeof vscode {
|
||||
const extension = this._extensionPaths.findSubstr(modulePath) || nullExtensionDescription;
|
||||
const id = ExtensionIdentifier.toKey(extension.identifier);
|
||||
add(name: string) {
|
||||
this._exports.set(name, Object.create(null));
|
||||
this._names.push(name);
|
||||
|
||||
let apiInstance = this._apiInstances.get(id);
|
||||
if (!apiInstance) {
|
||||
apiInstance = this._apiFactory(extension, this._extensionRegistry, this._configProvider);
|
||||
this._apiInstances.set(id, apiInstance);
|
||||
return {
|
||||
claim: () => {
|
||||
const result = this._exports.get(name);
|
||||
this._exports.delete(name);
|
||||
this._names.pop();
|
||||
return result;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
class WorkerRequireInterceptor extends RequireInterceptor {
|
||||
|
||||
_installInterceptor() { }
|
||||
|
||||
getModule(request: string, parent: URI): undefined | any {
|
||||
for (let alternativeModuleName of this._alternatives) {
|
||||
let alternative = alternativeModuleName(request);
|
||||
if (alternative) {
|
||||
request = alternative;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return apiInstance;
|
||||
|
||||
if (this._factories.has(request)) {
|
||||
return this._factories.get(request)!.load(request, parent, false, () => { throw new Error(); });
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
export class ExtHostExtensionService extends AbstractExtHostExtensionService {
|
||||
|
||||
private _apiInstances?: ApiInstances;
|
||||
private _fakeModules: WorkerRequireInterceptor;
|
||||
|
||||
protected async _beforeAlmostReadyToRunExtensions(): Promise<void> {
|
||||
// initialize API and register actors
|
||||
const apiFactory = this._instaService.invokeFunction(createApiFactoryAndRegisterActors);
|
||||
const configProvider = await this._extHostConfiguration.getConfigProvider();
|
||||
const extensionPath = await this.getExtensionPathIndex();
|
||||
this._apiInstances = new ApiInstances(apiFactory, extensionPath, this._registry, configProvider);
|
||||
this._fakeModules = this._instaService.createInstance(WorkerRequireInterceptor, apiFactory, this._registry);
|
||||
await this._fakeModules.install();
|
||||
}
|
||||
|
||||
protected _loadCommonJSModule<T>(module: URI, activationTimesBuilder: ExtensionActivationTimesBuilder): Promise<T> {
|
||||
|
||||
|
||||
interface FakeCommonJSSelf {
|
||||
module?: object;
|
||||
exports?: object;
|
||||
require?: (module: string) => any;
|
||||
window?: object;
|
||||
__dirname: never;
|
||||
__filename: never;
|
||||
}
|
||||
|
||||
// FAKE commonjs world that only collects exports
|
||||
const patchSelf: FakeCommonJSSelf = <any>self;
|
||||
patchSelf.window = self; // <- that's improper but might help extensions that aren't authored correctly
|
||||
(<any>self).window = self; // <- that's improper but might help extensions that aren't authored correctly
|
||||
|
||||
// FAKE require function that only works for the vscode-module
|
||||
const moduleStack: URI[] = [];
|
||||
patchSelf.require = (mod: string) => {
|
||||
(<any>self).require = (mod: string) => {
|
||||
|
||||
const parent = moduleStack[moduleStack.length - 1];
|
||||
if (mod === 'vscode') {
|
||||
return this._apiInstances!.get(parent.fsPath);
|
||||
const result = this._fakeModules.getModule(mod, parent);
|
||||
|
||||
if (result !== undefined) {
|
||||
return result;
|
||||
}
|
||||
|
||||
if (!startsWith(mod, '.')) {
|
||||
throw new Error(`Cannot load module '${mod}'`);
|
||||
}
|
||||
|
||||
const exports = Object.create(null);
|
||||
patchSelf.module = { exports };
|
||||
patchSelf.exports = exports;
|
||||
|
||||
const next = joinPath(parent, '..', ensureSuffix(mod, '.js'));
|
||||
moduleStack.push(next);
|
||||
const trap = ExportsTrap.Instance.add(next.toString());
|
||||
importScripts(asDomUri(next).toString(true));
|
||||
moduleStack.pop();
|
||||
|
||||
return exports;
|
||||
return trap.claim();
|
||||
};
|
||||
|
||||
try {
|
||||
activationTimesBuilder.codeLoadingStart();
|
||||
|
||||
const exports = Object.create(null);
|
||||
patchSelf.module = { exports };
|
||||
patchSelf.exports = exports;
|
||||
|
||||
module = module.with({ path: ensureSuffix(module.path, '.js') });
|
||||
moduleStack.push(module);
|
||||
|
||||
const trap = ExportsTrap.Instance.add(module.toString());
|
||||
importScripts(asDomUri(module).toString(true));
|
||||
moduleStack.pop();
|
||||
return Promise.resolve<T>(trap.claim());
|
||||
|
||||
} finally {
|
||||
activationTimesBuilder.codeLoadingStop();
|
||||
}
|
||||
|
||||
return Promise.resolve<T>(exports);
|
||||
}
|
||||
|
||||
async $setRemoteEnvironment(env: { [key: string]: string | null }): Promise<void> {
|
||||
async $setRemoteEnvironment(_env: { [key: string]: string | null }): Promise<void> {
|
||||
throw new Error('Not supported');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user