Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions rascal-lsp/src/main/checkerframework/rascal.astub
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,14 @@ public abstract class TreeVisitor<E extends Throwable> extends IdentityVisitor<E
public abstract @Nullable ITree visitTreeChar(ITree arg) throws E;
public abstract @Nullable ITree visitTreeCycle(ITree arg) throws E;
}

package org.rascalmpl.values.functions;

import io.usethesource.vallang.IExternalValue;
import io.usethesource.vallang.IValue;

import org.checkerframework.checker.nullness.qual.NonNull;

public interface IFunction extends IExternalValue {
default <T extends @NonNull IValue> T call(IValue... parameters) { }
}
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ public InterruptibleFuture<IValue> execution(String command) {
), exec);
}

private <T extends @NonNull Object> InterruptibleFuture<T> execFunction(String name, CompletableFuture<@Nullable IFunction> target, T defaultResult, IValue... args) {
private <T extends @NonNull IValue> InterruptibleFuture<T> execFunction(String name, CompletableFuture<@Nullable IFunction> target, T defaultResult, IValue... args) {
if (target == null) {
return InterruptibleFuture.completedFuture(defaultResult, exec);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,21 +230,14 @@
private <T> CompletableFuture<T> anyTrue(
Function<ILanguageContributions, CompletableFuture<T>> predicate,
T falsy, BinaryOperator<T> or) {

var result = CompletableFutureUtils.completedFuture(falsy, exec);
// no short-circuiting, but it's not problem, it's only triggered at the beginning of a registry
// pretty soon the future will be completed.
for (var c: contributions) {
var checkCurrent = predicate.apply(c.contrib)
.exceptionally(e -> falsy);
result = result.thenCombine(checkCurrent, or);
}
return result;
return CompletableFutureUtils.reduce(contributions.stream().map(c -> predicate.apply(c.contrib).exceptionally(_e -> falsy)), CompletableFutureUtils.completedFuture(falsy, exec), Function.identity(), or);
}

@Override
public String getName() {
return name;

Check warning on line 240 in rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/LanguageContributionsMultiplexer.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Rename this local variable to match the regular expression '^[a-z][a-zA-Z0-9]*$'.

See more on https://sonarcloud.io/project/issues?id=usethesource_rascal-language-servers&issues=AZzSIfP1IvXDyzdoLlpf&open=AZzSIfP1IvXDyzdoLlpf&pullRequest=1009
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import org.apache.logging.log4j.core.util.IOUtils;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.checker.nullness.qual.PolyNull;
import org.eclipse.lsp4j.ApplyWorkspaceEditParams;
import org.eclipse.lsp4j.CallHierarchyIncomingCall;
import org.eclipse.lsp4j.CallHierarchyIncomingCallsParams;
Expand Down Expand Up @@ -441,7 +442,7 @@ public CompletableFuture<List<? extends CodeLens>> codeLens(CodeLensParams param
.thenApply(s -> s.stream()
.map(e -> locCommandTupleToCodeLense(contrib.getName(), e))
.collect(Collectors.toList())
), () -> null);
), Collections::<CodeLens>emptyList);
}


Expand Down Expand Up @@ -625,11 +626,11 @@ public CompletableFuture<List<InlayHint>> inlayHint(InlayHintParams params) {
.thenApply(s -> s.stream()
.map(this::rowToInlayHint)
.collect(Collectors.toList())
), () -> null);
), Collections::emptyList);
}


private static <T> CompletableFuture<T> recoverExceptions(CompletableFuture<T> future, Supplier<T> defaultValue) {
private static <T> CompletableFuture<@PolyNull T> recoverExceptions(CompletableFuture<@PolyNull T> future, Supplier<@PolyNull T> defaultValue) {
return future
.exceptionally(e -> {
logger.error("Operation failed with", e);
Expand Down Expand Up @@ -870,7 +871,7 @@ public CompletableFuture<List<FoldingRange>> foldingRange(FoldingRangeRequestPar
return recoverExceptions(file.getCurrentTreeAsync(true).thenApply(Versioned::get).thenApply(FoldingRanges::getFoldingRanges)
.whenComplete((r, e) ->
logger.trace("Folding regions success, reporting {} regions back", r == null ? 0 : r.size())
), Collections::emptyList);
), Collections::<FoldingRange>emptyList);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public class CapabilityRegistration {

private final LanguageClient client;
private final Executor exec;
private final CompletableFuture<Void> noop;
private final CompletableFuture<@Nullable Void> noop;

private final Set<AbstractDynamicCapability<?>> dynamicCapabilities;
private final Set<AbstractDynamicCapability<?>> staticCapabilities;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import org.apache.logging.log4j.Logger;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.checker.nullness.qual.PolyNull;
import org.eclipse.lsp4j.ApplyWorkspaceEditParams;
import org.eclipse.lsp4j.ApplyWorkspaceEditResponse;
import org.eclipse.lsp4j.ClientCapabilities;
Expand Down Expand Up @@ -346,10 +347,10 @@ public CompletableFuture<Either<List<? extends Location>, List<? extends Locatio
return recoverExceptions(facts.getSummary(Locations.toLoc(params.getTextDocument()))
.thenApply(s -> s == null ? Collections.<Location>emptyList() : s.getDefinition(params.getPosition()))
.thenApply(Either::forLeft)
, () -> Either.forLeft(Collections.emptyList()));
, () -> Either.forLeft(Collections.<Location>emptyList()));
}
else {
return CompletableFutureUtils.completedFuture(Either.forLeft(Collections.emptyList()), exec);
return CompletableFutureUtils.completedFuture(Either.forLeft(Collections.<Location>emptyList()), exec);
}
}

Expand Down Expand Up @@ -413,7 +414,7 @@ public CompletableFuture<Either3<Range, PrepareRenameResult, PrepareRenameDefaul
return findQualifiedNameUnderCursor(focus);
})
.thenApply(cur -> Locations.toRange(TreeAdapter.getLocation(cur), columns))
.thenApply(Either3::forFirst), () -> null);
.thenApply(Either3::forFirst), () -> Either3.forSecond(new PrepareRenameResult()));
}

@Override
Expand Down Expand Up @@ -670,9 +671,7 @@ public CompletableFuture<List<? extends CodeLens>> codeLens(CodeLensParams param
return recoverExceptions(f.getLastTreeAsync(false)
.thenApply(Versioned::get)
.thenApplyAsync(availableRascalServices()::locateCodeLenses, exec)
.thenApply(List::stream)
.thenApply(res -> res.map(this::makeRunCodeLens))
.thenApply(s -> s.collect(Collectors.toList())), () -> null)
.thenApply(lenses -> lenses.stream().map(this::makeRunCodeLens).collect(Collectors.toList())), () -> null)
;
}

Expand Down Expand Up @@ -724,7 +723,7 @@ public CompletableFuture<IValue> executeCommand(String extension, String command
return availableRascalServices().executeCommand(command).get();
}

private static <T, S extends T> CompletableFuture<T> recoverExceptions(CompletableFuture<T> future, Supplier<S> defaultValue) {
private static <T> CompletableFuture<@PolyNull T> recoverExceptions(CompletableFuture<@PolyNull T> future, Supplier<@PolyNull T> defaultValue) {
return future
.exceptionally(e -> {
if (e instanceof ResponseErrorException) {
Expand All @@ -735,7 +734,7 @@ private static <T, S extends T> CompletableFuture<T> recoverExceptions(Completab
});
}

private static <T> CompletableFuture<List<T>> recoverExceptions(CompletableFuture<List<T>> future) {
private static <T> CompletableFuture<List<@PolyNull T>> recoverExceptions(CompletableFuture<List<@PolyNull T>> future) {
return recoverExceptions(future, Collections::emptyList);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public static CompletableFuture<Stream<IValue>> extractActionsFromDiagnostics(Co
/* merges two streams of CodeAction terms and then converts them to LSP objects */
public static CompletableFuture<List<Either<Command, CodeAction>>> mergeAndConvertCodeActions(IBaseTextDocumentService doc, String dedicatedLanguageName, String languageName, CompletableFuture<Stream<IValue>> quickfixes, CompletableFuture<Stream<IValue>> codeActions) {
return codeActions.thenCombine(quickfixes, (actions, quicks) ->
Stream.concat(quicks, actions)
Stream.<IValue>concat(quicks, actions)
.map(IConstructor.class::cast)
.map(cons -> constructorToCodeAction(doc, dedicatedLanguageName, languageName, cons))
.map(Either::<Command,CodeAction>forRight)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ private static List<Diagnostic> translateDiagnostics(ICollection<?> messages, Co
.collect(Collectors.toList());
}

public static Map<ISourceLocation, List<Diagnostic>> translateMessages(ICollection<?> messages, ColumnMaps cm) {
public static Map<ISourceLocation, List<Diagnostic>> translateMessages(IList messages, ColumnMaps cm) {
return messages.stream()
.filter(IConstructor.class::isInstance)
.map(IConstructor.class::cast)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.checkerframework.checker.nullness.qual.PolyNull;

public class CompletableFutureUtils {
private CompletableFutureUtils() {/* hidden */ }
Expand Down Expand Up @@ -133,23 +132,23 @@ public static <I, C> CompletableFuture<C> reduce(Stream<CompletableFuture<I>> fu
*/
public static <I, C> CompletableFuture<C> reduce(Iterable<CompletableFuture<I>> futures,
CompletableFuture<C> identity, Function<I, C> map, BinaryOperator<C> concat) {
CompletableFuture<C> result = identity;
var result = identity;
for (var fut : futures) {
result = result.thenCombine(fut, (acc, t) -> concat.apply(acc, map.apply(t)));
}

return result;
}

private static <T> List<@PolyNull T> concat(List<@PolyNull T> l, List<@PolyNull T> r) {
private static <T> List<T> concat(List<T> l, List<T> r) {
if (r.isEmpty()) {
return l;
}
if (l.isEmpty()) {
return r;
}

var ls = new LinkedList<@PolyNull T>(l);
var ls = new LinkedList<T>(l);
ls.addAll(r);
return ls;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.Function;
import org.checkerframework.checker.nullness.qual.PolyNull;

public class InterruptibleFuture<T> {

Expand Down Expand Up @@ -102,9 +101,9 @@ public static <T> InterruptibleFuture<T> completedFuture(T result, Executor exec
* Turn an completable future with a interruptible future inside into a
* normal interruptible future by inlining them
*/
public static <T> InterruptibleFuture<@PolyNull T> flatten(CompletableFuture<InterruptibleFuture<@PolyNull T>> f, Executor exec) {
public static <T> InterruptibleFuture<T> flatten(CompletableFuture<InterruptibleFuture<T>> f, Executor exec) {
return new InterruptibleFuture<>(
f.<@PolyNull T>thenCompose(InterruptibleFuture::get),
f.thenCompose(InterruptibleFuture::get),
() -> f.thenAcceptAsync(InterruptibleFuture::interrupt, exec) // schedule interrupt async so that we don't deadlock during interrupt
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executor;
import java.util.concurrent.atomic.AtomicReference;

import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.checker.nullness.qual.PolyNull;

/**
* A wrapper around CompletableFuture's that allow for us to replace the results of a still running future, and call an
Expand Down Expand Up @@ -111,7 +111,7 @@ public InterruptibleFuture<T> replace(InterruptibleFuture<T> with) {
return new InterruptibleFuture<>(result, with::interrupt);
}

public static <T> ReplaceableFuture<T> completedFuture(T result, Executor exec) {
public static <T> ReplaceableFuture<@PolyNull T> completedFuture(@PolyNull T result, Executor exec) {
return new ReplaceableFuture<>(CompletableFutureUtils.completedFuture(result, exec));
}
}
Loading