Skip to content

Conversation

@AlexXuChen
Copy link
Contributor

@AlexXuChen AlexXuChen commented Jul 5, 2021

Added new command, "Bind to grammar/schema", to command palette menu.

Closes #514

Signed-off-by: Alexander Chen alchen@redhat.com

@datho7561
Copy link
Contributor

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.

@datho7561 datho7561 modified the milestone: 0.17.1 Jul 8, 2021
@fbricon fbricon changed the title Added "Bind to grammer/schema" to command palette Added "Bind to grammar/schema" to command palette Jul 13, 2021
@AlexXuChen
Copy link
Contributor Author

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);

@AlexXuChen AlexXuChen force-pushed the issue514 branch 4 times, most recently from 38d7b93 to 42de534 Compare July 19, 2021 18:09
@AlexXuChen AlexXuChen marked this pull request as ready for review July 19, 2021 18:11
@AlexXuChen AlexXuChen requested a review from angelozerr July 19, 2021 18:11
@angelozerr
Copy link
Contributor

angelozerr commented Jul 19, 2021

this fix won't solve if the user manually deletes the schema binding, this can be added with an onDidChangeTextDocument listener:

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.

@angelozerr
Copy link
Contributor

After playing with this PR, I think hide command with setContext is not a good idea because:

  • we need to track the binding declaration inside XML file and I find code is complex just to hide a menu.
  • I have in my mind a new feature to give the capability to rebind a XML with an another XSD/DTD file for instance. In this case the command should be visible every time. But it's out the scope of the PR.

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.

@angelozerr
Copy link
Contributor

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.

@AlexXuChen AlexXuChen requested a review from datho7561 July 22, 2021 19:15
@datho7561 datho7561 merged commit a7259ed into redhat-developer:master Jul 22, 2021
@AlexXuChen AlexXuChen deleted the issue514 branch July 22, 2021 19:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"Bind to grammar/schema..." should be a command available from the palette

3 participants