Skip to content

Commit

Permalink
Lazy load documents from files for the Symbols View in Eclipse
Browse files Browse the repository at this point in the history
  • Loading branch information
BoykoAlex committed Nov 26, 2024
1 parent 55bf699 commit 2d78997
Showing 1 changed file with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,16 @@ public static synchronized void disposeAll(IWorkbenchWindow[] workbenchWindows)
// 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) {
Expand All @@ -105,13 +110,22 @@ public void dispose() {
}
}

/**
* 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 + "]";
}

}
Expand Down

0 comments on commit 2d78997

Please sign in to comment.