From 55bf699c4f839f11968e8f956608b8f018413299 Mon Sep 17 00:00:00 2001 From: aboyko Date: Tue, 26 Nov 2024 15:18:04 -0500 Subject: [PATCH] Fix symbols view in Eclipse for "File" mode --- .../dialogs/InFileSymbolsProvider.java | 29 ++++++++++--------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/eclipse-language-servers/org.springframework.tooling.ls.eclipse.gotosymbol/src/org/springframework/tooling/ls/eclipse/gotosymbol/dialogs/InFileSymbolsProvider.java b/eclipse-language-servers/org.springframework.tooling.ls.eclipse.gotosymbol/src/org/springframework/tooling/ls/eclipse/gotosymbol/dialogs/InFileSymbolsProvider.java index 28e515669..f41bfef50 100644 --- a/eclipse-language-servers/org.springframework.tooling.ls.eclipse.gotosymbol/src/org/springframework/tooling/ls/eclipse/gotosymbol/dialogs/InFileSymbolsProvider.java +++ b/eclipse-language-servers/org.springframework.tooling.ls.eclipse.gotosymbol/src/org/springframework/tooling/ls/eclipse/gotosymbol/dialogs/InFileSymbolsProvider.java @@ -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 @@ -13,6 +13,7 @@ package org.springframework.tooling.ls.eclipse.gotosymbol.dialogs; 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; @@ -39,20 +40,21 @@ import com.google.common.collect.ImmutableList; @SuppressWarnings("restriction") public class InFileSymbolsProvider implements SymbolsProvider { - private IDocument doc; + private Supplier doc; - public InFileSymbolsProvider(IDocument doc) { + public InFileSymbolsProvider(Supplier doc) { super(); this.doc = doc; } @Override public List 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>>> symbolsFuture = LanguageServers - .forDocument(doc) + .forDocument(document) .withFilter(capabilities -> LSPEclipseUtils.hasCapability(capabilities.getDocumentSymbolProvider())) .collectAll(ls -> ls.getTextDocumentService().documentSymbol(params)); @@ -67,15 +69,15 @@ public class InFileSymbolsProvider implements SymbolsProvider { } public static SymbolsProvider createFor(LiveExpression documentData) { - DocumentData data = documentData.getValue(); - return new InFileSymbolsProvider(data == null ? null : data.getDocument()); + Supplier 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 supplier = () -> LSPEclipseUtils.getDocument(textEditor); + return new InFileSymbolsProvider(supplier); } - + @Override public String getName() { return "Symbols in File"; @@ -83,8 +85,9 @@ public class InFileSymbolsProvider implements SymbolsProvider { @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();