From 24784c60df583d1807faa889a84312df1d2e3b22 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Sun, 21 Jul 2019 20:51:27 +0300 Subject: Code review fixes --- crates/ra_ide_api/src/inlay_hints.rs | 64 ++++++++++++++++++++-- crates/ra_ide_api/src/lib.rs | 4 +- .../src/snapshots/tests__inlay_hints.snap | 63 --------------------- 3 files changed, 62 insertions(+), 69 deletions(-) delete mode 100644 crates/ra_ide_api/src/snapshots/tests__inlay_hints.snap (limited to 'crates') diff --git a/crates/ra_ide_api/src/inlay_hints.rs b/crates/ra_ide_api/src/inlay_hints.rs index 4d1df65d0..739a44b19 100644 --- a/crates/ra_ide_api/src/inlay_hints.rs +++ b/crates/ra_ide_api/src/inlay_hints.rs @@ -61,7 +61,7 @@ fn get_inlay_hints(node: &SyntaxNode) -> Vec { } }) .accept(&node) - .unwrap_or_else(Vec::new) + .unwrap_or_default() } #[cfg(test)] @@ -93,7 +93,7 @@ fn main() { let i_squared = i * i; i_squared }); - + let test: i32 = 33; let (x, c) = (42, 'a'); @@ -104,7 +104,63 @@ fn main() { ) .ok() .unwrap(); - let hints = inlay_hints(&file); - assert_debug_snapshot_matches!("inlay_hints", hints); + assert_debug_snapshot_matches!(inlay_hints(&file), @r#"[ + InlayHint { + range: [71; 75), + text: "let test = 54;", + inlay_kind: LetBinding, + }, + InlayHint { + range: [90; 94), + text: "let test = InnerStruct {};", + inlay_kind: LetBinding, + }, + InlayHint { + range: [121; 125), + text: "let test = OuterStruct {};", + inlay_kind: LetBinding, + }, + InlayHint { + range: [152; 156), + text: "let test = vec![222];", + inlay_kind: LetBinding, + }, + InlayHint { + range: [178; 186), + text: "let mut test = Vec::new();", + inlay_kind: LetBinding, + }, + InlayHint { + range: [229; 233), + text: "let test = test.into_iter().map(|i| i * i).collect::>();", + inlay_kind: LetBinding, + }, + InlayHint { + range: [258; 259), + text: "i", + inlay_kind: ClosureParameter, + }, + InlayHint { + range: [297; 305), + text: "let mut test = 33;", + inlay_kind: LetBinding, + }, + InlayHint { + range: [417; 426), + text: "let i_squared = i * i;", + inlay_kind: LetBinding, + }, + InlayHint { + range: [496; 502), + text: "let (x, c) = (42, \'a\');", + inlay_kind: LetBinding, + }, + InlayHint { + range: [524; 528), + text: "let test = (42, \'a\');", + inlay_kind: LetBinding, + }, +]"# + ); } } diff --git a/crates/ra_ide_api/src/lib.rs b/crates/ra_ide_api/src/lib.rs index af163088a..32168f12d 100644 --- a/crates/ra_ide_api/src/lib.rs +++ b/crates/ra_ide_api/src/lib.rs @@ -399,8 +399,8 @@ impl Analysis { } /// Returns a list of the places in the file where type hints can be displayed. - pub fn inlay_hints(&self, file_id: FileId) -> Vec { - inlay_hints::inlay_hints(&self.db.parse(file_id).tree()) + pub fn inlay_hints(&self, file_id: FileId) -> Cancelable> { + self.with_db(|db| inlay_hints::inlay_hints(&db.parse(file_id).tree())) } /// Returns the set of folding ranges. diff --git a/crates/ra_ide_api/src/snapshots/tests__inlay_hints.snap b/crates/ra_ide_api/src/snapshots/tests__inlay_hints.snap deleted file mode 100644 index f4d562314..000000000 --- a/crates/ra_ide_api/src/snapshots/tests__inlay_hints.snap +++ /dev/null @@ -1,63 +0,0 @@ ---- -created: "2019-07-20T20:13:53.385368Z" -creator: insta@0.8.1 -source: crates/ra_ide_api/src/inlay_hints.rs -expression: hints ---- -[ - InlayHint { - range: [71; 75), - text: "let test = 54;", - inlay_kind: LetBinding, - }, - InlayHint { - range: [90; 94), - text: "let test = InnerStruct {};", - inlay_kind: LetBinding, - }, - InlayHint { - range: [121; 125), - text: "let test = OuterStruct {};", - inlay_kind: LetBinding, - }, - InlayHint { - range: [152; 156), - text: "let test = vec![222];", - inlay_kind: LetBinding, - }, - InlayHint { - range: [178; 186), - text: "let mut test = Vec::new();", - inlay_kind: LetBinding, - }, - InlayHint { - range: [229; 233), - text: "let test = test.into_iter().map(|i| i * i).collect::>();", - inlay_kind: LetBinding, - }, - InlayHint { - range: [258; 259), - text: "i", - inlay_kind: ClosureParameter, - }, - InlayHint { - range: [297; 305), - text: "let mut test = 33;", - inlay_kind: LetBinding, - }, - InlayHint { - range: [417; 426), - text: "let i_squared = i * i;", - inlay_kind: LetBinding, - }, - InlayHint { - range: [500; 506), - text: "let (x, c) = (42, \'a\');", - inlay_kind: LetBinding, - }, - InlayHint { - range: [528; 532), - text: "let test = (42, \'a\');", - inlay_kind: LetBinding, - }, -] -- cgit v1.2.3