From 45997ad6f3658168a847045e0caa228202c530c9 Mon Sep 17 00:00:00 2001 From: beratagaca_9a91 Date: Tue, 2 Sep 2025 15:06:53 +0300 Subject: [PATCH] [LSPAPI]: removing fix_expected_comma codefix Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICW1R7 Signed-off-by: beratagaca_9a91 --- ets2panda/lsp/BUILD.gn | 1 - ets2panda/lsp/CMakeLists.txt | 1 - .../register_code_fix/fix_expected_comma.h | 37 ------ .../register_code_fix/fix_expected_comma.cpp | 105 ------------------ ets2panda/test/unit/lsp/CMakeLists.txt | 4 - .../test/unit/lsp/fix_expected_comma_test.cpp | 83 -------------- ets2panda/util/diagnostic/syntax.yaml | 1 - 7 files changed, 232 deletions(-) delete mode 100644 ets2panda/lsp/include/register_code_fix/fix_expected_comma.h delete mode 100644 ets2panda/lsp/src/register_code_fix/fix_expected_comma.cpp delete mode 100644 ets2panda/test/unit/lsp/fix_expected_comma_test.cpp diff --git a/ets2panda/lsp/BUILD.gn b/ets2panda/lsp/BUILD.gn index 2e6655e584..0a0ce936b1 100644 --- a/ets2panda/lsp/BUILD.gn +++ b/ets2panda/lsp/BUILD.gn @@ -99,7 +99,6 @@ ohos_source_set("libes2panda_lsp_static") { "src/register_code_fix/fix_class_doesnt_implement_inherited_abstract_member.cpp", "src/register_code_fix/fix_class_incorrectly_implements_interface.cpp", "src/register_code_fix/fix_class_super_must_precede_this_access.cpp", - "src/register_code_fix/fix_expected_comma.cpp", "src/register_code_fix/fix_extends_interface_becomes_implements.cpp", "src/register_code_fix/fix_import_non_exported_member.cpp", "src/register_code_fix/fix_missing_call_parantheses.cpp", diff --git a/ets2panda/lsp/CMakeLists.txt b/ets2panda/lsp/CMakeLists.txt index 97b269d5fe..623c13db2f 100644 --- a/ets2panda/lsp/CMakeLists.txt +++ b/ets2panda/lsp/CMakeLists.txt @@ -113,7 +113,6 @@ set(ES2PANDA_LSP_SRC ./src/register_code_fix/add_local_variable.cpp ./src/register_code_fix/add_missing_new_operator.cpp ./src/register_code_fix/fix_class_doesnt_implement_inherited_abstract_member.cpp - ./src/register_code_fix/fix_expected_comma.cpp ./src/register_code_fix/fix_extends_interface_becomes_implements.cpp ./src/register_code_fix/fix_class_super_must_precede_this_access.cpp ./src/register_code_fix/fix_return_type_in_async_function.cpp diff --git a/ets2panda/lsp/include/register_code_fix/fix_expected_comma.h b/ets2panda/lsp/include/register_code_fix/fix_expected_comma.h deleted file mode 100644 index d1aea039ba..0000000000 --- a/ets2panda/lsp/include/register_code_fix/fix_expected_comma.h +++ /dev/null @@ -1,37 +0,0 @@ -/** - * 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. - */ - -#ifndef FIX_EXPECTED_COMMA_H -#define FIX_EXPECTED_COMMA_H - -#include "lsp/include/services/text_change/change_tracker.h" -#include "lsp/include/code_fixes/code_fix_types.h" -#include "lsp/include/types.h" -#include "lsp/include/api.h" - -namespace ark::es2panda::lsp { - -class FixExpectedComma : public CodeFixRegistration { -public: - FixExpectedComma(); - std::vector GetCodeActions(const CodeFixContext &context) override; - CombinedCodeActions GetAllCodeActions(const CodeFixAllContext &codeFixAll) override; - static std::vector GetCodeActionsToFix(const CodeFixContext &context); - static ir::AstNode *GetNodeAtLocation(es2panda_Context *context, Range range); - static void MakeChange(ChangeTracker &changeTracker, es2panda_Context *context, Range range, - const std::string &possibleFix); -}; -} // namespace ark::es2panda::lsp -#endif // FIX_EXPECTED_COMMA_H diff --git a/ets2panda/lsp/src/register_code_fix/fix_expected_comma.cpp b/ets2panda/lsp/src/register_code_fix/fix_expected_comma.cpp deleted file mode 100644 index e37751fd2d..0000000000 --- a/ets2panda/lsp/src/register_code_fix/fix_expected_comma.cpp +++ /dev/null @@ -1,105 +0,0 @@ -/** - * 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/internal_api.h" -#include "lsp/include/code_fix_provider.h" -#include "lsp/include/register_code_fix/fix_expected_comma.h" - -namespace ark::es2panda::lsp { -const int G_FIX_EXPECTED_COMMA = 1016; - -void FixExpectedComma::MakeChange(ChangeTracker &changeTracker, es2panda_Context *context, Range range, - const std::string &possibleFix) -{ - if (possibleFix.empty()) { - return; - } - - auto node = GetNodeAtLocation(context, range); - if (node == nullptr) { - return; - } - - if (node->Parent()->IsObjectExpression() && node->IsProperty()) { - changeTracker.ReplaceNodeWithText(context, node->Parent(), possibleFix); - } -} - -ir::AstNode *FixExpectedComma::GetNodeAtLocation(es2panda_Context *context, Range range) -{ - auto *ctx = reinterpret_cast(context); - auto ast = ctx->parserProgram->Ast(); - auto nodeAtLocation = - ast->FindChild([&range](ir::AstNode *node) { return node->Range().start.line == range.start.line_; }); - - return nodeAtLocation; -} - -std::vector FixExpectedComma::GetCodeActionsToFix(const CodeFixContext &context) -{ - CodeFixProvider provider; - auto diagnostics = provider.GetDiagnostics(context); - TextChangesContext textChangesContext = {context.host, context.formatContext, context.preferences}; - std::vector fileTextChanges; - - for (auto &diag : diagnostics->diagnostic) { - auto code = std::get(diag.code_); - if (code != G_FIX_EXPECTED_COMMA) { - continue; - } - - auto changes = ChangeTracker::With(textChangesContext, [&](ChangeTracker &tracker) { - MakeChange(tracker, context.context, diag.range_, diag.source_); - }); - - fileTextChanges.insert(fileTextChanges.end(), changes.begin(), changes.end()); - } - - return fileTextChanges; -} - -FixExpectedComma::FixExpectedComma() -{ - const char *fixId = "FixExpectedComma"; - SetErrorCodes({G_FIX_EXPECTED_COMMA}); - SetFixIds({fixId}); -} - -std::vector FixExpectedComma::GetCodeActions(const CodeFixContext &context) -{ - std::vector returnedActions; - - auto changes = GetCodeActionsToFix(context); - if (!changes.empty()) { - CodeFixAction codeAction; - codeAction.fixName = "fixExpectedComma"; - codeAction.description = "Use comma instead of semicolon at possition"; - codeAction.changes = changes; - codeAction.fixId = "FixExpectedComma"; - returnedActions.push_back(codeAction); - } - - return returnedActions; -} - -CombinedCodeActions FixExpectedComma::GetAllCodeActions(const CodeFixAllContext &codeFixAll) -{ - std::vector fixedNodes; - CodeFixProvider provider; - - return provider.GetAllFixes(codeFixAll); -} -// NOLINTNEXTLINE(fuchsia-statically-constructed-objects, cert-err58-cpp) -} // namespace ark::es2panda::lsp diff --git a/ets2panda/test/unit/lsp/CMakeLists.txt b/ets2panda/test/unit/lsp/CMakeLists.txt index 660f7a8294..df98617b1b 100644 --- a/ets2panda/test/unit/lsp/CMakeLists.txt +++ b/ets2panda/test/unit/lsp/CMakeLists.txt @@ -228,10 +228,6 @@ ets2panda_add_gtest(lsp_api_test_find_rename_locations_2 CPP_SOURCES find_rename_locations_test_2.cpp ) -ets2panda_add_gtest(lsp_api_test_fix_expected_comma CPP_SOURCES - fix_expected_comma_test.cpp -) - ets2panda_add_gtest(lsp_api_test_change_tracker CPP_SOURCES change_tracker_test.cpp ) diff --git a/ets2panda/test/unit/lsp/fix_expected_comma_test.cpp b/ets2panda/test/unit/lsp/fix_expected_comma_test.cpp deleted file mode 100644 index 7723cf669d..0000000000 --- a/ets2panda/test/unit/lsp/fix_expected_comma_test.cpp +++ /dev/null @@ -1,83 +0,0 @@ -/** - * 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 "gtest/gtest.h" -#include "lsp/include/code_fixes/code_fix_types.h" -#include "lsp/include/register_code_fix/fix_expected_comma.h" -#include "lsp/include/internal_api.h" -#include "public/es2panda_lib.h" -#include "lsp_api_test.h" - -namespace { -constexpr int DEFAULT_THROTTLE = 20; -const size_t GETTER_CALL_IDX = 92; - -class FixExpectedCommaTests : public LSPAPITests { -public: - class NullCancellationToken : public ark::es2panda::lsp::HostCancellationToken { - public: - bool IsCancellationRequested() override - { - return false; - } - }; - - static ark::es2panda::lsp::CancellationToken CreateToken() - { - static NullCancellationToken nullToken; - return ark::es2panda::lsp::CancellationToken(DEFAULT_THROTTLE, &nullToken); - } - - static ark::es2panda::lsp::CodeFixContext CreateCodeFixContext(es2panda_Context *ctx, size_t pos) - { - ark::es2panda::lsp::RulesMap rules; - ark::es2panda::lsp::FormatCodeSettings formatSettings; - ark::es2panda::lsp::UserPreferences preferences; - LanguageServiceHost host; - ark::es2panda::lsp::FormatContext fmtCtx {formatSettings, rules}; - TextChangesContext textCtx {host, fmtCtx, preferences}; - return ark::es2panda::lsp::CodeFixContext {{textCtx, ctx, CreateToken()}, 0, TextSpan {pos, 0}}; - } -}; - -TEST_F(FixExpectedCommaTests, FixObjectExpression) -{ - ark::es2panda::lsp::Initializer initializer; - const std::string sourceCode = R"( -interface A { -name: string; -age: number; -} -const a: A = { -name: "foo"; -age: 123; -} - )"; - - const auto c1 = 1; - const auto textChange = R"({ - name: "foo", - age: 123, -})"; - es2panda_Context *ctx = - initializer.CreateContext("fec_fix_object_expression.ets", ES2PANDA_STATE_CHECKED, sourceCode.c_str()); - ark::es2panda::lsp::FixExpectedComma fix; - ark::es2panda::lsp::CodeFixContext context = CreateCodeFixContext(ctx, GETTER_CALL_IDX); - auto actions = fix.GetCodeActions(context); - ASSERT_EQ(actions.size(), c1); - ASSERT_EQ(actions[0].changes[0].textChanges[0].newText, textChange); - initializer.DestroyContext(ctx); -} -} // namespace diff --git a/ets2panda/util/diagnostic/syntax.yaml b/ets2panda/util/diagnostic/syntax.yaml index 6ce29340a6..4048a5559e 100644 --- a/ets2panda/util/diagnostic/syntax.yaml +++ b/ets2panda/util/diagnostic/syntax.yaml @@ -1194,7 +1194,6 @@ syntax: - name: UNEXPECTED_TOKEN id: 16 message: "Unexpected token." - code_fix_ids: [FixExpectedToken] - name: UNEXPECTED_TOKEN_AS id: 95 -- Gitee