-
Notifications
You must be signed in to change notification settings - Fork 97
Added "Bind to grammar/schema" to command palette #544
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
Conversation
|
Something that I ran into is that this will fail if the document has no root element. The code for the CodeLens assumes that there is a root element, since the CodeLens is placed right above the root element. eg. try binding the following file to a grammar: <?xml version="1.0" encoding="UTF-8"?>This will involve adding a check in LemMinX to see if there is a root element when trying to build the edit to add the grammar association. |
|
FOR REFERENCE: this fix won't solve if the user manually deletes the schema binding, this can be added with an onDidChangeTextDocument listener: async function onDidChangeTextDocument(document: TextDocument) {
if (typeof timeout !== 'undefined') {
clearTimeout(timeout);
}
await checkCanBindGrammar(document);
}
return Disposable.from(...disposables);and called as: workspace.onDidChangeTextDocument(event => onDidChangeTextDocument(event.document), null, disposables); |
38d7b93 to
42de534
Compare
AssociateGrammarCommand should throw an error when XML document is already bound to a XSD/DTD. See my comments at https://github.com/eclipse/lemminx/pull/1084/files#r672637564 I agree with you, without onDidChangeTextDocument, the menu to bind a grammar will appear if user write teh binding with the editor, but if it applies the binding, AssociateGrammarCommand will throw an error. |
|
After playing with this PR, I think hide command with setContext is not a good idea because:
In other words, I think should remove the canBindGrammar from package.json and all code which update setContext. When user will try to bind the XML with a grammar and this XML i salready bound, we should just display an error message like I suggested in https://github.com/redhat-developer/vscode-xml/pull/544/files#r673821683 We could improve that in future release by rebind teh XMLwith a new XSD/DTD by improving AssociateGrammarCommand. |
|
Code is now perfect and I play with the lemMinx / vscode-xml PR and it works great. There is some usecase that we must improve but we can do that in an another PR (ex : try to bind with XML which have no root tag element, bind a xml-model, etc.). I will create an issue for that as soon as this PR are merged. Once LemMinx PR will be merged (see my comments), I'm OK to merge this PR. |
Added new command, "Bind to grammar/schema", to command palette menu.
Closes #514
Signed-off-by: Alexander Chen alchen@redhat.com