diff --git a/docs/Commands.md b/docs/Commands.md index 7c936fdc..7fe5c61b 100644 --- a/docs/Commands.md +++ b/docs/Commands.md @@ -20,6 +20,12 @@ This command re-triggers the [XML Validation](Validation.md#xml-validation) for When the [Server Cache Path](Preferences.md#server-cache-path) is activated, the command removes the referenced XSD, DTD grammar from the local cache. +## Revalidate current XML file (XML Syntax Only) + +This command re-triggers the [XML Validation](Validation.md#xml-validation) for the current file only for XML syntax even if XML is bound to a DTD, XML Schema, RelaxNG. + +When the [Server Cache Path](Preferences.md#server-cache-path) is activated, the command removes the referenced XSD, DTD grammar from the local cache. + ## Revalidate all open XML files This command re-triggers the [XML Validation](Validation.md#xml-validation) for the all opened XML files. diff --git a/docs/Validation.md b/docs/Validation.md index 6ffaf8b4..f3cb68ed 100644 --- a/docs/Validation.md +++ b/docs/Validation.md @@ -518,6 +518,14 @@ Now, update the xsi:schemaLocation with bad location hint In `always` you will have error, in `onValidSchema` you will have none error. +## xml.validation.dtd.enabled + +The `xml.validation.dtd.enabled` gives the capability to enable / disable the validation based on DTD. It can be configured with 3 values: + + * `always`: enable DTD based validation. + * `never`: disable DTD based validation. + * `onValidDTD`: enable DTD based validation only when the declared DOCTYPE is valid. + ## xml.validation.filters XML validation filter gives you the capability to define validation rules for files matching a given pattern. For instance if you wish to disable validation for all files which have the `*.myxml` file extension, you must declare this filter in the `settings.json`: @@ -554,7 +562,7 @@ By default, vscode-xml uses this default validation filter: "noGrammar": "ignore", "schema": { "enabled": "never" - } + } }, // Ignore no grammar hint for Eclipse files like .project { diff --git a/package.json b/package.json index f4abde36..435e275e 100644 --- a/package.json +++ b/package.json @@ -506,6 +506,22 @@ "markdownDescription": "Enable/disable schema based validation. Default is `always`. Ignored if `#xml.validation.enabled#` is set to `false`. See [here](command:xml.open.docs?%5B%7B%22page%22%3A%22Validation%22%2C%22section%22%3A%22xmlvalidationschemaenabled%22%7D%5D) for more information.", "scope": "window" }, + "xml.validation.dtd.enabled": { + "type": "string", + "default": "always", + "enum": [ + "always", + "never", + "onValidDTD" + ], + "markdownEnumDescriptions": [ + "Enable DTD based validation.", + "Disable DTD based validation.", + "Enable DTD based validation only when the declared DOCTYPE is valid for the root element." + ], + "markdownDescription": "Enable/disable DTD based validation. Default is `always`. Ignored if `#xml.validation.enabled#` is set to `false`. See [here](command:xml.open.docs?%5B%7B%22page%22%3A%22Validation%22%2C%22section%22%3A%22xmlvalidationdtdenabled%22%7D%5D) for more information.", + "scope": "window" + }, "xml.validation.disallowDocTypeDecl": { "type": "boolean", "default": false, @@ -765,6 +781,11 @@ "title": "Revalidate current XML file", "category": "XML" }, + { + "command": "xml.validation.syntax.current.file", + "title": "Revalidate current XML file (XML syntax Only)", + "category": "XML" + }, { "command": "xml.validation.all.files", "title": "Revalidate all opened XML files", @@ -802,6 +823,10 @@ "command": "xml.validation.current.file", "when": "editorLangId in xml.supportedLanguageIds && XMLLSReady" }, + { + "command": "xml.validation.syntax.current.file", + "when": "editorLangId == xml && XMLLSReady" + }, { "command": "xml.validation.all.files", "when": "XMLLSReady" diff --git a/src/commands/clientCommandConstants.ts b/src/commands/clientCommandConstants.ts index 7b021f85..fe01eadf 100644 --- a/src/commands/clientCommandConstants.ts +++ b/src/commands/clientCommandConstants.ts @@ -43,6 +43,8 @@ export const OPEN_DOCS = 'xml.open.docs'; */ export const VALIDATE_CURRENT_FILE = 'xml.validation.current.file'; +export const VALIDATE_ONLY_SYNTAX_CURRENT_FILE = 'xml.validation.syntax.current.file'; + export const VALIDATE_ALL_FILES = 'xml.validation.all.files'; export const OPEN_DOCS_HOME = 'xml.open.docs.home'; @@ -74,4 +76,4 @@ export const EXECUTE_WORKSPACE_COMMAND = 'xml.workspace.executeCommand'; export const REFACTOR_SURROUND_WITH_COMMENTS = 'xml.refactor.surround.with.comments'; - export const REFACTOR_SURROUND_WITH_CDATA = 'xml.refactor.surround.with.cdata'; \ No newline at end of file + export const REFACTOR_SURROUND_WITH_CDATA = 'xml.refactor.surround.with.cdata'; diff --git a/src/commands/registerCommands.ts b/src/commands/registerCommands.ts index 6c7c3e6a..b08e7ff8 100644 --- a/src/commands/registerCommands.ts +++ b/src/commands/registerCommands.ts @@ -141,6 +141,27 @@ function registerValidationCommands(context: ExtensionContext) { window.showErrorMessage('Error during XML validation ' + error.message); }); })); + + // Revalidate (Only XML syntax) current file + context.subscriptions.push(commands.registerCommand(ClientCommandConstants.VALIDATE_ONLY_SYNTAX_CURRENT_FILE, async (identifierParam, validationArgs) => { + let identifier = identifierParam; + if (!identifier) { + const uri = window.activeTextEditor.document.uri; + identifier = TextDocumentIdentifier.create(uri.toString()); + } + const configXML = workspace.getConfiguration().get('xml.validation'); + const x = JSON.stringify(configXML); //configXML is not a JSON type + const validationSettings = JSON.parse(x); + validationSettings['dtd']['enabled'] = 'never'; + validationSettings['schema']['enabled'] = 'never'; + commands.executeCommand(ClientCommandConstants.EXECUTE_WORKSPACE_COMMAND, ServerCommandConstants.VALIDATE_CURRENT_FILE, identifier, validationArgs, validationSettings). + then(() => { + window.showInformationMessage('The current XML file was successfully validated (XML Syntax Only).'); + }, error => { + window.showErrorMessage('Error during XML validation (XML Syntax Only) ' + error.message); + }); + })); + // Revalidate all open files context.subscriptions.push(commands.registerCommand(ClientCommandConstants.VALIDATE_ALL_FILES, async () => { commands.executeCommand(ClientCommandConstants.EXECUTE_WORKSPACE_COMMAND, ServerCommandConstants.VALIDATE_ALL_FILES).