Skip to content

Commit

Permalink
perf: add findResourceFor(URI) cache to SymbolsLabelProvider #907
Browse files Browse the repository at this point in the history
  • Loading branch information
sebthom committed Jan 13, 2025
1 parent 5e38b95 commit 308d167
Showing 1 changed file with 18 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
*******************************************************************************/
package org.eclipse.lsp4e.outline;

import static org.eclipse.lsp4e.LSPEclipseUtils.findResourceFor;
import static org.eclipse.lsp4e.internal.NullSafetyHelper.castNullable;

import java.net.URI;
Expand Down Expand Up @@ -91,6 +92,7 @@ public class SymbolsLabelProvider extends LabelProvider
* value: array of images decorated with marker for severity (index + 1)
*/
private final Map<Image, Image[]> overlays = new HashMap<>();
private final Map<Object /*URI|String*/, IResource> resourceCache = new HashMap<>();

private final boolean showLocation;

Expand Down Expand Up @@ -119,7 +121,7 @@ public void dispose() {

@Override
public @Nullable Image getImage(@Nullable Object element) {
if (element == null){
if (element == null) {
return null;
}
if (element instanceof PendingUpdateAdapter) {
Expand All @@ -131,28 +133,26 @@ public void dispose() {
if (element instanceof Either<?, ?> either) {
element = either.get();
}
Image res = null;

Image image = null;
IResource file = null;
if (element instanceof SymbolInformation info) {
res = LSPImages.imageFromSymbolKind(info.getKind());
image = LSPImages.imageFromSymbolKind(info.getKind());
file = resourceCache.computeIfAbsent(info.getLocation().getUri(), uri -> findResourceFor((String) uri));
} else if (element instanceof WorkspaceSymbol symbol) {
res = LSPImages.imageFromSymbolKind(symbol.getKind());
image = LSPImages.imageFromSymbolKind(symbol.getKind());
file = resourceCache.computeIfAbsent(getUri(symbol), uri -> findResourceFor((String) uri));
} else if (element instanceof DocumentSymbol symbol) {
res = LSPImages.imageFromSymbolKind(symbol.getKind());
image = LSPImages.imageFromSymbolKind(symbol.getKind());
} else if (element instanceof DocumentSymbolWithURI symbolWithURI) {
res = LSPImages.imageFromSymbolKind(symbolWithURI.symbol.getKind());
}
IResource file = null;
if (element instanceof SymbolInformation symbol) {
file = LSPEclipseUtils.findResourceFor(symbol.getLocation().getUri());
} else if (element instanceof WorkspaceSymbol symbol) {
file = LSPEclipseUtils.findResourceFor(getUri(symbol));
} else if (element instanceof DocumentSymbolWithURI symbolWithURI) {
file = LSPEclipseUtils.findResourceFor(symbolWithURI.uri);
image = LSPImages.imageFromSymbolKind(symbolWithURI.symbol.getKind());
file = resourceCache.computeIfAbsent(symbolWithURI.uri, uri -> findResourceFor((URI) uri));
}

/*
* Implementation node: for problem decoration,m aybe consider using a ILabelDecorator/IDelayedLabelDecorator?
* Implementation node: for problem decoration, maybe consider using a ILabelDecorator/IDelayedLabelDecorator?
*/
if (file != null && res != null) {
if (file != null && image != null) {
Range range = null;
if (element instanceof SymbolInformation symbol) {
range = symbol.getLocation().getRange();
Expand All @@ -173,15 +173,15 @@ public void dispose() {
if (doc != null) {
int maxSeverity = getMaxSeverity(file, doc, range);
if (maxSeverity > IMarker.SEVERITY_INFO) {
return getOverlay(res, maxSeverity);
return getOverlay(image, maxSeverity);
}
}
} catch (CoreException | BadLocationException e) {
LanguageServerPlugin.logError(e);
}
}
}
return res;
return image;
}

protected int getMaxSeverity(IResource resource, IDocument doc, Range range)
Expand Down

0 comments on commit 308d167

Please sign in to comment.