avoid blocking the UI thread while waiting for lsp4e coming back with document infos
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2018 Pivotal, Inc.
|
||||
* Copyright (c) 2018, 2019 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
|
||||
@@ -72,22 +72,29 @@ public class HighlightsCodeLensProvider extends AbstractCodeMiningProvider {
|
||||
IPreferenceStore store = LanguageServerCommonsActivator.getInstance().getPreferenceStore();
|
||||
if (store.getBoolean(PreferenceConstants.HIGHLIGHT_CODELENS_PREFS)) {
|
||||
IDocument document = viewer.getDocument();
|
||||
List<LSPDocumentInfo> docInfos = LanguageServiceAccessor.getLSPDocumentInfosFor(document, (x) -> true);
|
||||
if (!docInfos.isEmpty()) {
|
||||
LSPDocumentInfo info = docInfos.get(0);
|
||||
HighlightParams highlights = STS4LanguageClientImpl.currentHighlights.get(info.getFileUri().toString());
|
||||
if (highlights != null) {
|
||||
return CompletableFuture.completedFuture(highlights.getCodeLenses().stream()
|
||||
.filter(codeLens -> codeLens.getCommand() != null).map(codeLens -> {
|
||||
try {
|
||||
return new HighlightCodeMining(codeLens, document, this, action(codeLens.getCommand()));
|
||||
} catch (BadLocationException e) {
|
||||
LanguageServerCommonsActivator.logError(e, "Failed to create Eclipse client CodeLens");
|
||||
return null;
|
||||
}
|
||||
}).filter(Objects::nonNull).collect(Collectors.toList()));
|
||||
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
List<LSPDocumentInfo> docInfos = LanguageServiceAccessor.getLSPDocumentInfosFor(document, null);
|
||||
if (!docInfos.isEmpty()) {
|
||||
LSPDocumentInfo info = docInfos.get(0);
|
||||
HighlightParams highlights = STS4LanguageClientImpl.currentHighlights.get(info.getFileUri().toString());
|
||||
if (highlights != null) {
|
||||
return highlights.getCodeLenses().stream()
|
||||
.filter(codeLens -> codeLens.getCommand() != null)
|
||||
.map(codeLens -> {
|
||||
try {
|
||||
return new HighlightCodeMining(codeLens, document, this, action(codeLens.getCommand()));
|
||||
} catch (BadLocationException e) {
|
||||
LanguageServerCommonsActivator.logError(e, "Failed to create Eclipse client CodeLens");
|
||||
return null;
|
||||
}
|
||||
})
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
});
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user