From 206d0b9c765617da73e07a09fb7201ee04069527 Mon Sep 17 00:00:00 2001 From: Dietrich Travkin Date: Tue, 13 Aug 2024 14:30:48 +0200 Subject: [PATCH] Simplify and clean-up code as suggested by @rubenporras --- .../outline/LSSymbolsContentProvider.java | 38 +++++-------------- ...lineViewHideSymbolKindMenuContributor.java | 2 +- 2 files changed, 11 insertions(+), 29 deletions(-) diff --git a/org.eclipse.lsp4e/src/org/eclipse/lsp4e/outline/LSSymbolsContentProvider.java b/org.eclipse.lsp4e/src/org/eclipse/lsp4e/outline/LSSymbolsContentProvider.java index d9dd05456..28909e541 100644 --- a/org.eclipse.lsp4e/src/org/eclipse/lsp4e/outline/LSSymbolsContentProvider.java +++ b/org.eclipse.lsp4e/src/org/eclipse/lsp4e/outline/LSSymbolsContentProvider.java @@ -164,11 +164,8 @@ public void uninstall() { @Override public void preferenceChange(PreferenceChangeEvent event) { - if (viewer == null || outlineViewerInput == null) { - return; - } - - if (event.getKey().startsWith(CNFOutlinePage.HIDE_DOCUMENT_SYMBOL_KIND_PREFERENCE_PREFIX)) { + if (viewer != null + && event.getKey().startsWith(CNFOutlinePage.HIDE_DOCUMENT_SYMBOL_KIND_PREFERENCE_PREFIX)) { viewer.getControl().getDisplay().asyncExec(() -> { if(viewer.getTree().isDisposed()) { return; @@ -341,33 +338,18 @@ public Object[] getChildren(Object parentElement) { .toArray(Object[]::new); } - /** - * Decide whether to hide the given element or not. - * Default implementation hides elements depending on a preference - * that determines which {@link SymbolKind}s - * (property in {@link DocumentSymbol}, {@link DocumentSymbolWithURI}s, and {@link SymbolInformation}) - * are to be hidden in the outline view. - * Sub-classes may override this method to add language-specific filtering. - * - * @param element an outline view contents element to be checked - * @return true if the given element is not to be shown in the outline view - */ - protected boolean hideElement(Object element) { + private boolean hideElement(Object element) { SymbolKind kind = null; - if (element instanceof DocumentSymbol) { - kind = ((DocumentSymbol) element).getKind(); - } else if (element instanceof DocumentSymbolWithURI) { - kind = ((DocumentSymbolWithURI) element).symbol.getKind(); - } else if (element instanceof SymbolInformation) { - kind = ((SymbolInformation) element).getKind(); - } - - if (OutlineViewHideSymbolKindMenuContributor.isHideSymbolKind(kind)) { - return true; + if (element instanceof DocumentSymbol documentSymbol) { + kind = documentSymbol.getKind(); + } else if (element instanceof DocumentSymbolWithURI documentSymbolWithURI) { + kind = documentSymbolWithURI.symbol.getKind(); + } else if (element instanceof SymbolInformation symbolInformation) { + kind = symbolInformation.getKind(); } - return false; + return OutlineViewHideSymbolKindMenuContributor.isHideSymbolKind(kind); } @Override diff --git a/org.eclipse.lsp4e/src/org/eclipse/lsp4e/outline/OutlineViewHideSymbolKindMenuContributor.java b/org.eclipse.lsp4e/src/org/eclipse/lsp4e/outline/OutlineViewHideSymbolKindMenuContributor.java index f930ee2d8..9abb46a61 100644 --- a/org.eclipse.lsp4e/src/org/eclipse/lsp4e/outline/OutlineViewHideSymbolKindMenuContributor.java +++ b/org.eclipse.lsp4e/src/org/eclipse/lsp4e/outline/OutlineViewHideSymbolKindMenuContributor.java @@ -36,7 +36,7 @@ protected IContributionItem[] getContributionItems() { @Override public int compare(SymbolKind sk1, SymbolKind sk2) { - return sk1.name().compareToIgnoreCase(sk2.name()); + return sk1.name().compareTo(sk2.name()); } })