-
Notifications
You must be signed in to change notification settings - Fork 65
Add content filtering to outline view based on SymbolKind (fix issue #254) #1049
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
2c145b3
[#254] Initial implementation of outline filters
travkin79 ceb557e
[#254] Add menu item icons
travkin79 8b2e728
[#254] Add sorting of menu items
travkin79 49eee0c
[#254] Extend documentation
travkin79 4073214
[#254] Rename class
travkin79 206d0b9
Simplify and clean-up code as suggested by @rubenporras
travkin79 e096c41
Further simplify code
travkin79 6d2ab14
Fix null type mismatch
travkin79 33163ab
Remove unnecessary "this." prefixes
travkin79 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
...eclipse.lsp4e/src/org/eclipse/lsp4e/outline/OutlineViewHideSymbolKindMenuContributor.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 Advantest Europe GmbH. All rights reserved. | ||
* 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: | ||
* Dietrich Travkin (Solunar GmbH) - initial implementation of outline contents filtering (issue #254) | ||
*******************************************************************************/ | ||
package org.eclipse.lsp4e.outline; | ||
|
||
import java.util.Arrays; | ||
import java.util.Comparator; | ||
|
||
import org.eclipse.core.runtime.preferences.IEclipsePreferences; | ||
import org.eclipse.core.runtime.preferences.InstanceScope; | ||
import org.eclipse.jface.action.Action; | ||
import org.eclipse.jface.action.ActionContributionItem; | ||
import org.eclipse.jface.action.IAction; | ||
import org.eclipse.jface.action.IContributionItem; | ||
import org.eclipse.jface.resource.ImageDescriptor; | ||
import org.eclipse.lsp4e.LanguageServerPlugin; | ||
import org.eclipse.lsp4e.ui.LSPImages; | ||
import org.eclipse.lsp4j.SymbolKind; | ||
import org.eclipse.swt.graphics.Image; | ||
import org.eclipse.ui.actions.CompoundContributionItem; | ||
|
||
public class OutlineViewHideSymbolKindMenuContributor extends CompoundContributionItem { | ||
|
||
@Override | ||
protected IContributionItem[] getContributionItems() { | ||
return Arrays.stream(SymbolKind.values()) | ||
.sorted(new Comparator<SymbolKind>() { | ||
|
||
@Override | ||
public int compare(SymbolKind sk1, SymbolKind sk2) { | ||
return sk1.name().compareTo(sk2.name()); | ||
} | ||
|
||
}) | ||
.map(kind -> createHideSymbolKindContributionItem(kind)) | ||
.toArray(IContributionItem[]::new); | ||
} | ||
|
||
private IContributionItem createHideSymbolKindContributionItem(SymbolKind kind) { | ||
return new ActionContributionItem(new HideSymbolKindAction(kind)); | ||
} | ||
|
||
static boolean isHideSymbolKind(SymbolKind kind) { | ||
IEclipsePreferences preferences = InstanceScope.INSTANCE.getNode(LanguageServerPlugin.PLUGIN_ID); | ||
return preferences.getBoolean(CNFOutlinePage.HIDE_DOCUMENT_SYMBOL_KIND_PREFERENCE_PREFIX + kind.name(), false); | ||
} | ||
|
||
static boolean toggleHideSymbolKind(SymbolKind kind) { | ||
IEclipsePreferences preferences = InstanceScope.INSTANCE.getNode(LanguageServerPlugin.PLUGIN_ID); | ||
boolean oldValue = isHideSymbolKind(kind); | ||
|
||
preferences.putBoolean(CNFOutlinePage.HIDE_DOCUMENT_SYMBOL_KIND_PREFERENCE_PREFIX + kind.name(), !oldValue); | ||
|
||
return !oldValue; | ||
} | ||
|
||
private static class HideSymbolKindAction extends Action { | ||
private final SymbolKind kind; | ||
|
||
HideSymbolKindAction(SymbolKind kind) { | ||
super(kind.name(), IAction.AS_CHECK_BOX); | ||
this.kind = kind; | ||
setChecked(isHideSymbolKind(kind)); | ||
|
||
Image img = LSPImages.imageFromSymbolKind(kind); | ||
if (img != null) { | ||
setImageDescriptor(ImageDescriptor.createFromImage(img)); | ||
} | ||
} | ||
|
||
@Override | ||
public void run() { | ||
boolean checkedState = toggleHideSymbolKind(kind); | ||
setChecked(checkedState); | ||
} | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.