Skip to content
Draft
Show file tree
Hide file tree
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
5 changes: 4 additions & 1 deletion org.eclipse.wildwebdeveloper.xml/plugin.properties
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,7 @@ XMLCodeMiningsPreferencePage.preferenceKeywords.xmlcodeminings=xml codeminings
XMLFormattingPreferencePage.name=Formatting
XMLFormattingPreferencePage.preferenceKeywords.xmlformatting=xml formatting
XMLValidationPreferencePage.name=Validation & Resolution
XMLValidationPreferencePage.preferenceKeywords.xmlvalidation=xml validation resolution download external sources
XMLValidationPreferencePage.preferenceKeywords.xmlvalidation=xml validation resolution download external sources
XMLWorkspaceIndexPreferencePage.name=Workspace Index
XMLWorkspaceIndexPreferencesPage.preferenceKeywords.xmlworkspaceindex=xml workspace index grammar references bloom
command.xmlFindReferences.name=Find References
53 changes: 53 additions & 0 deletions org.eclipse.wildwebdeveloper.xml/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,13 @@
name="%XMLValidationPreferencePage.name">
<keywordReference id="org.eclipse.wildwebdeveloper.xml.ui.xmlvalidation"/>
</page>
<page
category="org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.XMLPreferencePage"
class="org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.XMLWorkspaceIndexPreferencePage"
id="org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.XMLWorkspaceIndexPreferencePage"
name="%XMLWorkspaceIndexPreferencePage.name">
<keywordReference id="org.eclipse.wildwebdeveloper.xml.ui.xmlworkspaceindex"/>
</page>
</extension>

<!-- Keywords for preference and properties pages -->
Expand All @@ -219,6 +226,9 @@
<keyword
label="%XMLValidationPreferencesPage.preferenceKeywords.xmlvalidation"
id="org.eclipse.wildwebdeveloper.xml.ui.xmlvalidation"/>
<keyword
label="%XMLWorkspaceIndexPreferencesPage.preferenceKeywords.xmlworkspaceindex"
id="org.eclipse.wildwebdeveloper.xml.ui.xmlworkspaceindex"/>
</extension>

<extension
Expand All @@ -228,6 +238,17 @@
</initializer>
</extension>

<extension point="org.eclipse.ui.startup">
<startup class="org.eclipse.wildwebdeveloper.xml.internal.startup.XMLWorkspaceIndexDetector"/>
</extension>

<extension point="org.eclipse.ui.commands">
<command
id="org.eclipse.wildwebdeveloper.xml.findReferences"
name="%command.xmlFindReferences.name">
</command>
</extension>

<extension
point="org.eclipse.ui.handlers">
<handler
Expand All @@ -246,5 +267,37 @@
class="org.eclipse.wildwebdeveloper.xml.internal.commands.UpdateConfigurationHandler"
commandId="xml.update.configuration">
</handler>
<handler
class="org.eclipse.wildwebdeveloper.xml.internal.commands.XMLFindReferencesInExplorerHandler"
commandId="org.eclipse.wildwebdeveloper.xml.findReferences">
</handler>
</extension>

<extension point="org.eclipse.ui.menus">
<menuContribution
allPopups="false"
locationURI="popup:org.eclipse.ui.popup.any?after=additions">
<command
commandId="org.eclipse.wildwebdeveloper.xml.findReferences"
label="%command.xmlFindReferences.name"
style="push">
<visibleWhen checkEnabled="false">
<with variable="selection">
<count value="1"/>
<iterate>
<and>
<instanceof value="org.eclipse.core.resources.IFile"/>
<or>
<test property="org.eclipse.core.resources.name" value="*.xsd"/>
<test property="org.eclipse.core.resources.name" value="*.dtd"/>
<test property="org.eclipse.core.resources.name" value="*.rng"/>
<test property="org.eclipse.core.resources.name" value="*.rnc"/>
Comment thread
angelozerr marked this conversation as resolved.
Resolved
</or>
</and>
</iterate>
</with>
</visibleWhen>
</command>
</menuContribution>
</extension>
</plugin>
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*******************************************************************************
* Copyright (c) 2026 Red Hat Inc. and others.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Angelo ZERR (Red Hat Inc.) - initial implementation
*******************************************************************************/
package org.eclipse.wildwebdeveloper.xml.internal.commands;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.ILog;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.handlers.HandlerUtil;
import org.eclipse.ui.handlers.IHandlerService;
import org.eclipse.ui.ide.IDE;
import org.eclipse.ui.texteditor.ITextEditor;
import org.eclipse.wildwebdeveloper.xml.internal.Activator;
import org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.XMLPreferenceServerConstants;

/**
* Triggers "Find References" on a grammar file selected in the file explorer.
* When the workspace index is not enabled, offers to enable it.
*/
public class XMLFindReferencesInExplorerHandler extends AbstractHandler {

private static final String FIND_REFERENCES_COMMAND = "org.eclipse.ui.genericeditor.findReferences";

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
ISelection selection = HandlerUtil.getCurrentSelection(event);
if (!(selection instanceof IStructuredSelection structured)) {
return null;
}
Object first = structured.getFirstElement();
if (!(first instanceof IFile file)) {
return null;
}

IPreferenceStore store = Activator.getDefault().getPreferenceStore();
if (!store.getBoolean(XMLPreferenceServerConstants.XML_PREFERENCES_WORKSPACE_INDEX_ENABLED.preferenceId)) {
boolean enable = MessageDialog.openQuestion(
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
"Workspace Index Not Enabled",
"Find References on grammar files requires the XML workspace index.\n\nEnable it now?");
if (enable) {
store.setValue(XMLPreferenceServerConstants.XML_PREFERENCES_WORKSPACE_INDEX_ENABLED.preferenceId, true);
} else {
return null;
}
}

try {
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
var editor = IDE.openEditor(page, file);
if (editor instanceof ITextEditor) {
IHandlerService handlerService = PlatformUI.getWorkbench().getService(IHandlerService.class);
handlerService.executeCommand(FIND_REFERENCES_COMMAND, null);
}
} catch (Exception e) {
ILog.get().error("Error finding references for file: " + file.getName(), e);
}
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
/*******************************************************************************
* Copyright (c) 2026 Red Hat Inc. and others.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Angelo ZERR (Red Hat Inc.) - initial implementation
*******************************************************************************/
package org.eclipse.wildwebdeveloper.xml.internal.startup;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.MessageDialogWithToggle;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IStartup;
import org.eclipse.ui.PlatformUI;
import org.eclipse.wildwebdeveloper.xml.internal.Activator;
import org.eclipse.wildwebdeveloper.xml.internal.ui.Messages;
import org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.XMLPreferenceServerConstants;

/**
* Runs at Eclipse startup to detect grammar files in the workspace and prompt
* the user to enable the XML workspace index (like VSCode XML does).
*/
public class XMLWorkspaceIndexDetector implements IStartup {

public static final String PREF_WORKSPACE_INDEX_DETECTION_IGNORE = //
"org.eclipse.wildwebdeveloper.xml.workspaceIndex.detection.ignore";

private static final String[] GRAMMAR_EXTENSIONS = { "xsd", "dtd", "rng", "rnc" };
private static final String[] EXCLUDED_DIRS = { "node_modules", "target", "build", ".git", ".hg", ".svn", "out",
"dist", "bin", ".gradle" };

@Override
public void earlyStartup() {
IPreferenceStore store = Activator.getDefault().getPreferenceStore();
if (store.getBoolean(XMLPreferenceServerConstants.XML_PREFERENCES_WORKSPACE_INDEX_ENABLED.preferenceId)) {
return;
}
if (store.getBoolean(PREF_WORKSPACE_INDEX_DETECTION_IGNORE)) {
return;
}

Job job = new Job("Detecting XML grammar files") {
@Override
protected IStatus run(IProgressMonitor monitor) {
if (hasGrammarFiles()) {
Display.getDefault().asyncExec(() -> promptEnableWorkspaceIndex(store));
}
return Status.OK_STATUS;
}
};
job.setSystem(true);
job.schedule(3000);
}

private static boolean hasGrammarFiles() {
boolean[] found = { false };
try {
ResourcesPlugin.getWorkspace().getRoot().accept(resource -> {
if (found[0]) {
return false;
}
if (resource.getType() == IResource.FOLDER || resource.getType() == IResource.PROJECT) {
for (String excluded : EXCLUDED_DIRS) {
if (excluded.equals(resource.getName())) {
return false;
}
}
}
if (resource instanceof IFile file) {
String ext = file.getFileExtension();
if (ext != null) {
for (String grammarExt : GRAMMAR_EXTENSIONS) {
if (grammarExt.equals(ext)) {
found[0] = true;
return false;
}
}
}
}
return true;
});
} catch (CoreException e) {
// ignore
}
return found[0];
}

private static void promptEnableWorkspaceIndex(IPreferenceStore store) {
if (!PlatformUI.isWorkbenchRunning()) {
return;
}
var window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (window == null) {
return;
}
MessageDialogWithToggle dialog = MessageDialogWithToggle.openYesNoCancelQuestion(
window.getShell(),
Messages.XMLWorkspaceIndexDetector_promptTitle,
Messages.XMLWorkspaceIndexDetector_promptMessage,
Messages.XMLWorkspaceIndexDetector_promptToggle,
false,
store,
PREF_WORKSPACE_INDEX_DETECTION_IGNORE);
if (dialog.getReturnCode() == IDialogConstants.YES_ID) {
store.setValue(XMLPreferenceServerConstants.XML_PREFERENCES_WORKSPACE_INDEX_ENABLED.preferenceId, true);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,19 @@ public class Messages extends NLS {
public static String AssociateGrammarDialog_download_prompt_message;
public static String AssociateGrammarDialog_download_prompt_toggle;

// --------- XML Workspace Index preference page
public static String XMLWorkspaceIndexPreferencePage_description;
public static String XMLWorkspaceIndexPreferencePage_enabled;
public static String XMLWorkspaceIndexPreferencePage_excludeDirectories;
public static String XMLWorkspaceIndexPreferencePage_excludeDirectories_inputTitle;
public static String XMLWorkspaceIndexPreferencePage_excludeDirectories_inputMessage;
public static String XMLWorkspaceIndexPreferencePage_headLimits;

// --------- XML Workspace Index Detector
public static String XMLWorkspaceIndexDetector_promptTitle;
public static String XMLWorkspaceIndexDetector_promptMessage;
public static String XMLWorkspaceIndexDetector_promptToggle;

// --------- Buttons
public static String Add_button;
public static String Remove_button;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,19 @@ AssociateGrammarDialog_download_prompt_title=Enable download of external resourc
AssociateGrammarDialog_download_prompt_message=The preference "Download external resources like referenced DTD, XSD" is currently disabled.\n\nWithout it, LemMinX will not fetch the remote grammar and grammar-driven features (completion, validation, hover, code actions…) will be unavailable.\n\nDo you want to enable it now?
AssociateGrammarDialog_download_prompt_toggle=Don''t ask again

# XML Workspace Index preference page
XMLWorkspaceIndexPreferencePage_description=Configure the XML workspace index for cross-file references, code lens and grammar rename support.
XMLWorkspaceIndexPreferencePage_enabled=Enable &workspace index (cross-file references and grammar rename)
XMLWorkspaceIndexPreferencePage_excludeDirectories=&Exclude directories
XMLWorkspaceIndexPreferencePage_excludeDirectories_inputTitle=Exclude directory
XMLWorkspaceIndexPreferencePage_excludeDirectories_inputMessage=Enter directory name to exclude from workspace index:
XMLWorkspaceIndexPreferencePage_headLimits=Head &limits (JSON, e.g. {"**/*.xsd":"1MB"})

# XML Workspace Index Detector
XMLWorkspaceIndexDetector_promptTitle=Enable XML Workspace Index?
XMLWorkspaceIndexDetector_promptMessage=Grammar files (XSD, DTD, RelaxNG) were detected in the workspace.\n\nEnable the workspace index to get cross-file Find References, code lens reference counts, and automatic grammar rename support?
XMLWorkspaceIndexDetector_promptToggle=Don''t ask again

# Buttons
Add_button=\u2795 &Add...
Remove_button=\uD83D\uDDD1 &Remove
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@
import static org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.XMLPreferenceServerConstants.XML_PREFERENCES_VALIDATION_NO_GRAMMAR;
import static org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.XMLPreferenceServerConstants.XML_PREFERENCES_VALIDATION_RESOLVE_EXTERNAL_ENTITIES;
import static org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.XMLPreferenceServerConstants.XML_PREFERENCES_VALIDATION_SCHEMA_ENABLED;
import static org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.XMLPreferenceServerConstants.XML_PREFERENCES_WORKSPACE_INDEX_ENABLED;
import static org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.XMLPreferenceServerConstants.XML_PREFERENCES_WORKSPACE_INDEX_EXCLUDE_DIRECTORIES;
import static org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.XMLPreferenceServerConstants.XML_PREFERENCES_WORKSPACE_INDEX_HEAD_LIMITS;

import org.eclipse.wildwebdeveloper.xml.internal.startup.XMLWorkspaceIndexDetector;

import java.util.Arrays;
import java.util.List;
Expand Down Expand Up @@ -117,6 +122,13 @@ public void initializeDefaultPreferences() {
STORE.setDefault(XML_PREFERENCES_VALIDATION_DISALLOW_DOCTYPE_DECL.preferenceId, false);
STORE.setDefault(XML_PREFERENCES_VALIDATION_RESOLVE_EXTERNAL_ENTITIES.preferenceId, false);
STORE.setDefault(XML_PREFERENCES_VALIDATION_NO_GRAMMAR.preferenceId, "hint");

// Workspace Index settings
STORE.setDefault(XML_PREFERENCES_WORKSPACE_INDEX_ENABLED.preferenceId, false);
STORE.setDefault(XML_PREFERENCES_WORKSPACE_INDEX_EXCLUDE_DIRECTORIES.preferenceId,
".git,.hg,.svn,node_modules,target,build,.gradle,out,dist,bin");
STORE.setDefault(XML_PREFERENCES_WORKSPACE_INDEX_HEAD_LIMITS.preferenceId, "");
STORE.setDefault(XMLWorkspaceIndexDetector.PREF_WORKSPACE_INDEX_DETECTION_IGNORE, false);
}

}
Loading
Loading