Skip to content

Commit af429c2

Browse files
angelozerrdatho7561
authored andcommitted
Reloading remote schema
Fixes #284 Signed-off-by: azerr <azerr@redhat.com>
1 parent c79e830 commit af429c2

File tree

6 files changed

+86
-21
lines changed

6 files changed

+86
-21
lines changed

docs/Commands.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Commands
2+
3+
[vscode-xml](https://github.com/redhat-developer/vscode-xml) provides several vscode commands which are available with `Ctrl+Shift+P`.
4+
5+
![XML Commands](images/Commands/XMLCommands.png)
6+
7+
## Open XML Documentation
8+
9+
This command opens the `XML Documentation`
10+
11+
## Revalidate current XML file
12+
13+
This command re-triggers the [XML Validation](Validation.md#xml-validation) for the current file.
14+
15+
When the [Server Cache Path](Preferences.md#server-cache-path) is activated, the command removes the referenced XSD, DTD grammar from the local cache.
16+
17+
## Revalidate all open XML files
18+
19+
This command re-triggers the [XML Validation](Validation.md#xml-validation) for the all opened XML files.
20+
21+
When the [Server Cache Path](Preferences.md#server-cache-path) is activated, the command clear remote grammar cache and revalidate all opened files.

docs/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ As [vscode-xml](https://github.com/redhat-developer/vscode-xml) consumes the [Le
99
* [XML Validation](Validation.md#xml-validation): How to validate XML with a grammar (XSD/DTD)?
1010
* [Preferences](Preferences.md#preferences): More info on available [vscode-xml](https://github.com/redhat-developer/vscode-xml) preferences.
1111
* [Formatting](Formatting.md#formatting): More info on the available formatting preferences.
12+
* [XML Commands](Commands.md#commands): More info on the available XML vscode commands.
1213
* [Troubleshooting](Troubleshooting.md#troubleshooting): Info on troubleshooting and fixes to issues.
1314

1415
## Developer Guide
7.07 KB
Loading

package.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,8 +379,26 @@
379379
"command": "xml.open.docs.home",
380380
"title": "Open XML Documentation",
381381
"category": "XML"
382+
},
383+
{
384+
"command": "xml.validation.current.file",
385+
"title": "Revalidate current XML file",
386+
"category": "XML"
387+
},
388+
{
389+
"command": "xml.validation.all.files",
390+
"title": "Revalidate all opened XML files",
391+
"category": "XML"
382392
}
383393
],
394+
"menus": {
395+
"commandPalette": [
396+
{
397+
"command": "xml.validation.current.file",
398+
"when": "editorLangId == xml"
399+
}
400+
]
401+
},
384402
"languages": [
385403
{
386404
"id": "xml",

src/commands.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,13 @@ export namespace Commands {
5050
export const OPEN_DOCS = "xml.open.docs";
5151

5252
export const OPEN_DOCS_HOME = "xml.open.docs.home";
53-
53+
5454
/**
5555
* VSCode client command to executes an LSP command on the XML Language Server
5656
*/
5757
export const EXECUTE_WORKSPACE_COMMAND = "xml.workspace.executeCommand";
58+
59+
export const VALIDATE_CURRENT_FILE = "xml.validation.current.file";
60+
61+
export const VALIDATE_ALL_FILES = "xml.validation.all.files";
5862
}

src/extension.ts

Lines changed: 41 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*/
1212

1313
import { prepareExecutable } from './javaServerStarter';
14-
import {
14+
import {
1515
LanguageClientOptions,
1616
RevealOutputChannelOn,
1717
LanguageClient,
@@ -25,7 +25,7 @@ import {
2525
ConfigurationParams,
2626
ExecuteCommandParams,
2727
CancellationToken,
28-
ExecuteCommandRequest
28+
ExecuteCommandRequest, TextDocumentIdentifier
2929
} from 'vscode-languageclient';
3030
import * as requirements from './requirements';
3131
import { languages, IndentAction, workspace, window, commands, ExtensionContext, TextDocument, Position, LanguageConfiguration, Uri, extensions, Command, TextEditor } from "vscode";
@@ -163,9 +163,9 @@ export function activate(context: ExtensionContext) {
163163
const sectionId = '';
164164
markdownPreviewProvider.show(context.asAbsolutePath(path.join('docs', uri)), title, sectionId, context);
165165
}));
166-
context.subscriptions.push(commands.registerCommand(Commands.OPEN_DOCS, async (params: {page: string, section: string}) => {
166+
context.subscriptions.push(commands.registerCommand(Commands.OPEN_DOCS, async (params: { page: string, section: string }) => {
167167
const page = params.page.endsWith('.md') ? params.page.substr(0, params.page.length - 3) : params.page;
168-
const uri = page + '.md';
168+
const uri = page + '.md';
169169
const sectionId = params.section || '';
170170
const title = 'XML ' + page;
171171
markdownPreviewProvider.show(context.asAbsolutePath(path.join('docs', uri)), title, sectionId, context);
@@ -262,31 +262,52 @@ export function activate(context: ExtensionContext) {
262262
// Handler for 'xml/executeClientCommand` request message that executes a command on the client
263263
languageClient.onRequest(ExecuteClientCommandRequest.type, async (params: ExecuteCommandParams) => {
264264
return await commands.executeCommand(params.command, ...params.arguments);
265-
});
265+
});
266+
267+
// Register custom XML commands
268+
context.subscriptions.push(commands.registerCommand(Commands.VALIDATE_CURRENT_FILE, async (params) => {
269+
const uri = window.activeTextEditor.document.uri;
270+
const identifier = TextDocumentIdentifier.create(uri.toString());
271+
commands.executeCommand(Commands.EXECUTE_WORKSPACE_COMMAND, Commands.VALIDATE_CURRENT_FILE, identifier).
272+
then(() => {
273+
window.showInformationMessage('The current XML file was successfully validated.');
274+
}, error => {
275+
window.showErrorMessage('Error during XML validation ' + error.message);
276+
});
277+
}));
278+
context.subscriptions.push(commands.registerCommand(Commands.VALIDATE_ALL_FILES, async () => {
279+
commands.executeCommand(Commands.EXECUTE_WORKSPACE_COMMAND, Commands.VALIDATE_ALL_FILES).
280+
then(() => {
281+
window.showInformationMessage('All open XML files were successfully validated.');
282+
}, error => {
283+
window.showErrorMessage('Error during XML validation: ' + error.message);
284+
});
285+
}));
266286

267287
// Register client command to execute custom XML Language Server command
268288
context.subscriptions.push(commands.registerCommand(Commands.EXECUTE_WORKSPACE_COMMAND, (command, ...rest) => {
269-
let token: CancellationToken;
270-
let commandArgs: any[] = rest;
271-
if (rest && rest.length && CancellationToken.is(rest[rest.length - 1])) {
272-
token = rest[rest.length - 1];
273-
commandArgs = rest.slice(0, rest.length - 1);
274-
}
275-
const params: ExecuteCommandParams = {
276-
command,
277-
arguments: commandArgs
278-
};
279-
if (token) {
280-
return languageClient.sendRequest(ExecuteCommandRequest.type, params, token);
281-
} else {
282-
return languageClient.sendRequest(ExecuteCommandRequest.type, params);
283-
}
289+
let token: CancellationToken;
290+
let commandArgs: any[] = rest;
291+
if (rest && rest.length && CancellationToken.is(rest[rest.length - 1])) {
292+
token = rest[rest.length - 1];
293+
commandArgs = rest.slice(0, rest.length - 1);
294+
}
295+
const params: ExecuteCommandParams = {
296+
command,
297+
arguments: commandArgs
298+
};
299+
if (token) {
300+
return languageClient.sendRequest(ExecuteCommandRequest.type, params, token);
301+
} else {
302+
return languageClient.sendRequest(ExecuteCommandRequest.type, params);
303+
}
284304
}));
285305

286306
context.subscriptions.push(commands.registerCommand(Commands.OPEN_SETTINGS, async (settingId?: string) => {
287307
commands.executeCommand('workbench.action.openSettings', settingId);
288308
}));
289309

310+
290311
// Setup autoCloseTags
291312
const tagProvider = (document: TextDocument, position: Position) => {
292313
let param = languageClient.code2ProtocolConverter.asTextDocumentPositionParams(document, position);

0 commit comments

Comments
 (0)