Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide the capability to bind RelaxNG schema #807

Merged
merged 1 commit into from
Nov 16, 2022
Merged
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
59 changes: 34 additions & 25 deletions src/commands/registerCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,12 @@ for (const label of bindingTypes.keys()) {
bindingTypeOptions.push({ "label": label });
}

const bindingTypeOptionsForRelaxNG: QuickPickItem[] = [];
for (const entry of bindingTypes.entries()) {
if (entry[1] !== 'standard') {
bindingTypeOptionsForRelaxNG.push({ "label": entry[0] });
}
}
/**
* The function passed to context subscriptions for grammar association
*
Expand All @@ -168,38 +174,41 @@ for (const label of bindingTypes.keys()) {
async function grammarAssociationCommand(documentURI: Uri, languageClient: LanguageClient) {
// A click on Bind to grammar/schema... has been processed in the XML document which is not bound to a grammar

// Step 1 : open a combo to select the binding type ("standard", "xml-model", "fileAssociation")
const pickedBindingTypeOption = await window.showQuickPick(bindingTypeOptions, { placeHolder: "Binding type" });
if (!pickedBindingTypeOption) {
return;
}
const bindingType = bindingTypes.get(pickedBindingTypeOption.label);

// Open a dialog to select the XSD, DTD to bind.
// step 1: Open a dialog to select the XSD, DTD, RelaxNG file to bind.
const options: OpenDialogOptions = {
canSelectMany: false,
openLabel: 'Select XSD or DTD file',
openLabel: 'Select XSD, DTD, RNG or RNC file',
datho7561 marked this conversation as resolved.
Show resolved Hide resolved
filters: {
'Grammar files': ['xsd', 'dtd']
'Grammar files': ['xsd', 'dtd', 'rng', 'rnc']
}
};

const fileUri = await window.showOpenDialog(options);
if (fileUri && fileUri[0]) {
// The XSD, DTD has been selected, get the proper syntax for binding this grammar file in the XML document.
const grammarURI = fileUri[0];
try {
const currentFile = (window.activeTextEditor && window.activeTextEditor.document && window.activeTextEditor.document.languageId === 'xml') ? window.activeTextEditor.document : undefined;
if (bindingType == 'fileAssociation') {
// Bind grammar using file association
await bindWithFileAssociation(documentURI, grammarURI, currentFile);
} else {
// Bind grammar using standard binding
await bindWithStandard(documentURI, grammarURI, bindingType, languageClient);
}
} catch (error) {
window.showErrorMessage('Error during grammar binding: ' + error.message);
const grammarURI = fileUri && fileUri[0];
if (!grammarURI) {
return;
}

const isRelaxNG = grammarURI.fsPath.endsWith('.rng') || grammarURI.fsPath.endsWith('.rnc');
// Step 2 : open a combo to select the binding type ("standard", "xml-model", "fileAssociation")
const bindingTypesQuickPick = isRelaxNG ? bindingTypeOptionsForRelaxNG : bindingTypeOptions;
const pickedBindingTypeOption = await window.showQuickPick(bindingTypesQuickPick, { placeHolder: "Binding type" });
if (!pickedBindingTypeOption) {
return;
}
const bindingType = bindingTypes.get(pickedBindingTypeOption.label);

// The XSD, DTD has been selected, get the proper syntax for binding this grammar file in the XML document.
try {
const currentFile = (window.activeTextEditor && window.activeTextEditor.document && window.activeTextEditor.document.languageId === 'xml') ? window.activeTextEditor.document : undefined;
if (bindingType === 'fileAssociation') {
// Bind grammar using file association
await bindWithFileAssociation(documentURI, grammarURI, currentFile);
} else {
// Bind grammar using standard binding
await bindWithStandard(documentURI, grammarURI, bindingType, languageClient);
}
} catch (error) {
window.showErrorMessage('Error during grammar binding: ' + error.message);
}
}

Expand Down