From 2d78997a6bce9a2491715e92ea8816b62de80efb Mon Sep 17 00:00:00 2001 From: aboyko Date: Tue, 26 Nov 2024 16:35:54 -0500 Subject: [PATCH] Lazy load documents from files for the Symbols View in Eclipse --- .../gotosymbol/dialogs/SelectionTracker.java | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/eclipse-language-servers/org.springframework.tooling.ls.eclipse.gotosymbol/src/org/springframework/tooling/ls/eclipse/gotosymbol/dialogs/SelectionTracker.java b/eclipse-language-servers/org.springframework.tooling.ls.eclipse.gotosymbol/src/org/springframework/tooling/ls/eclipse/gotosymbol/dialogs/SelectionTracker.java index 2760dad31..926491499 100644 --- a/eclipse-language-servers/org.springframework.tooling.ls.eclipse.gotosymbol/src/org/springframework/tooling/ls/eclipse/gotosymbol/dialogs/SelectionTracker.java +++ b/eclipse-language-servers/org.springframework.tooling.ls.eclipse.gotosymbol/src/org/springframework/tooling/ls/eclipse/gotosymbol/dialogs/SelectionTracker.java @@ -77,11 +77,16 @@ public class SelectionTracker extends AbstractDisposable { // there is a selection change static class DocumentData implements Disposable { - public final IFileEditorInput input; - private final IDocumentProvider documentProvider; + private final IFile file; + + private IFileEditorInput input; + private IDocumentProvider documentProvider; public DocumentData(IFile file) { - super(); + this.file = file; + } + + private void init() { this.input = new FileEditorInput(file); this.documentProvider = DocumentProviderRegistry.getDefault().getDocumentProvider(input); if (this.documentProvider != null) { @@ -105,13 +110,22 @@ public class SelectionTracker extends AbstractDisposable { } } + /** + * May load the contents of the file into a document if there is no editor + * opened for the file therefore do not execute on the UI thread + * + * @return the document + */ public IDocument getDocument() { + if (input == null) { + init(); + } return this.documentProvider != null ? this.documentProvider.getDocument(input) : null; } @Override public String toString() { - return "DocumentData [file=" + input.getFile() + "]"; + return "DocumentData [file=" + file + "]"; } }