mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 05:23:24 +00:00
Address comments and fix build.
This commit is contained in:
parent
8a2803d9ae
commit
f57c15f3e9
5 changed files with 34 additions and 40 deletions
|
@ -41,7 +41,7 @@ pub struct AnnotationConfig {
|
||||||
pub annotate_references: bool,
|
pub annotate_references: bool,
|
||||||
pub annotate_method_references: bool,
|
pub annotate_method_references: bool,
|
||||||
pub annotate_enum_variant_references: bool,
|
pub annotate_enum_variant_references: bool,
|
||||||
pub annotation_location: AnnotationLocation,
|
pub location: AnnotationLocation,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum AnnotationLocation {
|
pub enum AnnotationLocation {
|
||||||
|
@ -137,7 +137,7 @@ pub(crate) fn annotations(
|
||||||
) -> Option<TextRange> {
|
) -> Option<TextRange> {
|
||||||
if let Some(InFile { file_id, value }) = node.original_ast_node(db) {
|
if let Some(InFile { file_id, value }) = node.original_ast_node(db) {
|
||||||
if file_id == source_file_id.into() {
|
if file_id == source_file_id.into() {
|
||||||
return match config.annotation_location {
|
return match config.location {
|
||||||
AnnotationLocation::AboveName => {
|
AnnotationLocation::AboveName => {
|
||||||
value.name().map(|name| name.syntax().text_range())
|
value.name().map(|name| name.syntax().text_range())
|
||||||
}
|
}
|
||||||
|
@ -212,10 +212,10 @@ mod tests {
|
||||||
annotate_references: true,
|
annotate_references: true,
|
||||||
annotate_method_references: true,
|
annotate_method_references: true,
|
||||||
annotate_enum_variant_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 (analysis, file_id) = fixture::file(ra_fixture);
|
||||||
|
|
||||||
let annotations: Vec<Annotation> = analysis
|
let annotations: Vec<Annotation> = analysis
|
||||||
|
@ -228,6 +228,10 @@ mod tests {
|
||||||
expect.assert_debug_eq(&annotations);
|
expect.assert_debug_eq(&annotations);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn check(ra_fixture: &str, expect: Expect) {
|
||||||
|
check_with_config(ra_fixture, expect, &DEFAULT_CONFIG);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn const_annotations() {
|
fn const_annotations() {
|
||||||
check(
|
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#"
|
expect![[r#"
|
||||||
[]
|
[]
|
||||||
"#]],
|
"#]],
|
||||||
&DEFAULT_CONFIG,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -808,13 +805,12 @@ m!();
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
[]
|
[]
|
||||||
"#]],
|
"#]],
|
||||||
&DEFAULT_CONFIG,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_annotations_appear_above_whole_item_when_configured_to_do_so() {
|
fn test_annotations_appear_above_whole_item_when_configured_to_do_so() {
|
||||||
check(
|
check_with_config(
|
||||||
r#"
|
r#"
|
||||||
/// This is a struct named Foo, obviously.
|
/// This is a struct named Foo, obviously.
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
|
@ -844,10 +840,7 @@ struct Foo;
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
"#]],
|
"#]],
|
||||||
&AnnotationConfig {
|
&AnnotationConfig { location: AnnotationLocation::AboveWholeItem, ..DEFAULT_CONFIG },
|
||||||
annotation_location: AnnotationLocation::AboveWholeItem,
|
|
||||||
..DEFAULT_CONFIG
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -307,8 +307,7 @@ config_data! {
|
||||||
/// Join lines unwraps trivial blocks.
|
/// Join lines unwraps trivial blocks.
|
||||||
joinLines_unwrapTrivialBlock: bool = "true",
|
joinLines_unwrapTrivialBlock: bool = "true",
|
||||||
|
|
||||||
/// Where to render annotations.
|
|
||||||
lens_annotationLocation: AnnotationLocation = "\"above_name\"",
|
|
||||||
/// Whether to show `Debug` lens. Only applies when
|
/// Whether to show `Debug` lens. Only applies when
|
||||||
/// `#rust-analyzer.lens.enable#` is set.
|
/// `#rust-analyzer.lens.enable#` is set.
|
||||||
lens_debug_enable: bool = "true",
|
lens_debug_enable: bool = "true",
|
||||||
|
@ -320,6 +319,8 @@ config_data! {
|
||||||
/// Whether to show `Implementations` lens. Only applies when
|
/// Whether to show `Implementations` lens. Only applies when
|
||||||
/// `#rust-analyzer.lens.enable#` is set.
|
/// `#rust-analyzer.lens.enable#` is set.
|
||||||
lens_implementations_enable: bool = "true",
|
lens_implementations_enable: bool = "true",
|
||||||
|
/// Where to render annotations.
|
||||||
|
lens_location: AnnotationLocation = "\"above_name\"",
|
||||||
/// Whether to show `References` lens for Struct, Enum, and Union.
|
/// Whether to show `References` lens for Struct, Enum, and Union.
|
||||||
/// Only applies when `#rust-analyzer.lens.enable#` is set.
|
/// Only applies when `#rust-analyzer.lens.enable#` is set.
|
||||||
lens_references_adt_enable: bool = "false",
|
lens_references_adt_enable: bool = "false",
|
||||||
|
@ -498,7 +499,7 @@ pub struct LensConfig {
|
||||||
pub enum_variant_refs: bool,
|
pub enum_variant_refs: bool,
|
||||||
|
|
||||||
// annotations
|
// annotations
|
||||||
pub annotation_location: AnnotationLocation,
|
pub location: AnnotationLocation,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, PartialEq, Eq, Deserialize)]
|
#[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,
|
refs_trait: self.data.lens_enable && self.data.lens_references_trait_enable,
|
||||||
enum_variant_refs: self.data.lens_enable
|
enum_variant_refs: self.data.lens_enable
|
||||||
&& self.data.lens_references_enumVariant_enable,
|
&& self.data.lens_references_enumVariant_enable,
|
||||||
annotation_location: self.data.lens_annotationLocation,
|
location: self.data.lens_location,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1234,7 +1234,7 @@ pub(crate) fn handle_code_lens(
|
||||||
annotate_references: lens_config.refs_adt,
|
annotate_references: lens_config.refs_adt,
|
||||||
annotate_method_references: lens_config.method_refs,
|
annotate_method_references: lens_config.method_refs,
|
||||||
annotate_enum_variant_references: lens_config.enum_variant_refs,
|
annotate_enum_variant_references: lens_config.enum_variant_refs,
|
||||||
annotation_location: lens_config.annotation_location.into(),
|
location: lens_config.location.into(),
|
||||||
},
|
},
|
||||||
file_id,
|
file_id,
|
||||||
)?;
|
)?;
|
||||||
|
|
|
@ -451,11 +451,6 @@ Join lines removes trailing commas.
|
||||||
--
|
--
|
||||||
Join lines unwraps trivial blocks.
|
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`)::
|
[[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
|
Whether to show `Implementations` lens. Only applies when
|
||||||
`#rust-analyzer.lens.enable#` is set.
|
`#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`)::
|
[[rust-analyzer.lens.references.adt.enable]]rust-analyzer.lens.references.adt.enable (default: `false`)::
|
||||||
+
|
+
|
||||||
--
|
--
|
||||||
|
|
|
@ -943,19 +943,6 @@
|
||||||
"default": true,
|
"default": true,
|
||||||
"type": "boolean"
|
"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": {
|
"rust-analyzer.lens.debug.enable": {
|
||||||
"markdownDescription": "Whether to show `Debug` lens. Only applies when\n`#rust-analyzer.lens.enable#` is set.",
|
"markdownDescription": "Whether to show `Debug` lens. Only applies when\n`#rust-analyzer.lens.enable#` is set.",
|
||||||
"default": true,
|
"default": true,
|
||||||
|
@ -976,6 +963,19 @@
|
||||||
"default": true,
|
"default": true,
|
||||||
"type": "boolean"
|
"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": {
|
"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.",
|
"markdownDescription": "Whether to show `References` lens for Struct, Enum, and Union.\nOnly applies when `#rust-analyzer.lens.enable#` is set.",
|
||||||
"default": false,
|
"default": false,
|
||||||
|
|
Loading…
Reference in a new issue