diff --git a/ets2panda/bindings/test/cases.ts b/ets2panda/bindings/test/cases.ts index 7dcce4ef7936d009a076981acf1cf1107f177dfb..583e8a93d3d8e6a5e1dc135f76861e28a38fd9f7 100644 --- a/ets2panda/bindings/test/cases.ts +++ b/ets2panda/bindings/test/cases.ts @@ -168,11 +168,7 @@ export const basicCases: TestCases = { }, getSignatureHelpItems: { expectedFilePath: resolveTestPath('test/expected/getSignatureHelpItems.json'), - '1': [resolveTestPath('test/testcases/getSignatureHelpItems/getSignatureHelpItems1.ets'), 613], - '2': [resolveTestPath('test/testcases/getSignatureHelpItems/getSignatureHelpItems1.ets'), 620], - '3': [resolveTestPath('test/testcases/getSignatureHelpItems/getSignatureHelpItems1.ets'), 678], - '4': [resolveTestPath('test/testcases/getSignatureHelpItems/getSignatureHelpItems2.ets'), 697], - '5': [resolveTestPath('test/testcases/getSignatureHelpItems/getSignatureHelpItems2.ets'), 773] + '1': [resolveTestPath('test/testcases/getSignatureHelpItems/getSignatureHelpItems1.ets'), 678] }, findRenameLocations: { expectedFilePath: resolveTestPath('test/expected/findRenameLocations.json'), diff --git a/ets2panda/bindings/test/expected/getSignatureHelpItems.json b/ets2panda/bindings/test/expected/getSignatureHelpItems.json index 1298c568414cbe6d1d84f1a5c99d2fe54153159d..fc085309d9033a97bfd331ed8a9a77da105ccaec 100644 --- a/ets2panda/bindings/test/expected/getSignatureHelpItems.json +++ b/ets2panda/bindings/test/expected/getSignatureHelpItems.json @@ -4,82 +4,9 @@ { "prefixDisplayParts": [ { - "text": "(", - "kind": "punctuation" - } - ], - "suffixDisplayParts": [ - { - "text": ")", - "kind": "punctuation" - }, - { - "text": ":", - "kind": "punctuation" - }, - { - "text": "void", - "kind": "typeName" - } - ], - "separatorDisplayParts": [], - "parameters": [ - { - "name": "a", - "documentation": [], - "displayParts": [ - { - "text": "a", - "kind": "paramName" - }, - { - "text": ":", - "kind": "punctuation" - }, - { - "text": "Double", - "kind": "typeName" - }, - { - "text": ",", - "kind": "punctuation" - } - ] + "text": "add", + "kind": "functionName" }, - { - "name": "b", - "documentation": [], - "displayParts": [ - { - "text": "b", - "kind": "paramName" - }, - { - "text": ":", - "kind": "punctuation" - }, - { - "text": "String", - "kind": "typeName" - } - ] - } - ], - "documentation": [] - } - ], - "applicableSpan": { - "start": 609, - "length": 65 - }, - "selectedItemIndex": 0, - "argumentIndex": 1, - "argumentCount": 1 - }, - "2": { - "items": [ - { - "prefixDisplayParts": [ { "text": "(", "kind": "punctuation" @@ -91,158 +18,32 @@ "kind": "punctuation" }, { - "text": ":", - "kind": "punctuation" - }, - { - "text": "void", - "kind": "typeName" - } - ], - "separatorDisplayParts": [], - "parameters": [ - { - "name": "a", - "documentation": [], - "displayParts": [ - { - "text": "a", - "kind": "paramName" - }, - { - "text": ":", - "kind": "punctuation" - }, - { - "text": "Double", - "kind": "typeName" - }, - { - "text": ",", - "kind": "punctuation" - } - ] - }, - { - "name": "b", - "documentation": [], - "displayParts": [ - { - "text": "b", - "kind": "paramName" - }, - { - "text": ":", - "kind": "punctuation" - }, - { - "text": "String", - "kind": "typeName" - } - ] - } - ], - "documentation": [] - } - ], - "applicableSpan": { - "start": 609, - "length": 65 - }, - "selectedItemIndex": 0, - "argumentIndex": 1, - "argumentCount": 1 - }, - "3": { - "items": [ - { - "prefixDisplayParts": [ - { - "text": "(", - "kind": "punctuation" - } - ], - "suffixDisplayParts": [ - { - "text": ")", - "kind": "punctuation" + "text": " ", + "kind": "space" }, { - "text": ":", + "text": "=>", "kind": "punctuation" }, { - "text": "void", - "kind": "typeName" - } - ], - "separatorDisplayParts": [], - "parameters": [ - { - "name": "a", - "documentation": [], - "displayParts": [ - { - "text": "a", - "kind": "paramName" - }, - { - "text": ":", - "kind": "punctuation" - }, - { - "text": "Double", - "kind": "typeName" - }, - { - "text": ",", - "kind": "punctuation" - } - ] + "text": " ", + "kind": "space" }, { - "name": "b", - "documentation": [], - "displayParts": [ - { - "text": "b", - "kind": "paramName" - }, - { - "text": ":", - "kind": "punctuation" - }, - { - "text": "String", - "kind": "typeName" - } - ] - } - ], - "documentation": [] - }, - { - "prefixDisplayParts": [ - { - "text": "(", - "kind": "punctuation" + "text": "Double", + "kind": "keyword" } ], - "suffixDisplayParts": [ + "separatorDisplayParts": [ { - "text": ")", + "text": ",", "kind": "punctuation" }, { - "text": ":", - "kind": "punctuation" - }, - { - "text": "void", - "kind": "typeName" + "text": " ", + "kind": "space" } ], - "separatorDisplayParts": [], "parameters": [ { "name": "a", @@ -250,19 +51,19 @@ "displayParts": [ { "text": "a", - "kind": "paramName" + "kind": "parameterNmae" }, { "text": ":", "kind": "punctuation" }, { - "text": "Double", - "kind": "typeName" + "text": " ", + "kind": "space" }, { - "text": ",", - "kind": "punctuation" + "text": "Double", + "kind": "keyword" } ] }, @@ -272,169 +73,19 @@ "displayParts": [ { "text": "b", - "kind": "paramName" + "kind": "parameterNmae" }, { "text": ":", "kind": "punctuation" }, { - "text": "String", - "kind": "typeName" - } - ] - } - ], - "documentation": [] - } - ], - "applicableSpan": { - "start": 675, - "length": 15 - }, - "selectedItemIndex": 0, - "argumentIndex": 1, - "argumentCount": 0 - }, - "4": { - "items": [ - { - "prefixDisplayParts": [ - { - "text": "(", - "kind": "punctuation" - } - ], - "suffixDisplayParts": [ - { - "text": ")", - "kind": "punctuation" - }, - { - "text": ":", - "kind": "punctuation" - }, - { - "text": "Double", - "kind": "typeName" - } - ], - "separatorDisplayParts": [], - "parameters": [ - { - "name": "item", - "documentation": [], - "displayParts": [ - { - "text": "item", - "kind": "paramName" - }, - { - "text": ":", - "kind": "punctuation" + "text": " ", + "kind": "space" }, { "text": "Double", - "kind": "typeName" - } - ] - } - ], - "documentation": [] - } - ], - "applicableSpan": { - "start": 691, - "length": 11 - }, - "selectedItemIndex": 0, - "argumentIndex": 0, - "argumentCount": 1 - }, - "5": { - "items": [ - { - "prefixDisplayParts": [ - { - "text": "(", - "kind": "punctuation" - } - ], - "suffixDisplayParts": [ - { - "text": ")", - "kind": "punctuation" - }, - { - "text": ":", - "kind": "punctuation" - }, - { - "text": "Double|undefined", - "kind": "typeName" - } - ], - "separatorDisplayParts": [], - "parameters": [ - { - "name": "key", - "documentation": [], - "displayParts": [ - { - "text": "key", - "kind": "paramName" - }, - { - "text": ":", - "kind": "punctuation" - }, - { - "text": "String", - "kind": "typeName" - } - ] - } - ], - "documentation": [] - }, - { - "prefixDisplayParts": [ - { - "text": "(", - "kind": "punctuation" - } - ], - "suffixDisplayParts": [ - { - "text": ")", - "kind": "punctuation" - }, - { - "text": ":", - "kind": "punctuation" - }, - { - "text": "Double|undefined", - "kind": "typeName" - } - ], - "separatorDisplayParts": [], - "parameters": [ - { - "name": "key", - "documentation": [], - "displayParts": [ - { - "text": "key", - "kind": "paramName" - }, - { - "text": ":", - "kind": "punctuation" - }, - { - "text": "String", - "kind": "typeName" + "kind": "keyword" } ] } @@ -443,11 +94,11 @@ } ], "applicableSpan": { - "start": 767, - "length": 12 + "start": 678, + "length": 0 }, "selectedItemIndex": 0, "argumentIndex": 0, - "argumentCount": 1 + "argumentCount": 2 } } diff --git a/ets2panda/bindings/test/testcases/getSignatureHelpItems/getSignatureHelpItems1.ets b/ets2panda/bindings/test/testcases/getSignatureHelpItems/getSignatureHelpItems1.ets index fc4ebb691ae3db8f38eff3d873346482cc815b1c..d84f944c3985933399d2008023077b5bd5596834 100644 --- a/ets2panda/bindings/test/testcases/getSignatureHelpItems/getSignatureHelpItems1.ets +++ b/ets2panda/bindings/test/testcases/getSignatureHelpItems/getSignatureHelpItems1.ets @@ -13,7 +13,7 @@ * limitations under the License. */ -function test(a: number, b: string): void { - console.log(a); +function add(a: number, b: number): number { + return a + b; } -test(1, "test"); +add() diff --git a/ets2panda/lsp/BUILD.gn b/ets2panda/lsp/BUILD.gn index b0aa7f38b26cab95a9ee241eed5c7dbba3d4843b..745905335a584e08f5b537e9c0048b2b171ead9c 100644 --- a/ets2panda/lsp/BUILD.gn +++ b/ets2panda/lsp/BUILD.gn @@ -72,6 +72,7 @@ ohos_source_set("libes2panda_lsp_static") { "src/get_name_or_dotted_name_span.cpp", "src/get_node.cpp", "src/get_safe_delete_info.cpp", + "src/get_signature.cpp", "src/inlay_hints.cpp", "src/internal_api.cpp", "src/isolated_declaration.cpp", diff --git a/ets2panda/lsp/CMakeLists.txt b/ets2panda/lsp/CMakeLists.txt index 5316352a2adb1a4b17c7353390ed64171140fb1d..579ff809fc35540c1b62394371462e46bfdba95e 100644 --- a/ets2panda/lsp/CMakeLists.txt +++ b/ets2panda/lsp/CMakeLists.txt @@ -125,6 +125,7 @@ set(ES2PANDA_LSP_SRC ./src/register_code_fix/remove_accidental_call_parentheses.cpp ./src/register_code_fix/fix_add_function_return_statement.cpp ./src/register_code_fix/ui_plugin_suggest.cpp + ./src/get_signature.cpp ./src/get_name_or_dotted_name_span.cpp ./src/get_node.cpp ) diff --git a/ets2panda/bindings/test/testcases/getSignatureHelpItems/getSignatureHelpItems2.ets b/ets2panda/lsp/include/get_signature.h similarity index 46% rename from ets2panda/bindings/test/testcases/getSignatureHelpItems/getSignatureHelpItems2.ets rename to ets2panda/lsp/include/get_signature.h index 551e7e896be9a72e4fdcc481fc997aec5c2eac84..ca8f94c4bd5293650d50410458f9581ff5747871 100644 --- a/ets2panda/bindings/test/testcases/getSignatureHelpItems/getSignatureHelpItems2.ets +++ b/ets2panda/lsp/include/get_signature.h @@ -1,10 +1,10 @@ -/* +/** * Copyright (c) 2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -13,10 +13,18 @@ * limitations under the License. */ -import {default as stack} from '@ohos.util.Stack'; -let stk = new stack(); -stk.push(1); +#ifndef LSP_GET_SIGNATURE_H +#define LSP_GET_SIGNATURE_H -let map = new Map(); -map.set("a", 1); -let a = map.get("a"); \ No newline at end of file +#include +#include "ir/astNode.h" +#include "lsp/include/types.h" +#include "public/es2panda_lib.h" +namespace ark::es2panda::lsp { +size_t FindFirstNonSpaceLeft(const std::string &str, size_t pos); +SignatureHelpItems MakeSignatureHelpItem(ir::AstNode *callExpressionNode, ir::AstNode *node, ir::AstNode *declNode, + checker::Signature *signature, size_t position); +SignatureHelpItems GetSignature(es2panda_Context *context, size_t position); +} // namespace ark::es2panda::lsp + +#endif \ No newline at end of file diff --git a/ets2panda/lsp/src/api.cpp b/ets2panda/lsp/src/api.cpp index 15a085857bcc5561302f64a5f99f2b795f50d5f3..e3e7fc75c77f0f164a50db6679e14ada720892a9 100644 --- a/ets2panda/lsp/src/api.cpp +++ b/ets2panda/lsp/src/api.cpp @@ -41,6 +41,7 @@ #include "signature_help.h" #include "completions_details.h" #include "get_name_or_dotted_name_span.h" +#include "get_signature.h" using ark::es2panda::lsp::details::GetCompletionEntryDetailsImpl; @@ -427,10 +428,7 @@ InlayHintList ProvideInlayHints(es2panda_Context *context, const TextSpan *span) SignatureHelpItems GetSignatureHelpItems(es2panda_Context *context, size_t position) { - const size_t defaultTime = 20; - auto invokedReason = ark::es2panda::lsp::SignatureHelpInvokedReason(); - auto cancellationToken = ark::es2panda::lsp::CancellationToken(defaultTime, nullptr); - return ark::es2panda::lsp::GetSignatureHelpItems(context, position, invokedReason, cancellationToken); + return ark::es2panda::lsp::GetSignature(context, position); } size_t GetOffsetByColAndLine(es2panda_Context *context, size_t line, size_t column) diff --git a/ets2panda/lsp/src/get_signature.cpp b/ets2panda/lsp/src/get_signature.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3247ca95ad78697fa2cb63a7c39433cc298f98e0 --- /dev/null +++ b/ets2panda/lsp/src/get_signature.cpp @@ -0,0 +1,131 @@ +/** + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "checker/types/signature.h" +#include "compiler/lowering/util.h" +#include "get_signature.h" +#include "internal_api.h" +#include "ir/astNode.h" +#include "public/es2panda_lib.h" +#include "public/public.h" +namespace ark::es2panda::lsp { + +size_t FindFirstNonSpaceLeft(const std::string &str, size_t pos) +{ + if (str.empty()) { + return std::string::npos; + } + + if (pos >= str.size()) { + pos = str.size() - 1; + } + + for (size_t i = pos;; --i) { + if (std::isspace(static_cast(str[i])) == 0) { + return i; + } + + if (i == 0) { + break; + } + } + + return std::string::npos; +} + +SignatureHelpItems MakeSignatureHelpItem(ir::AstNode *callExpressionNode, ir::AstNode *node, ir::AstNode *declNode, + checker::Signature *signature, size_t position) +{ + SignatureHelpItems res; + res.SetApplicableSpan(node->End().index + 1, position - node->End().index - 1); + res.SetArgumentIndex(callExpressionNode->AsCallExpression()->Arguments().size()); + auto params = signature->GetSignatureInfo()->params; + auto returnType = signature->ReturnType(); + res.SetArgumentCount(params.size()); + + SignatureHelpItem item; + auto methodName = std::string(declNode->AsMethodDefinition()->Id()->Name()); + item.SetPrefixDisplayParts(SymbolDisplayPart(methodName, "functionName")); + item.SetPrefixDisplayParts(SymbolDisplayPart("(", "punctuation")); + + item.SetSeparatorDisplayParts(SymbolDisplayPart(",", "punctuation")); + item.SetSeparatorDisplayParts(SymbolDisplayPart(" ", "space")); + + item.SetSuffixDisplayParts(SymbolDisplayPart(")", "punctuation")); + item.SetSuffixDisplayParts(SymbolDisplayPart(" ", "space")); + item.SetSuffixDisplayParts(SymbolDisplayPart("=>", "punctuation")); + item.SetSuffixDisplayParts(SymbolDisplayPart(" ", "space")); + item.SetSuffixDisplayParts(SymbolDisplayPart(returnType->ToString(), "keyword")); + + for (auto param : params) { + SignatureHelpParameter paramItem; + auto paramName = std::string(param->Name()); + auto paramType = param->TsType()->ToString(); + paramItem.SetName(paramName); + paramItem.SetDisplayParts(SymbolDisplayPart(paramName, "parameterNmae")); + paramItem.SetDisplayParts(SymbolDisplayPart(":", "punctuation")); + paramItem.SetDisplayParts(SymbolDisplayPart(" ", "space")); + paramItem.SetDisplayParts(SymbolDisplayPart(paramType, "keyword")); + item.SetParameters(paramItem); + } + + res.SetItems(item); + return res; +} + +SignatureHelpItems GetSignature(es2panda_Context *context, size_t position) +{ + SignatureHelpItems res; + if (context == nullptr) { + return res; + } + + auto callExpressionNode = GetTouchingToken(context, position, false); + if (callExpressionNode == nullptr || !callExpressionNode->IsCallExpression()) { + return res; + } + + auto ctx = reinterpret_cast(context); + auto sourceCode = ctx->parserProgram->SourceCode(); + if (position >= sourceCode.Length()) { + return res; + } + + auto foundPos = std::string(sourceCode).rfind('(', position); + auto targetPos = FindFirstNonSpaceLeft(std::string(sourceCode), foundPos); + auto node = GetTouchingToken(context, targetPos - 1, false); + if (node == nullptr || !node->IsIdentifier()) { + return res; + } + + auto declNode = compiler::DeclarationFromIdentifier(node->AsIdentifier()); + if (declNode == nullptr || !declNode->IsMethodDefinition()) { + return res; + } + + auto function = declNode->AsMethodDefinition()->Function(); + if (function == nullptr) { + return res; + } + + auto signature = function->Signature(); + if (signature == nullptr) { + return res; + } + res = MakeSignatureHelpItem(callExpressionNode, node, declNode, signature, position); + return res; +} +} // namespace ark::es2panda::lsp \ No newline at end of file diff --git a/ets2panda/test/unit/lsp/CMakeLists.txt b/ets2panda/test/unit/lsp/CMakeLists.txt index 169defec2fbf5af261349dd009247d5d815f847d..1e39ac80327ec356cbfd61d2afd8cd8caee4fe37 100644 --- a/ets2panda/test/unit/lsp/CMakeLists.txt +++ b/ets2panda/test/unit/lsp/CMakeLists.txt @@ -301,6 +301,10 @@ ets2panda_add_gtest(lsp_get_import_file_path_test CPP_SOURCES get_import_file_path_test.cpp ) +ets2panda_add_gtest(lsp_get_signature_test CPP_SOURCES + get_signature_test.cpp +) + ets2panda_add_gtest(lsp_api_get_node_test CPP_SOURCES get_node_test.cpp ) diff --git a/ets2panda/test/unit/lsp/get_signature_test.cpp b/ets2panda/test/unit/lsp/get_signature_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4e5454401130635d655204be852214f246502268 --- /dev/null +++ b/ets2panda/test/unit/lsp/get_signature_test.cpp @@ -0,0 +1,109 @@ +/** + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "lsp/include/api.h" +#include "lsp/include/internal_api.h" +#include "lsp/include/get_signature.h" +#include +#include +#include "test/unit/lsp/lsp_api_test.h" +namespace { + +using ark::es2panda::lsp::Initializer; + +class LspGetSignatureTests : public LSPAPITests {}; + +TEST_F(LspGetSignatureTests, LspTests) +{ + Initializer initializer = Initializer(); + auto ctx = initializer.CreateContext("get_signature_test.ets", ES2PANDA_STATE_CHECKED, + R"(function add(a:number, b:number): number { + return a + b; +} +add())"); + const LSPAPI *lspApi = GetImpl(); + const size_t offset = 65; + lspApi->getSignatureHelpItems(ctx, offset); + auto result = ark::es2panda::lsp::GetSignature(ctx, offset); + initializer.DestroyContext(ctx); + const size_t expectedCount = 2; + const size_t expectedIndex = 0; + const size_t expectedSpanLength = 0; + const size_t expectedSpanStart = 65; + const size_t typeIndex = 3; + const size_t returnTypeIndex = 4; + ASSERT_EQ(result.GetArgumentCount(), expectedCount); + ASSERT_EQ(result.GetArgumentIndex(), expectedIndex); + ASSERT_EQ(result.GetApplicableSpan().length, expectedSpanLength); + ASSERT_EQ(result.GetApplicableSpan().start, expectedSpanStart); + ASSERT_EQ(result.GetItems().at(0).GetPrefixDisplayParts().at(0).GetText(), "add"); + ASSERT_EQ(result.GetItems().at(0).GetPrefixDisplayParts().at(0).GetKind(), "functionName"); + ASSERT_EQ(result.GetItems().at(0).GetSuffixDisplayParts().at(returnTypeIndex).GetText(), "Double"); + ASSERT_EQ(result.GetItems().at(0).GetSuffixDisplayParts().at(returnTypeIndex).GetKind(), "keyword"); + ASSERT_EQ(result.GetItems().at(0).GetParameters().at(0).GetDisplayParts().at(0).GetText(), "a"); + ASSERT_EQ(result.GetItems().at(0).GetParameters().at(0).GetDisplayParts().at(typeIndex).GetText(), "Double"); + ASSERT_EQ(result.GetItems().at(0).GetParameters().at(1).GetDisplayParts().at(0).GetText(), "b"); + ASSERT_EQ(result.GetItems().at(0).GetParameters().at(1).GetDisplayParts().at(typeIndex).GetText(), "Double"); +} + +TEST_F(LspGetSignatureTests, LspTests2) +{ + Initializer initializer = Initializer(); + auto ctx = initializer.CreateContext("get_signature_test.ets", ES2PANDA_STATE_CHECKED, + R"(function add(a:number, b:number): number { + return a + b; +} +add(11,))"); + const LSPAPI *lspApi = GetImpl(); + const size_t offset = 68; + lspApi->getSignatureHelpItems(ctx, offset); + auto result = ark::es2panda::lsp::GetSignature(ctx, offset); + initializer.DestroyContext(ctx); + const size_t expectedCount = 2; + const size_t expectedIndex = 1; + const size_t expectedSpanLength = 3; + const size_t expectedSpanStart = 65; + ASSERT_EQ(result.GetArgumentCount(), expectedCount); + ASSERT_EQ(result.GetArgumentIndex(), expectedIndex); + ASSERT_EQ(result.GetApplicableSpan().length, expectedSpanLength); + ASSERT_EQ(result.GetApplicableSpan().start, expectedSpanStart); +} + +TEST_F(LspGetSignatureTests, LspTests3) +{ + Initializer initializer = Initializer(); + auto ctx = initializer.CreateContext("get_signature_test.ets", ES2PANDA_STATE_CHECKED, + R"(function add(a:number, b): number { + return a + b; +} +add(11,))"); + const LSPAPI *lspApi = GetImpl(); + const size_t offset = 61; + lspApi->getSignatureHelpItems(ctx, offset); + auto result = ark::es2panda::lsp::GetSignature(ctx, offset); + initializer.DestroyContext(ctx); + const size_t expectedCount = 2; + const size_t expectedIndex = 1; + const size_t expectedSpanLength = 3; + const size_t expectedSpanStart = 58; + const size_t typeIndex = 3; + ASSERT_EQ(result.GetArgumentCount(), expectedCount); + ASSERT_EQ(result.GetArgumentIndex(), expectedIndex); + ASSERT_EQ(result.GetApplicableSpan().length, expectedSpanLength); + ASSERT_EQ(result.GetApplicableSpan().start, expectedSpanStart); + ASSERT_EQ(result.GetItems().at(0).GetParameters().at(1).GetDisplayParts().at(typeIndex).GetText(), "*ERROR_TYPE*"); +} + +} // namespace \ No newline at end of file diff --git a/ets2panda/test/unit/lsp/signature_help_items_test.cpp b/ets2panda/test/unit/lsp/signature_help_items_test.cpp index f425a0de03b68cdfcd8373925bf89259f01ec22b..f1296efaa9848a8ab3efa4ed0ade94703a42ae5e 100644 --- a/ets2panda/test/unit/lsp/signature_help_items_test.cpp +++ b/ets2panda/test/unit/lsp/signature_help_items_test.cpp @@ -58,12 +58,14 @@ let a = map.get("a"); size_t const expectedFileCount = 1; ASSERT_EQ(filePaths.size(), expectedFileCount); - LSPAPI const *lspApi = GetImpl(); size_t const offset = 68; Initializer initializer = Initializer(); es2panda_Context *ctx = initializer.CreateContext(filePaths[0].c_str(), ES2PANDA_STATE_CHECKED); ASSERT_EQ(ContextState(ctx), ES2PANDA_STATE_CHECKED); - auto res = lspApi->getSignatureHelpItems(ctx, offset); + const size_t defaultTime = 20; + auto invokedReason = ark::es2panda::lsp::SignatureHelpInvokedReason(); + auto cancellationToken = ark::es2panda::lsp::CancellationToken(defaultTime, nullptr); + auto res = ark::es2panda::lsp::GetSignatureHelpItems(ctx, offset, invokedReason, cancellationToken); size_t const expectedSize = 2; size_t const expectedStart = 62; size_t const expectedLength = 12;