2019-09-30 08:58:53 +00:00
|
|
|
//! FIXME: write short doc here
|
|
|
|
|
2019-07-21 20:28:05 +00:00
|
|
|
use crate::{db::RootDatabase, FileId};
|
2019-07-26 11:10:29 +00:00
|
|
|
use hir::{HirDisplay, SourceAnalyzer, Ty};
|
2019-07-19 21:20:09 +00:00
|
|
|
use ra_syntax::{
|
|
|
|
algo::visit::{visitor, Visitor},
|
2019-08-19 11:27:15 +00:00
|
|
|
ast::{self, AstNode, TypeAscriptionOwner},
|
|
|
|
SmolStr, SourceFile, SyntaxKind, SyntaxNode, TextRange,
|
2019-07-19 21:20:09 +00:00
|
|
|
};
|
|
|
|
|
2019-08-04 21:28:36 +00:00
|
|
|
#[derive(Debug, PartialEq, Eq)]
|
2019-07-19 21:20:09 +00:00
|
|
|
pub enum InlayKind {
|
2019-08-04 21:28:36 +00:00
|
|
|
TypeHint,
|
2019-07-19 21:20:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct InlayHint {
|
|
|
|
pub range: TextRange,
|
2019-07-22 18:52:47 +00:00
|
|
|
pub kind: InlayKind,
|
|
|
|
pub label: SmolStr,
|
2019-07-19 21:20:09 +00:00
|
|
|
}
|
|
|
|
|
2019-07-21 20:28:05 +00:00
|
|
|
pub(crate) fn inlay_hints(db: &RootDatabase, file_id: FileId, file: &SourceFile) -> Vec<InlayHint> {
|
|
|
|
file.syntax()
|
|
|
|
.descendants()
|
|
|
|
.map(|node| get_inlay_hints(db, file_id, &node).unwrap_or_default())
|
|
|
|
.flatten()
|
|
|
|
.collect()
|
2019-07-19 21:20:09 +00:00
|
|
|
}
|
|
|
|
|
2019-07-21 20:28:05 +00:00
|
|
|
fn get_inlay_hints(
|
|
|
|
db: &RootDatabase,
|
|
|
|
file_id: FileId,
|
|
|
|
node: &SyntaxNode,
|
|
|
|
) -> Option<Vec<InlayHint>> {
|
2019-07-19 21:20:09 +00:00
|
|
|
visitor()
|
2019-08-19 11:27:15 +00:00
|
|
|
.visit(|let_statement: ast::LetStmt| {
|
2019-07-19 21:20:09 +00:00
|
|
|
if let_statement.ascribed_type().is_some() {
|
2019-07-21 20:28:05 +00:00
|
|
|
return None;
|
2019-07-19 21:20:09 +00:00
|
|
|
}
|
2019-07-27 21:50:26 +00:00
|
|
|
let pat = let_statement.pat()?;
|
2019-07-26 11:10:29 +00:00
|
|
|
let analyzer = SourceAnalyzer::new(db, file_id, let_statement.syntax(), None);
|
2019-08-04 21:28:36 +00:00
|
|
|
Some(get_pat_type_hints(db, &analyzer, pat, false))
|
2019-07-19 21:20:09 +00:00
|
|
|
})
|
2019-08-19 11:27:15 +00:00
|
|
|
.visit(|closure_parameter: ast::LambdaExpr| {
|
2019-07-26 11:10:29 +00:00
|
|
|
let analyzer = SourceAnalyzer::new(db, file_id, closure_parameter.syntax(), None);
|
|
|
|
closure_parameter.param_list().map(|param_list| {
|
2019-07-19 21:20:09 +00:00
|
|
|
param_list
|
|
|
|
.params()
|
|
|
|
.filter(|closure_param| closure_param.ascribed_type().is_none())
|
2019-07-26 11:10:29 +00:00
|
|
|
.filter_map(|closure_param| closure_param.pat())
|
2019-08-04 21:28:36 +00:00
|
|
|
.map(|root_pat| get_pat_type_hints(db, &analyzer, root_pat, false))
|
2019-07-26 11:10:29 +00:00
|
|
|
.flatten()
|
|
|
|
.collect()
|
|
|
|
})
|
|
|
|
})
|
2019-08-19 11:27:15 +00:00
|
|
|
.visit(|for_expression: ast::ForExpr| {
|
2019-07-27 21:50:26 +00:00
|
|
|
let pat = for_expression.pat()?;
|
2019-07-26 11:10:29 +00:00
|
|
|
let analyzer = SourceAnalyzer::new(db, file_id, for_expression.syntax(), None);
|
2019-08-04 21:28:36 +00:00
|
|
|
Some(get_pat_type_hints(db, &analyzer, pat, false))
|
2019-07-27 21:50:26 +00:00
|
|
|
})
|
2019-08-19 11:27:15 +00:00
|
|
|
.visit(|if_expr: ast::IfExpr| {
|
2019-07-27 21:50:26 +00:00
|
|
|
let pat = if_expr.condition()?.pat()?;
|
|
|
|
let analyzer = SourceAnalyzer::new(db, file_id, if_expr.syntax(), None);
|
2019-08-04 21:28:36 +00:00
|
|
|
Some(get_pat_type_hints(db, &analyzer, pat, true))
|
2019-07-27 21:50:26 +00:00
|
|
|
})
|
2019-08-19 11:27:15 +00:00
|
|
|
.visit(|while_expr: ast::WhileExpr| {
|
2019-07-27 21:50:26 +00:00
|
|
|
let pat = while_expr.condition()?.pat()?;
|
|
|
|
let analyzer = SourceAnalyzer::new(db, file_id, while_expr.syntax(), None);
|
2019-08-04 21:28:36 +00:00
|
|
|
Some(get_pat_type_hints(db, &analyzer, pat, true))
|
2019-07-27 21:50:26 +00:00
|
|
|
})
|
2019-08-19 11:27:15 +00:00
|
|
|
.visit(|match_arm_list: ast::MatchArmList| {
|
2019-07-27 21:50:26 +00:00
|
|
|
let analyzer = SourceAnalyzer::new(db, file_id, match_arm_list.syntax(), None);
|
|
|
|
Some(
|
|
|
|
match_arm_list
|
|
|
|
.arms()
|
|
|
|
.map(|match_arm| match_arm.pats())
|
|
|
|
.flatten()
|
2019-08-04 21:28:36 +00:00
|
|
|
.map(|root_pat| get_pat_type_hints(db, &analyzer, root_pat, true))
|
2019-07-27 21:50:26 +00:00
|
|
|
.flatten()
|
|
|
|
.collect(),
|
|
|
|
)
|
2019-07-19 21:20:09 +00:00
|
|
|
})
|
2019-07-21 20:28:05 +00:00
|
|
|
.accept(&node)?
|
|
|
|
}
|
|
|
|
|
2019-08-04 21:28:36 +00:00
|
|
|
fn get_pat_type_hints(
|
2019-07-26 11:10:29 +00:00
|
|
|
db: &RootDatabase,
|
|
|
|
analyzer: &SourceAnalyzer,
|
2019-08-19 11:13:58 +00:00
|
|
|
root_pat: ast::Pat,
|
2019-07-27 21:50:26 +00:00
|
|
|
skip_root_pat_hint: bool,
|
2019-07-26 11:10:29 +00:00
|
|
|
) -> Vec<InlayHint> {
|
2019-07-27 21:50:26 +00:00
|
|
|
let original_pat = &root_pat.clone();
|
|
|
|
|
2019-07-26 11:10:29 +00:00
|
|
|
get_leaf_pats(root_pat)
|
|
|
|
.into_iter()
|
2019-07-27 21:50:26 +00:00
|
|
|
.filter(|pat| !skip_root_pat_hint || pat != original_pat)
|
2019-07-26 11:10:29 +00:00
|
|
|
.filter_map(|pat| {
|
|
|
|
get_node_displayable_type(db, &analyzer, &pat)
|
|
|
|
.map(|pat_type| (pat.syntax().text_range(), pat_type))
|
|
|
|
})
|
|
|
|
.map(|(range, pat_type)| InlayHint {
|
|
|
|
range,
|
2019-08-04 21:28:36 +00:00
|
|
|
kind: InlayKind::TypeHint,
|
2019-07-26 11:10:29 +00:00
|
|
|
label: pat_type.display(db).to_string().into(),
|
|
|
|
})
|
|
|
|
.collect()
|
|
|
|
}
|
|
|
|
|
2019-08-19 11:13:58 +00:00
|
|
|
fn get_leaf_pats(root_pat: ast::Pat) -> Vec<ast::Pat> {
|
|
|
|
let mut pats_to_process = std::collections::VecDeque::<ast::Pat>::new();
|
2019-07-26 11:10:29 +00:00
|
|
|
pats_to_process.push_back(root_pat);
|
|
|
|
|
|
|
|
let mut leaf_pats = Vec::new();
|
|
|
|
|
|
|
|
while let Some(maybe_leaf_pat) = pats_to_process.pop_front() {
|
2019-08-19 11:13:58 +00:00
|
|
|
match &maybe_leaf_pat {
|
|
|
|
ast::Pat::BindPat(bind_pat) => {
|
2019-07-26 11:10:29 +00:00
|
|
|
if let Some(pat) = bind_pat.pat() {
|
|
|
|
pats_to_process.push_back(pat);
|
|
|
|
} else {
|
|
|
|
leaf_pats.push(maybe_leaf_pat);
|
|
|
|
}
|
|
|
|
}
|
2019-08-19 11:13:58 +00:00
|
|
|
ast::Pat::TuplePat(tuple_pat) => {
|
2019-07-26 11:10:29 +00:00
|
|
|
for arg_pat in tuple_pat.args() {
|
|
|
|
pats_to_process.push_back(arg_pat);
|
|
|
|
}
|
|
|
|
}
|
2019-08-23 12:55:21 +00:00
|
|
|
ast::Pat::RecordPat(record_pat) => {
|
|
|
|
if let Some(pat_list) = record_pat.record_field_pat_list() {
|
2019-07-27 21:50:26 +00:00
|
|
|
pats_to_process.extend(
|
|
|
|
pat_list
|
2019-08-23 12:55:21 +00:00
|
|
|
.record_field_pats()
|
|
|
|
.filter_map(|record_field_pat| {
|
|
|
|
record_field_pat
|
2019-07-27 21:50:26 +00:00
|
|
|
.pat()
|
|
|
|
.filter(|pat| pat.syntax().kind() != SyntaxKind::BIND_PAT)
|
|
|
|
})
|
|
|
|
.chain(pat_list.bind_pats().map(|bind_pat| {
|
2019-08-19 11:13:58 +00:00
|
|
|
bind_pat.pat().unwrap_or_else(|| ast::Pat::from(bind_pat))
|
2019-07-27 21:50:26 +00:00
|
|
|
})),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2019-08-19 11:13:58 +00:00
|
|
|
ast::Pat::TupleStructPat(tuple_struct_pat) => {
|
2019-07-27 21:50:26 +00:00
|
|
|
for arg_pat in tuple_struct_pat.args() {
|
|
|
|
pats_to_process.push_back(arg_pat);
|
|
|
|
}
|
|
|
|
}
|
2019-07-26 11:10:29 +00:00
|
|
|
_ => (),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
leaf_pats
|
|
|
|
}
|
|
|
|
|
2019-07-21 20:28:05 +00:00
|
|
|
fn get_node_displayable_type(
|
|
|
|
db: &RootDatabase,
|
2019-07-26 11:10:29 +00:00
|
|
|
analyzer: &SourceAnalyzer,
|
2019-08-19 11:13:58 +00:00
|
|
|
node_pat: &ast::Pat,
|
2019-07-21 20:28:05 +00:00
|
|
|
) -> Option<Ty> {
|
|
|
|
analyzer.type_of_pat(db, node_pat).and_then(|resolved_type| {
|
|
|
|
if let Ty::Apply(_) = resolved_type {
|
|
|
|
Some(resolved_type)
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
})
|
2019-07-19 21:20:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
2019-07-21 20:28:05 +00:00
|
|
|
use crate::mock_analysis::single_file;
|
2019-08-29 13:49:10 +00:00
|
|
|
use insta::assert_debug_snapshot;
|
2019-07-19 21:20:09 +00:00
|
|
|
|
|
|
|
#[test]
|
2019-07-27 21:50:26 +00:00
|
|
|
fn let_statement() {
|
2019-07-21 20:28:05 +00:00
|
|
|
let (analysis, file_id) = single_file(
|
2019-07-19 21:20:09 +00:00
|
|
|
r#"
|
2019-07-27 21:50:26 +00:00
|
|
|
#[derive(PartialEq)]
|
|
|
|
enum CustomOption<T> {
|
|
|
|
None,
|
|
|
|
Some(T),
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(PartialEq)]
|
|
|
|
struct Test {
|
|
|
|
a: CustomOption<u32>,
|
|
|
|
b: u8,
|
|
|
|
}
|
2019-07-19 21:20:09 +00:00
|
|
|
|
|
|
|
fn main() {
|
|
|
|
struct InnerStruct {}
|
|
|
|
|
|
|
|
let test = 54;
|
2019-07-26 11:10:29 +00:00
|
|
|
let test: i32 = 33;
|
|
|
|
let mut test = 33;
|
|
|
|
let _ = 22;
|
|
|
|
let test = "test";
|
2019-07-19 21:20:09 +00:00
|
|
|
let test = InnerStruct {};
|
2019-07-26 11:10:29 +00:00
|
|
|
|
2019-07-19 21:20:09 +00:00
|
|
|
let test = vec![222];
|
2019-07-26 11:10:29 +00:00
|
|
|
let test: Vec<_> = (0..3).collect();
|
2019-07-27 21:50:26 +00:00
|
|
|
let test = (0..3).collect::<Vec<i128>>();
|
|
|
|
let test = (0..3).collect::<Vec<_>>();
|
2019-07-26 11:10:29 +00:00
|
|
|
|
2019-07-19 21:20:09 +00:00
|
|
|
let mut test = Vec::new();
|
|
|
|
test.push(333);
|
2019-07-26 11:10:29 +00:00
|
|
|
|
2019-07-19 21:20:09 +00:00
|
|
|
let test = (42, 'a');
|
2019-07-26 11:10:29 +00:00
|
|
|
let (a, (b, c, (d, e), f)) = (2, (3, 4, (6.6, 7.7), 5));
|
2019-07-27 21:50:26 +00:00
|
|
|
}"#,
|
2019-07-21 20:28:05 +00:00
|
|
|
);
|
|
|
|
|
2019-08-29 13:49:10 +00:00
|
|
|
assert_debug_snapshot!(analysis.inlay_hints(file_id).unwrap(), @r#"[
|
2019-07-21 17:51:27 +00:00
|
|
|
InlayHint {
|
2019-07-27 21:50:26 +00:00
|
|
|
range: [193; 197),
|
2019-08-04 21:47:14 +00:00
|
|
|
kind: TypeHint,
|
2019-07-22 18:52:47 +00:00
|
|
|
label: "i32",
|
2019-07-21 17:51:27 +00:00
|
|
|
},
|
|
|
|
InlayHint {
|
2019-07-27 21:50:26 +00:00
|
|
|
range: [236; 244),
|
2019-08-04 21:47:14 +00:00
|
|
|
kind: TypeHint,
|
2019-07-26 11:10:29 +00:00
|
|
|
label: "i32",
|
2019-07-21 17:51:27 +00:00
|
|
|
},
|
|
|
|
InlayHint {
|
2019-07-27 21:50:26 +00:00
|
|
|
range: [275; 279),
|
2019-08-04 21:47:14 +00:00
|
|
|
kind: TypeHint,
|
2019-07-26 11:10:29 +00:00
|
|
|
label: "&str",
|
2019-07-21 17:51:27 +00:00
|
|
|
},
|
|
|
|
InlayHint {
|
2019-07-27 21:50:26 +00:00
|
|
|
range: [539; 543),
|
2019-08-04 21:47:14 +00:00
|
|
|
kind: TypeHint,
|
2019-07-27 21:50:26 +00:00
|
|
|
label: "(i32, char)",
|
2019-07-26 11:10:29 +00:00
|
|
|
},
|
|
|
|
InlayHint {
|
2019-07-27 21:50:26 +00:00
|
|
|
range: [566; 567),
|
2019-08-04 21:47:14 +00:00
|
|
|
kind: TypeHint,
|
2019-07-27 21:50:26 +00:00
|
|
|
label: "i32",
|
2019-07-21 17:51:27 +00:00
|
|
|
},
|
|
|
|
InlayHint {
|
2019-07-27 21:50:26 +00:00
|
|
|
range: [570; 571),
|
2019-08-04 21:47:14 +00:00
|
|
|
kind: TypeHint,
|
2019-07-27 21:50:26 +00:00
|
|
|
label: "i32",
|
2019-07-21 17:51:27 +00:00
|
|
|
},
|
|
|
|
InlayHint {
|
2019-07-27 21:50:26 +00:00
|
|
|
range: [573; 574),
|
2019-08-04 21:47:14 +00:00
|
|
|
kind: TypeHint,
|
2019-07-26 11:10:29 +00:00
|
|
|
label: "i32",
|
|
|
|
},
|
|
|
|
InlayHint {
|
2019-07-27 21:50:26 +00:00
|
|
|
range: [584; 585),
|
2019-08-04 21:47:14 +00:00
|
|
|
kind: TypeHint,
|
2019-07-26 11:10:29 +00:00
|
|
|
label: "i32",
|
|
|
|
},
|
|
|
|
InlayHint {
|
2019-07-27 21:50:26 +00:00
|
|
|
range: [577; 578),
|
2019-08-04 21:47:14 +00:00
|
|
|
kind: TypeHint,
|
2019-07-27 21:50:26 +00:00
|
|
|
label: "f64",
|
|
|
|
},
|
|
|
|
InlayHint {
|
|
|
|
range: [580; 581),
|
2019-08-04 21:47:14 +00:00
|
|
|
kind: TypeHint,
|
2019-07-27 21:50:26 +00:00
|
|
|
label: "f64",
|
|
|
|
},
|
|
|
|
]"#
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn closure_parameter() {
|
|
|
|
let (analysis, file_id) = single_file(
|
|
|
|
r#"
|
|
|
|
fn main() {
|
|
|
|
let mut start = 0;
|
|
|
|
(0..2).for_each(|increment| {
|
|
|
|
start += increment;
|
|
|
|
})
|
|
|
|
}"#,
|
|
|
|
);
|
|
|
|
|
2019-08-29 13:49:10 +00:00
|
|
|
assert_debug_snapshot!(analysis.inlay_hints(file_id).unwrap(), @r#"[
|
2019-07-27 21:50:26 +00:00
|
|
|
InlayHint {
|
|
|
|
range: [21; 30),
|
2019-08-04 21:47:14 +00:00
|
|
|
kind: TypeHint,
|
2019-07-27 21:50:26 +00:00
|
|
|
label: "i32",
|
|
|
|
},
|
|
|
|
InlayHint {
|
|
|
|
range: [57; 66),
|
2019-08-04 21:47:14 +00:00
|
|
|
kind: TypeHint,
|
2019-07-26 11:10:29 +00:00
|
|
|
label: "i32",
|
|
|
|
},
|
2019-07-27 21:50:26 +00:00
|
|
|
]"#
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn for_expression() {
|
|
|
|
let (analysis, file_id) = single_file(
|
|
|
|
r#"
|
|
|
|
fn main() {
|
|
|
|
let mut start = 0;
|
|
|
|
for increment in 0..2 {
|
|
|
|
start += increment;
|
|
|
|
}
|
|
|
|
}"#,
|
|
|
|
);
|
|
|
|
|
2019-08-29 13:49:10 +00:00
|
|
|
assert_debug_snapshot!(analysis.inlay_hints(file_id).unwrap(), @r#"[
|
2019-07-26 11:10:29 +00:00
|
|
|
InlayHint {
|
2019-07-27 21:50:26 +00:00
|
|
|
range: [21; 30),
|
2019-08-04 21:47:14 +00:00
|
|
|
kind: TypeHint,
|
2019-07-26 11:10:29 +00:00
|
|
|
label: "i32",
|
|
|
|
},
|
|
|
|
InlayHint {
|
2019-07-27 21:50:26 +00:00
|
|
|
range: [44; 53),
|
2019-08-04 21:47:14 +00:00
|
|
|
kind: TypeHint,
|
2019-07-27 21:50:26 +00:00
|
|
|
label: "i32",
|
|
|
|
},
|
|
|
|
]"#
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn if_expr() {
|
|
|
|
let (analysis, file_id) = single_file(
|
|
|
|
r#"
|
|
|
|
#[derive(PartialEq)]
|
|
|
|
enum CustomOption<T> {
|
|
|
|
None,
|
|
|
|
Some(T),
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(PartialEq)]
|
|
|
|
struct Test {
|
|
|
|
a: CustomOption<u32>,
|
|
|
|
b: u8,
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let test = CustomOption::Some(Test { a: CustomOption::Some(3), b: 1 });
|
|
|
|
if let CustomOption::None = &test {};
|
|
|
|
if let test = &test {};
|
|
|
|
if let CustomOption::Some(test) = &test {};
|
|
|
|
if let CustomOption::Some(Test { a, b }) = &test {};
|
|
|
|
if let CustomOption::Some(Test { a: x, b: y }) = &test {};
|
|
|
|
if let CustomOption::Some(Test { a: CustomOption::Some(x), b: y }) = &test {};
|
|
|
|
if let CustomOption::Some(Test { a: CustomOption::None, b: y }) = &test {};
|
|
|
|
if let CustomOption::Some(Test { b: y, .. }) = &test {};
|
2019-08-04 21:28:36 +00:00
|
|
|
|
2019-07-27 21:50:26 +00:00
|
|
|
if test == CustomOption::None {}
|
|
|
|
}"#,
|
|
|
|
);
|
|
|
|
|
2019-08-29 13:49:10 +00:00
|
|
|
assert_debug_snapshot!(analysis.inlay_hints(file_id).unwrap(), @r#"[
|
2019-07-27 21:50:26 +00:00
|
|
|
InlayHint {
|
|
|
|
range: [166; 170),
|
2019-08-04 21:47:14 +00:00
|
|
|
kind: TypeHint,
|
2019-07-27 21:50:26 +00:00
|
|
|
label: "CustomOption<Test>",
|
|
|
|
},
|
|
|
|
InlayHint {
|
|
|
|
range: [334; 338),
|
2019-08-04 21:47:14 +00:00
|
|
|
kind: TypeHint,
|
2019-07-27 21:50:26 +00:00
|
|
|
label: "&Test",
|
|
|
|
},
|
|
|
|
InlayHint {
|
|
|
|
range: [389; 390),
|
2019-08-04 21:47:14 +00:00
|
|
|
kind: TypeHint,
|
2019-07-27 21:50:26 +00:00
|
|
|
label: "&CustomOption<u32>",
|
|
|
|
},
|
|
|
|
InlayHint {
|
|
|
|
range: [392; 393),
|
2019-08-04 21:47:14 +00:00
|
|
|
kind: TypeHint,
|
2019-07-27 21:50:26 +00:00
|
|
|
label: "&u8",
|
|
|
|
},
|
|
|
|
InlayHint {
|
|
|
|
range: [531; 532),
|
2019-08-04 21:47:14 +00:00
|
|
|
kind: TypeHint,
|
2019-07-27 21:50:26 +00:00
|
|
|
label: "&u32",
|
2019-07-26 11:10:29 +00:00
|
|
|
},
|
2019-07-27 21:50:26 +00:00
|
|
|
]"#
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn while_expr() {
|
|
|
|
let (analysis, file_id) = single_file(
|
|
|
|
r#"
|
|
|
|
#[derive(PartialEq)]
|
|
|
|
enum CustomOption<T> {
|
|
|
|
None,
|
|
|
|
Some(T),
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(PartialEq)]
|
|
|
|
struct Test {
|
|
|
|
a: CustomOption<u32>,
|
|
|
|
b: u8,
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let test = CustomOption::Some(Test { a: CustomOption::Some(3), b: 1 });
|
|
|
|
while let CustomOption::None = &test {};
|
|
|
|
while let test = &test {};
|
|
|
|
while let CustomOption::Some(test) = &test {};
|
|
|
|
while let CustomOption::Some(Test { a, b }) = &test {};
|
|
|
|
while let CustomOption::Some(Test { a: x, b: y }) = &test {};
|
|
|
|
while let CustomOption::Some(Test { a: CustomOption::Some(x), b: y }) = &test {};
|
|
|
|
while let CustomOption::Some(Test { a: CustomOption::None, b: y }) = &test {};
|
|
|
|
while let CustomOption::Some(Test { b: y, .. }) = &test {};
|
2019-08-04 21:28:36 +00:00
|
|
|
|
2019-07-27 21:50:26 +00:00
|
|
|
while test == CustomOption::None {}
|
|
|
|
}"#,
|
|
|
|
);
|
|
|
|
|
2019-08-29 13:49:10 +00:00
|
|
|
assert_debug_snapshot!(analysis.inlay_hints(file_id).unwrap(), @r###"
|
2019-08-07 13:14:22 +00:00
|
|
|
⋮[
|
|
|
|
⋮ InlayHint {
|
|
|
|
⋮ range: [166; 170),
|
|
|
|
⋮ kind: TypeHint,
|
|
|
|
⋮ label: "CustomOption<Test>",
|
|
|
|
⋮ },
|
|
|
|
⋮ InlayHint {
|
|
|
|
⋮ range: [343; 347),
|
|
|
|
⋮ kind: TypeHint,
|
|
|
|
⋮ label: "&Test",
|
|
|
|
⋮ },
|
|
|
|
⋮ InlayHint {
|
|
|
|
⋮ range: [401; 402),
|
|
|
|
⋮ kind: TypeHint,
|
|
|
|
⋮ label: "&CustomOption<u32>",
|
|
|
|
⋮ },
|
|
|
|
⋮ InlayHint {
|
|
|
|
⋮ range: [404; 405),
|
|
|
|
⋮ kind: TypeHint,
|
|
|
|
⋮ label: "&u8",
|
|
|
|
⋮ },
|
|
|
|
⋮ InlayHint {
|
|
|
|
⋮ range: [549; 550),
|
|
|
|
⋮ kind: TypeHint,
|
|
|
|
⋮ label: "&u32",
|
|
|
|
⋮ },
|
|
|
|
⋮]
|
|
|
|
"###
|
2019-07-27 21:50:26 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn match_arm_list() {
|
|
|
|
let (analysis, file_id) = single_file(
|
|
|
|
r#"
|
|
|
|
#[derive(PartialEq)]
|
2019-08-04 21:28:36 +00:00
|
|
|
enum CustomOption<T> {
|
2019-07-27 21:50:26 +00:00
|
|
|
None,
|
|
|
|
Some(T),
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(PartialEq)]
|
|
|
|
struct Test {
|
|
|
|
a: CustomOption<u32>,
|
|
|
|
b: u8,
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
match CustomOption::Some(Test { a: CustomOption::Some(3), b: 1 }) {
|
|
|
|
CustomOption::None => (),
|
|
|
|
test => (),
|
|
|
|
CustomOption::Some(test) => (),
|
|
|
|
CustomOption::Some(Test { a, b }) => (),
|
|
|
|
CustomOption::Some(Test { a: x, b: y }) => (),
|
|
|
|
CustomOption::Some(Test { a: CustomOption::Some(x), b: y }) => (),
|
|
|
|
CustomOption::Some(Test { a: CustomOption::None, b: y }) => (),
|
|
|
|
CustomOption::Some(Test { b: y, .. }) => (),
|
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
}"#,
|
|
|
|
);
|
|
|
|
|
2019-08-29 13:49:10 +00:00
|
|
|
assert_debug_snapshot!(analysis.inlay_hints(file_id).unwrap(), @r#"[
|
2019-07-27 21:50:26 +00:00
|
|
|
InlayHint {
|
2019-08-04 21:47:14 +00:00
|
|
|
range: [311; 315),
|
|
|
|
kind: TypeHint,
|
2019-07-27 21:50:26 +00:00
|
|
|
label: "Test",
|
|
|
|
},
|
|
|
|
InlayHint {
|
2019-08-04 21:47:14 +00:00
|
|
|
range: [358; 359),
|
|
|
|
kind: TypeHint,
|
2019-07-27 21:50:26 +00:00
|
|
|
label: "CustomOption<u32>",
|
|
|
|
},
|
|
|
|
InlayHint {
|
2019-08-04 21:47:14 +00:00
|
|
|
range: [361; 362),
|
|
|
|
kind: TypeHint,
|
2019-07-27 21:50:26 +00:00
|
|
|
label: "u8",
|
|
|
|
},
|
|
|
|
InlayHint {
|
2019-08-04 21:47:14 +00:00
|
|
|
range: [484; 485),
|
|
|
|
kind: TypeHint,
|
2019-07-27 21:50:26 +00:00
|
|
|
label: "u32",
|
2019-07-21 17:51:27 +00:00
|
|
|
},
|
|
|
|
]"#
|
|
|
|
);
|
2019-07-19 21:20:09 +00:00
|
|
|
}
|
|
|
|
}
|