From 2b9e2332af7adcf91ed148ad437a5c1ae6abbd09 Mon Sep 17 00:00:00 2001 From: Nipuna Fernando Date: Wed, 18 Oct 2023 11:45:47 +0530 Subject: [PATCH] Fix invalid stream signature in CreateVariable --- .../CreateVariableWithTypeCodeAction.java | 2 +- .../CreateVariableWithTypeTest.java | 1 + ...ype_infer_for_resource_action_config2.json | 29 ++++++++++++++++ .../create-var-with-type/source/source1.bal | 4 +++ ...lient_resource_access_action_config21.json | 34 +++++++++++++++++++ ...client_resource_access_action_config8.json | 19 +++++++++++ .../config/remote_action_config1.json | 19 +++++++++++ .../config/remote_action_config2.json | 19 +++++++++++ .../config/remote_action_config4.json | 19 +++++++++++ .../config/remote_action_config5.json | 19 +++++++++++ .../configs/hover_for_api_docs_client.json | 2 +- .../hover/configs/hover_performance.json | 2 +- .../hover/configs/hover_typeref1.json | 2 +- .../src/main/ballerina/clients_source1.bal | 10 ++++++ .../langserver/stdlib/ClientAction.java | 7 ++++ 15 files changed, 184 insertions(+), 4 deletions(-) create mode 100644 language-server/modules/langserver-core/src/test/resources/codeaction/create-var-with-type/config/type_infer_for_resource_action_config2.json diff --git a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/codeaction/providers/createvar/CreateVariableWithTypeCodeAction.java b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/codeaction/providers/createvar/CreateVariableWithTypeCodeAction.java index 56652d78ad7c..983975973206 100644 --- a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/codeaction/providers/createvar/CreateVariableWithTypeCodeAction.java +++ b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/codeaction/providers/createvar/CreateVariableWithTypeCodeAction.java @@ -261,7 +261,7 @@ private String getTypeName(TypeSymbol symbol, CodeActionContext context) { : getRawType(symbol, context).signature()); return FunctionGenerator.processModuleIDsInText(new ImportsAcceptor(context), moduleQualifiedName, context); } - return symbol.signature(); + return FunctionGenerator.processModuleIDsInText(new ImportsAcceptor(context), symbol.signature(), context); } private boolean isLangAnnotationModule(ModuleID moduleID) { diff --git a/language-server/modules/langserver-core/src/test/java/org/ballerinalang/langserver/codeaction/CreateVariableWithTypeTest.java b/language-server/modules/langserver-core/src/test/java/org/ballerinalang/langserver/codeaction/CreateVariableWithTypeTest.java index 68a08a1a9f92..c4f21743ff11 100644 --- a/language-server/modules/langserver-core/src/test/java/org/ballerinalang/langserver/codeaction/CreateVariableWithTypeTest.java +++ b/language-server/modules/langserver-core/src/test/java/org/ballerinalang/langserver/codeaction/CreateVariableWithTypeTest.java @@ -52,6 +52,7 @@ public Object[][] dataProvider() { {"type_infer_for_remote_method_call_config1.json"}, {"type_infer_for_remote_method_call_config2.json"}, {"type_infer_for_resource_action_config.json"}, + {"type_infer_for_resource_action_config2.json"}, {"type_infer_for_resource_action_with_check1.json"}, {"type_infer_for_resource_action_with_check2.json"} }; diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/create-var-with-type/config/type_infer_for_resource_action_config2.json b/language-server/modules/langserver-core/src/test/resources/codeaction/create-var-with-type/config/type_infer_for_resource_action_config2.json new file mode 100644 index 000000000000..08c983678a70 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/create-var-with-type/config/type_infer_for_resource_action_config2.json @@ -0,0 +1,29 @@ +{ + "position": { + "line": 27, + "character": 23 + }, + "source": "source1.bal", + "expected": [ + { + "title": "Create variable", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 27, + "character": 4 + }, + "end": { + "line": 27, + "character": 4 + } + }, + "newText": "stream streamResult = " + } + ], + "resolvable": false + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/create-var-with-type/source/source1.bal b/language-server/modules/langserver-core/src/test/resources/codeaction/create-var-with-type/source/source1.bal index 089970262b8e..eb66ff0be1ba 100644 --- a/language-server/modules/langserver-core/src/test/resources/codeaction/create-var-with-type/source/source1.bal +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/create-var-with-type/source/source1.bal @@ -23,3 +23,7 @@ function testRemoteMethodCallWithCheck() returns error? { function testRemoteMethodCallWithCheck2() returns error? { check 'client->/path4/["pathParam"]; } + +function testResourceAccessOfStreamReturnType() returns error? { + 'client->/responses +} diff --git a/language-server/modules/langserver-core/src/test/resources/completion/action_node_context/config/client_resource_access_action_config21.json b/language-server/modules/langserver-core/src/test/resources/completion/action_node_context/config/client_resource_access_action_config21.json index dc6db1d61e51..0926b8d372f0 100644 --- a/language-server/modules/langserver-core/src/test/resources/completion/action_node_context/config/client_resource_access_action_config21.json +++ b/language-server/modules/langserver-core/src/test/resources/completion/action_node_context/config/client_resource_access_action_config21.json @@ -243,6 +243,40 @@ "title": "editor.action.triggerParameterHints", "command": "editor.action.triggerParameterHints" } + }, + { + "label": "/responses(module1:TargetType2 targetType)", + "kind": "Function", + "detail": "stream", + "documentation": { + "right": { + "kind": "markdown", + "value": "**Package:** _ballerina/module1:0.1.0_ \n \nSample resource function to return a stream of objects\n \n**Params** \n- `module1:TargetType2` targetType: Response or `anydata`, which is expected to be returned after data binding(Defaultable) \n \n**Return** `stream` \n- A stream of targetType and/or ClientError \n \n" + } + }, + "sortText": "C", + "filterText": "responses|get", + "insertText": "/responses(${1});", + "insertTextFormat": "Snippet", + "additionalTextEdits": [ + { + "range": { + "start": { + "line": 5, + "character": 22 + }, + "end": { + "line": 5, + "character": 23 + } + }, + "newText": "" + } + ], + "command": { + "title": "editor.action.triggerParameterHints", + "command": "editor.action.triggerParameterHints" + } } ] } diff --git a/language-server/modules/langserver-core/src/test/resources/completion/action_node_context/config/client_resource_access_action_config8.json b/language-server/modules/langserver-core/src/test/resources/completion/action_node_context/config/client_resource_access_action_config8.json index 4c5ef064d217..91e45276bc73 100644 --- a/language-server/modules/langserver-core/src/test/resources/completion/action_node_context/config/client_resource_access_action_config8.json +++ b/language-server/modules/langserver-core/src/test/resources/completion/action_node_context/config/client_resource_access_action_config8.json @@ -214,6 +214,25 @@ "title": "editor.action.triggerParameterHints", "command": "editor.action.triggerParameterHints" } + }, + { + "label": "/responses(module1:TargetType2 targetType)", + "kind": "Function", + "detail": "stream", + "documentation": { + "right": { + "kind": "markdown", + "value": "**Package:** _ballerina/module1:0.1.0_ \n \nSample resource function to return a stream of objects\n \n**Params** \n- `module1:TargetType2` targetType: Response or `anydata`, which is expected to be returned after data binding(Defaultable) \n \n**Return** `stream` \n- A stream of targetType and/or ClientError \n \n" + } + }, + "sortText": "CC", + "filterText": "responses|get", + "insertText": "/responses(${1});", + "insertTextFormat": "Snippet", + "command": { + "title": "editor.action.triggerParameterHints", + "command": "editor.action.triggerParameterHints" + } } ] } diff --git a/language-server/modules/langserver-core/src/test/resources/completion/action_node_context/config/remote_action_config1.json b/language-server/modules/langserver-core/src/test/resources/completion/action_node_context/config/remote_action_config1.json index 3b332de160c9..3aac992a0ee8 100644 --- a/language-server/modules/langserver-core/src/test/resources/completion/action_node_context/config/remote_action_config1.json +++ b/language-server/modules/langserver-core/src/test/resources/completion/action_node_context/config/remote_action_config1.json @@ -214,6 +214,25 @@ "title": "editor.action.triggerParameterHints", "command": "editor.action.triggerParameterHints" } + }, + { + "label": "/responses(module1:TargetType2 targetType)", + "kind": "Function", + "detail": "stream", + "documentation": { + "right": { + "kind": "markdown", + "value": "**Package:** _ballerina/module1:0.1.0_ \n \nSample resource function to return a stream of objects\n \n**Params** \n- `module1:TargetType2` targetType: Response or `anydata`, which is expected to be returned after data binding(Defaultable) \n \n**Return** `stream` \n- A stream of targetType and/or ClientError \n \n" + } + }, + "sortText": "CC", + "filterText": "responses|get", + "insertText": "/responses(${1});", + "insertTextFormat": "Snippet", + "command": { + "title": "editor.action.triggerParameterHints", + "command": "editor.action.triggerParameterHints" + } } ] } diff --git a/language-server/modules/langserver-core/src/test/resources/completion/action_node_context/config/remote_action_config2.json b/language-server/modules/langserver-core/src/test/resources/completion/action_node_context/config/remote_action_config2.json index c0a587a73e29..0deebde40c30 100644 --- a/language-server/modules/langserver-core/src/test/resources/completion/action_node_context/config/remote_action_config2.json +++ b/language-server/modules/langserver-core/src/test/resources/completion/action_node_context/config/remote_action_config2.json @@ -214,6 +214,25 @@ "title": "editor.action.triggerParameterHints", "command": "editor.action.triggerParameterHints" } + }, + { + "label": "/responses(module1:TargetType2 targetType)", + "kind": "Function", + "detail": "stream", + "documentation": { + "right": { + "kind": "markdown", + "value": "**Package:** _ballerina/module1:0.1.0_ \n \nSample resource function to return a stream of objects\n \n**Params** \n- `module1:TargetType2` targetType: Response or `anydata`, which is expected to be returned after data binding(Defaultable) \n \n**Return** `stream` \n- A stream of targetType and/or ClientError \n \n" + } + }, + "sortText": "CC", + "filterText": "responses|get", + "insertText": "/responses(${1});", + "insertTextFormat": "Snippet", + "command": { + "title": "editor.action.triggerParameterHints", + "command": "editor.action.triggerParameterHints" + } } ] } diff --git a/language-server/modules/langserver-core/src/test/resources/completion/action_node_context/config/remote_action_config4.json b/language-server/modules/langserver-core/src/test/resources/completion/action_node_context/config/remote_action_config4.json index 83cc41d3921e..e56c92acc586 100644 --- a/language-server/modules/langserver-core/src/test/resources/completion/action_node_context/config/remote_action_config4.json +++ b/language-server/modules/langserver-core/src/test/resources/completion/action_node_context/config/remote_action_config4.json @@ -214,6 +214,25 @@ "title": "editor.action.triggerParameterHints", "command": "editor.action.triggerParameterHints" } + }, + { + "label": "/responses(mod:TargetType2 targetType)", + "kind": "Function", + "detail": "stream", + "documentation": { + "right": { + "kind": "markdown", + "value": "**Package:** _ballerina/module1:0.1.0_ \n \nSample resource function to return a stream of objects\n \n**Params** \n- `mod:TargetType2` targetType: Response or `anydata`, which is expected to be returned after data binding(Defaultable) \n \n**Return** `stream` \n- A stream of targetType and/or ClientError \n \n" + } + }, + "sortText": "CC", + "filterText": "responses|get", + "insertText": "/responses(${1});", + "insertTextFormat": "Snippet", + "command": { + "title": "editor.action.triggerParameterHints", + "command": "editor.action.triggerParameterHints" + } } ] } diff --git a/language-server/modules/langserver-core/src/test/resources/completion/action_node_context/config/remote_action_config5.json b/language-server/modules/langserver-core/src/test/resources/completion/action_node_context/config/remote_action_config5.json index 9951cbdc988f..9e861cc4ed87 100644 --- a/language-server/modules/langserver-core/src/test/resources/completion/action_node_context/config/remote_action_config5.json +++ b/language-server/modules/langserver-core/src/test/resources/completion/action_node_context/config/remote_action_config5.json @@ -214,6 +214,25 @@ "title": "editor.action.triggerParameterHints", "command": "editor.action.triggerParameterHints" } + }, + { + "label": "/responses(module1:TargetType2 targetType)", + "kind": "Function", + "detail": "stream", + "documentation": { + "right": { + "kind": "markdown", + "value": "**Package:** _ballerina/module1:0.1.0_ \n \nSample resource function to return a stream of objects\n \n**Params** \n- `module1:TargetType2` targetType: Response or `anydata`, which is expected to be returned after data binding(Defaultable) \n \n**Return** `stream` \n- A stream of targetType and/or ClientError \n \n" + } + }, + "sortText": "CC", + "filterText": "responses|get", + "insertText": "/responses(${1});", + "insertTextFormat": "Snippet", + "command": { + "title": "editor.action.triggerParameterHints", + "command": "editor.action.triggerParameterHints" + } } ] } diff --git a/language-server/modules/langserver-core/src/test/resources/hover/configs/hover_for_api_docs_client.json b/language-server/modules/langserver-core/src/test/resources/hover/configs/hover_for_api_docs_client.json index 7eb4f891af0e..648683a43532 100644 --- a/language-server/modules/langserver-core/src/test/resources/hover/configs/hover_for_api_docs_client.json +++ b/language-server/modules/langserver-core/src/test/resources/hover/configs/hover_for_api_docs_client.json @@ -10,7 +10,7 @@ "result": { "contents": { "kind": "markdown", - "value": "The HTTP client provides the capability for initiating contact with a remote HTTP service. The API it\nprovides includes functions for the standard HTTP methods, forwarding a received request and sending requests\nusing custom HTTP verbs. \n \n--- \n \n### Fields \n \n`string` ***url*** : Target service url \n \n--- \n \n### Methods \n \n+ `remote function post(string path, module1:RequestMessage message, string targetType) returns module1:Response` \nThe `Client.post()` function can be used to send HTTP POST requests to HTTP endpoints. \n \n+ `resource function post path1/[string id1]/path2/[string... ids] (string str, string... ids2) returns module1:Response` \nSample resource method. \n \n+ `remote function get(string path, module1:TargetType targetType) returns targetType|module1:ClientError` \nSample remote method with java interoperability \n \n+ `remote function forward(string path, handle request, module1:TargetType targetType) returns targetType` \nSample remote method with java interoperability \n \n+ `remote function delete(module1:TargetType2 targetType) returns targetType` \nSample remote method with java interoperability \n \n+ `resource function get path3 (module1:TargetType targetType) returns targetType|module1:ClientError` \nSample resource function with java interoperability \n \n+ `resource function get path4/[string pathParam] (module1:TargetType targetType) returns targetType|module1:ClientError|error` \nSample resource function with multiple target types with java interoperability \n \n+ `isolated resource function post [string... path] (module1:RequestMessage message, map? headers, string? mediaType, module1:TargetType targetType) returns targetType|module1:ClientError` \nSample resource function with rest path praram with multiple target types with java interoperability \n \n \n--- \n \n[View API Docs](https://lib.ballerina.io/ballerina/module1/0.1.0#Client)" + "value": "The HTTP client provides the capability for initiating contact with a remote HTTP service. The API it\nprovides includes functions for the standard HTTP methods, forwarding a received request and sending requests\nusing custom HTTP verbs. \n \n--- \n \n### Fields \n \n`string` ***url*** : Target service url \n \n--- \n \n### Methods \n \n+ `remote function post(string path, module1:RequestMessage message, string targetType) returns module1:Response` \nThe `Client.post()` function can be used to send HTTP POST requests to HTTP endpoints. \n \n+ `resource function post path1/[string id1]/path2/[string... ids] (string str, string... ids2) returns module1:Response` \nSample resource method. \n \n+ `remote function get(string path, module1:TargetType targetType) returns targetType|module1:ClientError` \nSample remote method with java interoperability \n \n+ `remote function forward(string path, handle request, module1:TargetType targetType) returns targetType` \nSample remote method with java interoperability \n \n+ `remote function delete(module1:TargetType2 targetType) returns targetType` \nSample remote method with java interoperability \n \n+ `resource function get path3 (module1:TargetType targetType) returns targetType|module1:ClientError` \nSample resource function with java interoperability \n \n+ `resource function get path4/[string pathParam] (module1:TargetType targetType) returns targetType|module1:ClientError|error` \nSample resource function with multiple target types with java interoperability \n \n+ `isolated resource function post [string... path] (module1:RequestMessage message, map? headers, string? mediaType, module1:TargetType targetType) returns targetType|module1:ClientError` \nSample resource function with rest path praram with multiple target types with java interoperability \n \n+ `isolated resource function get responses (module1:TargetType2 targetType) returns stream` \nSample resource function to return a stream of objects \n \n \n--- \n \n[View API Docs](https://lib.ballerina.io/ballerina/module1/0.1.0#Client)" } }, "id": { diff --git a/language-server/modules/langserver-core/src/test/resources/hover/configs/hover_performance.json b/language-server/modules/langserver-core/src/test/resources/hover/configs/hover_performance.json index 83cee93ac2e2..41a7543de1a0 100644 --- a/language-server/modules/langserver-core/src/test/resources/hover/configs/hover_performance.json +++ b/language-server/modules/langserver-core/src/test/resources/hover/configs/hover_performance.json @@ -10,7 +10,7 @@ "result": { "contents": { "kind": "markdown", - "value": "The HTTP client provides the capability for initiating contact with a remote HTTP service. The API it\nprovides includes functions for the standard HTTP methods, forwarding a received request and sending requests\nusing custom HTTP verbs. \n \n--- \n \n### Fields \n \n`string` ***url*** : Target service url \n \n--- \n \n### Methods \n \n+ `remote function post(string path, module1:RequestMessage message, string targetType) returns module1:Response` \nThe `Client.post()` function can be used to send HTTP POST requests to HTTP endpoints. \n \n+ `resource function post path1/[string id1]/path2/[string... ids] (string str, string... ids2) returns module1:Response` \nSample resource method. \n \n+ `remote function get(string path, module1:TargetType targetType) returns targetType|module1:ClientError` \nSample remote method with java interoperability \n \n+ `remote function forward(string path, handle request, module1:TargetType targetType) returns targetType` \nSample remote method with java interoperability \n \n+ `remote function delete(module1:TargetType2 targetType) returns targetType` \nSample remote method with java interoperability \n \n+ `resource function get path3 (module1:TargetType targetType) returns targetType|module1:ClientError` \nSample resource function with java interoperability \n \n+ `resource function get path4/[string pathParam] (module1:TargetType targetType) returns targetType|module1:ClientError|error` \nSample resource function with multiple target types with java interoperability \n \n+ `isolated resource function post [string... path] (module1:RequestMessage message, map? headers, string? mediaType, module1:TargetType targetType) returns targetType|module1:ClientError` \nSample resource function with rest path praram with multiple target types with java interoperability \n \n \n--- \n \n[View API Docs](https://lib.ballerina.io/ballerina/module1/0.1.0#Client)" + "value": "The HTTP client provides the capability for initiating contact with a remote HTTP service. The API it\nprovides includes functions for the standard HTTP methods, forwarding a received request and sending requests\nusing custom HTTP verbs. \n \n--- \n \n### Fields \n \n`string` ***url*** : Target service url \n \n--- \n \n### Methods \n \n+ `remote function post(string path, module1:RequestMessage message, string targetType) returns module1:Response` \nThe `Client.post()` function can be used to send HTTP POST requests to HTTP endpoints. \n \n+ `resource function post path1/[string id1]/path2/[string... ids] (string str, string... ids2) returns module1:Response` \nSample resource method. \n \n+ `remote function get(string path, module1:TargetType targetType) returns targetType|module1:ClientError` \nSample remote method with java interoperability \n \n+ `remote function forward(string path, handle request, module1:TargetType targetType) returns targetType` \nSample remote method with java interoperability \n \n+ `remote function delete(module1:TargetType2 targetType) returns targetType` \nSample remote method with java interoperability \n \n+ `resource function get path3 (module1:TargetType targetType) returns targetType|module1:ClientError` \nSample resource function with java interoperability \n \n+ `resource function get path4/[string pathParam] (module1:TargetType targetType) returns targetType|module1:ClientError|error` \nSample resource function with multiple target types with java interoperability \n \n+ `isolated resource function post [string... path] (module1:RequestMessage message, map? headers, string? mediaType, module1:TargetType targetType) returns targetType|module1:ClientError` \nSample resource function with rest path praram with multiple target types with java interoperability \n \n+ `isolated resource function get responses (module1:TargetType2 targetType) returns stream` \nSample resource function to return a stream of objects \n \n \n--- \n \n[View API Docs](https://lib.ballerina.io/ballerina/module1/0.1.0#Client)" } }, "id": { diff --git a/language-server/modules/langserver-core/src/test/resources/hover/configs/hover_typeref1.json b/language-server/modules/langserver-core/src/test/resources/hover/configs/hover_typeref1.json index 83cee93ac2e2..41a7543de1a0 100644 --- a/language-server/modules/langserver-core/src/test/resources/hover/configs/hover_typeref1.json +++ b/language-server/modules/langserver-core/src/test/resources/hover/configs/hover_typeref1.json @@ -10,7 +10,7 @@ "result": { "contents": { "kind": "markdown", - "value": "The HTTP client provides the capability for initiating contact with a remote HTTP service. The API it\nprovides includes functions for the standard HTTP methods, forwarding a received request and sending requests\nusing custom HTTP verbs. \n \n--- \n \n### Fields \n \n`string` ***url*** : Target service url \n \n--- \n \n### Methods \n \n+ `remote function post(string path, module1:RequestMessage message, string targetType) returns module1:Response` \nThe `Client.post()` function can be used to send HTTP POST requests to HTTP endpoints. \n \n+ `resource function post path1/[string id1]/path2/[string... ids] (string str, string... ids2) returns module1:Response` \nSample resource method. \n \n+ `remote function get(string path, module1:TargetType targetType) returns targetType|module1:ClientError` \nSample remote method with java interoperability \n \n+ `remote function forward(string path, handle request, module1:TargetType targetType) returns targetType` \nSample remote method with java interoperability \n \n+ `remote function delete(module1:TargetType2 targetType) returns targetType` \nSample remote method with java interoperability \n \n+ `resource function get path3 (module1:TargetType targetType) returns targetType|module1:ClientError` \nSample resource function with java interoperability \n \n+ `resource function get path4/[string pathParam] (module1:TargetType targetType) returns targetType|module1:ClientError|error` \nSample resource function with multiple target types with java interoperability \n \n+ `isolated resource function post [string... path] (module1:RequestMessage message, map? headers, string? mediaType, module1:TargetType targetType) returns targetType|module1:ClientError` \nSample resource function with rest path praram with multiple target types with java interoperability \n \n \n--- \n \n[View API Docs](https://lib.ballerina.io/ballerina/module1/0.1.0#Client)" + "value": "The HTTP client provides the capability for initiating contact with a remote HTTP service. The API it\nprovides includes functions for the standard HTTP methods, forwarding a received request and sending requests\nusing custom HTTP verbs. \n \n--- \n \n### Fields \n \n`string` ***url*** : Target service url \n \n--- \n \n### Methods \n \n+ `remote function post(string path, module1:RequestMessage message, string targetType) returns module1:Response` \nThe `Client.post()` function can be used to send HTTP POST requests to HTTP endpoints. \n \n+ `resource function post path1/[string id1]/path2/[string... ids] (string str, string... ids2) returns module1:Response` \nSample resource method. \n \n+ `remote function get(string path, module1:TargetType targetType) returns targetType|module1:ClientError` \nSample remote method with java interoperability \n \n+ `remote function forward(string path, handle request, module1:TargetType targetType) returns targetType` \nSample remote method with java interoperability \n \n+ `remote function delete(module1:TargetType2 targetType) returns targetType` \nSample remote method with java interoperability \n \n+ `resource function get path3 (module1:TargetType targetType) returns targetType|module1:ClientError` \nSample resource function with java interoperability \n \n+ `resource function get path4/[string pathParam] (module1:TargetType targetType) returns targetType|module1:ClientError|error` \nSample resource function with multiple target types with java interoperability \n \n+ `isolated resource function post [string... path] (module1:RequestMessage message, map? headers, string? mediaType, module1:TargetType targetType) returns targetType|module1:ClientError` \nSample resource function with rest path praram with multiple target types with java interoperability \n \n+ `isolated resource function get responses (module1:TargetType2 targetType) returns stream` \nSample resource function to return a stream of objects \n \n \n--- \n \n[View API Docs](https://lib.ballerina.io/ballerina/module1/0.1.0#Client)" } }, "id": { diff --git a/language-server/modules/langserver-stdlib/src/main/ballerina/clients_source1.bal b/language-server/modules/langserver-stdlib/src/main/ballerina/clients_source1.bal index 4ac0d14425fd..2b6db9930653 100644 --- a/language-server/modules/langserver-stdlib/src/main/ballerina/clients_source1.bal +++ b/language-server/modules/langserver-stdlib/src/main/ballerina/clients_source1.bal @@ -93,6 +93,16 @@ public client class Client { 'class: "org.ballerinalang.langserver.stdlib.ClientAction", name: "postResource" } external; + + + # Sample resource function to return a stream of objects + # + # + targetType - Response or `anydata`, which is expected to be returned after data binding + # + return - A stream of targetType and/or ClientError + isolated resource function get responses(TargetType2 targetType = <>) returns stream = @java:Method { + 'class: "org.ballerinalang.langserver.stdlib.ClientAction", + name: "responses" + } external; } # Represents a response. diff --git a/language-server/modules/langserver-stdlib/src/main/java/org/ballerinalang/langserver/stdlib/ClientAction.java b/language-server/modules/langserver-stdlib/src/main/java/org/ballerinalang/langserver/stdlib/ClientAction.java index 7c6aa52dc890..92494df24e38 100644 --- a/language-server/modules/langserver-stdlib/src/main/java/org/ballerinalang/langserver/stdlib/ClientAction.java +++ b/language-server/modules/langserver-stdlib/src/main/java/org/ballerinalang/langserver/stdlib/ClientAction.java @@ -15,8 +15,11 @@ */ package org.ballerinalang.langserver.stdlib; +import io.ballerina.runtime.api.creators.TypeCreator; +import io.ballerina.runtime.api.creators.ValueCreator; import io.ballerina.runtime.api.values.BArray; import io.ballerina.runtime.api.values.BObject; +import io.ballerina.runtime.api.values.BStream; import io.ballerina.runtime.api.values.BString; import io.ballerina.runtime.api.values.BTypedesc; @@ -42,6 +45,10 @@ public static Object delete(BTypedesc targetType) { return new Object(); } + public static BStream responses(BTypedesc targetType) { + return ValueCreator.createStreamValue(TypeCreator.createStreamType(targetType.getDescribingType())); + } + public static Object postResource(BArray path, Object message, Object headers, Object mediaType, BTypedesc targetType) { return new Object();