redhat-developer / redhat-developer/vscode-xml
Add further support for environment variables, file globbing, and relative file path notations in xml.FileAssociations
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 328
- Forks
- 101
- Avg merge
- 1d 17h
- Merged PRs (30d)
- 7
Description
I left a comment on #307 about trying to use environment variables for a file with a team structure that can have varying workspace configurations. A few different options that work elsewhere don't work in xml.FileAssociations. Namely:
- VS code environment variables
- home directory aliases
- Globbed file patterns
As an example, I have a folder structure like the following:
root
| - Repo1
| - | format.xsd
| - Repo2
| - Repo3
Other coworkers might have these set up slightly differently, depending on their environment, i.e. windows, mac, or linux.
We all have an environment variable set to our specific path so that all instructions and code shared can reference the same environment variable and resolve properly for each individual. i.e. on macOS, my path to Repo1 might look like:
/Users/my_name/projects/root/Repo1
and a linux coworker's would be slightly different
/home/their_name/projects/root/Repo1
OR
/home/their_name/projects/Repo1
Now we all individually set an environment variable to make code references seamless, i.e. $REPO1 would expand into the above paths, depending on the user.
I was unsuccessful in trying to implement a solution that would cover everyone without manual configuration to an XSD file. I tried the following xml.FileAssociations configurations in root/.vscode/settings.json:
"xml.fileAssociations": [
{
"pattern": "**/foo*.xml",
"systemId": "${workspaceFolder}/**/format.xsd"
}
],
"xml.fileAssociations": [
{
"pattern": "**/foo*.xml",
"systemId": "**/format.xsd"
}
],
"xml.fileAssociations": [
{
"pattern": "**/foo*.xml",
"systemId": "${env:REPO1}/format.xsd"
}
],
"xml.fileAssociations": [
{
"pattern": "**/foo*.xml",
"systemId": "~/projects/root/Repo1/format.xsd"
}
],
I also noticed multiple associations for the same pattern didn't work either. I had thought they might work due to this snippet from your documentation: "If one of the variables for an association can't be expanded (eg. because vscode is opened in rootless mode), the association is ignored. This feature is specific to the VSCode client."
I thought that if the systemId could not be located, it would continue on to looking at the next entry for the same pattern.
What happens is if the first path fails to match, it does not continue to the second, valid systemId.
This was an attempt to try to configure both possible path types for different environments and let VS code find and use the one that existed.
"xml.fileAssociations": [
{
"pattern": "**/foo*.xml",
"systemId": "home/my_name/projects/root/Repo1/format.xsd"
},
{
"pattern": "**/foo*.xml",
"systemId": "Users/my_name/projects/root/Repo1/format.xsd"
},
],
The only way I could get the "xml.fileAssociations" to work in root/.vscode/settings.json was the following, a hard-coded path to the .xsd file:
"xml.fileAssociations": [
{
"pattern": "**/foo*.xml",
"systemId": "Repo1/format.xsd"
}
],
And all of these failed to expand and parse the file location of my XSD file. Variable substitution is important for configuring paths, especially with cross collaboration of teams trying to rely on a defined schema for XML files we're working on. Having a diverse team means different paths, which we've solved for the rest of our code base by using our environment variables.
@angelozerr I've seen you comment around a lot of the issues related to this. This doesn't seem like much further work to support at least environment variables, and it appears that VS Code supports "untildifying" home paths for macOS, linux, and windows with powershell. So I appreciate all the work you do to support this.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The issue names xml.FileAssociations and root/.vscode/settings.json but no implementation files or tests. Start by tracing how file associations resolve systemId values and how VS Code variables are expanded; done should include the requested environment-variable, home-directory, relative-path, glob, and fallback behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript, vscode
- Domain
- developer-experience, tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100