ballerina-lang icon indicating copy to clipboard operation
ballerina-lang copied to clipboard

[Bug]: [Project API] `document` API is throwing an exception for generated IDL client

Open malinthar opened this issue 2 years ago • 7 comments

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.

image

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 avatar Oct 17 '22 07:10 malinthar

@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)

azinneera avatar Oct 17 '22 08:10 azinneera

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?

azinneera avatar Oct 17 '22 08:10 azinneera

@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.

image

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.

malinthar avatar Oct 17 '22 08:10 malinthar

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

malinthar avatar Oct 17 '22 08:10 malinthar

@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.

image

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?

azinneera avatar Oct 17 '22 08:10 azinneera

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

dulajdilshan avatar Oct 17 '22 09:10 dulajdilshan

@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. image

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

malinthar avatar Oct 18 '22 05:10 malinthar

Closing as fixed with https://github.com/ballerina-platform/ballerina-lang/pull/38272

malinthar avatar Oct 19 '22 12:10 malinthar

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.

github-actions[bot] avatar Oct 19 '22 14:10 github-actions[bot]