Skip to content

Commit f98dfed

Browse files
authored
Merge pull request #2384 from henryhchchc/master
Checking the validity of line range before generating code actions
2 parents 1f2b094 + 8240142 commit f98dfed

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

verible/verilog/tools/ls/autoexpand.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1689,6 +1689,7 @@ std::vector<CodeAction> GenerateAutoExpandCodeActions(
16891689
const BufferTracker *const tracker, const CodeActionParams &p) {
16901690
Interval<size_t> line_range{static_cast<size_t>(p.range.start.line),
16911691
static_cast<size_t>(p.range.end.line)};
1692+
if (!line_range.valid()) return {};
16921693
if (!tracker) return {};
16931694
const auto current = tracker->current();
16941695
if (!current) return {}; // Can only expand if we have latest version

verible/verilog/tools/ls/autoexpand_test.cc

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3600,6 +3600,43 @@ endmodule
36003600
);
36013601
}
36023602

3603+
TEST(Autoexpand, InvalidLineRange) {
3604+
TestTextEdits(
3605+
R"(
3606+
module foo ( /*AUTOARG*/);
3607+
/*AUTOINPUT*/
3608+
/*AUTOOUTPUT*/
3609+
3610+
/* qux AUTO_TEMPLATE
3611+
bar AUTO_TEMPLATE (
3612+
.o1(out_a[]),
3613+
.o2(out_b[])
3614+
); */
3615+
bar b ( /*AUTOINST*/);
3616+
endmodule
3617+
)",
3618+
R"(
3619+
module foo ( /*AUTOARG*/);
3620+
/*AUTOINPUT*/
3621+
/*AUTOOUTPUT*/
3622+
3623+
/* qux AUTO_TEMPLATE
3624+
bar AUTO_TEMPLATE (
3625+
.o1(out_a[]),
3626+
.o2(out_b[])
3627+
); */
3628+
bar b ( /*AUTOINST*/);
3629+
endmodule
3630+
)",
3631+
TestRun{.edit_fn = [](SymbolTableHandler *symbol_table_handler,
3632+
BufferTracker *tracker) {
3633+
return AutoExpandCodeActionToTextEdits(
3634+
symbol_table_handler, tracker,
3635+
{.start = {.line = 5}, .end = {.line = 1}},
3636+
"Expand with invalid range");
3637+
}}.repeat());
3638+
}
3639+
36033640
TEST(Autoexpand, InstanceNotModule) {
36043641
TestTextEdits(
36053642
R"(

0 commit comments

Comments
 (0)