lf-lang / vscode-lingua-franca

Lingua Franca extension for Visual Studio Code
Other
5 stars 3 forks source link

IndexOutOfBoundsException from hover request #63

Closed petervdonovan closed 1 year ago

petervdonovan commented 2 years ago

The following error message appeared while I was testing the LF formatter in VS Code:

    at java.base/java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:332)
    at java.base/java.util.concurrent.CompletableFuture.andTree(CompletableFuture.java:1527)
    at java.base/java.util.concurrent.CompletableFuture.andTree(CompletableFuture.java:1517)
    at java.base/java.util.concurrent.CompletableFuture.andTree(CompletableFuture.java:1517)
    at java.base/java.util.concurrent.CompletableFuture.allOf(CompletableFuture.java:2419)
    at org.eclipse.xtext.ide.server.concurrent.RequestManager.cancel(RequestManager.java:114)
    at org.eclipse.xtext.ide.server.concurrent.RequestManager.runWrite(RequestManager.java:80)
    at org.eclipse.xtext.ide.server.LanguageServerImpl.runBuildable(LanguageServerImpl.java:457)
    at org.eclipse.xtext.ide.server.LanguageServerImpl.didChange(LanguageServerImpl.java:397)
    at jdk.internal.reflect.GeneratedMethodAccessor82.invoke(Unknown Source)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:568)
    at org.eclipse.lsp4j.jsonrpc.services.GenericEndpoint.lambda$null$0(GenericEndpoint.java:65)
    at org.eclipse.lsp4j.jsonrpc.services.GenericEndpoint.notify(GenericEndpoint.java:152)
    at org.eclipse.lsp4j.jsonrpc.RemoteEndpoint.handleNotification(RemoteEndpoint.java:220)
    at org.eclipse.lsp4j.jsonrpc.RemoteEndpoint.consume(RemoteEndpoint.java:187)
    at org.eclipse.lsp4j.jsonrpc.validation.ReflectiveMessageValidator.consume(ReflectiveMessageValidator.java:68)
    at org.eclipse.lsp4j.jsonrpc.json.StreamMessageProducer.handleMessage(StreamMessageProducer.java:194)
    at org.eclipse.lsp4j.jsonrpc.json.StreamMessageProducer.listen(StreamMessageProducer.java:94)
    at org.eclipse.lsp4j.jsonrpc.json.ConcurrentMessageProcessor.run(ConcurrentMessageProcessor.java:113)
    at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
    at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: java.lang.IndexOutOfBoundsException: Position [
  line = 32
  character = 43
] text was : // Test logical action with delay.
target TypeScript

reactor GeneratedDelay {
    input y_in: number

    output y_out: number

    logical action act(100 msec)

    state y_state: number(0)

    reaction(y_in) -> act {=
        y_state = y_in as number;
        actions.act.schedule(0, null);
    =}

    reaction(act) -> y_out {=
        y_out = y_state;
    =}
}

reactor Source {
    output out: number

    reaction(startup) -> out {=
        out = 1;
    =}
}

reactor Sink(a: number(0), b: number(0), c: number(0), d: number(0)) {
    input x: number

    reaction(x) {=
        const elapsed_logical = util.getElapsedLogicalTime();
        const logical = util.getCurrentLogicalTime();
        const physical = util.getCurrentPhysicalTime();
        console.log("Logical, physical, and elapsed logical: " + logical + physical + elapsed_logical);
        const oneHundredMsec = TimeValue.msec(100);
        if (!elapsed_logical.isEqualTo(oneHundredMsec)) {
            util.requestErrorStop("Expected " + oneHundredMsec + " but got " + elapsed_logical);
        } else {
            console.log("SUCCESS. Elapsed logical time is " + elapsed_logical);
        }
    =}
}

main reactor ActionDelay {
    source = new Source()
    sink = new Sink()
    g = new GeneratedDelay()

    source.out -> g.y_in
    g.y_out -> sink.x
}

    at org.eclipse.xtext.ide.server.Document.getOffSet(Document.java:62)
    at org.eclipse.xtext.ide.server.hover.HoverService.hover(HoverService.java:53)
    at org.eclipse.xtext.ide.server.LanguageServerImpl.lambda$hover$32(LanguageServerImpl.java:718)
    at org.eclipse.xtext.ide.server.WorkspaceManager.doRead(WorkspaceManager.java:438)
    at org.eclipse.xtext.ide.server.LanguageServerImpl.hover(LanguageServerImpl.java:717)
    at org.eclipse.xtext.ide.server.LanguageServerImpl.lambda$hover$31(LanguageServerImpl.java:704)
    at org.eclipse.xtext.ide.server.concurrent.ReadRequest.lambda$doRun$0(ReadRequest.java:66)
    ... 5 more

Perhaps this happened because the content of the document changed during the request -- I'm not sure.

I wonder if this is something that we can tolerate until we decide it is time to move away from Xtext.

lhstrh commented 2 years ago

Is there a way to make calls to the formatting blocking?

petervdonovan commented 2 years ago

Is there a way to make calls to the formatting blocking?

Maybe... If we did that, then I think we might have to implement it on the client side (TS), so that the requests do not get interleaved. There might be a way to intercept them.

Another alternative would be for the server to fail more gracefully when it receives these invalid requests. I think XText has a way for us to bind our own hover provider, which can probably extend the one that they provide.

petervdonovan commented 1 year ago

This seems to have been fixed by https://github.com/lf-lang/lingua-franca/commit/9bd1792605528d5e6323338291cebbde2a19c3bf.