Skip to content

Commit

Permalink
[vscode] support for 'pathSeparator' variable substitution,
Browse files Browse the repository at this point in the history
where ${pathSeparator} - / on macOS or linux, \\ on Windows

Signed-off-by: Alex Gilin <alexander.gilin@sap.com>
  • Loading branch information
alex-gilin committed Feb 14, 2021
1 parent f1d4690 commit 9dcd317
Showing 1 changed file with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import { injectable, inject } from 'inversify';
import { injectable, inject, postConstruct } from 'inversify';
import { VariableContribution, VariableRegistry } from './variable';
import { ApplicationServer } from '@theia/core/lib/common/application-protocol';
import { EnvVariablesServer } from '@theia/core/lib/common/env-variables';
import { CommandService } from '@theia/core/lib/common/command';
import { OS } from '@theia/core/lib/common/os';
import { PreferenceService } from '@theia/core/lib/browser/preferences/preference-service';
import { ResourceContextKey } from '@theia/core/lib/browser/resource-context-key';
import { VariableInput } from './variable-input';
Expand Down Expand Up @@ -46,6 +48,18 @@ export class CommonVariableContribution implements VariableContribution {
@inject(QuickPickService)
protected readonly quickPickService: QuickPickService;

@inject(ApplicationServer)
protected readonly applicationServer!: ApplicationServer;

private isWindowsBackend: boolean;

@postConstruct()
public init(): void {
this.applicationServer.getBackendOS().then(os => {
this.isWindowsBackend = os === OS.Type.Windows;
});
}

async registerVariables(variables: VariableRegistry): Promise<void> {
const execPath = await this.env.getExecPath();
variables.registerVariable({
Expand Down Expand Up @@ -129,6 +143,10 @@ export class CommonVariableContribution implements VariableContribution {
return undefined;
}
});
variables.registerVariable({
name: 'pathSeparator',
resolve: () => this.isWindowsBackend ? '\\' : '/'
});
}

}

0 comments on commit 9dcd317

Please sign in to comment.