Skip to content

Commit

Permalink
Fix symbols view in Eclipse for "File" mode
Browse files Browse the repository at this point in the history
  • Loading branch information
BoykoAlex committed Nov 26, 2024
1 parent 01c4cf9 commit 55bf699
Showing 1 changed file with 16 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2017, 2023 Pivotal, Inc.
* Copyright (c) 2017, 2024 Pivotal, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
Expand All @@ -13,6 +13,7 @@
import java.net.URI;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.function.Supplier;
import java.util.stream.Collectors;

import org.eclipse.jface.text.IDocument;
Expand All @@ -39,20 +40,21 @@
@SuppressWarnings("restriction")
public class InFileSymbolsProvider implements SymbolsProvider {

private IDocument doc;
private Supplier<IDocument> doc;

public InFileSymbolsProvider(IDocument doc) {
public InFileSymbolsProvider(Supplier<IDocument> doc) {
super();
this.doc = doc;
}

@Override
public List<SymbolContainer> fetchFor(String query) throws Exception {
if (doc != null) {
DocumentSymbolParams params = new DocumentSymbolParams(new TextDocumentIdentifier(LSPEclipseUtils.toUri(doc).toASCIIString()));
final IDocument document = doc.get();
if (document != null) {
DocumentSymbolParams params = new DocumentSymbolParams(new TextDocumentIdentifier(LSPEclipseUtils.toUri(document).toASCIIString()));

CompletableFuture<List<List<Either<SymbolInformation, DocumentSymbol>>>> symbolsFuture = LanguageServers
.forDocument(doc)
.forDocument(document)
.withFilter(capabilities -> LSPEclipseUtils.hasCapability(capabilities.getDocumentSymbolProvider()))
.collectAll(ls -> ls.getTextDocumentService().documentSymbol(params));

Expand All @@ -67,24 +69,25 @@ public List<SymbolContainer> fetchFor(String query) throws Exception {
}

public static SymbolsProvider createFor(LiveExpression<DocumentData> documentData) {
DocumentData data = documentData.getValue();
return new InFileSymbolsProvider(data == null ? null : data.getDocument());
Supplier<IDocument> supllier = () -> documentData == null ? null : documentData.getValue().getDocument();
return new InFileSymbolsProvider(supllier);
}

public static SymbolsProvider createFor(ITextEditor textEditor) {
IDocument document = LSPEclipseUtils.getDocument(textEditor);
return new InFileSymbolsProvider(document);
Supplier<IDocument> supplier = () -> LSPEclipseUtils.getDocument(textEditor);
return new InFileSymbolsProvider(supplier);
}

@Override
public String getName() {
return "Symbols in File";
}

@Override
public boolean fromFile(SymbolContainer symbol) {
if (symbol != null) {
URI uri = LSPEclipseUtils.toUri(doc);
IDocument document = doc.get();
if (symbol != null && document != null) {
URI uri = LSPEclipseUtils.toUri(document);
if (symbol.isSymbolInformation() && symbol.getSymbolInformation().getLocation() != null) {
String symbolUri = symbol.getSymbolInformation().getLocation().getUri();

Expand Down

0 comments on commit 55bf699

Please sign in to comment.