diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/TypeChecker.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/TypeChecker.java index 862182a3ff13..53fb819705dd 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/TypeChecker.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/TypeChecker.java @@ -3823,6 +3823,7 @@ public void visit(BLangInvocation.BLangResourceAccessInvocation resourceAccessIn } if (resourceFunctions.size() == 0) { + checkExpr(resourceAccessInvocation.resourceAccessPathSegments, data); dlog.error(resourceAccessInvocation.resourceAccessPathSegments.pos, DiagnosticErrorCode.UNDEFINED_RESOURCE, lhsExprType); data.resultType = symTable.semanticError; @@ -3833,10 +3834,12 @@ public void visit(BLangInvocation.BLangResourceAccessInvocation resourceAccessIn resourceFunctions.removeIf(func -> !func.accessor.value.equals(resourceAccessInvocation.name.value)); int targetResourceFuncCount = resourceFunctions.size(); if (targetResourceFuncCount == 0) { + checkExpr(resourceAccessInvocation.resourceAccessPathSegments, data); dlog.error(resourceAccessInvocation.name.pos, DiagnosticErrorCode.UNDEFINED_RESOURCE_METHOD, resourceAccessInvocation.name, lhsExprType); data.resultType = symTable.semanticError; } else if (targetResourceFuncCount > 1) { + checkExpr(resourceAccessInvocation.resourceAccessPathSegments, data); dlog.error(resourceAccessInvocation.pos, DiagnosticErrorCode.AMBIGUOUS_RESOURCE_ACCESS_NOT_YET_SUPPORTED); data.resultType = symTable.semanticError; } else { diff --git a/language-server/modules/langserver-core/src/test/resources/completion/action_node_context/config/client_resource_access_action_config44.json b/language-server/modules/langserver-core/src/test/resources/completion/action_node_context/config/client_resource_access_action_config44.json new file mode 100644 index 000000000000..2f3801fcc192 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/completion/action_node_context/config/client_resource_access_action_config44.json @@ -0,0 +1,40 @@ +{ + "position": { + "line": 7, + "character": 25 + }, + "source": "action_node_context/source/client_resource_access_action_source37.bal", + "description": "", + "items": [ + { + "label": "/third", + "kind": "Function", + "detail": "()", + "documentation": { + "right": { + "kind": "markdown", + "value": "**Package:** _._ \n \n \n**Params** \n- `string` second" + } + }, + "sortText": "C", + "filterText": "third|get", + "insertText": "/third;", + "insertTextFormat": "Snippet", + "additionalTextEdits": [ + { + "range": { + "start": { + "line": 7, + "character": 24 + }, + "end": { + "line": 7, + "character": 25 + } + }, + "newText": "" + } + ] + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/completion/action_node_context/source/client_resource_access_action_source37.bal b/language-server/modules/langserver-core/src/test/resources/completion/action_node_context/source/client_resource_access_action_source37.bal new file mode 100644 index 000000000000..b48acd886e4c --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/completion/action_node_context/source/client_resource_access_action_source37.bal @@ -0,0 +1,9 @@ +client class MyClient { + resource function get first/[string second]/third() {} +} + +public function main() { + string someVar = "check"; + MyClient cl = new; + cl->/first/[someVar]/; +}