Skip to content

Add xml.colors and xml.references preference pages with shared DocumentMatcherWidget - #2316

Open
angelozerr wants to merge 1 commit into
eclipse-wildwebdeveloper:masterfrom
angelozerr:xml_colors_references
Open

angelozerr wants to merge 1 commit into
eclipse-wildwebdeveloper:masterfrom
angelozerr:xml_colors_references

Conversation

@angelozerr

@angelozerr angelozerr commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Add xml.colors and xml.references preference pages with shared DocumentMatcherWidget

Introduces UI for configuring LemMinX's xml.colors and xml.references settings
in Eclipse preferences (XML > Colors, XML > References). Both features share a
reusable DocumentMatcherWidget that captures the file/document matcher criteria
(pattern, namespaceURI, rootElement, publicId, systemId, grammarURI). Colors
entries define XPath expressions pointing to color-valued nodes; references
entries define from/to XPath pairs enabling cross-element navigation and rename.
Settings are stored as JSON in the Eclipse preference store and sent to LemMinX
via the existing initialization options mechanism.

xml.colors

Given this XML android colors.xml file:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="white">#FFFFFF</color>
    <color name="ivory">#FFFFF0</color>
    <color name="light_yellow">#FFFFE0</color>
    <color name="yellow">#FFFF00</color>
    <color name="snow">#FFFAFA</color>
    <color name="floral_white">#FFFAF0</color>
    <color name="lemon_chiffon">#FFFACD</color>
    <color name="cornsilk">#FFF8DC</color>
    <color name="seashell">#FFF5EE</color>
    <color name="lavender_blush">#FFF0F5</color>
    <color name="papaya_whip">#FFEFD5</color>
    <color name="blanched_almond">#FFEBCD</color>
    <color name="misty_rose">#FFE4E1</color>
    <color name="bisque">#FFE4C4</color>
    <color name="moccasin">#FFE4B5</color>
    <color name="navajo_white">#FFDEAD</color>
    <color name="peach_puff">#FFDAB9</color>
    <color name="cold">#FFD700</color>
    <color name="pink">#FFC0CB</color>
    <color name="light_pink">#FFB6C1</color>
    <color name="orange">#FFA500</color>
    <color name="light_salmon">#FFA07A</color>
    <color name="dark_orange">#FF8C00</color>
    <color name="coral">#FF7F50</color>
    <color name="hot_pink">#FF69B4</color>
    <color name="tomato">#FF6347</color>
    <color name="orange_red">#FF4500</color>
    <color name="deep_pink">#FF1493</color>
    <color name="fuchsia">#FF00FF</color>
    <color name="magenta">#FF00FF</color>
    <color name="red">#FF0000</color>
    <color name="old_lace">#FDF5E6</color>
    <color name="light_goldenrod_yellow">#FAFAD2</color>
    <color name="linen">#FAF0E6</color>
    <color name="antique_white">#FAEBD7</color>
    <color name="salmon">#FA8072</color>
    <color name="ghost_white">#F8F8FF</color>
    <color name="mint_cream">#F5FFFA</color>
    <color name="white_smoke">#F5F5F5</color>
    <color name="beige">#F5F5DC</color>
    <color name="wheat">#F5DEB3</color>
    <color name="sandy_brown">#F4A460</color>
    <color name="azure">#F0FFFF</color>
    <color name="honeydew">#F0FFF0</color>
    <color name="alice_blue">#F0F8FF</color>
    <color name="khaki">#F0E68C</color>
    <color name="light_coral">#F08080</color>
    <color name="pale_goldenrod">#EEE8AA</color>
    <color name="violet">#EE82EE</color>
    <color name="dark_salmon">#E9967A</color>
    <color name="lavender">#E6E6FA</color>
    <color name="light_cyan">#E0FFFF</color>
    <color name="burlyWood">#DEB887</color>
    <color name="plum">#DDA0DD</color>
    <color name="gainsboro">#DCDCDC</color>
    <color name="crimson">#DC143C</color>
    <color name="pale_violet_red">#DB7093</color>
    <color name="goldenrod">#DAA520</color>
    <color name="orchid">#DA70D6</color>
    <color name="thistle">#D8BFD8</color>
    <color name="light_grey">#D3D3D3</color>
    <color name="tan">#D2B48C</color>
    <color name="chocolate">#D2691E</color>
    <color name="peru">#CD853F</color>
    <color name="indian_red">#CD5C5C</color>
    <color name="medium_violet_red">#C71585</color>
    <color name="silver">#C0C0C0</color>
    <color name="dark_khaki">#BDB76B</color>
    <color name="rosy_brown">#BC8F8F</color>
    <color name="medium_orchid">#BA55D3</color>
    <color name="dark_goldenrod">#B8860B</color>
    <color name="fire_brick">#B22222</color>
    <color name="powder_blue">#B0E0E6</color>
    <color name="light_steel_blue">#B0C4DE</color>
    <color name="pale_turquoise">#AFEEEE</color>
    <color name="greenYellow">#ADFF2F</color>
    <color name="light_blue">#ADD8E6</color>
    <color name="dark_gray">#A9A9A9</color>
    <color name="brown">#A52A2A</color>
    <color name="sienna">#A0522D</color>
    <color name="yellow_green">#9ACD32</color>
    <color name="dark_orchid">#9932CC</color>
    <color name="pale_green">#98FB98</color>
    <color name="dark_violet">#9400D3</color>
    <color name="mediumPurple">#9370DB</color>
    <color name="_light_green">#90EE90</color>
    <color name="dark_sea_green">#8FBC8F</color>
    <color name="saddle_brown">#8B4513</color>
    <color name="dark_magenta">#8B008B</color>
    <color name="dark_red">#8B0000</color>
    <color name="blue_violet">#8A2BE2</color>
    <color name="light_sky_blue">#87CEFA</color>
    <color name="sky_blue">#87CEEB</color>
    <color name="gray">#808080</color>
    <color name="olive">#808000</color>
    <color name="purple">#800080</color>
    <color name="maroon">#800000</color>
    <color name="aquamarine">#7FFFD4</color>
    <color name="chartreuse">#7FFF00</color>
    <color name="lawn_green">#7CFC00</color>
    <color name="medium_slate_blue">#7B68EE</color>
    <color name="light_slate_gray">#778899</color>
    <color name="slate_gray">#708090</color>
    <color name="olive_drab">#6B8E23</color>
    <color name="slate_blue">#6A5ACD</color>
    <color name="dim_gray">#696969</color>
    <color name="medium_aquamarine">#66CDAA</color>
    <color name="cornflower_blue">#6495ED</color>
    <color name="cadet_blue">#5F9EA0</color>
    <color name="dark_olive_green">#556B2F</color>
    <color name="indigo">#4B0082</color>
    <color name="medium_turquoise">#48D1CC</color>
    <color name="dark_slate_blue">#483D8B</color>
    <color name="steel_blue">#4682B4</color>
    <color name="royal_blue">#4169E1</color>
    <color name="turquoise">#40E0D0</color>
    <color name="medium_sea_green">#3CB371</color>
    <color name="lime_green">#32CD32</color>
    <color name="dark_slate_gray">#2F4F4F</color>
    <color name="sea_green">#2E8B57</color>
    <color name="forest_green">#228B22</color>
    <color name="light_sea_green">#20B2AA</color>
    <color name="dodger_blue">#1E90FF</color>
    <color name="midnight_blue">#191970</color>
    <color name="aqua">#00FFFF</color>
    <color name="cyan">#00FFFF</color>
    <color name="spring_green">#00FF7F</color>
    <color name="lime">#00FF00</color>
    <color name="medium_spring_green">#00FA9A</color>
    <color name="dark_turquoise">#00CED1</color>
    <color name="deep_sky_blue">#00BFFF</color>
    <color name="dark_cyan">#008B8B</color>
    <color name="teal">#008080</color>
    <color name="green">#008000</color>
    <color name="dark_green">#006400</color>
    <color name="blue">#0000FF</color>
    <color name="medium_blue">#0000CD</color>
    <color name="dark_blue">#00008B</color>
    <color name="navy">#000080</color>
    <color name="black">#000000</color>
</resources>

With LemMinx you can configure where LSP color is defined by using XPath (see vscode-xml doc at https://github.com/redhat-developer/vscode-xml/blob/main/docs/Features/XMLColorsFeatures.md)

After defining this XPath expression for a given file:

image

You should benefit with colors:

XMLColorsInWWD

xml.references

Same thing for references, see doc at https://github.com/redhat-developer/vscode-xml/blob/main/docs/Features/XMLReferencesFeatures.md

image

@vogella vogella mentioned this pull request Nov 30, 2026
@angelozerr
angelozerr marked this pull request as ready for review November 30, 2026 10:45
@vogella

vogella commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

public void saveToJson(JsonObject obj) {
putIfNotEmpty(obj, "pattern", getPattern());
putIfNotEmpty(obj, "namespaceURI", getNamespaceURI());
putIfNotEmpty(obj, "rootElement", getRootElement());
putIfNotEmpty(obj, "publicId", getPublicId());
putIfNotEmpty(obj, "systemId", getSystemId());
putIfNotEmpty(obj, "grammarURI", getGrammarURI());
returns strings. AFAICS Lemmix expects array of strings. Can be be aligned?

@vogella

vogella commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

AFAICS we target Java 21 here, so the warnings for editButton.addSelectionListener(widgetSelectedAdapter(e -> editExpression())); should not be issued / cannot be fixed here.

@vogella

vogella commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

public void saveToJson(JsonObject obj) {
putIfNotEmpty(obj, "pattern", getPattern());
putIfNotEmpty(obj, "namespaceURI", getNamespaceURI());
putIfNotEmpty(obj, "rootElement", getRootElement());
putIfNotEmpty(obj, "publicId", getPublicId());
putIfNotEmpty(obj, "systemId", getSystemId());
putIfNotEmpty(obj, "grammarURI", getGrammarURI());

returns strings. AFAICS Lemmix expects array of strings. Can be be aligned?

@angelozerr WDYT?

@angelozerr

Copy link
Copy Markdown
Contributor Author

@vogella I wonder if we should add as default this Android sample for color. For Android user, It will work out of the box without configuring it. Wat do you think about that?

@vogella

vogella commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

@vogella I wonder if we should add as default this Android sample for color. For Android user, It will work out of the box without configuring it. Wat do you think about that?

I don't understand. Which Android users? Android development tools are AFAIK dead.

@angelozerr

Copy link
Copy Markdown
Contributor Author

I mean if user open a colors.xml file it will see color (like my demo) without some configuration.

@vogella

vogella commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

I mean if user open a colors.xml file it will see color (like my demo) without some configuration.

That would be IMHO great, if it needs to be activated almost nobody will think of that.

Copilot AI 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.

🟡 Changes recommended

Non-pattern matcher criteria are serialized as strings and discarded by the server, potentially matching unrelated documents, while both entry dialogs reject valid matchers without a file pattern.

2 open issues
What changed in this PR

Adds Eclipse preference pages for configuring LemMinX color detection and XPath-based references within Wild Web Developer’s XML support.

Changes:

  • Adds Colors and References pages with dialogs for managing XPath rules.
  • Introduces a shared widget for document-matching criteria.
  • Stores settings as JSON and connects them to the existing LemMinX initialization options.
File Description
org.eclipse.wildwebdeveloper.xml/​src/​org/​eclipse/​wildwebdeveloper/​xml/​internal/​ui/​preferences/​XMLReferencesPreferencePage.java Manages and persists reference entries.
org.eclipse.wildwebdeveloper.xml/​src/​org/​eclipse/​wildwebdeveloper/​xml/​internal/​ui/​preferences/​XMLReferencesEntryDialog.java Edits reference matchers and expression lists.
org.eclipse.wildwebdeveloper.xml/​src/​org/​eclipse/​wildwebdeveloper/​xml/​internal/​ui/​preferences/​XMLReferenceExpressionDialog.java Edits from/to XPath pairs, prefixes, and multiple-value settings.
org.eclipse.wildwebdeveloper.xml/​src/​org/​eclipse/​wildwebdeveloper/​xml/​internal/​ui/​preferences/​XMLPreferenceServerConstants.java Registers both settings and converts JSON for initialization options.
org.eclipse.wildwebdeveloper.xml/​src/​org/​eclipse/​wildwebdeveloper/​xml/​internal/​ui/​preferences/​XMLPreferenceInitializer.java Defines empty-array defaults for both settings.
org.eclipse.wildwebdeveloper.xml/​src/​org/​eclipse/​wildwebdeveloper/​xml/​internal/​ui/​preferences/​XMLColorsPreferencePage.java Manages and persists color entries.
org.eclipse.wildwebdeveloper.xml/​src/​org/​eclipse/​wildwebdeveloper/​xml/​internal/​ui/​preferences/​XMLColorsEntryDialog.java Edits color matchers and XPath expressions.
org.eclipse.wildwebdeveloper.xml/​src/​org/​eclipse/​wildwebdeveloper/​xml/​internal/​ui/​preferences/​DocumentMatcherWidget.java Provides shared matcher fields and JSON conversion.
org.eclipse.wildwebdeveloper.xml/​src/​org/​eclipse/​wildwebdeveloper/​xml/​internal/​ui/​messages.properties Adds UI labels, descriptions, and validation messages.
org.eclipse.wildwebdeveloper.xml/​src/​org/​eclipse/​wildwebdeveloper/​xml/​internal/​ui/​Messages.java Exposes the new localized message fields.
org.eclipse.wildwebdeveloper.xml/​plugin.xml Registers both preference pages and search keywords.
org.eclipse.wildwebdeveloper.xml/​plugin.properties Supplies page names and keyword text.

Review effort: Balanced

Comment on lines +107 to +111
putIfNotEmpty(obj, "namespaceURI", getNamespaceURI());
putIfNotEmpty(obj, "rootElement", getRootElement());
putIfNotEmpty(obj, "publicId", getPublicId());
putIfNotEmpty(obj, "systemId", getSystemId());
putIfNotEmpty(obj, "grammarURI", getGrammarURI());
Comment on lines +208 to +209
if (matcherWidget != null && matcherWidget.getPattern().isEmpty()) {
error = Messages.XMLColorsEntryDialog_error_pattern_required;
@akurtakov

Copy link
Copy Markdown
Contributor

I don't understand the use case for this quite big PR. Just so colors will be rendered in the editor or one can manually define their own references? If one wants to have good docbook experience , a lemminx extension like lemminx-maven will be needed, no?

@akurtakov

Copy link
Copy Markdown
Contributor

Such amount of code for rarely used (according to me) features is definetely what I look to support.
@angelozerr Have you considered having a preference page which embeds json editor so people can edit their lemminx config like they do in vscode for these cases? It would also allow people to use everything lemminx provides without UI for every single feature, commonly used features can still have dedicated UI configs.

@angelozerr

Copy link
Copy Markdown
Contributor Author

I don't understand the use case for this quite big PR. Just so colors will be rendered in the editor or one can manually define their own references? If one wants to have good docbook experience , a lemminx extension like lemminx-maven will be needed, no?

@akurtakov this PR provides

It is 2 different features.

XML references features support provide the capability to manage your own references with declarative mean without developping a LemMinx extension.

But if you want I can remove this support and provides only xml.colors?

@angelozerr

Copy link
Copy Markdown
Contributor Author

Such amount of code for rarely used (according to me) features is definetely what I look to support. @angelozerr Have you considered having a preference page which embeds json editor so people can edit their lemminx config like they do in vscode for these cases? It would also allow people to use everything lemminx provides without UI for every single feature, commonly used features can still have dedicated UI configs.

I had also this idea, but I think this feature should be managed by LSP4E to have the same UI settings than code. Having this kind of generic UI settings could allow to share the same settings between Eclipse IDE and vscode but it will not use the Eclipse preferences mechanism.

@angelozerr
angelozerr force-pushed the xml_colors_references branch from d4965c1 to 49d10b0 Compare November 30, 2026 14:50
@angelozerr
angelozerr marked this pull request as draft November 30, 2026 16:11
@angelozerr
angelozerr force-pushed the xml_colors_references branch from 49d10b0 to c9611d3 Compare November 30, 2026 17:52
@angelozerr
angelozerr force-pushed the xml_colors_references branch from c9611d3 to 24e3b97 Compare November 30, 2026 17:58
@angelozerr

Copy link
Copy Markdown
Contributor Author

I mean if user open a colors.xml file it will see color (like my demo) without some configuration.

That would be IMHO great, if it needs to be activated almost nobody will think of that.

done

@angelozerr
angelozerr marked this pull request as ready for review November 30, 2026 18:04
@angelozerr
angelozerr force-pushed the xml_colors_references branch 3 times, most recently from fa9c827 to 4efe426 Compare November 30, 2026 18:32
@angelozerr

Copy link
Copy Markdown
Contributor Author

@vogella please review again, it should be cleaner.

@vogella

vogella commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

@angelozerr can you check and resolve the Copilot review feedback? On of it is also what I have commented on.

@merks
merks requested a balanced review from Copilot December 1, 2026 10:23

Copilot AI 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.

🟡 Changes recommended

The matcher model incorrectly represents array-valued criteria as strings, causing valid entries to be lost on save, while the dialogs also discard non-pattern criteria.

7 open issues

Review effort: Balanced

@angelozerr

Copy link
Copy Markdown
Contributor Author

@angelozerr can you check and resolve the Copilot review feedback? On of it is also what I have commented on.

Yes sure! I am working on that.

@angelozerr
angelozerr force-pushed the xml_colors_references branch 2 times, most recently from 49fdc79 to b5254fa Compare December 1, 2026 13:52
Button addButton = new Button(btnComposite, SWT.PUSH);
addButton.setText(Messages.Add_button);
addButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
addButton.addSelectionListener(widgetSelectedAdapter(e -> addExpression()));
editButton.setText(Messages.XMLColorsEntryDialog_edit_button);
editButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
editButton.setEnabled(false);
editButton.addSelectionListener(widgetSelectedAdapter(e -> editExpression()));
removeButton.setText(Messages.Remove_button);
removeButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
removeButton.setEnabled(false);
removeButton.addSelectionListener(widgetSelectedAdapter(e -> removeExpression()));
Button addButton = new Button(btnComposite, SWT.PUSH);
addButton.setText(Messages.Add_button);
addButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
addButton.addSelectionListener(widgetSelectedAdapter(e -> addEntry()));
editButton.setText(Messages.XMLColorsEntryDialog_edit_button);
editButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
editButton.setEnabled(false);
editButton.addSelectionListener(widgetSelectedAdapter(e -> editEntry()));
removeButton.setText(Messages.Remove_button);
removeButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
removeButton.setEnabled(false);
removeButton.addSelectionListener(widgetSelectedAdapter(e -> removeEntry()));
Button addButton = new Button(buttonComposite, SWT.PUSH);
addButton.setText(Messages.Add_button);
addButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
addButton.addSelectionListener(widgetSelectedAdapter(e -> addMatcher()));
removeButton.setText(Messages.Remove_button);
removeButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
removeButton.setEnabled(false);
removeButton.addSelectionListener(widgetSelectedAdapter(e -> removeMatcher()));
Link colorsLink = new Link(composite, SWT.NONE);
colorsLink.setText("• <a>Colors</a> - Extract color values from XML files for color picker support");
colorsLink.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
colorsLink.addSelectionListener(org.eclipse.swt.events.SelectionListener.widgetSelectedAdapter(e -> {
Link referencesLink = new Link(composite, SWT.NONE);
referencesLink.setText("• <a>References</a> - Define reference relationships for navigation and rename refactoring");
referencesLink.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
referencesLink.addSelectionListener(org.eclipse.swt.events.SelectionListener.widgetSelectedAdapter(e -> {
@angelozerr
angelozerr force-pushed the xml_colors_references branch from b5254fa to c6d9c31 Compare December 1, 2026 14:01
@merks

merks commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

The unused parameter warnings are kind of annoying. There's not much choice unless we bump to Java 25.

Copilot AI 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.

@angelozerr
angelozerr force-pushed the xml_colors_references branch 2 times, most recently from 9c86737 to e9d58ae Compare December 1, 2026 14:22
@angelozerr

Copy link
Copy Markdown
Contributor Author

@vogella @merks all issues from Copilot should be fixed and I have improved UI. First I set olor and references in the File Rules page:

image

I will add in this File Rules (once this PR will be merged) the https://github.com/redhat-developer/vscode-xml/blob/main/docs/Features/XMLFilePathSupport.md support

Here the UI for Colors:

image

Here the UI for References

image

If you need to have several namespace uri you can add it in the table:

image

There is defaut references like explained https://github.com/redhat-developer/vscode-xml/blob/main/docs/Features/XMLReferencesFeatures.md (for docbook, tei and web.xml)

@angelozerr

Copy link
Copy Markdown
Contributor Author

Here a demo with docbook v5 which use XML references:

<book xmlns="http://docbook.org/ns/docbook"
	xmlns:xlink="http://w3.org"
	version="5.1">
	<chapter xml:id="chapter-1">

		<xref linkend="chapter-1" />

	</chapter>

	<chapter xml:id="chapter-2">

	</chapter>
</book>
DocbookV5Demo

DocumentMatcherWidget

Introduces UI for configuring LemMinX's xml.colors and xml.references
settings
in Eclipse preferences (XML > Colors, XML > References). Both features
share a
reusable DocumentMatcherWidget that captures the file/document matcher
criteria
(pattern, namespaceURI, rootElement, publicId, systemId, grammarURI).
Colors
entries define XPath expressions pointing to color-valued nodes;
references
entries define from/to XPath pairs enabling cross-element navigation and
rename.
Settings are stored as JSON in the Eclipse preference store and sent to
LemMinX
via the existing initialization options mechanism.

Signed-off-by: azerr <azerr@redhat.com>
@angelozerr
angelozerr force-pushed the xml_colors_references branch from e9d58ae to e98e354 Compare December 1, 2026 14:38
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.

6 participants