Skip to content
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

complete support of variable substitution #5835

Merged
merged 9 commits into from
Aug 13, 2019
Merged

complete support of variable substitution #5835

merged 9 commits into from
Aug 13, 2019

Conversation

akosyakov
Copy link
Member

@akosyakov akosyakov commented Aug 1, 2019

What it does

How to test

  • look at https://code.visualstudio.com/docs/editor/variables-reference and test different variables
  • you can also follow commit history to see support for which variables were added
  • for most variables, you can use Variables: List All command
    • then select a variable to test
    • then you will be prompted to provide an argument for a variable, an argument is a part of ':' in variable substitution expression
    • if a variable does not accept argument just press enter, if it accepts then provide a proper argument
    • you should see a variable value if it can be computed in the given context, or raw expression if it cannot
  • alternatively, you can define variables in tasks.json and launch.json and then try to run a task or launch configuration
    • like defined here for example, there is a bug though that an output for short-lived task is lost, you may want to add watch echo in order to keep a task running
  • for command variables you may want to install vscode node js extensions instead of native and test with extension.pickNodeProcess, don't forget that you need both vscode nodejs extension to use them
  • for input variables you can follow: https://code.visualstudio.com/docs/editor/variables-reference#_input-variables

Review checklist

  • as an author, I have thoroughly tested my changes and carefully reviewed following the review guidelines

Reminder for reviewers

@akosyakov akosyakov marked this pull request as ready for review August 1, 2019 15:43
@akosyakov akosyakov added vscode issues related to VSCode compatibility variable-resolver issues related to the variable-resolver extension labels Aug 2, 2019
@kittaakos
Copy link
Contributor

I am verifying it.

@kittaakos
Copy link
Contributor

What should happen when a variable is not available from the shell?
For instance, when I am usign "${env:PATH}" then I can see value of the PATH variable is printed. If I use "${env:USERNAME}" it is printed as ${env:USERNAME} instead of an empty string.

Akoss-MacBook-Pro:theia akos.kitta$ echo $USERNAME

Akoss-MacBook-Pro:theia akos.kitta$ 

@kittaakos
Copy link
Contributor

[bug]: When defining a variable, select Variable: List All > ${env} > Esc:

Screen Shot 2019-08-05 at 11 49 31

@akosyakov
Copy link
Member Author

If I use "${env:USERNAME}" it is printed as ${env:USERNAME} instead of an empty string

That's a great point! It should be an empty string for sure.

@kittaakos
Copy link
Contributor

I have verified the followinngs I could understand from the description; they work.

Verified variables:

"${workspaceFolder}",
"${workspaceFolderBasename}",
"${file}",
"${relativeFile}",
"${fileBasename}",
"${fileBasenameNoExtension}",
"${fileDirname}",
"${fileExtname}",
"${cwd}",
"${lineNumber}",
"${selectedText}",
"${execPath}",

Executed module:

console.log('ARGS:');
for (const e of process.argv.splice(2)) {
    console.log(e);
}

Running ./xxx/index.js:

ARGS:
/Users/akos.kitta/git/theia
theia
/Users/akos.kitta/git/theia/xxx/index.js
xxx/index.js
index.js
index
/Users/akos.kitta/git/theia/xxx
.js
/Users/akos.kitta/git/theia
2
process.argv.splice(2)
/Users/akos.kitta/.nvm/versions/node/v10.15.3/bin/node

Running ./index.js:

ARGS:
/Users/akos.kitta/git/theia
theia
/Users/akos.kitta/git/theia/index.js
index.js
index.js
index
/Users/akos.kitta/git/theia
.js
/Users/akos.kitta/git/theia
2
process.argv.splice(2)
/Users/akos.kitta/.nvm/versions/node/v10.15.3/bin/node

I did no verify the case sensitivity/insensitivity:

Note: Be sure to match the environment variable name's casing, for example ${env:Path} on Windows.

@akosyakov
Copy link
Member Author

I did no verify the case sensitivity/insensitivity:

I've noticed that VS Code always convert env var name to lower case on windows: https://github.com/microsoft/vscode/blob/0a34756cae4fc67739e60c708b04637089f8bb0d/src/vs/workbench/services/configurationResolver/common/variableResolver.ts#L172-L175 Should we do the same?

Copy link
Contributor

@kittaakos kittaakos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I have tested, worked as expected. Please note the following items:

@@ -44,26 +63,15 @@ export class VariableQuickOpenService implements QuickOpenModel {
onType(lookFor: string, acceptor: (items: QuickOpenItem[]) => void): void {
acceptor(this.items);
}
}

export class VariableQuickOpenItem extends QuickOpenItem {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should go to the breaking changes section.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@akosyakov
Copy link
Member Author

Unavailable variables should be empty strings

I don't think it is a case for all variables, just for env because they are evaluated to empty string when missing. In other cases it is not true. Maybe we should throw in other cases to prevent running tasks and launch configuration with bogus arguments.

@akosyakov
Copy link
Member Author

I will wait till CQ is resolved before continuing working on it. It is pending already for 5 days and they don't seem to work on it: https://dev.eclipse.org/ipzilla/show_bug.cgi?id=20504#c3 cc @marcdumais-work

@marcdumais-work
Copy link
Contributor

It is pending already for 5 days and they don't seem to work on it

Yes, I noticed things seem slow at the Foundation recently; I suspect late summer vacations.

@vince-fugnitto
Copy link
Member

I will wait till CQ is resolved before continuing working on it. It is pending already for 5 days and they don't seem to work on it: https://dev.eclipse.org/ipzilla/show_bug.cgi?id=20504#c3 cc @marcdumais-work

I believe the CQ is waiting for some form of feedback from you @akosyakov :( I see the message "IPTeam awaiting response from Committer."

@marcdumais-work
Copy link
Contributor

I believe the CQ is waiting for some form of feedback from you @akosyakov :( I see the message "IPTeam awaiting response from Committer."

Thanks for pointing this out, Vince. I answered the question and sent the CQ back to the IP team.

Copy link
Member

@azatsarynnyy azatsarynnyy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tested several random variables through the Variables: List All command
works as expected

Signed-off-by: Anton Kosyakov <anton.kosyakov@typefox.io>
Signed-off-by: Anton Kosyakov <anton.kosyakov@typefox.io>
@akosyakov akosyakov force-pushed the GH-3434 branch 3 times, most recently from 77f809e to b03777b Compare August 12, 2019 06:56
@akosyakov
Copy link
Member Author

@kittaakos I've pushed a commit to fix resolving env variables values on windows and evaluating them to an empty string if they are missing to align with the shell behaviour. I'm going to merge it tomorrow if no one objects and CI is green.

in order to simplify testing of variable substitution

Signed-off-by: Anton Kosyakov <anton.kosyakov@typefox.io>
Signed-off-by: Anton Kosyakov <anton.kosyakov@typefox.io>
- if an env variable does not exist it should resolve to an empty string to emulate the shell
- normalize env variable name to lower case in order to retrieve them from process.env on windows

Signed-off-by: Anton Kosyakov <anton.kosyakov@typefox.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
variable-resolver issues related to the variable-resolver extension vscode issues related to VSCode compatibility
Projects
None yet
Development

Successfully merging this pull request may close these issues.

support vscode variable substitution
5 participants