PT 166528899 - Only show preferences for installed LS

This commit is contained in:
nsingh@pivotal.io
2019-06-17 05:51:10 -07:00
parent 49d655d66c
commit 539f0677cb
4 changed files with 50 additions and 13 deletions

View File

@@ -19,10 +19,10 @@ public class LanguageServerConsolePreferenceConstants {
public static final String PREF_CLOUDFOUNDRY_CONSOLE_ENABLED = "cloudfoundry.console.enabled";
public static final String PREF_BOSH_CONSOLE_ENABLED = "bosh.console.enabled";
public static final ServerInfo SPRING_BOOT_SERVER = new ServerInfo(PREF_BOOT_JAVA_CONSOLE_ENABLED, "Spring Boot");
public static final ServerInfo CLOUDFOUNDRY_SERVER = new ServerInfo(PREF_CLOUDFOUNDRY_CONSOLE_ENABLED, "Cloudfoundry");
public static final ServerInfo CONCOURSE_SERVER = new ServerInfo(PREF_CONCOURSE_CONSOLE_ENABLED, "Concourse");
public static final ServerInfo BOSH_SERVER = new ServerInfo(PREF_BOSH_CONSOLE_ENABLED, "Bosh");
public static final ServerInfo SPRING_BOOT_SERVER = new ServerInfo(PREF_BOOT_JAVA_CONSOLE_ENABLED, "Spring Boot", "org.springframework.tooling.boot.ls");
public static final ServerInfo CLOUDFOUNDRY_SERVER = new ServerInfo(PREF_CLOUDFOUNDRY_CONSOLE_ENABLED, "Cloudfoundry", "org.springframework.tooling.cloudfoundry.manifest.ls");
public static final ServerInfo CONCOURSE_SERVER = new ServerInfo(PREF_CONCOURSE_CONSOLE_ENABLED, "Concourse", "org.springframework.tooling.concourse.ls");
public static final ServerInfo BOSH_SERVER = new ServerInfo(PREF_BOSH_CONSOLE_ENABLED, "Bosh", "org.springframework.tooling.bosh.ls");
public static final ServerInfo[] ALL_SERVERS = {
SPRING_BOOT_SERVER,
@@ -34,14 +34,16 @@ public class LanguageServerConsolePreferenceConstants {
public static class ServerInfo {
public final String preferenceKey;
public final String label;
public ServerInfo(String preferenceKey, String label) {
public final String bundleId;
public ServerInfo(String preferenceKey, String label, String bundleId) {
super();
this.preferenceKey = preferenceKey;
this.label = label;
this.bundleId = bundleId;
}
@Override
public String toString() {
return "ServerInfo [preferenceKey=" + preferenceKey + ", label=" + label + "]";
return "ServerInfo [preferenceKey=" + preferenceKey + ", label=" + label + ", bundleId=" + bundleId + "]";
}
}
}

View File

@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2018 Pivotal, Inc.
* Copyright (c) 2018, 2019 Pivotal, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -10,8 +10,6 @@
*******************************************************************************/
package org.springframework.tooling.ls.eclipse.commons.preferences;
import static org.springframework.tooling.ls.eclipse.commons.preferences.LanguageServerConsolePreferenceConstants.ALL_SERVERS;
import org.eclipse.jface.preference.BooleanFieldEditor;
import org.eclipse.jface.preference.FieldEditorPreferencePage;
import org.eclipse.jface.preference.IPreferenceStore;
@@ -37,7 +35,8 @@ public class LanguageServerPreferencesPage extends FieldEditorPreferencePage imp
@Override
protected void createFieldEditors() {
Composite parent = getFieldEditorParent();
for (ServerInfo s : ALL_SERVERS) {
ServerInfo[] installedServers = LsPreferencesUtil.getInstalledLs();
for (ServerInfo s : installedServers) {
addField(new BooleanFieldEditor(s.preferenceKey, s.label, parent));
}
}

View File

@@ -0,0 +1,36 @@
/*******************************************************************************
* Copyright (c) 2019 Pivotal, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Pivotal, Inc. - initial API and implementation
*******************************************************************************/
package org.springframework.tooling.ls.eclipse.commons.preferences;
import static org.springframework.tooling.ls.eclipse.commons.preferences.LanguageServerConsolePreferenceConstants.ALL_SERVERS;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.core.runtime.Platform;
import org.osgi.framework.Bundle;
import org.springframework.tooling.ls.eclipse.commons.preferences.LanguageServerConsolePreferenceConstants.ServerInfo;
public class LsPreferencesUtil {
public static ServerInfo[] getInstalledLs() {
List<ServerInfo> serverInfos = new ArrayList<>();
for (ServerInfo info : ALL_SERVERS) {
Bundle bundle = Platform.getBundle(info.bundleId);
if (bundle != null) {
serverInfos.add(info);
}
}
return serverInfos.toArray(new ServerInfo[serverInfos.size()]);
}
}

View File

@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2018 Pivotal, Inc.
* Copyright (c) 2018, 2019 Pivotal, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -10,7 +10,6 @@
*******************************************************************************/
package org.springframework.tooling.ls.eclipse.commons.preferences;
import static org.springframework.tooling.ls.eclipse.commons.preferences.LanguageServerConsolePreferenceConstants.ALL_SERVERS;
import static org.springframework.tooling.ls.eclipse.commons.preferences.LanguageServerConsolePreferenceConstants.ENABLE_BY_DEFAULT;
import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
@@ -21,7 +20,8 @@ public class PrefsInitializer extends AbstractPreferenceInitializer {
@Override
public void initializeDefaultPreferences() {
IPreferenceStore store = LanguageServerPreferencesPage.getPrefsStoreFromPlugin();
for (ServerInfo s : ALL_SERVERS) {
ServerInfo[] installedServers = LsPreferencesUtil.getInstalledLs();
for (ServerInfo s : installedServers) {
store.setDefault(s.preferenceKey, ENABLE_BY_DEFAULT);
}
store.setDefault(PreferenceConstants.HIGHLIGHT_CODELENS_PREFS, false);