Skip to content

Commit f57c15f

Browse files
committed
Address comments and fix build.
1 parent 8a2803d commit f57c15f

File tree

5 files changed

+34
-40
lines changed

5 files changed

+34
-40
lines changed

crates/ide/src/annotations.rs

+10-17
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ pub struct AnnotationConfig {
4141
pub annotate_references: bool,
4242
pub annotate_method_references: bool,
4343
pub annotate_enum_variant_references: bool,
44-
pub annotation_location: AnnotationLocation,
44+
pub location: AnnotationLocation,
4545
}
4646

4747
pub enum AnnotationLocation {
@@ -137,7 +137,7 @@ pub(crate) fn annotations(
137137
) -> Option<TextRange> {
138138
if let Some(InFile { file_id, value }) = node.original_ast_node(db) {
139139
if file_id == source_file_id.into() {
140-
return match config.annotation_location {
140+
return match config.location {
141141
AnnotationLocation::AboveName => {
142142
value.name().map(|name| name.syntax().text_range())
143143
}
@@ -212,10 +212,10 @@ mod tests {
212212
annotate_references: true,
213213
annotate_method_references: true,
214214
annotate_enum_variant_references: true,
215-
annotation_location: AnnotationLocation::AboveName,
215+
location: AnnotationLocation::AboveName,
216216
};
217217

218-
fn check(ra_fixture: &str, expect: Expect, config: &AnnotationConfig) {
218+
fn check_with_config(ra_fixture: &str, expect: Expect, config: &AnnotationConfig) {
219219
let (analysis, file_id) = fixture::file(ra_fixture);
220220

221221
let annotations: Vec<Annotation> = analysis
@@ -228,6 +228,10 @@ mod tests {
228228
expect.assert_debug_eq(&annotations);
229229
}
230230

231+
fn check(ra_fixture: &str, expect: Expect) {
232+
check_with_config(ra_fixture, expect, &DEFAULT_CONFIG);
233+
}
234+
231235
#[test]
232236
fn const_annotations() {
233237
check(
@@ -303,7 +307,6 @@ fn main() {
303307
},
304308
]
305309
"#]],
306-
&DEFAULT_CONFIG,
307310
);
308311
}
309312

@@ -380,7 +383,6 @@ fn main() {
380383
},
381384
]
382385
"#]],
383-
&DEFAULT_CONFIG,
384386
);
385387
}
386388

@@ -516,7 +518,6 @@ fn main() {
516518
},
517519
]
518520
"#]],
519-
&DEFAULT_CONFIG,
520521
);
521522
}
522523

@@ -560,7 +561,6 @@ fn main() {}
560561
},
561562
]
562563
"#]],
563-
&DEFAULT_CONFIG,
564564
);
565565
}
566566

@@ -675,7 +675,6 @@ fn main() {
675675
},
676676
]
677677
"#]],
678-
&DEFAULT_CONFIG,
679678
);
680679
}
681680

@@ -772,7 +771,6 @@ mod tests {
772771
},
773772
]
774773
"#]],
775-
&DEFAULT_CONFIG,
776774
);
777775
}
778776

@@ -788,7 +786,6 @@ struct Foo;
788786
expect![[r#"
789787
[]
790788
"#]],
791-
&DEFAULT_CONFIG,
792789
);
793790
}
794791

@@ -808,13 +805,12 @@ m!();
808805
expect![[r#"
809806
[]
810807
"#]],
811-
&DEFAULT_CONFIG,
812808
);
813809
}
814810

815811
#[test]
816812
fn test_annotations_appear_above_whole_item_when_configured_to_do_so() {
817-
check(
813+
check_with_config(
818814
r#"
819815
/// This is a struct named Foo, obviously.
820816
#[derive(Clone)]
@@ -844,10 +840,7 @@ struct Foo;
844840
},
845841
]
846842
"#]],
847-
&AnnotationConfig {
848-
annotation_location: AnnotationLocation::AboveWholeItem,
849-
..DEFAULT_CONFIG
850-
},
843+
&AnnotationConfig { location: AnnotationLocation::AboveWholeItem, ..DEFAULT_CONFIG },
851844
);
852845
}
853846
}

crates/rust-analyzer/src/config.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,7 @@ config_data! {
307307
/// Join lines unwraps trivial blocks.
308308
joinLines_unwrapTrivialBlock: bool = "true",
309309

310-
/// Where to render annotations.
311-
lens_annotationLocation: AnnotationLocation = "\"above_name\"",
310+
312311
/// Whether to show `Debug` lens. Only applies when
313312
/// `#rust-analyzer.lens.enable#` is set.
314313
lens_debug_enable: bool = "true",
@@ -320,6 +319,8 @@ config_data! {
320319
/// Whether to show `Implementations` lens. Only applies when
321320
/// `#rust-analyzer.lens.enable#` is set.
322321
lens_implementations_enable: bool = "true",
322+
/// Where to render annotations.
323+
lens_location: AnnotationLocation = "\"above_name\"",
323324
/// Whether to show `References` lens for Struct, Enum, and Union.
324325
/// Only applies when `#rust-analyzer.lens.enable#` is set.
325326
lens_references_adt_enable: bool = "false",
@@ -498,7 +499,7 @@ pub struct LensConfig {
498499
pub enum_variant_refs: bool,
499500

500501
// annotations
501-
pub annotation_location: AnnotationLocation,
502+
pub location: AnnotationLocation,
502503
}
503504

504505
#[derive(Copy, Clone, Debug, PartialEq, Eq, Deserialize)]
@@ -1206,7 +1207,7 @@ impl Config {
12061207
refs_trait: self.data.lens_enable && self.data.lens_references_trait_enable,
12071208
enum_variant_refs: self.data.lens_enable
12081209
&& self.data.lens_references_enumVariant_enable,
1209-
annotation_location: self.data.lens_annotationLocation,
1210+
location: self.data.lens_location,
12101211
}
12111212
}
12121213

crates/rust-analyzer/src/handlers.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1234,7 +1234,7 @@ pub(crate) fn handle_code_lens(
12341234
annotate_references: lens_config.refs_adt,
12351235
annotate_method_references: lens_config.method_refs,
12361236
annotate_enum_variant_references: lens_config.enum_variant_refs,
1237-
annotation_location: lens_config.annotation_location.into(),
1237+
location: lens_config.location.into(),
12381238
},
12391239
file_id,
12401240
)?;

docs/user/generated_config.adoc

+5-5
Original file line numberDiff line numberDiff line change
@@ -451,11 +451,6 @@ Join lines removes trailing commas.
451451
--
452452
Join lines unwraps trivial blocks.
453453
--
454-
[[rust-analyzer.lens.annotation.location]]rust-analyzer.lens.annotation.location (default: `above_name`)::
455-
+
456-
--
457-
Where to render annotations.
458-
--
459454
[[rust-analyzer.lens.debug.enable]]rust-analyzer.lens.debug.enable (default: `true`)::
460455
+
461456
--
@@ -479,6 +474,11 @@ client doesn't set the corresponding capability.
479474
Whether to show `Implementations` lens. Only applies when
480475
`#rust-analyzer.lens.enable#` is set.
481476
--
477+
[[rust-analyzer.lens.location]]rust-analyzer.lens.location (default: `"above_name"`)::
478+
+
479+
--
480+
Where to render annotations.
481+
--
482482
[[rust-analyzer.lens.references.adt.enable]]rust-analyzer.lens.references.adt.enable (default: `false`)::
483483
+
484484
--

editors/code/package.json

+13-13
Original file line numberDiff line numberDiff line change
@@ -943,19 +943,6 @@
943943
"default": true,
944944
"type": "boolean"
945945
},
946-
"rust-analyzer.lens.annotationLocation": {
947-
"markdownDescription": "Where to render annotations.",
948-
"default": "above_name",
949-
"type": "string",
950-
"enum": [
951-
"above_name",
952-
"above_whole_item"
953-
],
954-
"enumDescriptions": [
955-
"Render annotations above the name of the item.",
956-
"Render annotations above the whole item, including documentation comments and attributes."
957-
]
958-
},
959946
"rust-analyzer.lens.debug.enable": {
960947
"markdownDescription": "Whether to show `Debug` lens. Only applies when\n`#rust-analyzer.lens.enable#` is set.",
961948
"default": true,
@@ -976,6 +963,19 @@
976963
"default": true,
977964
"type": "boolean"
978965
},
966+
"rust-analyzer.lens.location": {
967+
"markdownDescription": "Where to render annotations.",
968+
"default": "above_name",
969+
"type": "string",
970+
"enum": [
971+
"above_name",
972+
"above_whole_item"
973+
],
974+
"enumDescriptions": [
975+
"Render annotations above the name of the item.",
976+
"Render annotations above the whole item, including documentation comments and attributes."
977+
]
978+
},
979979
"rust-analyzer.lens.references.adt.enable": {
980980
"markdownDescription": "Whether to show `References` lens for Struct, Enum, and Union.\nOnly applies when `#rust-analyzer.lens.enable#` is set.",
981981
"default": false,

0 commit comments

Comments
 (0)