Skip to content

Commit adf325c

Browse files
committed
Add missing test, remove redundant work
1 parent c7f287f commit adf325c

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

compiler-core/src/language_server/code_action.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1367,7 +1367,7 @@ pub struct AnnotateTopLevelDefinitions<'a> {
13671367
module: &'a Module,
13681368
params: &'a CodeActionParams,
13691369
edits: TextEdits<'a>,
1370-
is_hovering_definition: bool,
1370+
is_hovering_definition_requiring_annotations: bool,
13711371
}
13721372

13731373
impl<'a> AnnotateTopLevelDefinitions<'a> {
@@ -1380,7 +1380,7 @@ impl<'a> AnnotateTopLevelDefinitions<'a> {
13801380
module,
13811381
params,
13821382
edits: TextEdits::new(line_numbers),
1383-
is_hovering_definition: false,
1383+
is_hovering_definition_requiring_annotations: false,
13841384
}
13851385
}
13861386

@@ -1389,7 +1389,7 @@ impl<'a> AnnotateTopLevelDefinitions<'a> {
13891389

13901390
// We only want to trigger the action if we're over one of the definition
13911391
// which is lacking some annotations in the module
1392-
if !self.is_hovering_definition || self.edits.edits.is_empty() {
1392+
if !self.is_hovering_definition_requiring_annotations {
13931393
return vec![];
13941394
};
13951395

@@ -1414,7 +1414,7 @@ impl<'ast> ast::visit::Visit<'ast> for AnnotateTopLevelDefinitions<'_> {
14141414

14151415
// We're hovering definition which needs some annotations
14161416
if overlaps(code_action_range, self.params.range) {
1417-
self.is_hovering_definition = true;
1417+
self.is_hovering_definition_requiring_annotations = true;
14181418
}
14191419

14201420
self.edits.insert(
@@ -1441,16 +1441,15 @@ impl<'ast> ast::visit::Visit<'ast> for AnnotateTopLevelDefinitions<'_> {
14411441
return;
14421442
}
14431443

1444-
// Create new printer to ignore type variables from other definitions
1445-
let mut printer = Printer::new_without_type_variables(&self.module.ast.names);
1446-
collect_type_variables(&mut printer, fun);
1447-
14481444
let code_action_range = self.edits.src_span_to_lsp_range(fun.location);
1449-
14501445
if overlaps(code_action_range, self.params.range) {
1451-
self.is_hovering_definition = true;
1446+
self.is_hovering_definition_requiring_annotations = true;
14521447
}
14531448

1449+
// Create new printer to ignore type variables from other definitions
1450+
let mut printer = Printer::new_without_type_variables(&self.module.ast.names);
1451+
collect_type_variables(&mut printer, fun);
1452+
14541453
// Annotate each argument separately
14551454
for argument in arguments_to_annotate {
14561455
self.edits.insert(

compiler-core/src/language_server/tests/action.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11318,3 +11318,16 @@ fn wobble(other) { todo }
1131811318
find_position_of("wobble").to_selection()
1131911319
);
1132011320
}
11321+
11322+
#[test]
11323+
fn annotate_all_top_level_definitions_not_suggested_if_annotations_present() {
11324+
assert_no_code_actions!(
11325+
ANNOTATE_TOP_LEVEL_DEFINITIONS,
11326+
r#"
11327+
fn wibble(one: Int) -> Int { one }
11328+
11329+
fn wobble(one) { wibble(one) }
11330+
"#,
11331+
find_position_of("wibble").to_selection()
11332+
);
11333+
}

0 commit comments

Comments
 (0)