Skip to content

Commit 55bf699

Browse files
committed
Fix symbols view in Eclipse for "File" mode
1 parent 01c4cf9 commit 55bf699

File tree

1 file changed

+16
-13
lines changed
  • eclipse-language-servers/org.springframework.tooling.ls.eclipse.gotosymbol/src/org/springframework/tooling/ls/eclipse/gotosymbol/dialogs

1 file changed

+16
-13
lines changed

eclipse-language-servers/org.springframework.tooling.ls.eclipse.gotosymbol/src/org/springframework/tooling/ls/eclipse/gotosymbol/dialogs/InFileSymbolsProvider.java

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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
@@ -13,6 +13,7 @@
1313
import java.net.URI;
1414
import java.util.List;
1515
import java.util.concurrent.CompletableFuture;
16+
import java.util.function.Supplier;
1617
import java.util.stream.Collectors;
1718

1819
import org.eclipse.jface.text.IDocument;
@@ -39,20 +40,21 @@
3940
@SuppressWarnings("restriction")
4041
public 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

Comments
 (0)