提交 b41b85d2 编写于 作者: D Daniel Imms

Start building out env var service

上级 338d4298
......@@ -5,7 +5,7 @@
import { DisposableStore, Disposable, IDisposable } from 'vs/base/common/lifecycle';
import { IShellLaunchConfig, ITerminalProcessExtHostProxy, ISpawnExtHostProcessRequest, ITerminalDimensions, EXT_HOST_CREATION_DELAY, IAvailableShellsRequest, IDefaultShellAndArgsRequest, IStartExtensionTerminalRequest } from 'vs/workbench/contrib/terminal/common/terminal';
import { ExtHostContext, ExtHostTerminalServiceShape, MainThreadTerminalServiceShape, MainContext, IExtHostContext, IShellLaunchConfigDto, TerminalLaunchConfig, ITerminalDimensionsDto } from 'vs/workbench/api/common/extHost.protocol';
import { ExtHostContext, ExtHostTerminalServiceShape, MainThreadTerminalServiceShape, MainContext, IExtHostContext, IShellLaunchConfigDto, TerminalLaunchConfig, ITerminalDimensionsDto, IEnvironmentVariableCollectionDto } from 'vs/workbench/api/common/extHost.protocol';
import { extHostNamedCustomer } from 'vs/workbench/api/common/extHostCustomers';
import { URI } from 'vs/base/common/uri';
import { StopWatch } from 'vs/base/common/stopwatch';
......@@ -346,6 +346,11 @@ export class MainThreadTerminalService implements MainThreadTerminalServiceShape
}
return terminal;
}
$updateEnvironmentVariableCollections(collections: IEnvironmentVariableCollectionDto[]): void {
// TODO: Pass on to env var service
throw new Error('Method not implemented.');
}
}
/**
......
......@@ -426,6 +426,19 @@ export interface TerminalLaunchConfig {
isExtensionTerminal?: boolean;
}
export enum EnvironmentVariableMutatorType {
Replace = 1,
Append = 2,
Prepend = 3
}
export interface IEnvironmentVariableCollectionDto {
extensionIdentifier: string;
variables: string[];
values: string[];
types: EnvironmentVariableMutatorType[];
}
export interface MainThreadTerminalServiceShape extends IDisposable {
$createTerminal(config: TerminalLaunchConfig): Promise<{ id: number, name: string; }>;
$dispose(terminalId: number): void;
......@@ -436,6 +449,7 @@ export interface MainThreadTerminalServiceShape extends IDisposable {
$stopSendingDataEvents(): void;
$startHandlingLinks(): void;
$stopHandlingLinks(): void;
$updateEnvironmentVariableCollections(collections: IEnvironmentVariableCollectionDto[]): void;
// Process
$sendProcessTitle(terminalId: number, title: string): void;
......
......@@ -26,6 +26,7 @@ import { IExtensionDescription } from 'vs/platform/extensions/common/extensions'
import { EnvironmentVariableMutatorType } from 'vs/workbench/api/common/extHostTypes';
import { Emitter, Event } from 'vs/base/common/event';
import { debounce } from 'vs/base/common/decorators';
import { dispose } from 'vs/base/common/lifecycle';
class EnvironmentVariableMutator implements vscode.EnvironmentVariableMutator {
......@@ -85,7 +86,7 @@ export class ExtHostTerminalService extends BaseExtHostTerminalService {
private _variableResolver: ExtHostVariableResolverService | undefined;
private _lastActiveWorkspace: IWorkspaceFolder | undefined;
private _environmentVariableCollection: vscode.EnvironmentVariableCollection | undefined;
private _environmentVariableCollection: Map<string, vscode.EnvironmentVariableCollection> = new Map();
// TODO: Pull this from main side
private _isWorkspaceShellAllowed: boolean = false;
......@@ -276,6 +277,8 @@ export class ExtHostTerminalService extends BaseExtHostTerminalService {
}
public getEnvironmentVariableCollection(extension: IExtensionDescription, persistent?: boolean): vscode.EnvironmentVariableCollection {
dispose(this._environmentVariableCollection.get(extension.identifier.value));
let collection: EnvironmentVariableCollection;
if (persistent) {
// TODO: Persist when persistent is set
......@@ -285,8 +288,8 @@ export class ExtHostTerminalService extends BaseExtHostTerminalService {
collection = new EnvironmentVariableCollection();
}
collection.onDidChangeCollection(() => this._updateEnvironmentVariableCollection());
this._environmentVariableCollection = collection;
return this._environmentVariableCollection;
this._environmentVariableCollection.set(extension.identifier.value, collection);
return collection;
}
@debounce(1000)
......
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
export const IEnvironmentVariableService = createDecorator<IEnvironmentVariableService>('environmentVariableService');
export interface IEnvironmentVariableMutator {
readonly value: string;
readonly type: 'replace' | 'append' | 'prepend';
}
export interface IEnvironmentVariableCollection {
readonly entries: Map<string, IEnvironmentVariableMutator>;
}
/**
* Tracks and persists environment variable collections as defined by extensions.
*/
export interface IEnvironmentVariableService {
/**
* Gets a single collection constructed by merging all collections into one.
*/
readonly mergedCollection: IEnvironmentVariableCollection;
set(extensionIdentifier: string, collection: IEnvironmentVariableCollection): void;
delete(extensionIdentifier: string): void;
}
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { IEnvironmentVariableService, IEnvironmentVariableCollection, IEnvironmentVariableMutator } from 'vs/workbench/contrib/terminal/common/environmentVariable';
export class EnvironmentVariableCollection implements IEnvironmentVariableCollection {
readonly entries: Map<string, IEnvironmentVariableMutator>;
constructor(
// TODO: Init entries via ctor if specified
) {
this.entries = new Map();
}
}
/**
* Tracks and persists environment variable collections as defined by extensions.
*/
export class EnvironmentVariableService implements IEnvironmentVariableService {
/**
* The merged collection, this is set to undefined when it needs to be resolved again and is
* evaluated lazily as needed.
*/
private _mergedCollection: IEnvironmentVariableCollection | undefined;
private _collections: Map<string, IEnvironmentVariableCollection> = new Map();
// TODO: Load in persisted collections
// TODO: Fire an event when collections have changed that the terminal component can listen to
get mergedCollection(): IEnvironmentVariableCollection {
if (!this._mergedCollection) {
this._mergedCollection = this._resolveMergedCollection();
}
return this._mergedCollection;
}
set(extensionIdentifier: string, collection: IEnvironmentVariableCollection): void {
this._collections.set(extensionIdentifier, collection);
this._mergedCollection = undefined;
}
delete(extensionIdentifier: string): void {
this._collections.delete(extensionIdentifier);
this._mergedCollection = undefined;
}
private _resolveMergedCollection(): IEnvironmentVariableCollection {
const collection = new EnvironmentVariableCollection();
return collection;
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册