-
Notifications
You must be signed in to change notification settings - Fork 12
Customize C/C++ destructor symbol overlay icons in outline view (fix #608) #609
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
8 commits
Select commit
Hold shift + click to select a range
2240bfc
Customize C/C++ destructor symbol overlay icons in outline view
travkin79 6068f65
Increase min. LSP4E version because of required LSP4E extension point
travkin79 0ceb077
Add test case for custom symbol icon provider
travkin79 0ca709a
Do not register custom icon provider for C
travkin79 eac1c69
Cache destructor overlay icon
travkin79 4e23008
Remove unused method
travkin79 e5f126f
Add given, when, then comments to test
travkin79 d3664f4
Increase min. LSP4E version in order to include LSP4E bug fix
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
75 changes: 75 additions & 0 deletions
75
....lsp.test/src/org/eclipse/cdt/lsp/test/internal/ui/navigator/CSymbolIconProviderTest.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,75 @@ | ||
| /******************************************************************************* | ||
| * Copyright (c) 2026 Advantest 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: | ||
| * Dietrich Travkin (Solunar GmbH) - initial implementation | ||
| *******************************************************************************/ | ||
| package org.eclipse.cdt.lsp.test.internal.ui.navigator; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
|
||
| import java.net.URI; | ||
| import java.util.List; | ||
|
|
||
| import org.eclipse.cdt.lsp.plugin.LspPlugin; | ||
| import org.eclipse.jface.resource.ImageDescriptor; | ||
| import org.eclipse.lsp4e.outline.SymbolsLabelProvider; | ||
| import org.eclipse.lsp4e.outline.SymbolsModel.DocumentSymbolWithURI; | ||
| import org.eclipse.lsp4e.ui.LSPImages; | ||
| import org.eclipse.lsp4j.DocumentSymbol; | ||
| import org.eclipse.lsp4j.SymbolKind; | ||
| import org.eclipse.lsp4j.SymbolTag; | ||
| import org.eclipse.swt.graphics.Image; | ||
| import org.junit.jupiter.params.ParameterizedTest; | ||
| import org.junit.jupiter.params.provider.CsvSource; | ||
|
|
||
| public class CSymbolIconProviderTest { | ||
|
|
||
| @ParameterizedTest | ||
| @CsvSource({ | ||
| // @formatter:off | ||
| "~SomeType, true", | ||
| "SomeType, false", | ||
| "SomeType::~SomeType, true", | ||
| "SomeType::SomeType, false" | ||
| // @formatter:on | ||
| }) | ||
| public void testCustomDestructorOverlayIconUsed(String symbolName, boolean isDestructor) { | ||
| // GIVEN a document symbol representing a public destructor or constructor | ||
| DocumentSymbol documentSymbol = new DocumentSymbol(); | ||
|
|
||
| // LSP doesn't know destructors, they are modelled as constructors with a ~ in their name | ||
| documentSymbol.setKind(SymbolKind.Constructor); | ||
|
|
||
| documentSymbol.setName(symbolName); | ||
| documentSymbol.setTags(List.of(SymbolTag.Public)); | ||
| DocumentSymbolWithURI symbol = new DocumentSymbolWithURI(documentSymbol, | ||
| URI.create("file:///home/username/some/path/SomeType.cpp")); | ||
|
|
||
| // WHEN we get an image with overlay icons from the label provider for our destructor/constructor symbol | ||
| SymbolsLabelProvider labelProvider = new SymbolsLabelProvider(); | ||
| Image actualImage = labelProvider.getImage(symbol); | ||
|
|
||
| // THEN we expect the image to represent a public method (base image) | ||
| // with a destructor/constructor overlay icon in the top-right corner | ||
| ImageDescriptor topRightOverlay; | ||
| if (isDestructor) { | ||
| topRightOverlay = LspPlugin.getDefault().getImageDescriptor(LspPlugin.IMG_OVR_DESTRUCTOR); | ||
| } else { | ||
| topRightOverlay = LSPImages.getImageDescriptor(LSPImages.IMG_OVR_CONSTRUCTOR); | ||
| } | ||
| Image expectedImage = LSPImages.getImageWithOverlays( | ||
| // base image for a public method | ||
| LSPImages.IMG_METHOD_VIS_PUBLIC, | ||
| // no overlay icons except of our destructor overlay in the top right corner | ||
| null, topRightOverlay, null, null, null); | ||
|
|
||
| assertEquals(expectedImage, actualImage); | ||
| } | ||
|
|
||
| } | ||
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
53 changes: 53 additions & 0 deletions
53
...rg.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/internal/ui/navigator/CSymbolIconProvider.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,53 @@ | ||
| /******************************************************************************* | ||
| * Copyright (c) 2026 Advantest 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: | ||
| * Dietrich Travkin (Solunar GmbH) - initial implementation | ||
| *******************************************************************************/ | ||
| package org.eclipse.cdt.lsp.internal.ui.navigator; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import org.eclipse.cdt.lsp.plugin.LspPlugin; | ||
| import org.eclipse.jface.resource.ImageDescriptor; | ||
| import org.eclipse.lsp4e.ui.SymbolIconProvider; | ||
| import org.eclipse.lsp4j.SymbolKind; | ||
| import org.eclipse.lsp4j.SymbolTag; | ||
|
|
||
| public class CSymbolIconProvider extends SymbolIconProvider { | ||
|
ghentschke marked this conversation as resolved.
|
||
|
|
||
| private static ImageDescriptor IMG_DESTRUCTOR_OVERLAY = null; | ||
|
|
||
| private ImageDescriptor getDestructorOverlay() { | ||
| if (IMG_DESTRUCTOR_OVERLAY == null) { | ||
| IMG_DESTRUCTOR_OVERLAY = LspPlugin.getDefault().getImageDescriptor(LspPlugin.IMG_OVR_DESTRUCTOR); | ||
| } | ||
| return IMG_DESTRUCTOR_OVERLAY; | ||
| } | ||
|
|
||
| @Override | ||
| protected Overlays getOverlaysFor(final SymbolKind symbolKind, final List<SymbolTag> symbolTags, int severity, | ||
| Object symbol) { | ||
|
|
||
| final var overlays = super.getOverlaysFor(symbolKind, symbolTags, severity, symbol); | ||
|
|
||
| if (symbolKind == SymbolKind.Constructor) { | ||
| String name = getName(symbol); | ||
| // if the symbol's name represents a destructor, e.g. is named MyType::~MyType | ||
| if (name != null && name.contains("~")) { //$NON-NLS-1$ | ||
| // then replace the constructor overlay with a destructor overlay | ||
| ImageDescriptor destructorOverlayDescriptor = getDestructorOverlay(); | ||
| return new Overlays(overlays.topLeft, destructorOverlayDescriptor, overlays.bottomLeft, | ||
| overlays.bottomRight, overlays.underlay); | ||
| } | ||
| } | ||
|
|
||
| return overlays; | ||
| } | ||
|
|
||
| } | ||
Oops, something went wrong.
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.