Skip to content

Improve AssociateGrammarDialog with Local/Remote navigation - #2301

Merged
akurtakov merged 1 commit into
eclipse-wildwebdeveloper:masterfrom
angelozerr:improve_associate_dialog
Nov 26, 2026
Merged

akurtakov merged 1 commit into
eclipse-wildwebdeveloper:masterfrom
angelozerr:improve_associate_dialog

Conversation

@angelozerr

@angelozerr angelozerr commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Fix AssociateGrammarDialog validation and UX issues

Replace the single grammar file field with a two-row layout (Local/Remote)
inside a "Schema / Grammar" Group:

  • Local row: radio + text field + Browse button (workspace-relative path)
  • Remote row: radio + text field for remote grammar URLs (https://, http://...)
    with placeholder URL hint, select-all on focus
  • Browse dialog filtered to grammar extensions (xsd, dtd, rng, rnc)

Remote grammar support:

  • Validate remote URL with URI.isAbsolute() + toURL(); catch IllegalArgumentException
  • Show a warning in the TitleArea when "Download external resources" is disabled,
    since LemMinX will not fetch the grammar and grammar-driven features
    (completion, validation, hover, code actions...) will be unavailable
  • On OK, show a MessageDialogWithToggle offering to enable download now,
    with Yes/No/Cancel and a "Don't ask again" preference key

Association type section uses two radio buttons:

  • Standard (xsi, DOCTYPE)
  • XML Model association
    Standard is automatically disabled and deselected when a RelaxNG file
    (.rng/.rnc) is detected; re-enabled otherwise.

Validation fixes:

  • Disable OK button on validation error
  • Resolve grammar path relative to XML file folder (handles ../ segments)
  • Guard against null getLocation() for non-local file systems
  • Pass full file URI to command handler for local grammar files
  • Replace setText with setMessage on remote grammar text field
  • Rename updateBindingTypeCombo to updateBindingTypeRadios
  • Set dialog title via getShell().setText and setTitle

Here a demo:

AssociateGrammarDemo2

@angelozerr
angelozerr force-pushed the improve_associate_dialog branch from 0ab7dab to c4298b0 Compare November 26, 2026 01:40
@angelozerr
angelozerr marked this pull request as ready for review November 26, 2026 01:41
@angelozerr

Copy link
Copy Markdown
Contributor Author

@akurtakov @merks please review

@angelozerr
angelozerr force-pushed the improve_associate_dialog branch 2 times, most recently from ca5eaa1 to b115248 Compare November 26, 2026 09:50

@akurtakov akurtakov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some general points, details inline:

  1. The description doesn't match the code. It mentions a left-side navigation list (Local/Remote) with a stacked right panel, but the dialog uses two radio rows in a single Group, with no list and no StackLayout. Is the description (or the demo) outdated, or was another version meant to be pushed?

  2. A remote grammar doesn't give completion or validation by default. Wild Web Developer defaults downloadExternalResources to false (XMLPreferenceInitializer), so after binding to an https:// schema, LemMinX doesn't fetch it and the user gets no completion, validation or hover until they enable "Download external resources like referenced DTD, XSD". The dialog doesn't say anything about it. Could the Remote option show a hint/warning when the preference is disabled, or offer to enable it?

  3. Remote XSD with standard binding: did you try binding to a remote XSD that has a targetNamespace? For xsi:schemaLocation, LemMinX has to read the schema to get the namespace, which may not work while downloads are disabled.

  4. Pre-existing, not introduced here, but maybe worth fixing while the dialog is reworked:

    • The OK button is never disabled, so the dialog can be confirmed with an empty or invalid grammar.
    • Browse fills in a path relative to the XML file's folder (makeRelativeTo(xmlFilePath.removeLastSegments(1))), but validateLocal() resolves it against the project (xmlResourceContainer.getFile(...)), so for an XML file in a subfolder, a correctly browsed grammar is reported as not existing.

});

remoteGrammarURIText = new Text(group, SWT.BORDER);
remoteGrammarURIText.setText(Messages.AssociateGrammarDialog_remote_grammar_default);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This puts the example URL into the field as a real value, and it passes validation, so selecting Remote and pressing OK binds the document to http://example.com/schema.xsd. remoteGrammarURIText.setMessage(...) would show it as a greyed-out hint instead. The example also doesn't need to be a translatable message.

@angelozerr

Copy link
Copy Markdown
Contributor Author

Some general points, details inline:

  1. The description doesn't match the code. It mentions a left-side navigation list (Local/Remote) with a stacked right panel, but the dialog uses two radio rows in a single Group, with no list and no StackLayout. Is the description (or the demo) outdated, or was another version meant to be pushed?

You are right, I will change the description.

  1. A remote grammar doesn't give completion or validation by default. Wild Web Developer defaults downloadExternalResources to false (XMLPreferenceInitializer), so after binding to an https:// schema, LemMinX doesn't fetch it and the user gets no completion, validation or hover until they enable "Download external resources like referenced DTD, XSD". The dialog doesn't say anything about it. Could the Remote option show a hint/warning when the preference is disabled, or offer to enable it?

Ok I will add a warning about that, but you can see that as error in XML and you have even a quick fix which gives you the capability to force the download of the schema:

image

The missing quick fix is to suggest to the user to set the preferences to true. If I remember we did that in vscode-xml but it requires to implement a custom command to update preferences from LSP client side.

I will try to implement it.

  1. Remote XSD with standard binding: did you try binding to a remote XSD that has a targetNamespace? For xsi:schemaLocation, LemMinX has to read the schema to get the namespace, which may not work while downloads are disabled.

It is the job of LemMinX, and if I remember I take care of that in 0.40.0.

  1. Pre-existing, not introduced here, but maybe worth fixing while the dialog is reworked:

    • The OK button is never disabled, so the dialog can be confirmed with an empty or invalid grammar.
    • Browse fills in a path relative to the XML file's folder (makeRelativeTo(xmlFilePath.removeLastSegments(1))), but validateLocal() resolves it against the project (xmlResourceContainer.getFile(...)), so for an XML file in a subfolder, a correctly browsed grammar is reported as not existing.

@angelozerr
angelozerr force-pushed the improve_associate_dialog branch 3 times, most recently from ece5abd to 368b83c Compare November 26, 2026 12:58
@akurtakov

Copy link
Copy Markdown
Contributor

It fails for me in workbench with !ENTRY org.eclipse.ui 4 0 2026-11-26 15:00:36.592
!MESSAGE Unhandled event loop exception
!STACK 0
java.lang.Error: Unresolved compilation problem:
The method addListFilter(ViewerFilter) from the type FilteredItemsSelectionDialog is not visible

at org.eclipse.wildwebdeveloper.xml.internal.commands.AssociateGrammarDialog$2.widgetSelected(AssociateGrammarDialog.java:182)
at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:290)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:91)
at org.eclipse.swt.widgets.Display.sendEvent(Display.java:5888)

and I have :
image

@angelozerr

Copy link
Copy Markdown
Contributor Author

It fails for me in workbench with !ENTRY org.eclipse.ui 4 0 2026-11-26 15:00:36.592 !MESSAGE Unhandled event loop exception !STACK 0 java.lang.Error: Unresolved compilation problem: The method addListFilter(ViewerFilter) from the type FilteredItemsSelectionDialog is not visible

at org.eclipse.wildwebdeveloper.xml.internal.commands.AssociateGrammarDialog$2.widgetSelected(AssociateGrammarDialog.java:182)
at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:290)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:91)
at org.eclipse.swt.widgets.Display.sendEvent(Display.java:5888)

and I have : image

Sorry I pushed my code too quicly, I fixed that.

@angelozerr
angelozerr force-pushed the improve_associate_dialog branch from 368b83c to ac973ca Compare November 26, 2026 13:12

@akurtakov akurtakov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two leftovers from my earlier review:

  • The PR description still mentions a left-side navigation list (Local/Remote) with a stacked right panel, while the dialog uses radio buttons. Could you update it (and the demo if it's outdated)?
  • Did you try binding to a remote XSD that has a targetNamespace with the standard binding? For xsi:schemaLocation, LemMinX has to read the schema to get the namespace.

@angelozerr
angelozerr force-pushed the improve_associate_dialog branch 2 times, most recently from 7912722 to a06b1b5 Compare November 26, 2026 14:26
Replace the single grammar file field with a two-row layout
(Local/Remote)
inside a "Schema / Grammar" Group:

- Local row: radio + text field + Browse button (workspace-relative
path)
- Remote row: radio + text field for remote grammar URLs (https://,
http://...)
  with placeholder URL hint, select-all on focus
- Browse dialog filtered to grammar extensions (xsd, dtd, rng, rnc)

Remote grammar support:
- Validate remote URL with URI.isAbsolute() + toURL(); catch
IllegalArgumentException
- Show a warning in the TitleArea when "Download external resources" is
disabled,
  since LemMinX will not fetch the grammar and grammar-driven features
  (completion, validation, hover, code actions...) will be unavailable
- On OK, show a MessageDialogWithToggle offering to enable download now,
  with Yes/No/Cancel and a "Don't ask again" preference key

Association type section uses two radio buttons:
- Standard (xsi, DOCTYPE)
- XML Model association
Standard is automatically disabled and deselected when a RelaxNG file
(.rng/.rnc) is detected; re-enabled otherwise.

Validation fixes:
- Disable OK button on validation error
- Resolve grammar path relative to XML file folder (handles ../
segments)
- Guard against null getLocation() for non-local file systems
- Pass full file URI to command handler for local grammar files
- Replace setText with setMessage on remote grammar text field
- Rename updateBindingTypeCombo to updateBindingTypeRadios
- Set dialog title via getShell().setText and setTitle

Signed-off-by: azerr <azerr@redhat.com>
@angelozerr
angelozerr force-pushed the improve_associate_dialog branch from a06b1b5 to 411af73 Compare November 26, 2026 14:32
@angelozerr

Copy link
Copy Markdown
Contributor Author

Two leftovers from my earlier review:

  • The PR description still mentions a left-side navigation list (Local/Remote) with a stacked right panel, while the dialog uses radio buttons. Could you update it (and the demo if it's outdated)?

Description fixed and new demo recored:

  • Did you try binding to a remote XSD that has a targetNamespace with the standard binding? For xsi:schemaLocation, LemMinX has to read the schema to get the namespace.

I confirm that LemMinx 0.40.0 takes care of this usecase and generate the proper xmlns attribute and even generate the proper root element.

For instance with this XSD:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
           targetNamespace="http://example.com/schemas/product"
           xmlns:tns="http://example.com/schemas/product"
           elementFormDefault="qualified">

  <xs:element name="catalog">
   
  </xs:element>

</xs:schema>

LemMinx 0.40.0 will generate catalog as root element and xmlns="http://example.com/schemas/product"

<catalog xmlns="http://example.com/schemas/product"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://example.com/schemas/product workspaceIndex/schemas/product.xsd"></catalog>

@angelozerr

Copy link
Copy Markdown
Contributor Author

@akurtakov I need this PR to add the catalog support in the associate grammar catalog based on LemMinx 0.40.0 to have the same feature than https://github.com/redhat-developer/vscode-xml/blob/main/docs/Features/XMLCatalogFeatures.md#binding-with-catalog

@akurtakov

Copy link
Copy Markdown
Contributor

This is good to go from my side.

@akurtakov
akurtakov merged commit 0a00465 into eclipse-wildwebdeveloper:master Nov 26, 2026
8 checks passed
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.

3 participants