diff --git a/org.eclipse.corrosion/src/org/eclipse/corrosion/CorrosionPreferenceInitializer.java b/org.eclipse.corrosion/src/org/eclipse/corrosion/CorrosionPreferenceInitializer.java index 3e18019..ab4caee 100644 --- a/org.eclipse.corrosion/src/org/eclipse/corrosion/CorrosionPreferenceInitializer.java +++ b/org.eclipse.corrosion/src/org/eclipse/corrosion/CorrosionPreferenceInitializer.java @@ -10,6 +10,7 @@ * Contributors: * Lucas Bullen (Red Hat Inc.) - Initial implementation * Holger Voormann - Set correct default locations on Windows (https://github.com/eclipse/corrosion/issues/86) + * Nicola Orru - Added support for external RLS startup configuration *******************************************************************************/ package org.eclipse.corrosion; @@ -22,6 +23,7 @@ public class CorrosionPreferenceInitializer extends AbstractPreferenceInitializer { private static final IPreferenceStore STORE = CorrosionPlugin.getDefault().getPreferenceStore(); + private static final String CARGO_DEFAULT_ROOT = System.getProperty("user.home") + "/.cargo/"; //$NON-NLS-1$ //$NON-NLS-2$ private static final String CARGO_DEFAULT_HOME = System.getProperty("user.home") + "/.cargo/bin/"; //$NON-NLS-1$ //$NON-NLS-2$ private static final boolean IS_WINDOWS = Platform.getOS().equals(Platform.OS_WIN32); @@ -34,6 +36,7 @@ public class CorrosionPreferenceInitializer extends AbstractPreferenceInitialize public static final String TOOLCHAIN_TYPE_PREFERENCE = "corrosion.rustup_toolchain_type"; //$NON-NLS-1$ public static final String RLS_PATH_PREFERENCE = "corrosion.rslPath"; //$NON-NLS-1$ + public static final String RLS_CONFIGURATION_PATH_PREFERENCE = "corrosion.rls_configurationPath"; //$NON-NLS-1$ public static final String SYSROOT_PATH_PREFERENCE = "corrosion.sysrootPath"; //$NON-NLS-1$ public static final String WORKING_DIRECTORY_PREFERENCE = "corrosion.workingDirectory"; //$NON-NLS-1$ @@ -48,6 +51,8 @@ public void initializeDefaultPreferences() { setToolchainBestGuesses(); STORE.setDefault(RLS_PATH_PREFERENCE, getRLSPathBestGuess()); + STORE.setDefault(RLS_CONFIGURATION_PATH_PREFERENCE, getRLSConfigurationPathBestGuess()); + STORE.setDefault(SYSROOT_PATH_PREFERENCE, getSysrootPathBestGuess()); STORE.setDefault(WORKING_DIRECTORY_PREFERENCE, getWorkingDirectoryBestGuess()); @@ -117,6 +122,10 @@ private static String getRLSPathBestGuess() { return command; } + private static String getRLSConfigurationPathBestGuess() { + return CARGO_DEFAULT_ROOT + "rls.conf"; //$NON-NLS-1$ + } + private static String getSysrootPathBestGuess() { File rustc = new File(findCommandPath("rustc")); //$NON-NLS-1$ if (!(rustc.exists() && rustc.isFile() && rustc.canExecute())) { diff --git a/org.eclipse.corrosion/src/org/eclipse/corrosion/CorrosionPreferencePage.java b/org.eclipse.corrosion/src/org/eclipse/corrosion/CorrosionPreferencePage.java index 001cde5..ed59bd5 100644 --- a/org.eclipse.corrosion/src/org/eclipse/corrosion/CorrosionPreferencePage.java +++ b/org.eclipse.corrosion/src/org/eclipse/corrosion/CorrosionPreferencePage.java @@ -9,6 +9,7 @@ * * Contributors: * Lucas Bullen (Red Hat Inc.) - Initial implementation + * Nicola Orru - Added support for external RLS startup configuration *******************************************************************************/ package org.eclipse.corrosion; @@ -126,6 +127,8 @@ private void initializeContent() { rlsInput.setValue(store.getString(CorrosionPreferenceInitializer.RLS_PATH_PREFERENCE)); sysrootInput.setValue(store.getString(CorrosionPreferenceInitializer.SYSROOT_PATH_PREFERENCE)); workingDirectoryInput.setValue(store.getString(CorrosionPreferenceInitializer.WORKING_DIRECTORY_PREFERENCE)); + rlsConfigurationPathInput + .setValue(store.getString(CorrosionPreferenceInitializer.RLS_CONFIGURATION_PATH_PREFERENCE)); } @Override @@ -316,6 +319,9 @@ public boolean performOk() { int source = getRadioSelection(); store.setValue(CorrosionPreferenceInitializer.RUST_SOURCE_PREFERENCE, RUST_SOURCE_OPTIONS.get(source)); store.setValue(CorrosionPreferenceInitializer.WORKING_DIRECTORY_PREFERENCE, workingDirectoryInput.getValue()); + store.setValue(CorrosionPreferenceInitializer.RLS_CONFIGURATION_PATH_PREFERENCE, + rlsConfigurationPathInput.getValue()); + if (source == 0) { store.setValue(CorrosionPreferenceInitializer.TOOLCHAIN_TYPE_PREFERENCE, rustupToolchainCombo.getText()); store.setValue(CorrosionPreferenceInitializer.DEFAULT_PATHS_PREFERENCE, @@ -397,6 +403,13 @@ private void createCommandPathsPart(Composite container) { workingDirectoryInput.setTextGridData(wdTextData); workingDirectoryInput.createVariableSelection(); workingDirectoryInput.createFolderSelection(); + + rlsConfigurationPathInput = new InputComponent(parent, Messages.CorrosionPreferencePage_rlsConfigurationPath, + e -> setValid(isPageValid())); + rlsConfigurationPathInput.createComponent(); + rlsConfigurationPathInput.createVariableSelection(); + rlsConfigurationPathInput.createFileSelection(); + rlsConfigurationPathInput.setTextGridData(wdTextData); } private boolean installInProgress = false; @@ -523,6 +536,7 @@ private void setRustupEnabled(boolean enabled) { } private InputComponent rlsInput; + private InputComponent rlsConfigurationPathInput; private InputComponent sysrootInput; private void createOtherPart(Composite container) { diff --git a/org.eclipse.corrosion/src/org/eclipse/corrosion/Messages.java b/org.eclipse.corrosion/src/org/eclipse/corrosion/Messages.java index 83f3f90..be56d5c 100644 --- a/org.eclipse.corrosion/src/org/eclipse/corrosion/Messages.java +++ b/org.eclipse.corrosion/src/org/eclipse/corrosion/Messages.java @@ -9,6 +9,7 @@ * * Contributors: * Mickael Istria (Red Hat Inc.) - Initial implementation + * Nicola Orru - Added support for external RLS startup configuration *******************************************************************************/ package org.eclipse.corrosion; @@ -57,6 +58,9 @@ public class Messages extends NLS { public static String RLSStreamConnectionProvider_OpenPreferences; public static String RLSStreamConnectionProvider_requirementsNotFound; public static String RLSStreamConnectionProvider_rlsNotFound; + public static String RLSStreamConnectionProvider_rlsConfigurationNotFound; + public static String RLSStreamConnectionProvider_rlsConfigurationNotSet; + public static String RLSStreamConnectionProvider_rlsConfigurationError; public static String RLSStreamConnectionProvider_rustSupportNotFound; public static String RLSStreamConnectionProvider_unableToSet; public static String RustDebugDelegate_unableToLaunch_title; @@ -124,6 +128,7 @@ public class Messages extends NLS { public static String CorrosionPreferencePage_rlsLocation; public static String CorrosionPreferencePage_rlsNonExecutable; public static String CorrosionPreferencePage_rlsPath; + public static String CorrosionPreferencePage_rlsConfigurationPath; public static String CorrosionPreferencePage_Rustup; public static String CorrosionPreferencePage_rustupNonExecutable; public static String CorrosionPreferencePage_rustupMissingRLS; diff --git a/org.eclipse.corrosion/src/org/eclipse/corrosion/RustManager.java b/org.eclipse.corrosion/src/org/eclipse/corrosion/RustManager.java index b231e93..3af630f 100644 --- a/org.eclipse.corrosion/src/org/eclipse/corrosion/RustManager.java +++ b/org.eclipse.corrosion/src/org/eclipse/corrosion/RustManager.java @@ -9,6 +9,7 @@ * * Contributors: * Lucas Bullen (Red Hat Inc.) - Initial implementation + * Nicola Orru - Added support for external RLS startup configuration *******************************************************************************/ package org.eclipse.corrosion; @@ -258,6 +259,19 @@ public static boolean setSystemProperties() { return false; } + public static String getRlsConfigurationPath() { + CorrosionPlugin plugin = CorrosionPlugin.getDefault(); + IPreferenceStore preferenceStore = plugin.getPreferenceStore(); + String preferencePath = preferenceStore + .getString(CorrosionPreferenceInitializer.RLS_CONFIGURATION_PATH_PREFERENCE); + if (preferencePath.isEmpty()) { + CorrosionPlugin.getDefault().getLog() + .log(new Status(IStatus.WARNING, CorrosionPlugin.getDefault().getBundle().getSymbolicName(), + Messages.RLSStreamConnectionProvider_rlsConfigurationNotSet)); + } + return preferencePath; + } + public static String getRLS() { CorrosionPlugin plugin = CorrosionPlugin.getDefault(); IPreferenceStore preferenceStore = plugin.getPreferenceStore(); diff --git a/org.eclipse.corrosion/src/org/eclipse/corrosion/edit/RLSStreamConnectionProvider.java b/org.eclipse.corrosion/src/org/eclipse/corrosion/edit/RLSStreamConnectionProvider.java index 3033a42..e8872da 100644 --- a/org.eclipse.corrosion/src/org/eclipse/corrosion/edit/RLSStreamConnectionProvider.java +++ b/org.eclipse.corrosion/src/org/eclipse/corrosion/edit/RLSStreamConnectionProvider.java @@ -12,10 +12,20 @@ *******************************************************************************/ package org.eclipse.corrosion.edit; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.net.URI; +import java.text.MessageFormat; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; import org.eclipse.corrosion.CorrosionPlugin; import org.eclipse.corrosion.CorrosionPreferencePage; import org.eclipse.corrosion.Messages; @@ -30,6 +40,9 @@ import org.eclipse.ui.PlatformUI; import org.eclipse.ui.dialogs.PreferencesUtil; +import com.google.gson.Gson; +import com.google.gson.stream.JsonReader; + public class RLSStreamConnectionProvider implements StreamConnectionProvider { private static boolean hasCancelledSetup = false; @@ -71,6 +84,34 @@ private static synchronized void setHasCancelledSetup(Boolean newValue) { hasCancelledSetup = newValue; } + private static Map getDefaultInitializationOptions() { + final Map initializationSettings = new HashMap<>(); + initializationSettings.put("clippy_preference", "on"); //$NON-NLS-1$//$NON-NLS-2$ + // undocumented, transitional. Will be superseded by "racer_completion" which + // defaults to "true" + initializationSettings.put("goto_def_racer_fallback", true); //$NON-NLS-1$ + return Collections.singletonMap("settings", Collections.singletonMap("rust", initializationSettings)); //$NON-NLS-1$ //$NON-NLS-2$ + } + + @Override + public Object getInitializationOptions(URI rootUri) { + final String settingsPath = RustManager.getRlsConfigurationPath(); + final File settingsFile = new File(settingsPath); + final Gson gson = new Gson(); + try (JsonReader reader = new JsonReader(new FileReader(settingsFile))) { + return gson.fromJson(reader, HashMap.class); + } catch (FileNotFoundException e) { + CorrosionPlugin.getDefault().getLog().log(new Status(IStatus.WARNING, + CorrosionPlugin.getDefault().getBundle().getSymbolicName(), + MessageFormat.format(Messages.RLSStreamConnectionProvider_rlsConfigurationNotFound, settingsPath))); + } catch (Throwable e) { + CorrosionPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, + CorrosionPlugin.getDefault().getBundle().getSymbolicName(), + MessageFormat.format(Messages.RLSStreamConnectionProvider_rlsConfigurationError, settingsPath, e))); + } + return getDefaultInitializationOptions(); + } + @Override public InputStream getInputStream() { return process == null ? null : process.getInputStream(); diff --git a/org.eclipse.corrosion/src/org/eclipse/corrosion/messages.properties b/org.eclipse.corrosion/src/org/eclipse/corrosion/messages.properties index 57c95bc..a409156 100644 --- a/org.eclipse.corrosion/src/org/eclipse/corrosion/messages.properties +++ b/org.eclipse.corrosion/src/org/eclipse/corrosion/messages.properties @@ -25,6 +25,9 @@ OptionSelector_optionDescription=Option Description: RLSStreamConnectionProvider_OpenPreferences=Open Preferences RLSStreamConnectionProvider_requirementsNotFound=Requirments for Rust edition were not found. Install the required components or input their paths in the Rust Preferences. RLSStreamConnectionProvider_rlsNotFound=Rust Language Server not found. Update in Rust preferences. +RLSStreamConnectionProvider_rlsConfigurationNotSet=RLS settings for Corrosion path not set. +RLSStreamConnectionProvider_rlsConfigurationNotFound=RLS settings for Corrosion path not found at {0}. +RLSStreamConnectionProvider_rlsConfigurationError=RLS settings at {0} could not be parsed: {1}. RLSStreamConnectionProvider_rustSupportNotFound=Rust Support Not Found RLSStreamConnectionProvider_unableToSet=Was unable to set the `SYS_ROOT` and `LD_LIBRARY_PATH` environment variables. Please do so manually. RustDebugDelegate_unableToLaunch_title=Unable to Launch @@ -114,6 +117,7 @@ CorrosionPreferencePage_otherInstallation=Other installation CorrosionPreferencePage_rlsLocation=Rust Language Server Location: CorrosionPreferencePage_rlsNonExecutable=Inputted `rls` command is not executable CorrosionPreferencePage_rlsPath=Path to the Rust Language Server (rls): +CorrosionPreferencePage_rlsConfigurationPath=Rls config: CorrosionPreferencePage_Rustup=Rustup: CorrosionPreferencePage_rustupNonExecutable=Inputted `rustup` command is not executable CorrosionPreferencePage_rustupMissingRLS=Install missing rls component in Rustup