From 3a56c70b2cce2dc3b1b46e34ad9546243962b4fb Mon Sep 17 00:00:00 2001 From: Anton Kosyakov Date: Mon, 29 Jul 2019 13:12:50 +0000 Subject: [PATCH] [vscode] support `env:NAME` variable substitution VS Code doc: https://code.visualstudio.com/docs/editor/variables-reference#_environment-variables Signed-off-by: Anton Kosyakov --- CHANGELOG.md | 4 +++ .../src/browser/env-variable-contribution.ts | 36 +++++++++++++++++++ .../variable-resolver-frontend-module.ts | 4 +++ 3 files changed, 44 insertions(+) create mode 100644 packages/variable-resolver/src/browser/env-variable-contribution.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 94655c9083e19..064cea92f4a98 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Change Log +## v0.10.0 + +- [vscode] added env variable substitution support [5811](https://github.com/theia-ide/theia/pull/5811) + ## v0.9.0 - [core] added `theia-widget-noInfo` css class to be used by widgets when displaying no information messages [#5717](https://github.com/theia-ide/theia/pull/5717) - [core] added additional options to the tree search input [#5566](https://github.com/theia-ide/theia/pull/5566) diff --git a/packages/variable-resolver/src/browser/env-variable-contribution.ts b/packages/variable-resolver/src/browser/env-variable-contribution.ts new file mode 100644 index 0000000000000..2b71627aa33e1 --- /dev/null +++ b/packages/variable-resolver/src/browser/env-variable-contribution.ts @@ -0,0 +1,36 @@ +/******************************************************************************** + * Copyright (C) 2019 TypeFox and others. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the Eclipse + * Public License v. 2.0 are satisfied: GNU General Public License, version 2 + * with the GNU Classpath Exception which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + ********************************************************************************/ + +import { injectable, inject } from 'inversify'; +import { VariableContribution, VariableRegistry } from './variable'; +import { EnvVariablesServer } from '@theia/core/lib/common/env-variables'; + +@injectable() +export class EnvVariableContribution implements VariableContribution { + + @inject(EnvVariablesServer) + protected readonly env: EnvVariablesServer; + + async registerVariables(variables: VariableRegistry): Promise { + for (const variable of await this.env.getVariables()) { + variables.registerVariable({ + name: 'env:' + variable.name, + resolve: () => variable.value + }); + } + } + +} diff --git a/packages/variable-resolver/src/browser/variable-resolver-frontend-module.ts b/packages/variable-resolver/src/browser/variable-resolver-frontend-module.ts index 97af7035e34dd..c3656032df801 100644 --- a/packages/variable-resolver/src/browser/variable-resolver-frontend-module.ts +++ b/packages/variable-resolver/src/browser/variable-resolver-frontend-module.ts @@ -21,6 +21,7 @@ import { VariableRegistry, VariableContribution } from './variable'; import { VariableQuickOpenService } from './variable-quick-open-service'; import { VariableResolverFrontendContribution } from './variable-resolver-frontend-contribution'; import { VariableResolverService } from './variable-resolver-service'; +import { EnvVariableContribution } from './env-variable-contribution'; export default new ContainerModule(bind => { bind(VariableRegistry).toSelf().inSingletonScope(); @@ -33,4 +34,7 @@ export default new ContainerModule(bind => { } bind(VariableQuickOpenService).toSelf().inSingletonScope(); + + bind(EnvVariableContribution).toSelf().inSingletonScope(); + bind(VariableContribution).toService(EnvVariableContribution); });