Skip to content

Commit 7f3a13c

Browse files
rgrunberangelozerr
authored andcommitted
Validate the file assocation pattern in the wizard
- Fixes #586 - Declare command "xml.check.file.pattern" to be used on the server side to determine if a given pattern will match the given file Signed-off-by: Roland Grunberg <rgrunber@redhat.com>
1 parent 12564c9 commit 7f3a13c

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/commands/commandConstants.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,9 @@ export namespace ServerCommandConstants {
102102
* Command to check if the current XML document is bound to a grammar
103103
*/
104104
export const CHECK_BOUND_GRAMMAR = "xml.check.bound.grammar"
105+
106+
/**
107+
* Command to check if a given file pattern matches any file on the workspace
108+
*/
109+
export const CHECK_FILE_PATTERN = "xml.check.file.pattern"
105110
}

src/commands/registerCommands.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,16 @@ async function bindWithFileAssociation(documentURI: Uri, grammarURI: Uri, docume
216216
title: "File Association Pattern",
217217
value: defaultPattern,
218218
placeHolder: defaultPattern,
219-
prompt: "Enter the pattern of the XML document(s) to be bound."
219+
prompt: "Enter the pattern of the XML document(s) to be bound.",
220+
validateInput: async (pattern: string) => {
221+
let hasMatch = false;
222+
try {
223+
hasMatch = await commands.executeCommand(ClientCommandConstants.EXECUTE_WORKSPACE_COMMAND, ServerCommandConstants.CHECK_FILE_PATTERN, pattern, documentURI.toString());
224+
} catch (error) {
225+
console.log(`Error while validating file pattern : ${error}`);
226+
}
227+
return !hasMatch ? "The pattern will not match any file." : null
228+
}
220229
}
221230
const inputPattern = (await window.showInputBox(inputBoxOptions));
222231
if (!inputPattern) {

0 commit comments

Comments
 (0)