Repository navigation
Add XML workspace index settings, preference page, grammar detector and Find References in explorer (requires LemMinx 0.40.0) #2307
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
Draft
angelozerr
wants to merge
1
commit into
eclipse-wildwebdeveloper:master
Choose a base branch
from
angelozerr:workspace_index_wwd
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
...rg/eclipse/wildwebdeveloper/xml/internal/commands/XMLFindReferencesInExplorerHandler.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } | ||
| } |
121 changes: 121 additions & 0 deletions
121
....xml/src/org/eclipse/wildwebdeveloper/xml/internal/startup/XMLWorkspaceIndexDetector.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.