Skip to content
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

perf: add findResourceFor(URI) cache to SymbolsLabelProvider #907 #1172

Merged
merged 1 commit into from
Jan 13, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading