Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/Preferences.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@

Can be accessed through `xml.fileAssociations`.

Provides ability to associate a schema with a file pattern.
Provides ability to associate a schema with a file pattern. Both `pattern` and `systemId` support [variable substitution](Validation.md#file-variables) (e.g. `${workspaceFolder}`, `${fileDirname}`, `${env:Name}`).

Example:
```json
Expand All @@ -88,8 +88,8 @@
"pattern": "file1.xml"
},
{
"systemId": "http://www.w3.org/2001/XMLSchema.xsd",
"pattern": "**/*.xsd"
"systemId": "${workspaceFolder}/schemas/config.xsd",
"pattern": "${workspaceFolder}/config/**/*.xml"
}
]
```
Expand Down
85 changes: 65 additions & 20 deletions docs/Validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,17 +215,72 @@ Please note that you can use wildcards in the pattern (ex: `foo*.xml`):

In this case, all XML files that start with foo and end with .xml will be associated with the XSD (foo1.xml, foo2.xml, etc)

You can also use the following three variables in either the `pattern` or `systemId`:
You can also use variables in either the `pattern` or `systemId`. Variables are resolved per document at match time.

| Variable | Meaning |
| --------------------------- | ------------------------------------------------------------------------ |
| ${workspaceFolder} | The absolute path to root folder of the workspace that is currently open |
| ${fileDirname} | The absolute path to the folder of the file that is currently opened |
| ${fileBasenameNoExtension} | The current opened file's basename with no file extension |
#### File variables

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.
| Variable | Description | Example (`/home/user/project/src/data/test.xml`) |
| --------------------------- | ---------------------------------------------------- | ------------------------------------------------ |
| `${file}` | Full path of the document | `/home/user/project/src/data/test.xml` |
| `${fileDirname}` | Directory of the document | `/home/user/project/src/data` |
| `${fileBasename}` | File name with extension | `test.xml` |
| `${fileBasenameNoExtension}`| File name without extension | `test` |
| `${fileExtname}` | File extension (with dot) | `.xml` |

#### Workspace variables

| Variable | Description | Example (workspace: `/home/user/project`) |
| --------------------------- | ---------------------------------------------------- | ------------------------------------------------ |
| `${workspaceFolder}` | Workspace folder containing the document | `/home/user/project` |
| `${workspaceFolderBasename}`| Name of the workspace folder | `project` |
| `${fileWorkspaceFolder}` | Same as `${workspaceFolder}` | `/home/user/project` |
| `${relativeFile}` | Document path relative to workspace folder | `src/data/test.xml` |
| `${relativeFileDirname}` | Directory of the relative path | `src/data` |

In a multi-root workspace, the deepest workspace folder that contains the document is used. If no workspace folder contains the document, the first workspace folder is used as fallback.

#### Environment variables

| Variable | Description |
| --------------------------- | ---------------------------------------------------- |
| `${env:Name}` | Value of environment variable `Name` |

If an environment variable is not set, the variable reference is left unchanged.

#### Examples with variables

Associate all XML files under a workspace `data/` folder with a schema next to each file:

```json
"xml.fileAssociations": [
{
"systemId": "${fileDirname}/schema.xsd",
"pattern": "${workspaceFolder}/data/**/*.xml"
}
]
```

Use an environment variable to point to a shared schema directory:

```json
"xml.fileAssociations": [
{
"systemId": "${env:SCHEMA_HOME}/myschema.xsd",
"pattern": "**/*.myxml"
}
]
```

Use a schema stored inside the workspace:

```json
"xml.fileAssociations": [
{
"systemId": "${workspaceFolder}/schemas/config.xsd",
"pattern": "${workspaceFolder}/config/**/*.xml"
}
]
```

Please note that if the XSD defines a `targetNamespace="http://foo"` like the following `foo.xsd` XSD file:

Expand Down Expand Up @@ -387,17 +442,7 @@ Please note that you can use wildcards in the pattern (ex: `foo*.xml`):

In this case, all XML files that start with foo and end with .xml will be associated with the DTD (foo1.xml, foo2.xml, etc)

You can also use the following three variables in either the `pattern` or `systemId`:

| Variable | Meaning |
| --------------------------- | ------------------------------------------------------------------------ |
| ${workspaceFolder} | The absolute path to root folder of the workspace that is currently open |
| ${fileDirname} | The absolute path to the folder of the file that is currently opened |
| ${fileBasenameNoExtension} | The current opened file's basename with no file extension |

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.
You can also use variables in either the `pattern` or `systemId`. See [variable substitution in XSD file associations](#file-variables) for the full list of supported variables and examples.

## Validation with RelaxNG grammar

Expand Down
11 changes: 0 additions & 11 deletions src/client/xmlClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@
import { commands, ExtensionContext, extensions, Position, TextDocument, TextEditor, Uri, window, workspace } from 'vscode';
import { Command, ConfigurationParams, ConfigurationRequest, DidChangeConfigurationNotification, DocumentFilter, ExecuteCommandParams, LanguageClientOptions, MessageType, NotificationType, RequestType, RevealOutputChannelOn, State } from "vscode-languageclient";
import { Executable, LanguageClient } from 'vscode-languageclient/node';
import { XMLFileAssociation } from '../api/xmlExtensionApi';
import { registerClientServerCommands } from '../commands/registerCommands';
import * as ServerCommandConstants from '../commands/serverCommandConstants';
import { onExtensionChange } from '../plugin';
import { RequirementsData } from "../server/requirements";
import { ExternalXmlSettings } from "../settings/externalXmlSettings";
import { getXMLConfiguration, getXMLSettings, onConfigurationChange, subscribeJDKChangeConfiguration } from "../settings/settings";
import { containsVariableReferenceToCurrentFile } from '../settings/variableSubstitution';
import * as Telemetry from '../telemetry';
import { ClientErrorHandler } from './clientErrorHandler';
import { getLanguageParticipants } from './languageParticipants';
Expand All @@ -26,7 +24,7 @@
return l as string;
});

const ExecuteClientCommandRequest: RequestType<ExecuteCommandParams, any, void> = new RequestType('xml/executeClientCommand');

Check warning on line 27 in src/client/xmlClient.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

Check warning on line 27 in src/client/xmlClient.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

Check warning on line 27 in src/client/xmlClient.ts

View workflow job for this annotation

GitHub Actions / matrix-smoke-test (linux-x86_64) / smoke-test

Unexpected any. Specify a different type

Check warning on line 27 in src/client/xmlClient.ts

View workflow job for this annotation

GitHub Actions / matrix-smoke-test (linux-aarch_64) / smoke-test

Unexpected any. Specify a different type

Check warning on line 27 in src/client/xmlClient.ts

View workflow job for this annotation

GitHub Actions / matrix-smoke-test-windows (win32) / smoke-test

Unexpected any. Specify a different type

Check warning on line 27 in src/client/xmlClient.ts

View workflow job for this annotation

GitHub Actions / matrix-smoke-test (osx-aarch_64) / smoke-test

Unexpected any. Specify a different type

Check warning on line 27 in src/client/xmlClient.ts

View workflow job for this annotation

GitHub Actions / matrix-smoke-test (osx-x86_64) / smoke-test

Unexpected any. Specify a different type

interface AutoInsertParams {
kind: 'autoQuote' | 'autoClose';
Expand All @@ -34,12 +32,12 @@
position: { line: number; character: number };
}

const AutoInsertRequest: RequestType<AutoInsertParams, AutoInsertResult, any> = new RequestType('xml/autoInsert');

Check warning on line 35 in src/client/xmlClient.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

Check warning on line 35 in src/client/xmlClient.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

Check warning on line 35 in src/client/xmlClient.ts

View workflow job for this annotation

GitHub Actions / matrix-smoke-test (linux-x86_64) / smoke-test

Unexpected any. Specify a different type

Check warning on line 35 in src/client/xmlClient.ts

View workflow job for this annotation

GitHub Actions / matrix-smoke-test (linux-aarch_64) / smoke-test

Unexpected any. Specify a different type

Check warning on line 35 in src/client/xmlClient.ts

View workflow job for this annotation

GitHub Actions / matrix-smoke-test-windows (win32) / smoke-test

Unexpected any. Specify a different type

Check warning on line 35 in src/client/xmlClient.ts

View workflow job for this annotation

GitHub Actions / matrix-smoke-test (osx-aarch_64) / smoke-test

Unexpected any. Specify a different type

Check warning on line 35 in src/client/xmlClient.ts

View workflow job for this annotation

GitHub Actions / matrix-smoke-test (osx-x86_64) / smoke-test

Unexpected any. Specify a different type

interface ActionableMessage {
severity: MessageType;
message: string;
data?: any;

Check warning on line 40 in src/client/xmlClient.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

Check warning on line 40 in src/client/xmlClient.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

Check warning on line 40 in src/client/xmlClient.ts

View workflow job for this annotation

GitHub Actions / matrix-smoke-test (linux-x86_64) / smoke-test

Unexpected any. Specify a different type

Check warning on line 40 in src/client/xmlClient.ts

View workflow job for this annotation

GitHub Actions / matrix-smoke-test (linux-aarch_64) / smoke-test

Unexpected any. Specify a different type

Check warning on line 40 in src/client/xmlClient.ts

View workflow job for this annotation

GitHub Actions / matrix-smoke-test-windows (win32) / smoke-test

Unexpected any. Specify a different type

Check warning on line 40 in src/client/xmlClient.ts

View workflow job for this annotation

GitHub Actions / matrix-smoke-test (osx-aarch_64) / smoke-test

Unexpected any. Specify a different type

Check warning on line 40 in src/client/xmlClient.ts

View workflow job for this annotation

GitHub Actions / matrix-smoke-test (osx-x86_64) / smoke-test

Unexpected any. Specify a different type
commands?: Command[];
}

Expand Down Expand Up @@ -104,7 +102,7 @@
}

languageClient.onRequest(ConfigurationRequest.type, (params: ConfigurationParams) => {
const result: any[] = [];

Check warning on line 105 in src/client/xmlClient.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

Check warning on line 105 in src/client/xmlClient.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

Check warning on line 105 in src/client/xmlClient.ts

View workflow job for this annotation

GitHub Actions / matrix-smoke-test (linux-x86_64) / smoke-test

Unexpected any. Specify a different type

Check warning on line 105 in src/client/xmlClient.ts

View workflow job for this annotation

GitHub Actions / matrix-smoke-test (linux-aarch_64) / smoke-test

Unexpected any. Specify a different type

Check warning on line 105 in src/client/xmlClient.ts

View workflow job for this annotation

GitHub Actions / matrix-smoke-test-windows (win32) / smoke-test

Unexpected any. Specify a different type

Check warning on line 105 in src/client/xmlClient.ts

View workflow job for this annotation

GitHub Actions / matrix-smoke-test (osx-aarch_64) / smoke-test

Unexpected any. Specify a different type

Check warning on line 105 in src/client/xmlClient.ts

View workflow job for this annotation

GitHub Actions / matrix-smoke-test (osx-x86_64) / smoke-test

Unexpected any. Specify a different type
const activeEditor: TextEditor | undefined = window.activeTextEditor;
for (const item of params.items) {
const scopeUri = item.scopeUri ? Uri.parse(item.scopeUri) : undefined;
Expand Down Expand Up @@ -135,16 +133,7 @@
return result;
});

// When the current document changes, update variable values that refer to the current file if these variables are referenced,
// and send the updated settings to the server
context.subscriptions.push(window.onDidChangeActiveTextEditor(() => {
if (containsVariableReferenceToCurrentFile(getXMLConfiguration().get('fileAssociations') as XMLFileAssociation[])) {
languageClient.sendNotification(DidChangeConfigurationNotification.type, { settings: getXMLSettings(requirementsData.java_home, logfile, externalXmlSettings) });
onConfigurationChange();
}
}));

const onDidGrantWorkspaceTrust = (workspace as any).onDidGrantWorkspaceTrust;

Check warning on line 136 in src/client/xmlClient.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

Check warning on line 136 in src/client/xmlClient.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

Check warning on line 136 in src/client/xmlClient.ts

View workflow job for this annotation

GitHub Actions / matrix-smoke-test (linux-x86_64) / smoke-test

Unexpected any. Specify a different type

Check warning on line 136 in src/client/xmlClient.ts

View workflow job for this annotation

GitHub Actions / matrix-smoke-test (linux-aarch_64) / smoke-test

Unexpected any. Specify a different type

Check warning on line 136 in src/client/xmlClient.ts

View workflow job for this annotation

GitHub Actions / matrix-smoke-test-windows (win32) / smoke-test

Unexpected any. Specify a different type

Check warning on line 136 in src/client/xmlClient.ts

View workflow job for this annotation

GitHub Actions / matrix-smoke-test (osx-aarch_64) / smoke-test

Unexpected any. Specify a different type

Check warning on line 136 in src/client/xmlClient.ts

View workflow job for this annotation

GitHub Actions / matrix-smoke-test (osx-x86_64) / smoke-test

Unexpected any. Specify a different type
if (onDidGrantWorkspaceTrust !== undefined) {
context.subscriptions.push(onDidGrantWorkspaceTrust(() => {
languageClient.sendNotification(DidChangeConfigurationNotification.type, { settings: getXMLSettings(requirementsData.java_home, logfile, externalXmlSettings) });
Expand Down Expand Up @@ -220,7 +209,7 @@
show(notification.message, ...titles).then((selection) => {
for (const action of notification.commands) {
if (action.title === selection) {
const args: any[] = (action.arguments) ? action.arguments : [];

Check warning on line 212 in src/client/xmlClient.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

Check warning on line 212 in src/client/xmlClient.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

Check warning on line 212 in src/client/xmlClient.ts

View workflow job for this annotation

GitHub Actions / matrix-smoke-test (linux-x86_64) / smoke-test

Unexpected any. Specify a different type

Check warning on line 212 in src/client/xmlClient.ts

View workflow job for this annotation

GitHub Actions / matrix-smoke-test (linux-aarch_64) / smoke-test

Unexpected any. Specify a different type

Check warning on line 212 in src/client/xmlClient.ts

View workflow job for this annotation

GitHub Actions / matrix-smoke-test-windows (win32) / smoke-test

Unexpected any. Specify a different type

Check warning on line 212 in src/client/xmlClient.ts

View workflow job for this annotation

GitHub Actions / matrix-smoke-test (osx-aarch_64) / smoke-test

Unexpected any. Specify a different type

Check warning on line 212 in src/client/xmlClient.ts

View workflow job for this annotation

GitHub Actions / matrix-smoke-test (osx-x86_64) / smoke-test

Unexpected any. Specify a different type
commands.executeCommand(action.command, ...args);
break;
}
Expand Down
4 changes: 0 additions & 4 deletions src/settings/settings.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as path from 'path';
import { commands, Extension, extensions, window, workspace, WorkspaceConfiguration } from "vscode";
import { getVariableSubstitutedAssociations } from "./variableSubstitution";

export interface ScopeInfo {
scope: "default" | "global" | "workspace" | "folder";
Expand Down Expand Up @@ -248,8 +247,5 @@ export function getXMLSettings(javaHome: string | undefined, logfile: string, ex
}
});

// Apply variable substitutions for file associations
xml['xml']['fileAssociations'] = [...getVariableSubstitutedAssociations(xml['xml']['fileAssociations'])];

return xml;
}
154 changes: 0 additions & 154 deletions src/settings/variableSubstitution.ts

This file was deleted.

Loading