11/*******************************************************************************
2- * Copyright (c) 2017, 2023 Pivotal, Inc.
2+ * Copyright (c) 2017, 2024 Pivotal, Inc.
33 * All rights reserved. This program and the accompanying materials
44 * are made available under the terms of the Eclipse Public License v1.0
55 * which accompanies this distribution, and is available at
1313import java .net .URI ;
1414import java .util .List ;
1515import java .util .concurrent .CompletableFuture ;
16+ import java .util .function .Supplier ;
1617import java .util .stream .Collectors ;
1718
1819import org .eclipse .jface .text .IDocument ;
3940@ SuppressWarnings ("restriction" )
4041public class InFileSymbolsProvider implements SymbolsProvider {
4142
42- private IDocument doc ;
43+ private Supplier < IDocument > doc ;
4344
44- public InFileSymbolsProvider (IDocument doc ) {
45+ public InFileSymbolsProvider (Supplier < IDocument > doc ) {
4546 super ();
4647 this .doc = doc ;
4748 }
4849
4950 @ Override
5051 public List <SymbolContainer > fetchFor (String query ) throws Exception {
51- if (doc != null ) {
52- DocumentSymbolParams params = new DocumentSymbolParams (new TextDocumentIdentifier (LSPEclipseUtils .toUri (doc ).toASCIIString ()));
52+ final IDocument document = doc .get ();
53+ if (document != null ) {
54+ DocumentSymbolParams params = new DocumentSymbolParams (new TextDocumentIdentifier (LSPEclipseUtils .toUri (document ).toASCIIString ()));
5355
5456 CompletableFuture <List <List <Either <SymbolInformation , DocumentSymbol >>>> symbolsFuture = LanguageServers
55- .forDocument (doc )
57+ .forDocument (document )
5658 .withFilter (capabilities -> LSPEclipseUtils .hasCapability (capabilities .getDocumentSymbolProvider ()))
5759 .collectAll (ls -> ls .getTextDocumentService ().documentSymbol (params ));
5860
@@ -67,24 +69,25 @@ public List<SymbolContainer> fetchFor(String query) throws Exception {
6769 }
6870
6971 public static SymbolsProvider createFor (LiveExpression <DocumentData > documentData ) {
70- DocumentData data = documentData .getValue ();
71- return new InFileSymbolsProvider (data == null ? null : data . getDocument () );
72+ Supplier < IDocument > supllier = () -> documentData == null ? null : documentData .getValue (). getDocument ();
73+ return new InFileSymbolsProvider (supllier );
7274 }
7375
7476 public static SymbolsProvider createFor (ITextEditor textEditor ) {
75- IDocument document = LSPEclipseUtils .getDocument (textEditor );
76- return new InFileSymbolsProvider (document );
77+ Supplier < IDocument > supplier = () -> LSPEclipseUtils .getDocument (textEditor );
78+ return new InFileSymbolsProvider (supplier );
7779 }
78-
80+
7981 @ Override
8082 public String getName () {
8183 return "Symbols in File" ;
8284 }
8385
8486 @ Override
8587 public boolean fromFile (SymbolContainer symbol ) {
86- if (symbol != null ) {
87- URI uri = LSPEclipseUtils .toUri (doc );
88+ IDocument document = doc .get ();
89+ if (symbol != null && document != null ) {
90+ URI uri = LSPEclipseUtils .toUri (document );
8891 if (symbol .isSymbolInformation () && symbol .getSymbolInformation ().getLocation () != null ) {
8992 String symbolUri = symbol .getSymbolInformation ().getLocation ().getUri ();
9093
0 commit comments