From 49654fc8323832bbec593e34704c31c94ae5bfbe Mon Sep 17 00:00:00 2001 From: Kris De Volder Date: Mon, 17 Dec 2018 13:28:11 -0800 Subject: [PATCH] Enable codemining when STS4 codelenses enabled. --- .../plugin_customization.ini | 11 ----- .../boot/ls/BootLanguageServerPlugin.java | 2 +- .../ls/BootLanguageServerPreferencesPage.java | 42 +++++++++++++++++++ .../boot/ls/SpringBootLanguageServer.java | 2 +- 4 files changed, 44 insertions(+), 13 deletions(-) diff --git a/eclipse-distribution/org.springframework.boot.ide.branding/plugin_customization.ini b/eclipse-distribution/org.springframework.boot.ide.branding/plugin_customization.ini index ca124013d..2da68adcb 100644 --- a/eclipse-distribution/org.springframework.boot.ide.branding/plugin_customization.ini +++ b/eclipse-distribution/org.springframework.boot.ide.branding/plugin_customization.ini @@ -56,14 +56,3 @@ org.eclipse.oomph.setup.ui/enable.preference.recorder=false # Enable m2e APT. See: https://www.pivotaltracker.com/story/show/160300760 org.jboss.tools.maven.apt/org.jboss.tools.maven.apt.aptProcessDuringReconcile=true org.jboss.tools.maven.apt/org.jboss.tools.maven.apt.mode=jdt_apt - -# PT 162633928. JDT Code mining preference controls boot LS code lens preference. The -# following preferences are required in order to allow boot LS code lenses to appear -# in the editor IF the boot LS code lens preference is enabled -org.eclipse.jdt.ui/editor_codemining_enabled=true -org.eclipse.jdt.ui/java.codemining.references=false -org.eclipse.jdt.ui/java.codemining.references.onMethods=false -org.eclipse.jdt.ui/java.codemining.references.onFields=false -org.eclipse.jdt.ui/java.codemining.references.onTypes=false -org.eclipse.jdt.ui/java.codemining.implementations=false -org.eclipse.jdt.ui/java.codemining.atLeastOne=false diff --git a/eclipse-language-servers/org.springframework.tooling.boot.ls/src/org/springframework/tooling/boot/ls/BootLanguageServerPlugin.java b/eclipse-language-servers/org.springframework.tooling.boot.ls/src/org/springframework/tooling/boot/ls/BootLanguageServerPlugin.java index 04126eb3e..ee43da3de 100644 --- a/eclipse-language-servers/org.springframework.tooling.boot.ls/src/org/springframework/tooling/boot/ls/BootLanguageServerPlugin.java +++ b/eclipse-language-servers/org.springframework.tooling.boot.ls/src/org/springframework/tooling/boot/ls/BootLanguageServerPlugin.java @@ -45,8 +45,8 @@ public class BootLanguageServerPlugin extends AbstractUIPlugin { public void start(BundleContext context) throws Exception { plugin = this; super.start(context); - deactivateDuplicateKeybindings(); + BootLanguageServerPreferencesPage.manageCodeMiningPreferences(); } @Override diff --git a/eclipse-language-servers/org.springframework.tooling.boot.ls/src/org/springframework/tooling/boot/ls/BootLanguageServerPreferencesPage.java b/eclipse-language-servers/org.springframework.tooling.boot.ls/src/org/springframework/tooling/boot/ls/BootLanguageServerPreferencesPage.java index 94159272b..f8e383939 100644 --- a/eclipse-language-servers/org.springframework.tooling.boot.ls/src/org/springframework/tooling/boot/ls/BootLanguageServerPreferencesPage.java +++ b/eclipse-language-servers/org.springframework.tooling.boot.ls/src/org/springframework/tooling/boot/ls/BootLanguageServerPreferencesPage.java @@ -10,9 +10,13 @@ *******************************************************************************/ package org.springframework.tooling.boot.ls; +import org.eclipse.core.runtime.preferences.IEclipsePreferences; +import org.eclipse.core.runtime.preferences.InstanceScope; import org.eclipse.jface.preference.BooleanFieldEditor; import org.eclipse.jface.preference.FieldEditorPreferencePage; import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.util.IPropertyChangeListener; +import org.eclipse.jface.util.PropertyChangeEvent; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.widgets.Composite; @@ -33,6 +37,44 @@ public class BootLanguageServerPreferencesPage extends FieldEditorPreferencePage public BootLanguageServerPreferencesPage() { } + /** + * Starts a preference change listener that keeps code mining preferences in sync with + * whether or not STS4 codelenses are enabled. + */ + public static void manageCodeMiningPreferences() { + IPreferenceStore ourPrefs = LanguageServerCommonsActivator.getInstance().getPreferenceStore(); + synchronizeCodeMiningPrefs(ourPrefs); + ourPrefs.addPropertyChangeListener(new IPropertyChangeListener() { + + @Override + public void propertyChange(PropertyChangeEvent evt) { + if (evt.getProperty().equals(PreferenceConstants.HIGHLIGHT_CODELENS_PREFS)) { + synchronizeCodeMiningPrefs(ourPrefs); + } + } + }); + } + + private static void synchronizeCodeMiningPrefs(IPreferenceStore ourPrefs) { + boolean codeLensEnabled = ourPrefs.getBoolean(PreferenceConstants.HIGHLIGHT_CODELENS_PREFS); + if (codeLensEnabled) { + //Make sure jdt code mining is enabled. Codelenses do not work without it. + IEclipsePreferences jdtPrefs = InstanceScope.INSTANCE.getNode("org.eclipse.jdt.ui"); + boolean codeMiningIsEnabled = jdtPrefs.getBoolean("editor_codemining_enabled", false); + if (!codeMiningIsEnabled) { + jdtPrefs.putBoolean("editor_codemining_enabled", true); + //Disable all individual code minings. Since code mining wasn't enabled before... + //This merely serves to ensure they don't start showing up all of a sudden. + jdtPrefs.putBoolean("org.eclipse.jdt.ui/java.codemining.references", false); + jdtPrefs.putBoolean("org.eclipse.jdt.ui/java.codemining.references.onMethods", false); + jdtPrefs.putBoolean("org.eclipse.jdt.ui/java.codemining.references.onFields", false); + jdtPrefs.putBoolean("org.eclipse.jdt.ui/java.codemining.references.onTypes", false); + jdtPrefs.putBoolean("org.eclipse.jdt.ui/java.codemining.implementations", false); + jdtPrefs.putBoolean("org.eclipse.jdt.ui/java.codemining.atLeastOne", false); + } + } + } + @Override public void init(IWorkbench workbench) { setPreferenceStore(BootLanguageServerPlugin.getDefault().getPreferenceStore()); diff --git a/eclipse-language-servers/org.springframework.tooling.boot.ls/src/org/springframework/tooling/boot/ls/SpringBootLanguageServer.java b/eclipse-language-servers/org.springframework.tooling.boot.ls/src/org/springframework/tooling/boot/ls/SpringBootLanguageServer.java index eb0d4af57..79eaf3b9a 100644 --- a/eclipse-language-servers/org.springframework.tooling.boot.ls/src/org/springframework/tooling/boot/ls/SpringBootLanguageServer.java +++ b/eclipse-language-servers/org.springframework.tooling.boot.ls/src/org/springframework/tooling/boot/ls/SpringBootLanguageServer.java @@ -73,7 +73,7 @@ public class SpringBootLanguageServer extends STS4LanguageServerProcessStreamCon error = e; } } - if (!dataFile.exists()) { + if (bundleVersion.endsWith("qualifier")) { File userHome = new File(System.getProperty("user.home")); File locallyBuiltJar = new File( userHome,