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 cb5f93b9dda915eee2a779e1283cb51772b7c319..e450a3c3ecd961686459ebae171a3e13bfbbcfac 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 93c0d77ff82f8236c030d423a9da8b0aa90f7cad..e880bebb1db4ca319685a2e209547b211a317b86 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); }