From f57c15f3e9843ad6b220d5f75f3e0b2cb126098a Mon Sep 17 00:00:00 2001 From: Mathew Horner Date: Mon, 12 Sep 2022 16:34:13 -0500 Subject: [PATCH] Address comments and fix build. --- crates/ide/src/annotations.rs | 27 ++++++++++----------------- crates/rust-analyzer/src/config.rs | 9 +++++---- crates/rust-analyzer/src/handlers.rs | 2 +- docs/user/generated_config.adoc | 10 +++++----- editors/code/package.json | 26 +++++++++++++------------- 5 files changed, 34 insertions(+), 40 deletions(-) diff --git a/crates/ide/src/annotations.rs b/crates/ide/src/annotations.rs index 7019658a16..bfbe0db6e4 100644 --- a/crates/ide/src/annotations.rs +++ b/crates/ide/src/annotations.rs @@ -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 { 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 = 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 }, ); } } diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs index 6c6ad5f43a..68b4c20140 100644 --- a/crates/rust-analyzer/src/config.rs +++ b/crates/rust-analyzer/src/config.rs @@ -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, } } diff --git a/crates/rust-analyzer/src/handlers.rs b/crates/rust-analyzer/src/handlers.rs index edac9de69a..a1eb972f78 100644 --- a/crates/rust-analyzer/src/handlers.rs +++ b/crates/rust-analyzer/src/handlers.rs @@ -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, )?; diff --git a/docs/user/generated_config.adoc b/docs/user/generated_config.adoc index 3cd49bc5d8..6e6d40e3ff 100644 --- a/docs/user/generated_config.adoc +++ b/docs/user/generated_config.adoc @@ -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`):: + -- diff --git a/editors/code/package.json b/editors/code/package.json index 465d866021..3696c99624 100644 --- a/editors/code/package.json +++ b/editors/code/package.json @@ -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,