From 5fb185da1093422e0131ca3b732d002bf59fd115 Mon Sep 17 00:00:00 2001 From: Gesa HENTSCHKE Date: Tue, 8 Aug 2023 10:16:44 +0200 Subject: [PATCH] [#168] Use combo box for clangd Completion option fixes #168 --- .../editor/ClangdConfigurationArea.java | 42 +++++++++++++++++-- .../clangd/editor/LspEditorUiMessages.java | 3 ++ .../editor/LspEditorUiMessages.properties | 3 ++ 3 files changed, 44 insertions(+), 4 deletions(-) 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 3ee80645..c23fe902 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 @@ -39,6 +39,7 @@ import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.FileDialog; @@ -53,7 +54,7 @@ public final class ClangdConfigurationArea { private final Button prefer; private final Text path; private final Button tidy; - private final Text completion; + private final Combo completion; private final Button index; private final Button pretty; private final Text driver; @@ -64,13 +65,25 @@ public final class ClangdConfigurationArea { private final Map, Button> buttons; private final Map, Text> texts; + private final Map, Combo> combos; private final List> listeners; + private final static String[] completionOptions = { "detailed", "bundled", "" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + private final static String[] completionsKeys = { LspEditorUiMessages.LspEditorPreferencePage_completion_detailed, + LspEditorUiMessages.LspEditorPreferencePage_completion_bundled, + LspEditorUiMessages.LspEditorPreferencePage_completion_default }; + 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<>(); this.listeners = new ArrayList<>(); + this.completions = new HashMap<>(); + for (int i = 0; i < completionsKeys.length; i++) { + completions.put(completionsKeys[i], completionOptions[i]); + } Composite composite = new Composite(parent, SWT.NONE); composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); composite.setLayout(GridLayoutFactory.fillDefaults().numColumns(columns).create()); @@ -92,7 +105,7 @@ public void widgetSelected(SelectionEvent e) { this.path = createFileSelector(metadata.clangdPath(), group, this::selectClangdExecutable); this.tidy = createCheckbox(metadata.useTidy(), group); this.index = createCheckbox(metadata.useBackgroundIndex(), group); - this.completion = createText(metadata.completionStyle(), group, false); + this.completion = createCombo(metadata.completionStyle(), group, completionsKeys); this.pretty = createCheckbox(metadata.prettyPrint(), group); this.driver = createText(metadata.queryDriver(), group, false); this.additional = createText(metadata.additionalOptions(), group, true); @@ -162,6 +175,21 @@ private Text createText(PreferenceMetadata meta, Composite composite, bo return text; } + private Combo createCombo(PreferenceMetadata meta, Composite parent, String[] items) { + Label label = new Label(parent, SWT.NONE); + label.setText(meta.name()); + label.setToolTipText(meta.description()); + label.setLayoutData(GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).create()); + + Combo combo = new Combo(parent, SWT.READ_ONLY); + combo.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING)); + combo.setItems(items); + combo.setData(meta); + combos.put(meta, combo); + + return combo; + } + private void selectClangdExecutable(SelectionEvent e) { String selected = selectFile(path.getText()); if (selected != null) { @@ -200,7 +228,11 @@ void load(ClangdOptions options) { path.setText(options.clangdPath()); tidy.setSelection(options.useTidy()); index.setSelection(options.useBackgroundIndex()); - completion.setText(options.completionStyle()); + for (int i = 0; i < completionOptions.length; i++) { + if (completionOptions[i].equals(options.completionStyle())) { + completion.select(i); + } + } pretty.setSelection(options.prettyPrint()); driver.setText(options.queryDriver()); additional.setText(options.additionalOptions().stream().collect(Collectors.joining(System.lineSeparator()))); @@ -210,12 +242,14 @@ void store(IEclipsePreferences prefs) { OsgiPreferenceMetadataStore store = new OsgiPreferenceMetadataStore(prefs); buttons.entrySet().forEach(e -> store.save(e.getValue().getSelection(), e.getKey())); texts.entrySet().forEach(e -> store.save(e.getValue().getText(), e.getKey())); + combos.entrySet().forEach(e -> store.save(completions.get(e.getValue().getText()), e.getKey())); } void dispose() { listeners.clear(); buttons.clear(); texts.clear(); + combos.clear(); } public boolean optionsChanged(ClangdOptions options) { @@ -224,7 +258,7 @@ public boolean optionsChanged(ClangdOptions options) { } return !options.clangdPath().equals(path.getText()) || options.useTidy() != tidy.getSelection() || options.useBackgroundIndex() != index.getSelection() - || !options.completionStyle().equals(completion.getText()) + || !options.completionStyle().equals(completions.get(completion.getText())) || options.prettyPrint() != pretty.getSelection() || !options.queryDriver().equals(driver.getText()) || !options.additionalOptions().stream().collect(Collectors.joining(System.lineSeparator())) .equals(additional.getText()); 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 7ab24f7a..8cafa906 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 @@ -35,6 +35,9 @@ public class LspEditorUiMessages extends NLS { public static String LspEditorPreferencePage_clangd_options_label; public static String LspEditorPreferencePage_enable_project_specific; public static String LspEditorPreferencePage_configure_ws_specific; + public static String LspEditorPreferencePage_completion_detailed; + public static String LspEditorPreferencePage_completion_bundled; + public static String LspEditorPreferencePage_completion_default; public static String LspEditorPropertiesPage_projectSpecificSettings; 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 78b091a5..92e4ac36 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 @@ -23,6 +23,9 @@ LspEditorPreferencePage_restart_button=Restart LspEditorPreferencePage_clangd_options_label=clangd options LspEditorPreferencePage_enable_project_specific=Enable project-specific settings LspEditorPreferencePage_configure_ws_specific=Configure Workspace Settings... +LspEditorPreferencePage_completion_detailed=Detailed +LspEditorPreferencePage_completion_bundled=Bundled +LspEditorPreferencePage_completion_default=Default LspEditorPropertiesPage_projectSpecificSettings=Project specific editor settings