From 6f45c2821e4e851bf35fb12fb140cc86886180e8 Mon Sep 17 00:00:00 2001 From: yaohaosen Date: Fri, 13 Jun 2025 11:53:12 +0800 Subject: [PATCH] [LSP] Fix Wrong Span of UI Plugin Code Fix Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICEY82 Signed-off-by: yaohaosen --- ets2panda/lsp/src/register_code_fix/ui_plugin_suggest.cpp | 2 +- ets2panda/test/unit/lsp/code_fix/ui_plugin_suggest.cpp | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/ets2panda/lsp/src/register_code_fix/ui_plugin_suggest.cpp b/ets2panda/lsp/src/register_code_fix/ui_plugin_suggest.cpp index cb5f93b9dd..e450a3c3ec 100644 --- a/ets2panda/lsp/src/register_code_fix/ui_plugin_suggest.cpp +++ b/ets2panda/lsp/src/register_code_fix/ui_plugin_suggest.cpp @@ -39,7 +39,7 @@ std::vector GetTextChangesFromSuggestions(const ark::es2panda::util: for (auto suggestion : diag->Suggestion()) { auto sourceStart = suggestion->SourceRange()->start.index; auto sourceEnd = suggestion->SourceRange()->end.index; - auto span = TextSpan(sourceStart, sourceEnd); + auto span = TextSpan(sourceStart, sourceEnd - sourceStart); if (isAll) { textChanges.emplace_back(TextChange(span, suggestion->SubstitutionCode())); } else if (pos >= sourceStart && pos <= sourceEnd) { diff --git a/ets2panda/test/unit/lsp/code_fix/ui_plugin_suggest.cpp b/ets2panda/test/unit/lsp/code_fix/ui_plugin_suggest.cpp index 93c0d77ff8..e880bebb1d 100644 --- a/ets2panda/test/unit/lsp/code_fix/ui_plugin_suggest.cpp +++ b/ets2panda/test/unit/lsp/code_fix/ui_plugin_suggest.cpp @@ -62,7 +62,7 @@ TEST_F(LspUISuggestionTests, UIPluginsErrorTest1) const char *substitutionCode = "replace b"; const char *dmessage2 = "error"; const size_t argc0 = 0; - const size_t index1 = 0; + const size_t index1 = 1; const size_t line1 = 0; const size_t index2 = 15; const size_t line2 = 0; @@ -84,6 +84,7 @@ TEST_F(LspUISuggestionTests, UIPluginsErrorTest1) CodeFixOptions emptyOptions; auto fix = ark::es2panda::lsp::GetCodeFixesAtPositionImpl(ctx, index1, index2, codes, emptyOptions); ASSERT_EQ(fix.at(0).changes_.at(0).textChanges.at(0).newText, substitutionCode); + ASSERT_EQ(fix.at(0).changes_.at(0).textChanges.at(0).span.length, index2 - index1); initializer.DestroyContext(ctx); } -- Gitee