ballerina-lang
ballerina-lang copied to clipboard
[Bug]: [Project API] `document` API is throwing an exception for generated IDL client
Description
I generated an IDL client and reloaded the VSCode window. When I was trying to make a change in the generated client the following exception was thrown.
https://github.com/ballerina-platform/ballerina-lang/blob/656430fde21a51e5c01193a72127baf670bc4efe/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/workspace/BallerinaWorkspaceManager.java#L1108
Here we are trying to invoke the document
method and get the document for the path of the generated idl client. It throws an exception. Due to this the project can't be compiled.
Steps to Reproduce
Mentioned above
Affected Version(s)
2201.3.0-stage
OS, DB, other environment details and versions
No response
Related area
-> Editor
Related issue(s) (optional)
No response
Suggested label(s) (optional)
No response
Suggested assignee(s) (optional)
No response
@malinthar tested the scenario with changes in https://github.com/ballerina-platform/ballerina-lang/pull/38118 and got the following output:
[Info - 1:49:49 pm] Operation 'text/didChange' {fileUri: 'file:///home/user/test/idlPlugins/client_decl_test/generated/myapi/idl_client.bal'} updated
[Info - 1:49:51 pm] Operation 'text/didChange' {fileUri: 'file:///home/user/test/idlPlugins/client_decl_test/generated/myapi/idl_client.bal'} updated
[Error - 1:49:55 pm] Operation 'text/completion' failed! {uri: '/home/user/test/idlPlugins/client_decl_test/generated/myapi/idl_client.bal', [17:9], error: 'Semantic Model Cannot be Empty'}
java.lang.RuntimeException: Semantic Model Cannot be Empty
at org.ballerinalang.langserver.contexts.AbstractDocumentServiceContext.currentDocImportsMap(AbstractDocumentServiceContext.java:186)
at org.ballerinalang.langserver.completions.providers.AbstractCompletionProvider.getModuleCompletionItems(AbstractCompletionProvider.java:360)
at org.ballerinalang.langserver.completions.providers.AbstractCompletionProvider.getTypeDescContextItems(AbstractCompletionProvider.java:325)
at org.ballerinalang.langserver.completions.providers.context.BlockNodeContextProvider.getCompletions(BlockNodeContextProvider.java:95)
at org.ballerinalang.langserver.completions.providers.context.FunctionBodyBlockNodeContext.getCompletions(FunctionBodyBlockNodeContext.java:48)
at org.ballerinalang.langserver.completions.providers.context.FunctionBodyBlockNodeContext.getCompletions(FunctionBodyBlockNodeContext.java:39)
at org.ballerinalang.langserver.completions.util.CompletionUtil.route(CompletionUtil.java:125)
at org.ballerinalang.langserver.completions.util.CompletionUtil.getCompletionItems(CompletionUtil.java:81)
at org.ballerinalang.langserver.completions.BallerinaCompletionExtension.execute(BallerinaCompletionExtension.java:65)
at org.ballerinalang.langserver.completions.BallerinaCompletionExtension.execute(BallerinaCompletionExtension.java:40)
at org.ballerinalang.langserver.LangExtensionDelegator.completion(LangExtensionDelegator.java:124)
at org.ballerinalang.langserver.BallerinaTextDocumentService.lambda$completion$0(BallerinaTextDocumentService.java:149)
at java.base/java.util.concurrent.CompletableFuture$UniApply.tryFire(CompletableFuture.java:642)
at java.base/java.util.concurrent.CompletableFuture$Completion.exec(CompletableFuture.java:479)
at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290)
at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1020)
at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1656)
at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1594)
at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:183)
Ideally, a generated file should be in read-only mode and the user should not be able to edit it. Can we add this improvement?
@malinthar tested the scenario with changes in #38118 and got the following output:
[Info - 1:49:49 pm] Operation 'text/didChange' {fileUri: 'file:///home/user/test/idlPlugins/client_decl_test/generated/myapi/idl_client.bal'} updated [Info - 1:49:51 pm] Operation 'text/didChange' {fileUri: 'file:///home/user/test/idlPlugins/client_decl_test/generated/myapi/idl_client.bal'} updated [Error - 1:49:55 pm] Operation 'text/completion' failed! {uri: '/home/user/test/idlPlugins/client_decl_test/generated/myapi/idl_client.bal', [17:9], error: 'Semantic Model Cannot be Empty'} java.lang.RuntimeException: Semantic Model Cannot be Empty at org.ballerinalang.langserver.contexts.AbstractDocumentServiceContext.currentDocImportsMap(AbstractDocumentServiceContext.java:186) at org.ballerinalang.langserver.completions.providers.AbstractCompletionProvider.getModuleCompletionItems(AbstractCompletionProvider.java:360) at org.ballerinalang.langserver.completions.providers.AbstractCompletionProvider.getTypeDescContextItems(AbstractCompletionProvider.java:325) at org.ballerinalang.langserver.completions.providers.context.BlockNodeContextProvider.getCompletions(BlockNodeContextProvider.java:95) at org.ballerinalang.langserver.completions.providers.context.FunctionBodyBlockNodeContext.getCompletions(FunctionBodyBlockNodeContext.java:48) at org.ballerinalang.langserver.completions.providers.context.FunctionBodyBlockNodeContext.getCompletions(FunctionBodyBlockNodeContext.java:39) at org.ballerinalang.langserver.completions.util.CompletionUtil.route(CompletionUtil.java:125) at org.ballerinalang.langserver.completions.util.CompletionUtil.getCompletionItems(CompletionUtil.java:81) at org.ballerinalang.langserver.completions.BallerinaCompletionExtension.execute(BallerinaCompletionExtension.java:65) at org.ballerinalang.langserver.completions.BallerinaCompletionExtension.execute(BallerinaCompletionExtension.java:40) at org.ballerinalang.langserver.LangExtensionDelegator.completion(LangExtensionDelegator.java:124) at org.ballerinalang.langserver.BallerinaTextDocumentService.lambda$completion$0(BallerinaTextDocumentService.java:149) at java.base/java.util.concurrent.CompletableFuture$UniApply.tryFire(CompletableFuture.java:642) at java.base/java.util.concurrent.CompletableFuture$Completion.exec(CompletableFuture.java:479) at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290) at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1020) at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1656) at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1594) at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:183)
@azinneera Tried with the fix. I still get the issue when opening the document. After it's opened, when I do a change the issue is not there.
Regarding the st trace for empt semantic model. Looping in @dulajdilshan. Semantic model seems to be empty in this scenario. Hence, can't provide completions.
Ideally, a generated file should be in read-only mode and the user should not be able to edit it. Can we add this improvement?
Yes we can restrict edits
@azinneera Tried with the fix. I still get the issue when opening the document. After it's opened, when I do a change the issue is not there.
Is this document opened before issuing a compilation? Generated IDL client files are not loaded when loading the project. It is only resolved during package resolution. The reason is because if the user has removed the IDL import, then this client module is not necessary to be loaded into the package though its there in the FS.
Won't this be fixed if the file is in read-only mode?
Ideally, a generated file should be in read-only mode and the user should not be able to edit it. Can we add this improvement?
Then we can close https://github.com/ballerina-platform/ballerina-lang/issues/38017
@azinneera Tried with the fix. I still get the issue when opening the document. After it's opened, when I do a change the issue is not there.
Is this document opened before issuing a compilation? Generated IDL client files are not loaded when loading the project. It is only resolved during package resolution. The reason is because if the user has removed the IDL import, then this client module is not necessary to be loaded into the package though its there in the FS.
Won't this be fixed if the file is in read-only mode?
Let's refactor this from the LS side to prevent accessing the document before it's created
Closing as fixed with https://github.com/ballerina-platform/ballerina-lang/pull/38272
This issue is NOT closed with a proper Reason/ label. Make sure to add proper reason label before closing. Please add or leave a comment with the proper reason label now.
- Reason/EngineeringMistake - The issue occurred due to a mistake made in the past.
- Reason/Regression - The issue has introduced a regression.
- Reason/MultipleComponentInteraction - Issue occured due to interactions in multiple components.
- Reason/Complex - Issue occurred due to complex scenario.
- Reason/Invalid - Issue is invalid.
- Reason/Other - None of the above cases.