Address comments and fix build.

This commit is contained in:
Mathew Horner 2022-09-12 16:34:13 -05:00
parent 8a2803d9ae
commit f57c15f3e9
5 changed files with 34 additions and 40 deletions

View file

@ -41,7 +41,7 @@ pub struct AnnotationConfig {
pub annotate_references: bool,
pub annotate_method_references: bool,
pub annotate_enum_variant_references: bool,
pub annotation_location: AnnotationLocation,
pub location: AnnotationLocation,
}
pub enum AnnotationLocation {
@ -137,7 +137,7 @@ pub(crate) fn annotations(
) -> Option<TextRange> {
if let Some(InFile { file_id, value }) = node.original_ast_node(db) {
if file_id == source_file_id.into() {
return match config.annotation_location {
return match config.location {
AnnotationLocation::AboveName => {
value.name().map(|name| name.syntax().text_range())
}
@ -212,10 +212,10 @@ mod tests {
annotate_references: true,
annotate_method_references: true,
annotate_enum_variant_references: true,
annotation_location: AnnotationLocation::AboveName,
location: AnnotationLocation::AboveName,
};
fn check(ra_fixture: &str, expect: Expect, config: &AnnotationConfig) {
fn check_with_config(ra_fixture: &str, expect: Expect, config: &AnnotationConfig) {
let (analysis, file_id) = fixture::file(ra_fixture);
let annotations: Vec<Annotation> = analysis
@ -228,6 +228,10 @@ mod tests {
expect.assert_debug_eq(&annotations);
}
fn check(ra_fixture: &str, expect: Expect) {
check_with_config(ra_fixture, expect, &DEFAULT_CONFIG);
}
#[test]
fn const_annotations() {
check(
@ -303,7 +307,6 @@ fn main() {
},
]
"#]],
&DEFAULT_CONFIG,
);
}
@ -380,7 +383,6 @@ fn main() {
},
]
"#]],
&DEFAULT_CONFIG,
);
}
@ -516,7 +518,6 @@ fn main() {
},
]
"#]],
&DEFAULT_CONFIG,
);
}
@ -560,7 +561,6 @@ fn main() {}
},
]
"#]],
&DEFAULT_CONFIG,
);
}
@ -675,7 +675,6 @@ fn main() {
},
]
"#]],
&DEFAULT_CONFIG,
);
}
@ -772,7 +771,6 @@ mod tests {
},
]
"#]],
&DEFAULT_CONFIG,
);
}
@ -788,7 +786,6 @@ struct Foo;
expect![[r#"
[]
"#]],
&DEFAULT_CONFIG,
);
}
@ -808,13 +805,12 @@ m!();
expect![[r#"
[]
"#]],
&DEFAULT_CONFIG,
);
}
#[test]
fn test_annotations_appear_above_whole_item_when_configured_to_do_so() {
check(
check_with_config(
r#"
/// This is a struct named Foo, obviously.
#[derive(Clone)]
@ -844,10 +840,7 @@ struct Foo;
},
]
"#]],
&AnnotationConfig {
annotation_location: AnnotationLocation::AboveWholeItem,
..DEFAULT_CONFIG
},
&AnnotationConfig { location: AnnotationLocation::AboveWholeItem, ..DEFAULT_CONFIG },
);
}
}

View file

@ -307,8 +307,7 @@ config_data! {
/// Join lines unwraps trivial blocks.
joinLines_unwrapTrivialBlock: bool = "true",
/// Where to render annotations.
lens_annotationLocation: AnnotationLocation = "\"above_name\"",
/// Whether to show `Debug` lens. Only applies when
/// `#rust-analyzer.lens.enable#` is set.
lens_debug_enable: bool = "true",
@ -320,6 +319,8 @@ config_data! {
/// Whether to show `Implementations` lens. Only applies when
/// `#rust-analyzer.lens.enable#` is set.
lens_implementations_enable: bool = "true",
/// Where to render annotations.
lens_location: AnnotationLocation = "\"above_name\"",
/// Whether to show `References` lens for Struct, Enum, and Union.
/// Only applies when `#rust-analyzer.lens.enable#` is set.
lens_references_adt_enable: bool = "false",
@ -498,7 +499,7 @@ pub struct LensConfig {
pub enum_variant_refs: bool,
// annotations
pub annotation_location: AnnotationLocation,
pub location: AnnotationLocation,
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, Deserialize)]
@ -1206,7 +1207,7 @@ impl Config {
refs_trait: self.data.lens_enable && self.data.lens_references_trait_enable,
enum_variant_refs: self.data.lens_enable
&& self.data.lens_references_enumVariant_enable,
annotation_location: self.data.lens_annotationLocation,
location: self.data.lens_location,
}
}

View file

@ -1234,7 +1234,7 @@ pub(crate) fn handle_code_lens(
annotate_references: lens_config.refs_adt,
annotate_method_references: lens_config.method_refs,
annotate_enum_variant_references: lens_config.enum_variant_refs,
annotation_location: lens_config.annotation_location.into(),
location: lens_config.location.into(),
},
file_id,
)?;

View file

@ -451,11 +451,6 @@ Join lines removes trailing commas.
--
Join lines unwraps trivial blocks.
--
[[rust-analyzer.lens.annotation.location]]rust-analyzer.lens.annotation.location (default: `above_name`)::
+
--
Where to render annotations.
--
[[rust-analyzer.lens.debug.enable]]rust-analyzer.lens.debug.enable (default: `true`)::
+
--
@ -479,6 +474,11 @@ client doesn't set the corresponding capability.
Whether to show `Implementations` lens. Only applies when
`#rust-analyzer.lens.enable#` is set.
--
[[rust-analyzer.lens.location]]rust-analyzer.lens.location (default: `"above_name"`)::
+
--
Where to render annotations.
--
[[rust-analyzer.lens.references.adt.enable]]rust-analyzer.lens.references.adt.enable (default: `false`)::
+
--

View file

@ -943,19 +943,6 @@
"default": true,
"type": "boolean"
},
"rust-analyzer.lens.annotationLocation": {
"markdownDescription": "Where to render annotations.",
"default": "above_name",
"type": "string",
"enum": [
"above_name",
"above_whole_item"
],
"enumDescriptions": [
"Render annotations above the name of the item.",
"Render annotations above the whole item, including documentation comments and attributes."
]
},
"rust-analyzer.lens.debug.enable": {
"markdownDescription": "Whether to show `Debug` lens. Only applies when\n`#rust-analyzer.lens.enable#` is set.",
"default": true,
@ -976,6 +963,19 @@
"default": true,
"type": "boolean"
},
"rust-analyzer.lens.location": {
"markdownDescription": "Where to render annotations.",
"default": "above_name",
"type": "string",
"enum": [
"above_name",
"above_whole_item"
],
"enumDescriptions": [
"Render annotations above the name of the item.",
"Render annotations above the whole item, including documentation comments and attributes."
]
},
"rust-analyzer.lens.references.adt.enable": {
"markdownDescription": "Whether to show `References` lens for Struct, Enum, and Union.\nOnly applies when `#rust-analyzer.lens.enable#` is set.",
"default": false,