-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[vscode] support for 'pathSeparator' variable substitution #9054
Conversation
@alex-gilin please follow open PR template |
@@ -18,6 +18,7 @@ import { injectable, inject } from 'inversify'; | |||
import { VariableContribution, VariableRegistry } from './variable'; | |||
import { EnvVariablesServer } from '@theia/core/lib/common/env-variables'; | |||
import { CommandService } from '@theia/core/lib/common/command'; | |||
import { isWindows } from '@theia/core/lib/common/os'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Out of curiosity, what's the intention here? So if the backend is a Linux machine and the frontend is running on a Windows node, what do you want to see: \\
or /
?
If you need the backend OS, you have to use:
theia/packages/core/src/node/application-server.ts
Lines 45 to 47 in f1d4690
async getBackendOS(): Promise<OS.Type> { | |
return OS.type(); | |
} |
If you were aware of all these 👆 , just ignore my comment. 😊
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kittaakos
I agree, good point. Updated.
I would do like this, to make sure the backend OS is resolved by the time you register the variables. I did not debug into your code, but your diff --git a/packages/variable-resolver/src/browser/common-variable-contribution.ts b/packages/variable-resolver/src/browser/common-variable-contribution.ts
index 318f87d3c..b755f9a81 100644
--- a/packages/variable-resolver/src/browser/common-variable-contribution.ts
+++ b/packages/variable-resolver/src/browser/common-variable-contribution.ts
@@ -24,6 +24,8 @@ import { VariableInput } from './variable-input';
import { QuickInputService } from '@theia/core/lib/browser/quick-open/quick-input-service';
import { QuickPickService, QuickPickItem } from '@theia/core/lib/common/quick-pick-service';
import { MaybeArray, RecursivePartial } from '@theia/core/lib/common/types';
+import { ApplicationServer } from '@theia/core/lib/common/application-protocol';
+import { OS } from '@theia/core/lib/common/os';
@injectable()
export class CommonVariableContribution implements VariableContribution {
@@ -46,8 +48,18 @@ export class CommonVariableContribution implements VariableContribution {
@inject(QuickPickService)
protected readonly quickPickService: QuickPickService;
+ @inject(ApplicationServer)
+ protected readonly appServer: ApplicationServer;
+
async registerVariables(variables: VariableRegistry): Promise<void> {
- const execPath = await this.env.getExecPath();
+ const [execPath, backendOS] = await Promise.all([
+ this.env.getExecPath(),
+ this.appServer.getBackendOS()
+ ]);
+ variables.registerVariable({
+ name: 'pathSeparator',
+ resolve: () => backendOS === OS.Type.Windows ? '\\' : '/'
+ });
variables.registerVariable({
name: 'execPath',
resolve: () => execPath |
@kittaakos , |
where ${pathSeparator} - / on macOS or linux, \\ on Windows Signed-off-by: Alex Gilin <alexander.gilin@sap.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Thank you for the patch, @alex-gilin
Signed-off-by: Alexander Gilin alexander.gilin@sap.com
What it does
vscode alignment: allow using the predefined variable ${pathSeparator} (the character used by the operating system to separate components in file paths) in Debugging and Task configuration files
How to test
Variable substitution is supported inside key and value strings in launch.json and tasks.json files.
Expecting result: ${pathSeparator} - / on macOS or linux, \ on Windows
create simple "Hello World" TypeScript project like follows:
create an empty folder "myProject", generate a tsconfig.json file and open that folder in theia:
mkdir myProject
cd myProject
tsc --init
Now create a 'HelloWorld.ts' file with the following content:
function sayHello(name: string): void {
console.log('Hello ' + name + '!');
}
sayHello('Dave');
compile the code :
tsc -p .
open debug view -> Add configuration -> Node.js Launch Program
In the created configuration change a path to the program like next:
"program": "${workspaceFolder}${pathSeparator}helloworld.js"
run this configuration and verify the program path is resolved correctly.
Review checklist
Reminder for reviewers