Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: IndexOutOfBounds in text/hover #42909

Open
xlight05 opened this issue Jun 12, 2024 · 0 comments
Open

[Bug]: IndexOutOfBounds in text/hover #42909

xlight05 opened this issue Jun 12, 2024 · 0 comments
Labels
Area/Hover Language Server Hover related issues Crash All issues caused by NPE, CCE, etc Team/LanguageServer Language Server Implementation related issues. #Compiler Type/Bug

Comments

@xlight05
Copy link
Contributor

Description

There might be two issues here. please follow the reproduce steps and see.
Exception:

[Error - 10:38:39] Operation 'text/hover' failed! {uri: '/Users/wso2/ballerina-playground/ai_test/test_gen_client/main.bal', [23:32], error: 'Line number: '-1', Size: '323''}
java.lang.IndexOutOfBoundsException: Line number: '-1', Size: '323'
	at io.ballerina.tools.text.LineMap.lineRangeCheck(LineMap.java:78)
	at io.ballerina.tools.text.LineMap.textPositionFrom(LineMap.java:50)
	at io.ballerina.tools.text.TextDocument.textPositionFrom(TextDocument.java:52)
	at org.ballerinalang.langserver.common.utils.CommonUtil.findNode(CommonUtil.java:316)
	at org.ballerinalang.langserver.hover.HoverObjectResolver.lambda$getHoverObjectForSymbol$2(HoverObjectResolver.java:215)
	at java.base/java.util.Optional.flatMap(Optional.java:289)
	at org.ballerinalang.langserver.hover.HoverObjectResolver.lambda$getHoverObjectForSymbol$3(HoverObjectResolver.java:215)
	at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
	at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1625)
	at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
	at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
	at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921)
	at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
	at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:682)
	at org.ballerinalang.langserver.hover.HoverObjectResolver.getHoverObjectForSymbol(HoverObjectResolver.java:229)
	at org.ballerinalang.langserver.hover.HoverObjectResolver.getHoverObjectForSymbol(HoverObjectResolver.java:83)
	at org.ballerinalang.langserver.hover.HoverUtil.getHover(HoverUtil.java:94)
	at org.ballerinalang.langserver.BallerinaTextDocumentService.lambda$hover$1(BallerinaTextDocumentService.java:184)
	at java.base/java.util.concurrent.CompletableFuture$UniApply.tryFire(CompletableFuture.java:646)
	at java.base/java.util.concurrent.CompletableFuture$Completion.exec(CompletableFuture.java:483)
	at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373)
	at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1182)
	at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1655)
	at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1622)
	at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:165)

Steps to Reproduce

import ballerina/http;
import ballerina/io;
import ballerina/time;

final http:Client codeGenClient = check new ("http://localhost:9090", timeout = 350, cache = {enabled: false});

type TestGenRequest record {
    string openapiSpec;
};

type TestGenResponse record {
    string code;
};

public function main() returns error? {

    // string usecase = "Write an http service to read a specified csv file and add it to google sheet.";
    // // string usecase = "Write an application to read open github issues in a given repo and send those as a message to a slack channel.";
    // // string usecase = "Write an application to todos from a csv file and create github issues for each todo.";
    // // string usecase = "Write an application to read all the rows from a nosql db and set those data into another nosql db.";

    TestGenRequest req = {openapiSpec: usecase};
    time:Utc startTime = time:utcNow();
    Resp codeResp = check codeGenClient->/ai/tests.post(req, params= {"temp" : 0, "attempts": 0});
    time:Utc endTime = time:utcNow();
    io:println("Time taken to generate code: ", time:utcDiffSeconds(endTime, startTime));
    check io:fileWriteString("test.bal", codeResp.code, io:OVERWRITE);
}

When you change Resp to TestGenResponse while hovering HTTP client call, you still get an error saying unknown type Resp. which means state is out of sync. you should see the exception in the log.

Affected Version(s)

U9

OS, DB, other environment details and versions

No response

Related area

-> Compilation

Related issue(s) (optional)

No response

Suggested label(s) (optional)

No response

Suggested assignee(s) (optional)

No response

@ballerina-bot ballerina-bot added needTriage The issue has to be inspected and labeled manually userCategory/Compilation labels Jun 12, 2024
@xlight05 xlight05 added Team/LanguageServer Language Server Implementation related issues. #Compiler Area/Hover Language Server Hover related issues Crash All issues caused by NPE, CCE, etc and removed needTriage The issue has to be inspected and labeled manually userCategory/Compilation labels Jun 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area/Hover Language Server Hover related issues Crash All issues caused by NPE, CCE, etc Team/LanguageServer Language Server Implementation related issues. #Compiler Type/Bug
Projects
None yet
Development

No branches or pull requests

2 participants