From 8f87122e4cdab99209d3f0b7cf54e5a104fe8b8e Mon Sep 17 00:00:00 2001 From: Gesa HENTSCHKE Date: Fri, 8 Sep 2023 17:05:43 +0200 Subject: [PATCH] Refactor clangd preferences - separated editor from clangd preferences (needed for #178) --- .../META-INF/MANIFEST.MF | 3 +- .../OSGI-INF/l10n/bundle.properties | 1 + ...ernal.clangd.ClangdConfigurationAccess.xml | 1 - ...r.DefaultClangdConfigurationVisibility.xml | 8 - bundles/org.eclipse.cdt.lsp.clangd/plugin.xml | 15 +- .../clangd/BuiltinClangdOptionsDefaults.java | 4 - .../cdt/lsp/clangd/ClangdMetadata.java | 9 - .../eclipse/cdt/lsp/clangd/ClangdOptions.java | 7 - .../clangd/ClangdConfigurationAccess.java | 33 +-- .../clangd/ClangdLanguageServerProvider.java | 8 +- .../clangd/ClangdMetadataDefaults.java | 9 - .../clangd/ClangdPreferenceInitializer.java | 1 - .../clangd/ClangdPreferredOptions.java | 21 +- .../editor/ClangdConfigurationArea.java | 31 +-- .../editor/ClangdConfigurationPage.java | 6 +- .../DefaultClangdConfigurationVisibility.java | 26 -- .../clangd/editor/LspEditorUiMessages.java | 4 +- .../editor/LspEditorUiMessages.properties | 2 - .../org.eclipse.cdt.lsp/META-INF/MANIFEST.MF | 7 +- .../OSGI-INF/l10n/bundle.properties | 3 + ...lsp.editor.BuiltinEditorOptionsDefault.xml | 7 + ....editor.DefaultConfigurationVisibility.xml | 8 + ...t.lsp.editor.EditorConfigurationAccess.xml | 10 + ....cdt.lsp.editor.EditorMetadataDefaults.xml | 8 + bundles/org.eclipse.cdt.lsp/plugin.xml | 49 ++++ .../src/org/eclipse/cdt/lsp/LspQualifier.java | 25 ++ .../org/eclipse/cdt/lsp/PreferredOptions.java | 47 ++++ .../org/eclipse/cdt/lsp}/ResolveProject.java | 3 +- .../editor/BuiltinEditorOptionsDefault.java | 25 +- .../cdt/lsp/editor/ConfigurationAccess.java | 43 +++ .../cdt/lsp/editor/ConfigurationArea.java | 74 +++++ .../lsp/editor/ConfigurationVisibility.java} | 8 +- .../DefaultConfigurationVisibility.java | 13 + .../cdt/lsp/editor/EditorConfiguration.java | 57 ++++ .../lsp/editor/EditorConfigurationAccess.java | 81 ++++++ .../lsp/editor/EditorConfigurationArea.java | 59 ++++ .../cdt/lsp/editor/EditorMetadata.java | 54 ++++ .../lsp/editor/EditorMetadataDefaults.java | 62 +++++ .../eclipse/cdt/lsp/editor/EditorOptions.java | 45 ++++ .../cdt/lsp/editor/EditorOptionsDefaults.java | 17 ++ .../editor/EditorPreferenceInitializer.java | 39 +++ .../lsp/editor/EditorPreferredOptions.java | 60 +++++ .../cdt/lsp/editor/EditorPropertyPage.java | 255 ++++++++++++++++++ .../eclipse/cdt/lsp/editor/FormatOnSave.java | 67 +++-- .../cdt/lsp/editor/LanguageServerEnable.java} | 13 +- .../cdt/lsp/editor}/ResolveProjectScope.java | 3 +- .../editor/SaveActionsConfigurationArea.java | 74 +++++ .../lsp/editor/SaveActionsPropertyPage.java | 18 ++ .../lsp/internal/messages/LspUiMessages.java | 11 + .../messages/LspUiMessages.properties | 14 + .../META-INF/MANIFEST.MF | 7 +- ...sp.examples.preferences.HidePreferLsp.xml} | 8 +- ...sp.examples.preferences.MyClangdEnable.xml | 5 +- .../examples/preferences/HidePreferLsp.java | 14 + .../examples/preferences/MyClangdEnable.java | 6 +- .../preferences/MyClangdOptionsDefaults.java | 5 - .../cdt/lsp/clangd/tests/TestUtils.java | 10 +- 57 files changed, 1280 insertions(+), 223 deletions(-) delete mode 100644 bundles/org.eclipse.cdt.lsp.clangd/OSGI-INF/org.eclipse.cdt.lsp.internal.clangd.editor.DefaultClangdConfigurationVisibility.xml delete mode 100644 bundles/org.eclipse.cdt.lsp.clangd/src/org/eclipse/cdt/lsp/internal/clangd/editor/DefaultClangdConfigurationVisibility.java create mode 100644 bundles/org.eclipse.cdt.lsp/OSGI-INF/org.eclipse.cdt.lsp.editor.BuiltinEditorOptionsDefault.xml create mode 100644 bundles/org.eclipse.cdt.lsp/OSGI-INF/org.eclipse.cdt.lsp.editor.DefaultConfigurationVisibility.xml create mode 100644 bundles/org.eclipse.cdt.lsp/OSGI-INF/org.eclipse.cdt.lsp.editor.EditorConfigurationAccess.xml create mode 100644 bundles/org.eclipse.cdt.lsp/OSGI-INF/org.eclipse.cdt.lsp.editor.EditorMetadataDefaults.xml create mode 100644 bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/LspQualifier.java create mode 100644 bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/PreferredOptions.java rename bundles/{org.eclipse.cdt.lsp.clangd/src/org/eclipse/cdt/lsp/internal/clangd => org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp}/ResolveProject.java (94%) rename examples/org.eclipse.cdt.lsp.examples.preferences/src/org/eclipse/cdt/lsp/examples/preferences/HidePreferClangd.java => bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/editor/BuiltinEditorOptionsDefault.java (61%) create mode 100644 bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/editor/ConfigurationAccess.java create mode 100644 bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/editor/ConfigurationArea.java rename bundles/{org.eclipse.cdt.lsp.clangd/src/org/eclipse/cdt/lsp/clangd/ClangdConfigurationVisibility.java => org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/editor/ConfigurationVisibility.java} (77%) create mode 100644 bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/editor/DefaultConfigurationVisibility.java create mode 100644 bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/editor/EditorConfiguration.java create mode 100644 bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/editor/EditorConfigurationAccess.java create mode 100644 bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/editor/EditorConfigurationArea.java create mode 100644 bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/editor/EditorMetadata.java create mode 100644 bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/editor/EditorMetadataDefaults.java create mode 100644 bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/editor/EditorOptions.java create mode 100644 bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/editor/EditorOptionsDefaults.java create mode 100644 bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/editor/EditorPreferenceInitializer.java create mode 100644 bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/editor/EditorPreferredOptions.java create mode 100644 bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/editor/EditorPropertyPage.java rename bundles/{org.eclipse.cdt.lsp.clangd/src/org/eclipse/cdt/lsp/clangd/ClangdEnable.java => org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/editor/LanguageServerEnable.java} (63%) rename bundles/{org.eclipse.cdt.lsp.clangd/src/org/eclipse/cdt/lsp/internal/clangd => org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/editor}/ResolveProjectScope.java (93%) create mode 100644 bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/editor/SaveActionsConfigurationArea.java create mode 100644 bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/editor/SaveActionsPropertyPage.java rename examples/org.eclipse.cdt.lsp.examples.preferences/OSGI-INF/{org.eclipse.cdt.lsp.examples.preferences.HidePreferClangd.xml => org.eclipse.cdt.lsp.examples.preferences.HidePreferLsp.xml} (57%) create mode 100644 examples/org.eclipse.cdt.lsp.examples.preferences/src/org/eclipse/cdt/lsp/examples/preferences/HidePreferLsp.java diff --git a/bundles/org.eclipse.cdt.lsp.clangd/META-INF/MANIFEST.MF b/bundles/org.eclipse.cdt.lsp.clangd/META-INF/MANIFEST.MF index e93dcaeb..04dc92f4 100644 --- a/bundles/org.eclipse.cdt.lsp.clangd/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.cdt.lsp.clangd/META-INF/MANIFEST.MF @@ -34,5 +34,4 @@ Bundle-Activator: org.eclipse.cdt.lsp.internal.clangd.editor.ClangdPlugin Service-Component: OSGI-INF/org.eclipse.cdt.lsp.clangd.BuiltinClangdOptionsDefaults.xml, OSGI-INF/org.eclipse.cdt.lsp.internal.clangd.ClangdConfigurationAccess.xml, OSGI-INF/org.eclipse.cdt.lsp.internal.clangd.ClangdFallbackManager.xml, - OSGI-INF/org.eclipse.cdt.lsp.internal.clangd.ClangdMetadataDefaults.xml, - OSGI-INF/org.eclipse.cdt.lsp.internal.clangd.editor.DefaultClangdConfigurationVisibility.xml + OSGI-INF/org.eclipse.cdt.lsp.internal.clangd.ClangdMetadataDefaults.xml diff --git a/bundles/org.eclipse.cdt.lsp.clangd/OSGI-INF/l10n/bundle.properties b/bundles/org.eclipse.cdt.lsp.clangd/OSGI-INF/l10n/bundle.properties index ad5eb63e..678f0106 100644 --- a/bundles/org.eclipse.cdt.lsp.clangd/OSGI-INF/l10n/bundle.properties +++ b/bundles/org.eclipse.cdt.lsp.clangd/OSGI-INF/l10n/bundle.properties @@ -25,3 +25,4 @@ SPDX-License-Identifier: EPL-2.0\n\ Commands.ToggleSourceAndHeader.name=Toggle Source/Header PopupMenu.ToggleSourceAndHeader.label=Toggle Source/Header +ClangdConfigurationPage.name=clangd diff --git a/bundles/org.eclipse.cdt.lsp.clangd/OSGI-INF/org.eclipse.cdt.lsp.internal.clangd.ClangdConfigurationAccess.xml b/bundles/org.eclipse.cdt.lsp.clangd/OSGI-INF/org.eclipse.cdt.lsp.internal.clangd.ClangdConfigurationAccess.xml index 26aa0b27..82ffd03b 100644 --- a/bundles/org.eclipse.cdt.lsp.clangd/OSGI-INF/org.eclipse.cdt.lsp.internal.clangd.ClangdConfigurationAccess.xml +++ b/bundles/org.eclipse.cdt.lsp.clangd/OSGI-INF/org.eclipse.cdt.lsp.internal.clangd.ClangdConfigurationAccess.xml @@ -3,7 +3,6 @@ - diff --git a/bundles/org.eclipse.cdt.lsp.clangd/OSGI-INF/org.eclipse.cdt.lsp.internal.clangd.editor.DefaultClangdConfigurationVisibility.xml b/bundles/org.eclipse.cdt.lsp.clangd/OSGI-INF/org.eclipse.cdt.lsp.internal.clangd.editor.DefaultClangdConfigurationVisibility.xml deleted file mode 100644 index 1cd72145..00000000 --- a/bundles/org.eclipse.cdt.lsp.clangd/OSGI-INF/org.eclipse.cdt.lsp.internal.clangd.editor.DefaultClangdConfigurationVisibility.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/bundles/org.eclipse.cdt.lsp.clangd/plugin.xml b/bundles/org.eclipse.cdt.lsp.clangd/plugin.xml index d5e57c65..85e8603c 100644 --- a/bundles/org.eclipse.cdt.lsp.clangd/plugin.xml +++ b/bundles/org.eclipse.cdt.lsp.clangd/plugin.xml @@ -22,20 +22,19 @@ + id="org.eclipse.cdt.lsp.clangd.editor.preferencePage" + name="%ClangdConfigurationPage.name"> - + id="org.eclipse.cdt.lsp.clangd.editor.propertyPage" + name="%ClangdConfigurationPage.name"> @@ -49,8 +48,6 @@ - - null. - * - * @return the metadata for the "Prefer clangd" option - * - * @see ClangdOptions#preferClangd() - */ - PreferenceMetadata preferClangd(); - /** * Returns the metadata for the "Clangd path" option, must not return null. * diff --git a/bundles/org.eclipse.cdt.lsp.clangd/src/org/eclipse/cdt/lsp/clangd/ClangdOptions.java b/bundles/org.eclipse.cdt.lsp.clangd/src/org/eclipse/cdt/lsp/clangd/ClangdOptions.java index fbf63464..d8d452f5 100644 --- a/bundles/org.eclipse.cdt.lsp.clangd/src/org/eclipse/cdt/lsp/clangd/ClangdOptions.java +++ b/bundles/org.eclipse.cdt.lsp.clangd/src/org/eclipse/cdt/lsp/clangd/ClangdOptions.java @@ -21,13 +21,6 @@ */ public interface ClangdOptions { - /** - * Prefer to use clangd language server and related editor implementation - * - * @return if clangd language server should be preferred - */ - boolean preferClangd(); - /** * Path to clangd executable to be launched, must not return null * diff --git a/bundles/org.eclipse.cdt.lsp.clangd/src/org/eclipse/cdt/lsp/internal/clangd/ClangdConfigurationAccess.java b/bundles/org.eclipse.cdt.lsp.clangd/src/org/eclipse/cdt/lsp/internal/clangd/ClangdConfigurationAccess.java index 52eb83d9..3fd44255 100644 --- a/bundles/org.eclipse.cdt.lsp.clangd/src/org/eclipse/cdt/lsp/internal/clangd/ClangdConfigurationAccess.java +++ b/bundles/org.eclipse.cdt.lsp.clangd/src/org/eclipse/cdt/lsp/internal/clangd/ClangdConfigurationAccess.java @@ -18,14 +18,13 @@ import java.util.Optional; import org.eclipse.cdt.lsp.clangd.ClangdConfiguration; -import org.eclipse.cdt.lsp.clangd.ClangdEnable; import org.eclipse.cdt.lsp.clangd.ClangdMetadata; import org.eclipse.cdt.lsp.clangd.ClangdOptions; import org.eclipse.cdt.lsp.clangd.ClangdQualifier; +import org.eclipse.cdt.lsp.editor.ConfigurationAccess; import org.eclipse.core.resources.IWorkspace; import org.eclipse.core.resources.ProjectScope; import org.eclipse.core.runtime.preferences.DefaultScope; -import org.eclipse.core.runtime.preferences.IEclipsePreferences; import org.eclipse.core.runtime.preferences.IPreferenceMetadataStore; import org.eclipse.core.runtime.preferences.IScopeContext; import org.eclipse.core.runtime.preferences.InstanceScope; @@ -33,11 +32,9 @@ import org.eclipse.osgi.util.NLS; import org.osgi.service.component.annotations.Component; import org.osgi.service.component.annotations.Reference; -import org.osgi.service.component.annotations.ReferenceCardinality; @Component -public final class ClangdConfigurationAccess implements ClangdConfiguration { - private final String qualifier; +public final class ClangdConfigurationAccess extends ConfigurationAccess implements ClangdConfiguration { @Reference private ClangdMetadata metadata; @@ -45,11 +42,8 @@ public final class ClangdConfigurationAccess implements ClangdConfiguration { @Reference private IWorkspace workspace; - @Reference(cardinality = ReferenceCardinality.OPTIONAL) - private ClangdEnable enable; - public ClangdConfigurationAccess() { - this.qualifier = new ClangdQualifier().get(); + super(new ClangdQualifier().get()); } @Override @@ -59,26 +53,26 @@ public ClangdMetadata metadata() { @Override public ClangdOptions defaults() { - return new ClangdPreferredOptions(qualifier, new IScopeContext[] { DefaultScope.INSTANCE }, metadata, enable); + return new ClangdPreferredOptions(qualifier, new IScopeContext[] { DefaultScope.INSTANCE }, metadata); } @Override public ClangdOptions options(Object context) { - Optional project = projectScope(context); + Optional project = projectScope(workspace, context); IScopeContext[] scopes; if (project.isPresent()) { scopes = new IScopeContext[] { project.get(), InstanceScope.INSTANCE, DefaultScope.INSTANCE }; } else { scopes = new IScopeContext[] { InstanceScope.INSTANCE, DefaultScope.INSTANCE }; } - return new ClangdPreferredOptions(qualifier, scopes, metadata, enable); + return new ClangdPreferredOptions(qualifier, scopes, metadata); } @Override public IPreferenceMetadataStore storage(Object context) { return new OsgiPreferenceMetadataStore(// preferences(// - projectScope(context)// + projectScope(workspace, context)// .map(IScopeContext.class::cast)// .orElse(InstanceScope.INSTANCE))); } @@ -113,17 +107,4 @@ public List commands(Object context) { return list; } - private Optional projectScope(Object context) { - return new ResolveProjectScope(workspace).apply(context); - } - - private IEclipsePreferences preferences(IScopeContext scope) { - return Optional.ofNullable(scope.getNode(qualifier))// - .filter(IEclipsePreferences.class::isInstance)// - .map(IEclipsePreferences.class::cast)// - .orElseThrow(() -> new IllegalStateException(// - NLS.bind("Unable to get preferences for node: {0}", // - qualifier))); - } - } diff --git a/bundles/org.eclipse.cdt.lsp.clangd/src/org/eclipse/cdt/lsp/internal/clangd/ClangdLanguageServerProvider.java b/bundles/org.eclipse.cdt.lsp.clangd/src/org/eclipse/cdt/lsp/internal/clangd/ClangdLanguageServerProvider.java index c725cb8d..6050f6b0 100644 --- a/bundles/org.eclipse.cdt.lsp.clangd/src/org/eclipse/cdt/lsp/internal/clangd/ClangdLanguageServerProvider.java +++ b/bundles/org.eclipse.cdt.lsp.clangd/src/org/eclipse/cdt/lsp/internal/clangd/ClangdLanguageServerProvider.java @@ -21,8 +21,9 @@ import java.util.Objects; import org.eclipse.cdt.lsp.clangd.ClangdConfiguration; -import org.eclipse.cdt.lsp.clangd.ClangdEnable; import org.eclipse.cdt.lsp.clangd.ClangdFallbackFlags; +import org.eclipse.cdt.lsp.editor.EditorConfiguration; +import org.eclipse.cdt.lsp.editor.LanguageServerEnable; import org.eclipse.cdt.lsp.server.ICLanguageServerProvider; import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.ServiceCaller; @@ -32,6 +33,9 @@ public final class ClangdLanguageServerProvider implements ICLanguageServerProvi private final ServiceCaller configuration = new ServiceCaller<>(getClass(), ClangdConfiguration.class); + private final ServiceCaller editorConfiguration = new ServiceCaller<>(getClass(), + EditorConfiguration.class); + @Override public Object getInitializationOptions(URI rootUri) { List result = new ArrayList<>(); @@ -50,7 +54,7 @@ public List getCommands(URI rootUri) { @Override public boolean isEnabledFor(IProject project) { boolean[] enabled = new boolean[1]; - configuration.call(c -> enabled[0] = ((ClangdEnable) c.options(project)).isEnabledFor(project)); + editorConfiguration.call(c -> enabled[0] = ((LanguageServerEnable) c.options(project)).isEnabledFor(project)); return enabled[0]; } diff --git a/bundles/org.eclipse.cdt.lsp.clangd/src/org/eclipse/cdt/lsp/internal/clangd/ClangdMetadataDefaults.java b/bundles/org.eclipse.cdt.lsp.clangd/src/org/eclipse/cdt/lsp/internal/clangd/ClangdMetadataDefaults.java index 3fc26991..bf90c42d 100644 --- a/bundles/org.eclipse.cdt.lsp.clangd/src/org/eclipse/cdt/lsp/internal/clangd/ClangdMetadataDefaults.java +++ b/bundles/org.eclipse.cdt.lsp.clangd/src/org/eclipse/cdt/lsp/internal/clangd/ClangdMetadataDefaults.java @@ -28,15 +28,6 @@ public final class ClangdMetadataDefaults implements ClangdMetadata { @Reference private ClangdOptionsDefaults defaults; - @Override - public PreferenceMetadata preferClangd() { - return new PreferenceMetadata<>(Boolean.class, // - "prefer_clangd", //$NON-NLS-1$ - defaults.preferClangd(), // - LspEditorUiMessages.LspEditorPreferencePage_preferLspEditor, - LspEditorUiMessages.LspEditorPreferencePage_preferLspEditor_description); - } - @Override public PreferenceMetadata clangdPath() { return new PreferenceMetadata<>(String.class, // diff --git a/bundles/org.eclipse.cdt.lsp.clangd/src/org/eclipse/cdt/lsp/internal/clangd/ClangdPreferenceInitializer.java b/bundles/org.eclipse.cdt.lsp.clangd/src/org/eclipse/cdt/lsp/internal/clangd/ClangdPreferenceInitializer.java index 3f35ce7c..e22ee104 100644 --- a/bundles/org.eclipse.cdt.lsp.clangd/src/org/eclipse/cdt/lsp/internal/clangd/ClangdPreferenceInitializer.java +++ b/bundles/org.eclipse.cdt.lsp.clangd/src/org/eclipse/cdt/lsp/internal/clangd/ClangdPreferenceInitializer.java @@ -30,7 +30,6 @@ public void initializeDefaultPreferences() { private void initializeDefaults(ClangdConfiguration configuration) { ClangdMetadata metadata = configuration.metadata(); String qualifier = configuration.qualifier(); - initializeBoolean(metadata.preferClangd(), qualifier); initializeString(metadata.clangdPath(), qualifier); initializeBoolean(metadata.useTidy(), qualifier); initializeBoolean(metadata.useBackgroundIndex(), qualifier); diff --git a/bundles/org.eclipse.cdt.lsp.clangd/src/org/eclipse/cdt/lsp/internal/clangd/ClangdPreferredOptions.java b/bundles/org.eclipse.cdt.lsp.clangd/src/org/eclipse/cdt/lsp/internal/clangd/ClangdPreferredOptions.java index f9719847..c18e9df9 100644 --- a/bundles/org.eclipse.cdt.lsp.clangd/src/org/eclipse/cdt/lsp/internal/clangd/ClangdPreferredOptions.java +++ b/bundles/org.eclipse.cdt.lsp.clangd/src/org/eclipse/cdt/lsp/internal/clangd/ClangdPreferredOptions.java @@ -19,30 +19,21 @@ import java.util.Objects; import java.util.Optional; -import org.eclipse.cdt.lsp.clangd.ClangdEnable; import org.eclipse.cdt.lsp.clangd.ClangdMetadata; import org.eclipse.cdt.lsp.clangd.ClangdOptions; -import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.preferences.IScopeContext; import org.eclipse.core.runtime.preferences.PreferenceMetadata; -final class ClangdPreferredOptions implements ClangdOptions, ClangdEnable { +final class ClangdPreferredOptions implements ClangdOptions { private final String qualifier; private final IScopeContext[] scopes; private final ClangdMetadata metadata; - private final ClangdEnable enable; - ClangdPreferredOptions(String qualifier, IScopeContext[] scopes, ClangdMetadata metadata, ClangdEnable enable) { + ClangdPreferredOptions(String qualifier, IScopeContext[] scopes, ClangdMetadata metadata) { this.qualifier = Objects.requireNonNull(qualifier); this.scopes = Objects.requireNonNull(scopes); this.metadata = Objects.requireNonNull(metadata); - this.enable = enable; - } - - @Override - public boolean preferClangd() { - return booleanValue(metadata.preferClangd()); } @Override @@ -101,12 +92,4 @@ private boolean booleanValue(PreferenceMetadata meta) { .orElseGet(meta::defaultValue); } - @Override - public boolean isEnabledFor(IProject project) { - if (enable != null) { - return enable.isEnabledFor(project); - } - return booleanValue(metadata.preferClangd()); - } - } diff --git a/bundles/org.eclipse.cdt.lsp.clangd/src/org/eclipse/cdt/lsp/internal/clangd/editor/ClangdConfigurationArea.java b/bundles/org.eclipse.cdt.lsp.clangd/src/org/eclipse/cdt/lsp/internal/clangd/editor/ClangdConfigurationArea.java index 07fe835e..72bd0afe 100644 --- a/bundles/org.eclipse.cdt.lsp.clangd/src/org/eclipse/cdt/lsp/internal/clangd/editor/ClangdConfigurationArea.java +++ b/bundles/org.eclipse.cdt.lsp.clangd/src/org/eclipse/cdt/lsp/internal/clangd/editor/ClangdConfigurationArea.java @@ -21,7 +21,6 @@ import java.util.function.Consumer; import java.util.stream.Collectors; -import org.eclipse.cdt.lsp.clangd.ClangdConfigurationVisibility; import org.eclipse.cdt.lsp.clangd.ClangdMetadata; import org.eclipse.cdt.lsp.clangd.ClangdOptions; import org.eclipse.core.runtime.preferences.IEclipsePreferences; @@ -32,7 +31,6 @@ import org.eclipse.jface.layout.GridLayoutFactory; import org.eclipse.swt.SWT; import org.eclipse.swt.events.KeyListener; -import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.events.TypedEvent; @@ -46,12 +44,10 @@ import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Text; -import org.eclipse.ui.PlatformUI; public final class ClangdConfigurationArea { private final int columns = 3; - private final Button prefer; private final Text path; private final Button tidy; private final Combo completion; @@ -61,7 +57,6 @@ public final class ClangdConfigurationArea { private final Text additional; private final Group group; private ControlEnableState enableState; - private ClangdConfigurationVisibility visibility; private final Map, Button> buttons; private final Map, Text> texts; @@ -75,7 +70,6 @@ public final class ClangdConfigurationArea { private final Map completions; public ClangdConfigurationArea(Composite parent, ClangdMetadata metadata, boolean isProjectScope) { - this.visibility = PlatformUI.getWorkbench().getService(ClangdConfigurationVisibility.class); this.buttons = new HashMap<>(); this.texts = new HashMap<>(); this.combos = new HashMap<>(); @@ -87,19 +81,6 @@ public ClangdConfigurationArea(Composite parent, ClangdMetadata metadata, boolea Composite composite = new Composite(parent, SWT.NONE); composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); composite.setLayout(GridLayoutFactory.fillDefaults().numColumns(columns).create()); - if (visibility.showPreferClangd(isProjectScope)) { - final SelectionAdapter listener = new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - enableClangdOptionsGroup(prefer.getSelection()); - } - }; - - this.prefer = createCheckbox(metadata.preferClangd(), composite); - this.prefer.addSelectionListener(listener); - } else { - this.prefer = null; - } this.group = createGroup(composite, LspEditorUiMessages.LspEditorPreferencePage_clangd_options_label); this.path = createFileSelector(metadata.clangdPath(), group, this::selectClangdExecutable); this.tidy = createCheckbox(metadata.useTidy(), group); @@ -111,12 +92,7 @@ public void widgetSelected(SelectionEvent e) { } void enablePreferenceContent(boolean enable) { - if (prefer != null) { - prefer.setEnabled(enable); - enableClangdOptionsGroup(prefer.getSelection() && enable); - } else { - enableClangdOptionsGroup(enable); - } + enableClangdOptionsGroup(enable); } private void enableClangdOptionsGroup(boolean enable) { @@ -230,9 +206,6 @@ void changed(TypedEvent event) { } void load(ClangdOptions options, boolean enable) { - if (prefer != null) { - prefer.setSelection(options.preferClangd()); - } path.setText(options.clangdPath()); tidy.setSelection(options.useTidy()); index.setSelection(options.useBackgroundIndex()); @@ -262,7 +235,7 @@ void dispose() { } public boolean optionsChanged(ClangdOptions options) { - if (!group.isVisible() || (prefer != null && !prefer.getSelection())) { + if (!group.isVisible()) { return false; } return !options.clangdPath().equals(path.getText()) || options.useTidy() != tidy.getSelection() diff --git a/bundles/org.eclipse.cdt.lsp.clangd/src/org/eclipse/cdt/lsp/internal/clangd/editor/ClangdConfigurationPage.java b/bundles/org.eclipse.cdt.lsp.clangd/src/org/eclipse/cdt/lsp/internal/clangd/editor/ClangdConfigurationPage.java index bf7ebb01..5c34781d 100644 --- a/bundles/org.eclipse.cdt.lsp.clangd/src/org/eclipse/cdt/lsp/internal/clangd/editor/ClangdConfigurationPage.java +++ b/bundles/org.eclipse.cdt.lsp.clangd/src/org/eclipse/cdt/lsp/internal/clangd/editor/ClangdConfigurationPage.java @@ -20,7 +20,7 @@ import org.eclipse.cdt.lsp.LspUtils; import org.eclipse.cdt.lsp.clangd.ClangdConfiguration; import org.eclipse.cdt.lsp.clangd.ClangdOptions; -import org.eclipse.cdt.lsp.internal.clangd.ResolveProjectScope; +import org.eclipse.cdt.lsp.editor.ResolveProjectScope; import org.eclipse.core.resources.IWorkspace; import org.eclipse.core.resources.ProjectScope; import org.eclipse.core.runtime.Platform; @@ -58,7 +58,7 @@ public final class ClangdConfigurationPage extends PropertyPage implements IWorkbenchPreferencePage { - private final String id = "org.eclipse.cdt.lsp.clangd.editor.preference"; //$NON-NLS-1$ + private final String id = "org.eclipse.cdt.lsp.clangd.editor.preferencePage"; //$NON-NLS-1$ private ClangdConfiguration configuration; private IWorkspace workspace; @@ -245,7 +245,7 @@ private IScopeContext scope() { private boolean hasProjectSpecificOptions() { return projectScope()// .map(p -> p.getNode(configuration.qualifier()))// - .map(n -> n.get(configuration.metadata().preferClangd().identifer(), null))// + .map(n -> n.get(configuration.metadata().clangdPath().identifer(), null))// .isPresent(); } diff --git a/bundles/org.eclipse.cdt.lsp.clangd/src/org/eclipse/cdt/lsp/internal/clangd/editor/DefaultClangdConfigurationVisibility.java b/bundles/org.eclipse.cdt.lsp.clangd/src/org/eclipse/cdt/lsp/internal/clangd/editor/DefaultClangdConfigurationVisibility.java deleted file mode 100644 index c582dd8b..00000000 --- a/bundles/org.eclipse.cdt.lsp.clangd/src/org/eclipse/cdt/lsp/internal/clangd/editor/DefaultClangdConfigurationVisibility.java +++ /dev/null @@ -1,26 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2023 Bachmann electronic GmbH 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: - * Gesa Hentschke (Bachmann electronic GmbH) - initial implementation - *******************************************************************************/ -package org.eclipse.cdt.lsp.internal.clangd.editor; - -import org.eclipse.cdt.lsp.clangd.ClangdConfigurationVisibility; -import org.osgi.service.component.annotations.Component; - -@Component(property = { "service.ranking:Integer=0" }) -public final class DefaultClangdConfigurationVisibility implements ClangdConfigurationVisibility { - - @Override - public boolean showPreferClangd(boolean isProjectScope) { - return true; - } - -} diff --git a/bundles/org.eclipse.cdt.lsp.clangd/src/org/eclipse/cdt/lsp/internal/clangd/editor/LspEditorUiMessages.java b/bundles/org.eclipse.cdt.lsp.clangd/src/org/eclipse/cdt/lsp/internal/clangd/editor/LspEditorUiMessages.java index 5ab23931..3e3efb8f 100644 --- a/bundles/org.eclipse.cdt.lsp.clangd/src/org/eclipse/cdt/lsp/internal/clangd/editor/LspEditorUiMessages.java +++ b/bundles/org.eclipse.cdt.lsp.clangd/src/org/eclipse/cdt/lsp/internal/clangd/editor/LspEditorUiMessages.java @@ -23,8 +23,6 @@ public class LspEditorUiMessages extends NLS { NLS.initializeMessages(BUNDLE_NAME, LspEditorUiMessages.class); } - public static String LspEditorPreferencePage_preferLspEditor; - public static String LspEditorPreferencePage_preferLspEditor_description; public static String LspEditorPreferencePage_path; public static String LspEditorPreferencePage_path_description; public static String LspEditorPreferencePage_enable_tidy; @@ -46,7 +44,7 @@ public class LspEditorUiMessages extends NLS { public static String LspEditorPreferencePage_completion_detailed; public static String LspEditorPreferencePage_completion_bundled; public static String LspEditorPreferencePage_completion_default; - public static String LspEditorPreferencePage_select_clangd_executable; + public static String LspEditorPreferencePage_select_clangd_executable; public static String CProjectChangeMonitor_yaml_scanner_error; public static String CProjectChangeMonitor_yaml_scanner_error_message; diff --git a/bundles/org.eclipse.cdt.lsp.clangd/src/org/eclipse/cdt/lsp/internal/clangd/editor/LspEditorUiMessages.properties b/bundles/org.eclipse.cdt.lsp.clangd/src/org/eclipse/cdt/lsp/internal/clangd/editor/LspEditorUiMessages.properties index 6956af90..9340aea8 100644 --- a/bundles/org.eclipse.cdt.lsp.clangd/src/org/eclipse/cdt/lsp/internal/clangd/editor/LspEditorUiMessages.properties +++ b/bundles/org.eclipse.cdt.lsp.clangd/src/org/eclipse/cdt/lsp/internal/clangd/editor/LspEditorUiMessages.properties @@ -11,8 +11,6 @@ # Eclipse Foundation - initial API and implementation ############################################################################### -LspEditorPreferencePage_preferLspEditor=Prefer C/C++ Editor (LSP) -LspEditorPreferencePage_preferLspEditor_description=Prefer to use language server based C/C++ Editor instead of classic C/C++ Editor LspEditorPreferencePage_path=Path LspEditorPreferencePage_path_description=Path to clangd executable LspEditorPreferencePage_enable_tidy=Enable clang-tidy diagnostics diff --git a/bundles/org.eclipse.cdt.lsp/META-INF/MANIFEST.MF b/bundles/org.eclipse.cdt.lsp/META-INF/MANIFEST.MF index fbf11a89..2db874a5 100644 --- a/bundles/org.eclipse.cdt.lsp/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.cdt.lsp/META-INF/MANIFEST.MF @@ -4,6 +4,7 @@ Bundle-Name: %Bundle-Name Bundle-SymbolicName: org.eclipse.cdt.lsp;singleton:=true Bundle-Version: 1.0.0.qualifier Export-Package: org.eclipse.cdt.lsp, + org.eclipse.cdt.lsp.editor, org.eclipse.cdt.lsp.server, org.eclipse.cdt.lsp.server.enable, org.eclipse.cdt.lsp.services @@ -32,4 +33,8 @@ Require-Bundle: org.eclipse.ui, Bundle-RequiredExecutionEnvironment: JavaSE-17 Automatic-Module-Name: org.eclipse.cdt.lsp Bundle-ActivationPolicy: lazy -Service-Component: OSGI-INF/org.eclipse.cdt.lsp.internal.InitialFileManager.xml +Service-Component: OSGI-INF/org.eclipse.cdt.lsp.editor.BuiltinEditorOptionsDefault.xml, + OSGI-INF/org.eclipse.cdt.lsp.editor.DefaultConfigurationVisibility.xml, + OSGI-INF/org.eclipse.cdt.lsp.editor.EditorConfigurationAccess.xml, + OSGI-INF/org.eclipse.cdt.lsp.editor.EditorMetadataDefaults.xml, + OSGI-INF/org.eclipse.cdt.lsp.internal.InitialFileManager.xml diff --git a/bundles/org.eclipse.cdt.lsp/OSGI-INF/l10n/bundle.properties b/bundles/org.eclipse.cdt.lsp/OSGI-INF/l10n/bundle.properties index f1d337a7..426adc8d 100644 --- a/bundles/org.eclipse.cdt.lsp/OSGI-INF/l10n/bundle.properties +++ b/bundles/org.eclipse.cdt.lsp/OSGI-INF/l10n/bundle.properties @@ -22,3 +22,6 @@ available under the terms of the Eclipse Public License 2.0\n\ which is available at https://www.eclipse.org/legal/epl-2.0/\n\ \n\ SPDX-License-Identifier: EPL-2.0\n\ + +SaveActionsPreferencePage.name=Save Actions +EditorPreferencePage.name=Editor (LSP) diff --git a/bundles/org.eclipse.cdt.lsp/OSGI-INF/org.eclipse.cdt.lsp.editor.BuiltinEditorOptionsDefault.xml b/bundles/org.eclipse.cdt.lsp/OSGI-INF/org.eclipse.cdt.lsp.editor.BuiltinEditorOptionsDefault.xml new file mode 100644 index 00000000..0859936b --- /dev/null +++ b/bundles/org.eclipse.cdt.lsp/OSGI-INF/org.eclipse.cdt.lsp.editor.BuiltinEditorOptionsDefault.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/bundles/org.eclipse.cdt.lsp/OSGI-INF/org.eclipse.cdt.lsp.editor.DefaultConfigurationVisibility.xml b/bundles/org.eclipse.cdt.lsp/OSGI-INF/org.eclipse.cdt.lsp.editor.DefaultConfigurationVisibility.xml new file mode 100644 index 00000000..50f1d3bf --- /dev/null +++ b/bundles/org.eclipse.cdt.lsp/OSGI-INF/org.eclipse.cdt.lsp.editor.DefaultConfigurationVisibility.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/bundles/org.eclipse.cdt.lsp/OSGI-INF/org.eclipse.cdt.lsp.editor.EditorConfigurationAccess.xml b/bundles/org.eclipse.cdt.lsp/OSGI-INF/org.eclipse.cdt.lsp.editor.EditorConfigurationAccess.xml new file mode 100644 index 00000000..3a9b2486 --- /dev/null +++ b/bundles/org.eclipse.cdt.lsp/OSGI-INF/org.eclipse.cdt.lsp.editor.EditorConfigurationAccess.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/bundles/org.eclipse.cdt.lsp/OSGI-INF/org.eclipse.cdt.lsp.editor.EditorMetadataDefaults.xml b/bundles/org.eclipse.cdt.lsp/OSGI-INF/org.eclipse.cdt.lsp.editor.EditorMetadataDefaults.xml new file mode 100644 index 00000000..12edd8ef --- /dev/null +++ b/bundles/org.eclipse.cdt.lsp/OSGI-INF/org.eclipse.cdt.lsp.editor.EditorMetadataDefaults.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/bundles/org.eclipse.cdt.lsp/plugin.xml b/bundles/org.eclipse.cdt.lsp/plugin.xml index 060628be..0d4163cf 100644 --- a/bundles/org.eclipse.cdt.lsp/plugin.xml +++ b/bundles/org.eclipse.cdt.lsp/plugin.xml @@ -11,6 +11,12 @@ SPDX-License-Identifier: EPL-2.0 --> + + + + @@ -263,5 +269,48 @@ class="org.eclipse.cdt.lsp.editor.LspEditorFileImageDescriptor"> + + + + + + + + + + + + + + + + + + + + + + diff --git a/bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/LspQualifier.java b/bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/LspQualifier.java new file mode 100644 index 00000000..625710f8 --- /dev/null +++ b/bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/LspQualifier.java @@ -0,0 +1,25 @@ +/******************************************************************************* + * Copyright (c) 2023 ArSysOp. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Alexander Fedorov (ArSysOp) - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.lsp; + +import java.util.function.Supplier; + +public final class LspQualifier implements Supplier { + + @Override + public String get() { + return "org.eclipse.cdt.lsp"; //$NON-NLS-1$ + } + +} diff --git a/bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/PreferredOptions.java b/bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/PreferredOptions.java new file mode 100644 index 00000000..a5e99c00 --- /dev/null +++ b/bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/PreferredOptions.java @@ -0,0 +1,47 @@ +/******************************************************************************* + * Copyright (c) 2023 Contributors to the Eclipse Foundation. + * 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: + * See git history + *******************************************************************************/ + +package org.eclipse.cdt.lsp; + +import java.util.Objects; +import java.util.Optional; + +import org.eclipse.core.runtime.preferences.IScopeContext; +import org.eclipse.core.runtime.preferences.PreferenceMetadata; + +public abstract class PreferredOptions { + protected final String qualifier; + protected final IScopeContext[] scopes; + + public PreferredOptions(String qualifier, IScopeContext[] scopes) { + this.qualifier = Objects.requireNonNull(qualifier); + this.scopes = Objects.requireNonNull(scopes); + } + + protected String stringValue(PreferenceMetadata meta) { + String actual = String.valueOf(meta.defaultValue()); + for (int i = scopes.length - 1; i >= 0; i--) { + IScopeContext scope = scopes[i]; + String previous = actual; + actual = scope.getNode(qualifier).get(meta.identifer(), previous); + } + return actual; + } + + protected boolean booleanValue(PreferenceMetadata meta) { + return Optional.of(meta)// + .map(this::stringValue)// + .map(Boolean::valueOf)// + .orElseGet(meta::defaultValue); + } + +} diff --git a/bundles/org.eclipse.cdt.lsp.clangd/src/org/eclipse/cdt/lsp/internal/clangd/ResolveProject.java b/bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/ResolveProject.java similarity index 94% rename from bundles/org.eclipse.cdt.lsp.clangd/src/org/eclipse/cdt/lsp/internal/clangd/ResolveProject.java rename to bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/ResolveProject.java index c920fb25..9dae68a4 100644 --- a/bundles/org.eclipse.cdt.lsp.clangd/src/org/eclipse/cdt/lsp/internal/clangd/ResolveProject.java +++ b/bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/ResolveProject.java @@ -11,13 +11,12 @@ * Contributors: * Alexander Fedorov (ArSysOp) - Initial API and implementation *******************************************************************************/ -package org.eclipse.cdt.lsp.internal.clangd; +package org.eclipse.cdt.lsp; import java.net.URI; import java.util.Optional; import java.util.function.Function; -import org.eclipse.cdt.lsp.ExistingResource; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IWorkspace; diff --git a/examples/org.eclipse.cdt.lsp.examples.preferences/src/org/eclipse/cdt/lsp/examples/preferences/HidePreferClangd.java b/bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/editor/BuiltinEditorOptionsDefault.java similarity index 61% rename from examples/org.eclipse.cdt.lsp.examples.preferences/src/org/eclipse/cdt/lsp/examples/preferences/HidePreferClangd.java rename to bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/editor/BuiltinEditorOptionsDefault.java index e64ebddd..b8ac8038 100644 --- a/examples/org.eclipse.cdt.lsp.examples.preferences/src/org/eclipse/cdt/lsp/examples/preferences/HidePreferClangd.java +++ b/bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/editor/BuiltinEditorOptionsDefault.java @@ -9,16 +9,31 @@ * Contributors: * See git history *******************************************************************************/ -package org.eclipse.cdt.lsp.examples.preferences; -import org.eclipse.cdt.lsp.clangd.ClangdConfigurationVisibility; +package org.eclipse.cdt.lsp.editor; + import org.osgi.service.component.annotations.Component; -@Component(property = { "service.ranking:Integer=100" }) -public class HidePreferClangd implements ClangdConfigurationVisibility { +@Component +public class BuiltinEditorOptionsDefault implements EditorOptionsDefaults { + + @Override + public boolean preferLspEditor() { + return false; + } + + @Override + public boolean formatOnSave() { + return false; + } + + @Override + public boolean formatAllLines() { + return true; + } @Override - public boolean showPreferClangd(boolean isProjectScope) { + public boolean formatEditedLines() { return false; } diff --git a/bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/editor/ConfigurationAccess.java b/bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/editor/ConfigurationAccess.java new file mode 100644 index 00000000..e1f4e8a7 --- /dev/null +++ b/bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/editor/ConfigurationAccess.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright (c) 2023 Contributors to the Eclipse Foundation. + * 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: + * See git history + *******************************************************************************/ + +package org.eclipse.cdt.lsp.editor; + +import java.util.Optional; + +import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.resources.ProjectScope; +import org.eclipse.core.runtime.preferences.IEclipsePreferences; +import org.eclipse.core.runtime.preferences.IScopeContext; +import org.eclipse.osgi.util.NLS; + +public abstract class ConfigurationAccess { + protected final String qualifier; + + public ConfigurationAccess(String qualifier) { + this.qualifier = qualifier; + } + + protected Optional projectScope(IWorkspace workspace, Object context) { + return new ResolveProjectScope(workspace).apply(context); + } + + protected IEclipsePreferences preferences(IScopeContext scope) { + return Optional.ofNullable(scope.getNode(qualifier))// + .filter(IEclipsePreferences.class::isInstance)// + .map(IEclipsePreferences.class::cast)// + .orElseThrow(() -> new IllegalStateException(// + NLS.bind("Unable to get preferences for node: {0}", // //$NON-NLS-1$ + qualifier))); + } + +} diff --git a/bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/editor/ConfigurationArea.java b/bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/editor/ConfigurationArea.java new file mode 100644 index 00000000..e7303375 --- /dev/null +++ b/bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/editor/ConfigurationArea.java @@ -0,0 +1,74 @@ +package org.eclipse.cdt.lsp.editor; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.function.Consumer; + +import org.eclipse.core.runtime.preferences.IEclipsePreferences; +import org.eclipse.core.runtime.preferences.PreferenceMetadata; +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.TypedEvent; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Group; + +public abstract class ConfigurationArea { + protected final Map, Button> buttons; + protected final List> listeners; + protected final int columns; + + public ConfigurationArea(int columns) { + this.buttons = new HashMap<>(); + this.listeners = new ArrayList<>(); + this.columns = columns; + } + + protected Group createGroup(Composite parent, String label, int numColumns) { + Group group = new Group(parent, SWT.NONE); + group.setFont(parent.getFont()); + group.setText(label); + GridLayout layout = new GridLayout(); + layout.numColumns = numColumns; + group.setLayout(layout); + group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + return group; + } + + protected Button createButton(PreferenceMetadata meta, Composite composite, int style, + int horizontalIndent) { + Button button = new Button(composite, style); + button.setLayoutData(GridDataFactory.fillDefaults().span(columns, 1).indent(horizontalIndent, 0).create()); + button.setData(meta); + button.setText(meta.name()); + button.setToolTipText(meta.description()); + buttons.put(meta, button); + return button; + } + + public void addChangeListener(Consumer listener) { + listeners.add(listener); + } + + public void removeChangeListener(Consumer listener) { + listeners.add(listener); + } + + public void changed(TypedEvent event) { + listeners.forEach(c -> c.accept(event)); + } + + public void dispose() { + listeners.clear(); + buttons.clear(); + } + + public abstract void load(Object options, boolean enable); + + public abstract void store(IEclipsePreferences prefs); + +} diff --git a/bundles/org.eclipse.cdt.lsp.clangd/src/org/eclipse/cdt/lsp/clangd/ClangdConfigurationVisibility.java b/bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/editor/ConfigurationVisibility.java similarity index 77% rename from bundles/org.eclipse.cdt.lsp.clangd/src/org/eclipse/cdt/lsp/clangd/ClangdConfigurationVisibility.java rename to bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/editor/ConfigurationVisibility.java index ee25445d..a8369652 100644 --- a/bundles/org.eclipse.cdt.lsp.clangd/src/org/eclipse/cdt/lsp/clangd/ClangdConfigurationVisibility.java +++ b/bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/editor/ConfigurationVisibility.java @@ -10,20 +10,20 @@ * Contributors: * Gesa Hentschke (Bachmann electronic GmbH) - initial implementation *******************************************************************************/ -package org.eclipse.cdt.lsp.clangd; +package org.eclipse.cdt.lsp.editor; /** * Provides access to the visibility of configuration elements in the UI taking into account the scope (project or workspace). - * Should be implemented as OSGi service when {@link ClangdEnable} service has been provided + * Should be implemented as OSGi service when {@link org.eclipse.cdt.lsp.editor.LanguageServerEnable} service has been provided * to hide the 'Prefer C/C++ Editor (LSP)' check-box. */ -public interface ClangdConfigurationVisibility { +public interface ConfigurationVisibility { /** * Changes the visibility of the 'Prefer C/C++ Editor (LSP)' check-box. * @param isProjectScope * @return true when the check-box should be displayed. */ - boolean showPreferClangd(boolean isProjectScope); + boolean showPreferLsp(boolean isProjectScope); } diff --git a/bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/editor/DefaultConfigurationVisibility.java b/bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/editor/DefaultConfigurationVisibility.java new file mode 100644 index 00000000..76e3ddac --- /dev/null +++ b/bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/editor/DefaultConfigurationVisibility.java @@ -0,0 +1,13 @@ +package org.eclipse.cdt.lsp.editor; + +import org.osgi.service.component.annotations.Component; + +@Component(property = { "service.ranking:Integer=0" }) +public class DefaultConfigurationVisibility implements ConfigurationVisibility { + + @Override + public boolean showPreferLsp(boolean isProjectScope) { + return true; + } + +} diff --git a/bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/editor/EditorConfiguration.java b/bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/editor/EditorConfiguration.java new file mode 100644 index 00000000..48c9c0cf --- /dev/null +++ b/bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/editor/EditorConfiguration.java @@ -0,0 +1,57 @@ +/******************************************************************************* + * Copyright (c) 2023 Contributors to the Eclipse Foundation. + * 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: + * See git history + *******************************************************************************/ + +package org.eclipse.cdt.lsp.editor; + +import java.net.URI; + +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.preferences.IPreferenceMetadataStore; + +public interface EditorConfiguration { + + /** + * Returns the editor defaults + * + * @return editor defaults + */ + EditorOptions defaults(); + + /** + * Returns the editor options for the given context like {@link IResource} or {@link URI}, must not return null + * @param context to be adapter to the proper scope + * + * @return editor options + */ + EditorOptions options(Object context); + + /** + * Returns the editor preference store for the given context like {@link IResource} or {@link URI}, must not return null + * @param context to be adapter to the proper scope + * + * @return preference store + */ + IPreferenceMetadataStore storage(Object context); + + /** + * Return the metadata for editor options, must not return null + * + * @return the editor option metadata + */ + EditorMetadata metadata(); + + /** + * Default qualifier to use for preference storage + * @return preference qualifier + */ + String qualifier(); +} diff --git a/bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/editor/EditorConfigurationAccess.java b/bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/editor/EditorConfigurationAccess.java new file mode 100644 index 00000000..f2afda64 --- /dev/null +++ b/bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/editor/EditorConfigurationAccess.java @@ -0,0 +1,81 @@ +/******************************************************************************* + * Copyright (c) 2023 Contributors to the Eclipse Foundation. + * 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: + * See git history + *******************************************************************************/ + +package org.eclipse.cdt.lsp.editor; + +import java.util.Optional; + +import org.eclipse.cdt.lsp.LspQualifier; +import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.resources.ProjectScope; +import org.eclipse.core.runtime.preferences.DefaultScope; +import org.eclipse.core.runtime.preferences.IPreferenceMetadataStore; +import org.eclipse.core.runtime.preferences.IScopeContext; +import org.eclipse.core.runtime.preferences.InstanceScope; +import org.eclipse.core.runtime.preferences.OsgiPreferenceMetadataStore; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Reference; +import org.osgi.service.component.annotations.ReferenceCardinality; + +@Component +public class EditorConfigurationAccess extends ConfigurationAccess implements EditorConfiguration { + + @Reference + private EditorMetadata metadata; + + @Reference + private IWorkspace workspace; + + @Reference(cardinality = ReferenceCardinality.OPTIONAL) + private LanguageServerEnable enable; + + public EditorConfigurationAccess() { + super(new LspQualifier().get()); + } + + @Override + public EditorOptions defaults() { + return new EditorPreferredOptions(qualifier, new IScopeContext[] { DefaultScope.INSTANCE }, metadata, enable); + } + + @Override + public EditorOptions options(Object context) { + Optional project = projectScope(workspace, context); + IScopeContext[] scopes; + if (project.isPresent()) { + scopes = new IScopeContext[] { project.get(), InstanceScope.INSTANCE, DefaultScope.INSTANCE }; + } else { + scopes = new IScopeContext[] { InstanceScope.INSTANCE, DefaultScope.INSTANCE }; + } + return new EditorPreferredOptions(qualifier, scopes, metadata, enable); + } + + @Override + public IPreferenceMetadataStore storage(Object context) { + return new OsgiPreferenceMetadataStore(// + preferences(// + projectScope(workspace, context)// + .map(IScopeContext.class::cast)// + .orElse(InstanceScope.INSTANCE))); + } + + @Override + public EditorMetadata metadata() { + return metadata; + } + + @Override + public String qualifier() { + return qualifier; + } + +} diff --git a/bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/editor/EditorConfigurationArea.java b/bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/editor/EditorConfigurationArea.java new file mode 100644 index 00000000..b0e518d7 --- /dev/null +++ b/bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/editor/EditorConfigurationArea.java @@ -0,0 +1,59 @@ +/******************************************************************************* + * Copyright (c) 2023 ArSysOp. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Alexander Fedorov (ArSysOp) - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.lsp.editor; + +import org.eclipse.core.runtime.preferences.IEclipsePreferences; +import org.eclipse.core.runtime.preferences.OsgiPreferenceMetadataStore; +import org.eclipse.jface.layout.GridLayoutFactory; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.PlatformUI; + +public final class EditorConfigurationArea extends ConfigurationArea { + + private final Button prefer; + private ConfigurationVisibility visibility; + + public EditorConfigurationArea(Composite parent, EditorMetadata metadata, boolean isProjectScope) { + super(1); + this.visibility = PlatformUI.getWorkbench().getService(ConfigurationVisibility.class); + Composite composite = new Composite(parent, SWT.NONE); + composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + composite.setLayout(GridLayoutFactory.fillDefaults().numColumns(columns).create()); + if (visibility.showPreferLsp(isProjectScope)) { + this.prefer = createButton(metadata.preferLspEditor(), composite, SWT.CHECK, 0); + } else { + this.prefer = null; + } + } + + @Override + public void load(Object options, boolean enable) { + if (options instanceof EditorOptions editorOptions) { + if (prefer != null) { + prefer.setSelection(editorOptions.preferLspEditor()); + prefer.setEnabled(enable); + } + } + } + + @Override + public void store(IEclipsePreferences prefs) { + OsgiPreferenceMetadataStore store = new OsgiPreferenceMetadataStore(prefs); + buttons.entrySet().forEach(e -> store.save(e.getValue().getSelection(), e.getKey())); + } + +} diff --git a/bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/editor/EditorMetadata.java b/bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/editor/EditorMetadata.java new file mode 100644 index 00000000..5a8a5548 --- /dev/null +++ b/bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/editor/EditorMetadata.java @@ -0,0 +1,54 @@ +/******************************************************************************* + * Copyright (c) 2023 Contributors to the Eclipse Foundation. + * 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: + * See git history + *******************************************************************************/ + +package org.eclipse.cdt.lsp.editor; + +import org.eclipse.core.runtime.preferences.PreferenceMetadata; + +public interface EditorMetadata { + + /** + * Returns the metadata for the "Prefer C/C++ Editor (LSP)" option, must not return null. + * + * @return the metadata for the "Prefer C/C++ Editor (LSP)" option + * + * @see EditorOptions#preferLspEditor() + */ + PreferenceMetadata preferLspEditor(); + + /** + * Returns the metadata for the "Format source code" option, must not return null. + * + * @return the metadata for the "Format source code" option + * + * @see EditorOptions#formatOnSave() + */ + PreferenceMetadata formatOnSave(); + + /** + * Returns the metadata for the "Format all lines" option, must not return null. + * + * @return the metadata for the "Format all lines" option + * + * @see EditorOptions#formatAllLines() + */ + PreferenceMetadata formatAllLines(); + + /** + * Returns the metadata for the "Format edited lines" option, must not return null. + * + * @return the metadata for the "Format edited lines" option + * + * @see EditorOptions#formatEditedLines() + */ + PreferenceMetadata formatEditedLines(); +} diff --git a/bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/editor/EditorMetadataDefaults.java b/bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/editor/EditorMetadataDefaults.java new file mode 100644 index 00000000..1a8269a8 --- /dev/null +++ b/bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/editor/EditorMetadataDefaults.java @@ -0,0 +1,62 @@ +package org.eclipse.cdt.lsp.editor; + +/******************************************************************************* + * Copyright (c) 2023 Contributors to the Eclipse Foundation. + * 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: + * See git history + *******************************************************************************/ + +import org.eclipse.cdt.lsp.internal.messages.LspUiMessages; +import org.eclipse.core.runtime.preferences.PreferenceMetadata; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Reference; + +@Component +public class EditorMetadataDefaults implements EditorMetadata { + + @Reference + private EditorOptionsDefaults defaults; + + @Override + public PreferenceMetadata preferLspEditor() { + return new PreferenceMetadata<>(Boolean.class, // + "prefer_lsp", //$NON-NLS-1$ + defaults.preferLspEditor(), // + LspUiMessages.LspEditorConfigurationPage_preferLspEditor, + LspUiMessages.LspEditorConfigurationPage_preferLspEditor_description); + } + + @Override + public PreferenceMetadata formatOnSave() { + return new PreferenceMetadata<>(Boolean.class, // + "format_source", //$NON-NLS-1$ + defaults.formatOnSave(), // + LspUiMessages.SaveActionsPreferencePage_FormatSourceCode, + LspUiMessages.SaveActionsPreferencePage_FormatSourceCode_description); + } + + @Override + public PreferenceMetadata formatAllLines() { + return new PreferenceMetadata<>(Boolean.class, // + "format_all_lines", //$NON-NLS-1$ + defaults.formatAllLines(), // + LspUiMessages.SaveActionsPreferencePage_FormaAllLines, + LspUiMessages.SaveActionsPreferencePage_FormaAllLines_description); + } + + @Override + public PreferenceMetadata formatEditedLines() { + return new PreferenceMetadata<>(Boolean.class, // + "format_edited_lines", //$NON-NLS-1$ + defaults.formatEditedLines(), // + LspUiMessages.SaveActionsPreferencePage_FormaEditedLines, + LspUiMessages.SaveActionsPreferencePage_FormaEditedLines_description); + } + +} diff --git a/bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/editor/EditorOptions.java b/bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/editor/EditorOptions.java new file mode 100644 index 00000000..8b95cd70 --- /dev/null +++ b/bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/editor/EditorOptions.java @@ -0,0 +1,45 @@ +/******************************************************************************* + * Copyright (c) 2023 Contributors to the Eclipse Foundation. + * 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: + * See git history + *******************************************************************************/ + +package org.eclipse.cdt.lsp.editor; + +public interface EditorOptions { + + /** + * Prefer to use LSP based C/C++ Editor + * + * @return if LSP based C/C++ Editor should be preferred + */ + boolean preferLspEditor(); + + /** + * Format source code on file save action + * + * @return if source code should be formatted on file save action + */ + boolean formatOnSave(); + + /** + * Format all lines in source file + * + * @return if all lines should be formatted + */ + boolean formatAllLines(); + + /** + * Format edited lines only + * + * @return if only edited lines should be formatted + */ + boolean formatEditedLines(); + +} diff --git a/bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/editor/EditorOptionsDefaults.java b/bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/editor/EditorOptionsDefaults.java new file mode 100644 index 00000000..cdf5bf75 --- /dev/null +++ b/bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/editor/EditorOptionsDefaults.java @@ -0,0 +1,17 @@ +/******************************************************************************* + * Copyright (c) 2023 Contributors to the Eclipse Foundation. + * 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: + * See git history + *******************************************************************************/ + +package org.eclipse.cdt.lsp.editor; + +public interface EditorOptionsDefaults extends EditorOptions { + +} diff --git a/bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/editor/EditorPreferenceInitializer.java b/bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/editor/EditorPreferenceInitializer.java new file mode 100644 index 00000000..f8b217fb --- /dev/null +++ b/bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/editor/EditorPreferenceInitializer.java @@ -0,0 +1,39 @@ +/******************************************************************************* + * Copyright (c) 2023 Contributors to the Eclipse Foundation. + * 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: + * See git history + *******************************************************************************/ + +package org.eclipse.cdt.lsp.editor; + +import org.eclipse.core.runtime.ServiceCaller; +import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer; +import org.eclipse.core.runtime.preferences.DefaultScope; +import org.eclipse.core.runtime.preferences.PreferenceMetadata; + +public final class EditorPreferenceInitializer extends AbstractPreferenceInitializer { + + @Override + public void initializeDefaultPreferences() { + ServiceCaller.callOnce(getClass(), EditorConfiguration.class, this::initializeDefaults); + } + + private void initializeDefaults(EditorConfiguration configuration) { + EditorMetadata metadata = configuration.metadata(); + String qualifier = configuration.qualifier(); + initializeBoolean(metadata.preferLspEditor(), qualifier); + initializeBoolean(metadata.formatOnSave(), qualifier); + initializeBoolean(metadata.formatAllLines(), qualifier); + initializeBoolean(metadata.formatEditedLines(), qualifier); + } + + private void initializeBoolean(PreferenceMetadata preference, String qualifier) { + DefaultScope.INSTANCE.getNode(qualifier).putBoolean(preference.identifer(), preference.defaultValue()); + } +} diff --git a/bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/editor/EditorPreferredOptions.java b/bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/editor/EditorPreferredOptions.java new file mode 100644 index 00000000..a8527239 --- /dev/null +++ b/bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/editor/EditorPreferredOptions.java @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2023 Contributors to the Eclipse Foundation. + * 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: + * See git history + *******************************************************************************/ + +package org.eclipse.cdt.lsp.editor; + +import java.util.Objects; + +import org.eclipse.cdt.lsp.PreferredOptions; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.preferences.IScopeContext; + +public class EditorPreferredOptions extends PreferredOptions implements EditorOptions, LanguageServerEnable { + private final EditorMetadata metadata; + private final LanguageServerEnable enable; + + public EditorPreferredOptions(String qualifier, IScopeContext[] scopes, EditorMetadata metadata, + LanguageServerEnable enable) { + super(qualifier, scopes); + this.metadata = Objects.requireNonNull(metadata); + this.enable = enable; + } + + @Override + public boolean preferLspEditor() { + return booleanValue(metadata.preferLspEditor()); + } + + @Override + public boolean formatOnSave() { + return booleanValue(metadata.formatOnSave()); + } + + @Override + public boolean formatAllLines() { + return booleanValue(metadata.formatAllLines()); + } + + @Override + public boolean formatEditedLines() { + return booleanValue(metadata.formatEditedLines()); + } + + @Override + public boolean isEnabledFor(IProject project) { + if (enable != null) { + return enable.isEnabledFor(project); + } + return booleanValue(metadata.preferLspEditor()); + } + +} diff --git a/bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/editor/EditorPropertyPage.java b/bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/editor/EditorPropertyPage.java new file mode 100644 index 00000000..b5465ae9 --- /dev/null +++ b/bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/editor/EditorPropertyPage.java @@ -0,0 +1,255 @@ +/******************************************************************************* + * Copyright (c) 2023 ArSysOp. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Alexander Fedorov (ArSysOp) - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.cdt.lsp.editor; + +import java.util.Optional; + +import org.eclipse.cdt.lsp.internal.messages.LspUiMessages; +import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.resources.ProjectScope; +import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.preferences.IEclipsePreferences; +import org.eclipse.core.runtime.preferences.IScopeContext; +import org.eclipse.core.runtime.preferences.InstanceScope; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.layout.GridLayoutFactory; +import org.eclipse.jface.preference.IPreferencePageContainer; +import org.eclipse.jface.resource.JFaceResources; +import org.eclipse.jface.window.Window; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Link; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchPreferencePage; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.dialogs.PreferencesUtil; +import org.eclipse.ui.dialogs.PropertyPage; +import org.eclipse.ui.preferences.IWorkbenchPreferenceContainer; +import org.eclipse.ui.preferences.IWorkingCopyManager; +import org.eclipse.ui.preferences.WorkingCopyManager; +import org.osgi.service.prefs.BackingStoreException; + +public class EditorPropertyPage extends PropertyPage implements IWorkbenchPreferencePage { + + private final String id = "org.eclipse.cdt.lsp.editor.preferencePage"; //$NON-NLS-1$ + + protected EditorConfiguration configuration; + private IWorkspace workspace; + + private IWorkingCopyManager manager; + + private Link link; + private Button specific; + private Control control; + private ConfigurationArea area; + + @Override + public void init(IWorkbench workbench) { + this.configuration = workbench.getService(EditorConfiguration.class); + this.workspace = workbench.getService(IWorkspace.class); + } + + @Override + public void setContainer(IPreferencePageContainer container) { + super.setContainer(container); + if (manager == null) { + manager = Optional.ofNullable(container)// + .filter(IWorkbenchPreferenceContainer.class::isInstance)// + .map(IWorkbenchPreferenceContainer.class::cast)// + .map(IWorkbenchPreferenceContainer::getWorkingCopyManager)// + .orElseGet(WorkingCopyManager::new); + } + if (configuration == null) { + configuration = PlatformUI.getWorkbench().getService(EditorConfiguration.class); + } + if (workspace == null) { + workspace = PlatformUI.getWorkbench().getService(IWorkspace.class); + } + } + + @Override + protected Label createDescriptionLabel(Composite parent) { + if (projectScope().isPresent()) { + Composite composite = new Composite(parent, SWT.NONE); + composite.setFont(parent.getFont()); + composite.setLayout(GridLayoutFactory.fillDefaults().numColumns(2).create()); + composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + specific = new Button(composite, SWT.CHECK); + specific.setLayoutData(new GridData(SWT.BEGINNING, SWT.TOP, true, false)); + specific.setText(LspUiMessages.LspEditorConfigurationPage_enable_project_specific); + specific.setFont(JFaceResources.getDialogFont()); + specific.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> specificSelected())); + link = createLink(composite, LspUiMessages.LspEditorConfigurationPage_configure_ws_specific); + link.setLayoutData(new GridData(SWT.END, SWT.TOP, false, false)); + Label line = new Label(composite, SWT.SEPARATOR | SWT.HORIZONTAL); + line.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false, 2, 1)); + line.setFont(composite.getFont()); + } + return super.createDescriptionLabel(parent); + } + + private void specificSelected() { + enableProjectSpecificSettings(specific.getSelection()); + refreshWidgets(configuration.options(getElement())); + } + + private Link createLink(Composite composite, String text) { + Link link = new Link(composite, SWT.NONE); + link.setFont(composite.getFont()); + link.setText("" + text + ""); //$NON-NLS-1$ //$NON-NLS-2$ + link.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + if (PreferencesUtil.createPreferenceDialogOn(getShell(), getPreferenceId(), new String[] { id }, null) + .open() == Window.OK) { + refreshWidgets(configuration.options(getElement())); + } + } + }); + return link; + } + + protected String getPreferenceId() { + return id; + } + + @Override + protected Control createContents(Composite parent) { + var isProjectScope = projectScope().isPresent(); + Composite composite = new Composite(parent, SWT.NONE); + composite.setLayout(GridLayoutFactory.fillDefaults().numColumns(3).create()); + composite.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create()); + composite.setFont(parent.getFont()); + control = createPreferenceContent(composite, isProjectScope); + control.setLayoutData(new GridData(GridData.FILL_BOTH)); + if (isProjectScope) { + enableProjectSpecificSettings(hasProjectSpecificOptions()); + } + refreshWidgets(configuration.options(getElement())); + Dialog.applyDialogFont(composite); + return composite; + } + + protected ConfigurationArea getConfigurationArea(Composite composite, boolean isProjectScope) { + return new EditorConfigurationArea(composite, configuration.metadata(), isProjectScope); + } + + private Control createPreferenceContent(Composite parent, boolean isProjectScope) { + Composite composite = new Composite(parent, SWT.NONE); + composite.setLayout(GridLayoutFactory.fillDefaults().create()); + composite.setFont(parent.getFont()); + area = getConfigurationArea(composite, isProjectScope); + return composite; + } + + private void refreshWidgets(EditorOptions options) { + setErrorMessage(null); + area.load(options, useProjectSettings() || !projectScope().isPresent()); + } + + private Optional projectScope() { + return new ResolveProjectScope(workspace).apply(getElement()); + } + + @Override + protected void performDefaults() { + if (useProjectSettings()) { + enableProjectSpecificSettings(false); + } + IEclipsePreferences prefs = manager.getWorkingCopy(scope().getNode(configuration.qualifier())); + try { + for (String key : prefs.keys()) { + prefs.remove(key); + } + } catch (BackingStoreException e) { + Platform.getLog(getClass()).error("Unable to restore default values.", e); //$NON-NLS-1$ + } + refreshWidgets(configuration.defaults()); + super.performDefaults(); + } + + @Override + public boolean performOk() { + IEclipsePreferences prefs; + if (projectScope().isPresent()) { + prefs = manager.getWorkingCopy(projectScope().get().getNode(configuration.qualifier())); + if (!useProjectSettings()) { + try { + for (String key : prefs.keys()) { + prefs.remove(key); + } + } catch (BackingStoreException e) { + Platform.getLog(getClass()).error("Unable to reset project preferences.", e); //$NON-NLS-1$ + } + prefs = null; + } + } else { + prefs = manager.getWorkingCopy(InstanceScope.INSTANCE.getNode(configuration.qualifier())); + } + if (prefs != null) { + area.store(prefs); + } + try { + manager.applyChanges(); + } catch (BackingStoreException e) { + Platform.getLog(getClass()).error("Unable to save preferences.", e); //$NON-NLS-1$ + return false; + } + return true; + } + + private IScopeContext scope() { + return projectScope().map(IScopeContext.class::cast).orElse(InstanceScope.INSTANCE); + } + + private boolean hasProjectSpecificOptions() { + return projectScope()// + .map(p -> p.getNode(configuration.qualifier()))// + .map(n -> n.get(configuration.metadata().preferLspEditor().identifer(), null))// + .isPresent(); + } + + private boolean useProjectSettings() { + return Optional.ofNullable(specific)// + .map(s -> s.getSelection())// + .orElse(Boolean.FALSE); + } + + private void enableProjectSpecificSettings(boolean use) { + specific.setSelection(use); + updateLinkVisibility(); + } + + private void updateLinkVisibility() { + Optional.ofNullable(link)// + .filter(l -> !l.isDisposed())// + .ifPresent(l -> l.setEnabled(!useProjectSettings())); + } + + @Override + public void dispose() { + Optional.ofNullable(area).ifPresent(ConfigurationArea::dispose); + super.dispose(); + } + +} diff --git a/bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/editor/FormatOnSave.java b/bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/editor/FormatOnSave.java index edf80f15..f0bfac38 100644 --- a/bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/editor/FormatOnSave.java +++ b/bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/editor/FormatOnSave.java @@ -1,21 +1,48 @@ -package org.eclipse.cdt.lsp.editor; +/******************************************************************************* + * Copyright (c) 2023 Contributors to the Eclipse Foundation. + * 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: + * See git history + *******************************************************************************/ -import org.eclipse.core.filebuffers.ITextFileBuffer; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.IRegion; -import org.eclipse.jface.text.Region; -import org.eclipse.lsp4e.IFormatOnSave; - -public class FormatOnSave implements IFormatOnSave { - - @Override - public boolean isEnabledFor(IDocument document) { - return true; - } - - @Override - public IRegion[] getFormattingRegions(ITextFileBuffer buffer) { - return new IRegion[] { new Region(0, buffer.getDocument().getLength()) }; - } - -} +//package org.eclipse.cdt.lsp.editor; +// +//import org.eclipse.jface.text.IDocument; +//import org.eclipse.jface.text.IRegion; +//import org.eclipse.jface.text.Region; +//import org.eclipse.lsp4e.LSPEclipseUtils; +//import org.eclipse.lsp4e.format.FormatEditedLines; +//import org.eclipse.lsp4e.format.IFormatRegionsProvider; +//import org.osgi.service.component.annotations.Component; +//import org.osgi.service.component.annotations.Reference; +// +//@Component(property = { "serverDefinitionId:String=org.eclipse.cdt.lsp.server" }) +//public class FormatOnSave implements IFormatRegionsProvider { +// private final FormatEditedLines formatEditedLines = new FormatEditedLines(); +// +// @Reference +// private EditorConfiguration configuration; +// +// @Override +// public IRegion[] getFormattingRegions(IDocument document) { +// var file = LSPEclipseUtils.getFile(document); +// if (file != null) { +// var editorOptions = configuration.options(file); +// if (editorOptions != null && editorOptions.formatOnSave()) { +// if (editorOptions.formatAllLines()) { +// return new IRegion[] { new Region(0, document.getLength()) }; +// } +// if (editorOptions.formatEditedLines()) { +// return formatEditedLines.getFormattingRegions(document); +// } +// } +// } +// return null; +// } +// +//} diff --git a/bundles/org.eclipse.cdt.lsp.clangd/src/org/eclipse/cdt/lsp/clangd/ClangdEnable.java b/bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/editor/LanguageServerEnable.java similarity index 63% rename from bundles/org.eclipse.cdt.lsp.clangd/src/org/eclipse/cdt/lsp/clangd/ClangdEnable.java rename to bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/editor/LanguageServerEnable.java index 7d0c1444..348710c1 100644 --- a/bundles/org.eclipse.cdt.lsp.clangd/src/org/eclipse/cdt/lsp/clangd/ClangdEnable.java +++ b/bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/editor/LanguageServerEnable.java @@ -9,21 +9,18 @@ * Contributors: * See git history *******************************************************************************/ -package org.eclipse.cdt.lsp.clangd; + +package org.eclipse.cdt.lsp.editor; import org.eclipse.core.resources.IProject; -/** - * Should be implemented by bundles as OSGi service to enable the Language - * Server and LSP based C/C++ Editor via project properties. - */ -public interface ClangdEnable { +public interface LanguageServerEnable { /** - * Checks whether clangd and the LSP based C/C++ Editor should be enabled for the given project. + * Checks whether the language server and the LSP based C/C++ Editor should be enabled for the given project. * The enable can be linked with certain project properties (e.g. project natures). * @param project - * @return true when clangd and LSP based editor should be enabled for the given project + * @return true when language server and LSP based editor should be enabled for the given project */ public boolean isEnabledFor(IProject project); } diff --git a/bundles/org.eclipse.cdt.lsp.clangd/src/org/eclipse/cdt/lsp/internal/clangd/ResolveProjectScope.java b/bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/editor/ResolveProjectScope.java similarity index 93% rename from bundles/org.eclipse.cdt.lsp.clangd/src/org/eclipse/cdt/lsp/internal/clangd/ResolveProjectScope.java rename to bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/editor/ResolveProjectScope.java index dd3a30db..9b413f3f 100644 --- a/bundles/org.eclipse.cdt.lsp.clangd/src/org/eclipse/cdt/lsp/internal/clangd/ResolveProjectScope.java +++ b/bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/editor/ResolveProjectScope.java @@ -11,11 +11,12 @@ * Contributors: * Alexander Fedorov (ArSysOp) - Initial API and implementation *******************************************************************************/ -package org.eclipse.cdt.lsp.internal.clangd; +package org.eclipse.cdt.lsp.editor; import java.util.Optional; import java.util.function.Function; +import org.eclipse.cdt.lsp.ResolveProject; import org.eclipse.core.resources.IWorkspace; import org.eclipse.core.resources.ProjectScope; diff --git a/bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/editor/SaveActionsConfigurationArea.java b/bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/editor/SaveActionsConfigurationArea.java new file mode 100644 index 00000000..d62541ed --- /dev/null +++ b/bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/editor/SaveActionsConfigurationArea.java @@ -0,0 +1,74 @@ +package org.eclipse.cdt.lsp.editor; + +import org.eclipse.core.runtime.preferences.IEclipsePreferences; +import org.eclipse.core.runtime.preferences.OsgiPreferenceMetadataStore; +import org.eclipse.jface.layout.GridLayoutFactory; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; + +public class SaveActionsConfigurationArea extends ConfigurationArea { + + private final Button format; + private final Button formatAll; + private final Button formatEdited; + + public SaveActionsConfigurationArea(Composite parent, EditorMetadata metadata, boolean isProjectScope) { + super(1); + Composite composite = new Composite(parent, SWT.NONE); + composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + composite.setLayout(GridLayoutFactory.fillDefaults().numColumns(columns).create()); + + this.format = createButton(metadata.formatOnSave(), composite, SWT.CHECK, 0); + this.formatAll = createButton(metadata.formatAllLines(), composite, SWT.RADIO, 15); + this.formatEdited = createButton(metadata.formatEditedLines(), composite, SWT.RADIO, 15); + + final SelectionAdapter formatListener = new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + var selection = format.getSelection(); + formatAll.setEnabled(selection); + formatEdited.setEnabled(selection); + } + }; + this.format.addSelectionListener(formatListener); + + final SelectionAdapter allListener = new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + formatEdited.setSelection(!formatAll.getSelection()); + } + }; + this.formatAll.addSelectionListener(allListener); + + final SelectionAdapter editedListener = new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + formatAll.setSelection(!formatEdited.getSelection()); + } + }; + this.formatEdited.addSelectionListener(editedListener); + } + + @Override + public void load(Object options, boolean enable) { + if (options instanceof EditorOptions editorOptions) { + format.setSelection(editorOptions.formatOnSave()); + formatAll.setSelection(editorOptions.formatAllLines()); + formatEdited.setSelection(editorOptions.formatEditedLines()); + format.setEnabled(enable); + formatAll.setEnabled(enable && format.getSelection()); + formatEdited.setEnabled(enable && format.getSelection()); + } + } + + @Override + public void store(IEclipsePreferences prefs) { + OsgiPreferenceMetadataStore store = new OsgiPreferenceMetadataStore(prefs); + buttons.entrySet().forEach(e -> store.save(e.getValue().getSelection(), e.getKey())); + } + +} diff --git a/bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/editor/SaveActionsPropertyPage.java b/bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/editor/SaveActionsPropertyPage.java new file mode 100644 index 00000000..15b98179 --- /dev/null +++ b/bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/editor/SaveActionsPropertyPage.java @@ -0,0 +1,18 @@ +package org.eclipse.cdt.lsp.editor; + +import org.eclipse.swt.widgets.Composite; + +public class SaveActionsPropertyPage extends EditorPropertyPage { + private final String id = "org.eclipse.cdt.lsp.editor.SaveActionsPreferencePage"; //$NON-NLS-1$ + + @Override + protected ConfigurationArea getConfigurationArea(Composite composite, boolean isProjectScope) { + return new SaveActionsConfigurationArea(composite, configuration.metadata(), isProjectScope); + } + + @Override + protected String getPreferenceId() { + return id; + } + +} diff --git a/bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/internal/messages/LspUiMessages.java b/bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/internal/messages/LspUiMessages.java index 1aea4bb1..f883a3ff 100644 --- a/bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/internal/messages/LspUiMessages.java +++ b/bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/internal/messages/LspUiMessages.java @@ -24,5 +24,16 @@ public class LspUiMessages extends NLS { } public static String NavigatorView_ErrorOnLoad; + public static String LspEditorConfigurationPage_enable_project_specific; + public static String LspEditorConfigurationPage_configure_ws_specific; + public static String LspEditorConfigurationPage_preferLspEditor; + public static String LspEditorConfigurationPage_preferLspEditor_description; + public static String LspEditorConfigurationPage_saveAction; + public static String SaveActionsPreferencePage_FormatSourceCode; + public static String SaveActionsPreferencePage_FormatSourceCode_description; + public static String SaveActionsPreferencePage_FormaAllLines; + public static String SaveActionsPreferencePage_FormaAllLines_description; + public static String SaveActionsPreferencePage_FormaEditedLines; + public static String SaveActionsPreferencePage_FormaEditedLines_description; } diff --git a/bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/internal/messages/LspUiMessages.properties b/bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/internal/messages/LspUiMessages.properties index b58e458b..72b8866e 100644 --- a/bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/internal/messages/LspUiMessages.properties +++ b/bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/internal/messages/LspUiMessages.properties @@ -12,3 +12,17 @@ ############################################################################### NavigatorView_ErrorOnLoad = Loading the symbols encountered an error; see the Error Log for more information + +LspEditorConfigurationPage_enable_project_specific=Enable project-specific settings +LspEditorConfigurationPage_configure_ws_specific=Configure Workspace Settings... +LspEditorConfigurationPage_preferLspEditor=Prefer C/C++ Editor (LSP) +LspEditorConfigurationPage_preferLspEditor_description=Prefer to use language server based C/C++ Editor instead of classic C/C++ Editor +LspEditorConfigurationPage_saveAction=Save Action + +SaveActionsPreferencePage_FormatSourceCode=Format source code +SaveActionsPreferencePage_FormatSourceCode_description=Formats source code when file is saved +SaveActionsPreferencePage_FormaAllLines=Format all lines +SaveActionsPreferencePage_FormaAllLines_description=Formats all source code lines +SaveActionsPreferencePage_FormaEditedLines=Format edited lines +SaveActionsPreferencePage_FormaEditedLines_description=Formats edited source code lines only + diff --git a/examples/org.eclipse.cdt.lsp.examples.preferences/META-INF/MANIFEST.MF b/examples/org.eclipse.cdt.lsp.examples.preferences/META-INF/MANIFEST.MF index e278d1bc..b4887be6 100644 --- a/examples/org.eclipse.cdt.lsp.examples.preferences/META-INF/MANIFEST.MF +++ b/examples/org.eclipse.cdt.lsp.examples.preferences/META-INF/MANIFEST.MF @@ -7,10 +7,11 @@ Bundle-Version: 1.0.0.qualifier Require-Bundle: org.eclipse.ui, org.eclipse.core.runtime, org.eclipse.cdt.lsp.clangd, - org.eclipse.core.resources + org.eclipse.core.resources, + org.eclipse.cdt.lsp Bundle-RequiredExecutionEnvironment: JavaSE-17 Automatic-Module-Name: org.eclipse.cdt.lsp.examples.preferences Bundle-ActivationPolicy: lazy -Service-Component: OSGI-INF/org.eclipse.cdt.lsp.examples.preferences.MyClangdOptionsDefaults.xml, +Service-Component: OSGI-INF/org.eclipse.cdt.lsp.examples.preferences.HidePreferLsp.xml, OSGI-INF/org.eclipse.cdt.lsp.examples.preferences.MyClangdEnable.xml, - OSGI-INF/org.eclipse.cdt.lsp.examples.preferences.HidePreferClangd.xml + OSGI-INF/org.eclipse.cdt.lsp.examples.preferences.MyClangdOptionsDefaults.xml diff --git a/examples/org.eclipse.cdt.lsp.examples.preferences/OSGI-INF/org.eclipse.cdt.lsp.examples.preferences.HidePreferClangd.xml b/examples/org.eclipse.cdt.lsp.examples.preferences/OSGI-INF/org.eclipse.cdt.lsp.examples.preferences.HidePreferLsp.xml similarity index 57% rename from examples/org.eclipse.cdt.lsp.examples.preferences/OSGI-INF/org.eclipse.cdt.lsp.examples.preferences.HidePreferClangd.xml rename to examples/org.eclipse.cdt.lsp.examples.preferences/OSGI-INF/org.eclipse.cdt.lsp.examples.preferences.HidePreferLsp.xml index e7e5e680..4bf2064d 100644 --- a/examples/org.eclipse.cdt.lsp.examples.preferences/OSGI-INF/org.eclipse.cdt.lsp.examples.preferences.HidePreferClangd.xml +++ b/examples/org.eclipse.cdt.lsp.examples.preferences/OSGI-INF/org.eclipse.cdt.lsp.examples.preferences.HidePreferLsp.xml @@ -1,8 +1,8 @@ - - + - + - + + \ No newline at end of file diff --git a/examples/org.eclipse.cdt.lsp.examples.preferences/OSGI-INF/org.eclipse.cdt.lsp.examples.preferences.MyClangdEnable.xml b/examples/org.eclipse.cdt.lsp.examples.preferences/OSGI-INF/org.eclipse.cdt.lsp.examples.preferences.MyClangdEnable.xml index aa32183b..e4641c00 100644 --- a/examples/org.eclipse.cdt.lsp.examples.preferences/OSGI-INF/org.eclipse.cdt.lsp.examples.preferences.MyClangdEnable.xml +++ b/examples/org.eclipse.cdt.lsp.examples.preferences/OSGI-INF/org.eclipse.cdt.lsp.examples.preferences.MyClangdEnable.xml @@ -1,7 +1,8 @@ + - + - + \ No newline at end of file diff --git a/examples/org.eclipse.cdt.lsp.examples.preferences/src/org/eclipse/cdt/lsp/examples/preferences/HidePreferLsp.java b/examples/org.eclipse.cdt.lsp.examples.preferences/src/org/eclipse/cdt/lsp/examples/preferences/HidePreferLsp.java new file mode 100644 index 00000000..7d30b74d --- /dev/null +++ b/examples/org.eclipse.cdt.lsp.examples.preferences/src/org/eclipse/cdt/lsp/examples/preferences/HidePreferLsp.java @@ -0,0 +1,14 @@ +package org.eclipse.cdt.lsp.examples.preferences; + +import org.eclipse.cdt.lsp.editor.ConfigurationVisibility; +import org.osgi.service.component.annotations.Component; + +@Component(property = { "service.ranking:Integer=100" }) +public class HidePreferLsp implements ConfigurationVisibility { + + @Override + public boolean showPreferLsp(boolean isProjectScope) { + return false; + } + +} diff --git a/examples/org.eclipse.cdt.lsp.examples.preferences/src/org/eclipse/cdt/lsp/examples/preferences/MyClangdEnable.java b/examples/org.eclipse.cdt.lsp.examples.preferences/src/org/eclipse/cdt/lsp/examples/preferences/MyClangdEnable.java index c9b91836..fb517df5 100644 --- a/examples/org.eclipse.cdt.lsp.examples.preferences/src/org/eclipse/cdt/lsp/examples/preferences/MyClangdEnable.java +++ b/examples/org.eclipse.cdt.lsp.examples.preferences/src/org/eclipse/cdt/lsp/examples/preferences/MyClangdEnable.java @@ -11,13 +11,13 @@ *******************************************************************************/ package org.eclipse.cdt.lsp.examples.preferences; -import org.eclipse.cdt.lsp.clangd.ClangdEnable; +import org.eclipse.cdt.lsp.editor.LanguageServerEnable; import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.CoreException; import org.osgi.service.component.annotations.Component; -@Component -public class MyClangdEnable implements ClangdEnable { +@Component(property = { "service.ranking:Integer=100" }) +public class MyClangdEnable implements LanguageServerEnable { @Override public boolean isEnabledFor(IProject project) { diff --git a/examples/org.eclipse.cdt.lsp.examples.preferences/src/org/eclipse/cdt/lsp/examples/preferences/MyClangdOptionsDefaults.java b/examples/org.eclipse.cdt.lsp.examples.preferences/src/org/eclipse/cdt/lsp/examples/preferences/MyClangdOptionsDefaults.java index c4c8ed82..2107068b 100644 --- a/examples/org.eclipse.cdt.lsp.examples.preferences/src/org/eclipse/cdt/lsp/examples/preferences/MyClangdOptionsDefaults.java +++ b/examples/org.eclipse.cdt.lsp.examples.preferences/src/org/eclipse/cdt/lsp/examples/preferences/MyClangdOptionsDefaults.java @@ -21,11 +21,6 @@ @Component(service = ClangdOptionsDefaults.class, property = { "service.ranking:Integer=100" }) public class MyClangdOptionsDefaults extends BuiltinClangdOptionsDefaults { - @Override - public boolean preferClangd() { - return true; - } - @Override public List additionalOptions() { return List.of("--header-insertion=never", "--default-config"); diff --git a/tests/org.eclipse.cdt.lsp.clangd.tests/src/org/eclipse/cdt/lsp/clangd/tests/TestUtils.java b/tests/org.eclipse.cdt.lsp.clangd.tests/src/org/eclipse/cdt/lsp/clangd/tests/TestUtils.java index 43c52def..fb48e742 100644 --- a/tests/org.eclipse.cdt.lsp.clangd.tests/src/org/eclipse/cdt/lsp/clangd/tests/TestUtils.java +++ b/tests/org.eclipse.cdt.lsp.clangd.tests/src/org/eclipse/cdt/lsp/clangd/tests/TestUtils.java @@ -18,7 +18,7 @@ import java.io.ByteArrayInputStream; import java.io.UnsupportedEncodingException; -import org.eclipse.cdt.lsp.clangd.ClangdConfiguration; +import org.eclipse.cdt.lsp.editor.EditorConfiguration; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProjectDescription; @@ -31,14 +31,14 @@ public final class TestUtils { public static void setLspPreferred(IProject project, boolean value) { - ServiceCaller.callOnce(TestUtils.class, ClangdConfiguration.class, // - cc -> cc.storage(project).save(value, cc.metadata().preferClangd())); + ServiceCaller.callOnce(TestUtils.class, EditorConfiguration.class, // + cc -> cc.storage(project).save(value, cc.metadata().preferLspEditor())); } public static boolean isLspPreferred(IProject project) { boolean[] enabled = new boolean[1]; - ServiceCaller.callOnce(TestUtils.class, ClangdConfiguration.class, // - c -> enabled[0] = c.options(project).preferClangd()); + ServiceCaller.callOnce(TestUtils.class, EditorConfiguration.class, // + c -> enabled[0] = c.options(project).preferLspEditor()); return enabled[0]; }