Code review fixes

This commit is contained in:
Kirill Bulatov 2019-07-21 20:51:27 +03:00
parent 201b344f2b
commit 24784c60df
3 changed files with 62 additions and 69 deletions

View file

@ -61,7 +61,7 @@ fn get_inlay_hints(node: &SyntaxNode) -> Vec<InlayHint> {
} }
}) })
.accept(&node) .accept(&node)
.unwrap_or_else(Vec::new) .unwrap_or_default()
} }
#[cfg(test)] #[cfg(test)]
@ -93,7 +93,7 @@ fn main() {
let i_squared = i * i; let i_squared = i * i;
i_squared i_squared
}); });
let test: i32 = 33; let test: i32 = 33;
let (x, c) = (42, 'a'); let (x, c) = (42, 'a');
@ -104,7 +104,63 @@ fn main() {
) )
.ok() .ok()
.unwrap(); .unwrap();
let hints = inlay_hints(&file); assert_debug_snapshot_matches!(inlay_hints(&file), @r#"[
assert_debug_snapshot_matches!("inlay_hints", 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::<Vec<_>>();",
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,
},
]"#
);
} }
} }

View file

@ -399,8 +399,8 @@ impl Analysis {
} }
/// Returns a list of the places in the file where type hints can be displayed. /// Returns a list of the places in the file where type hints can be displayed.
pub fn inlay_hints(&self, file_id: FileId) -> Vec<InlayHint> { pub fn inlay_hints(&self, file_id: FileId) -> Cancelable<Vec<InlayHint>> {
inlay_hints::inlay_hints(&self.db.parse(file_id).tree()) self.with_db(|db| inlay_hints::inlay_hints(&db.parse(file_id).tree()))
} }
/// Returns the set of folding ranges. /// Returns the set of folding ranges.

View file

@ -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::<Vec<_>>();",
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,
},
]