From df6dce23a7d1a87617939fb9bd61a4d65933cef5 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 19 Aug 2019 14:13:58 +0300 Subject: remove ast::*Kind from ra_ide_api --- crates/ra_ide_api/src/call_info.rs | 4 ++-- crates/ra_ide_api/src/impls.rs | 8 +++----- crates/ra_ide_api/src/inlay_hints.rs | 22 +++++++++++----------- crates/ra_ide_api/src/references.rs | 2 +- crates/ra_ide_api/src/runnables.rs | 4 ++-- 5 files changed, 19 insertions(+), 21 deletions(-) (limited to 'crates/ra_ide_api') diff --git a/crates/ra_ide_api/src/call_info.rs b/crates/ra_ide_api/src/call_info.rs index 212448d41..d5e116526 100644 --- a/crates/ra_ide_api/src/call_info.rs +++ b/crates/ra_ide_api/src/call_info.rs @@ -91,8 +91,8 @@ impl FnCallNode { fn name_ref(&self) -> Option { match self { - FnCallNode::CallExpr(call_expr) => Some(match call_expr.expr()?.kind() { - ast::ExprKind::PathExpr(path_expr) => path_expr.path()?.segment()?.name_ref()?, + FnCallNode::CallExpr(call_expr) => Some(match call_expr.expr()? { + ast::Expr::PathExpr(path_expr) => path_expr.path()?.segment()?.name_ref()?, _ => return None, }), diff --git a/crates/ra_ide_api/src/impls.rs b/crates/ra_ide_api/src/impls.rs index 638f4cbde..c5620dd52 100644 --- a/crates/ra_ide_api/src/impls.rs +++ b/crates/ra_ide_api/src/impls.rs @@ -33,13 +33,11 @@ fn impls_for_def( node: &ast::NominalDef, module: hir::Module, ) -> Option> { - let ty = match node.kind() { - ast::NominalDefKind::StructDef(def) => { + let ty = match node { + ast::NominalDef::StructDef(def) => { source_binder::struct_from_module(db, module, &def).ty(db) } - ast::NominalDefKind::EnumDef(def) => { - source_binder::enum_from_module(db, module, &def).ty(db) - } + ast::NominalDef::EnumDef(def) => source_binder::enum_from_module(db, module, &def).ty(db), }; let krate = module.krate(db)?; diff --git a/crates/ra_ide_api/src/inlay_hints.rs b/crates/ra_ide_api/src/inlay_hints.rs index 0b3c96d26..058cd68e2 100644 --- a/crates/ra_ide_api/src/inlay_hints.rs +++ b/crates/ra_ide_api/src/inlay_hints.rs @@ -3,7 +3,7 @@ use hir::{HirDisplay, SourceAnalyzer, Ty}; use ra_syntax::{ algo::visit::{visitor, Visitor}, ast::{ - AstNode, ForExpr, IfExpr, LambdaExpr, LetStmt, MatchArmList, Pat, PatKind, SourceFile, + self, AstNode, ForExpr, IfExpr, LambdaExpr, LetStmt, MatchArmList, SourceFile, TypeAscriptionOwner, WhileExpr, }, SmolStr, SyntaxKind, SyntaxNode, TextRange, @@ -88,7 +88,7 @@ fn get_inlay_hints( fn get_pat_type_hints( db: &RootDatabase, analyzer: &SourceAnalyzer, - root_pat: Pat, + root_pat: ast::Pat, skip_root_pat_hint: bool, ) -> Vec { let original_pat = &root_pat.clone(); @@ -108,27 +108,27 @@ fn get_pat_type_hints( .collect() } -fn get_leaf_pats(root_pat: Pat) -> Vec { - let mut pats_to_process = std::collections::VecDeque::::new(); +fn get_leaf_pats(root_pat: ast::Pat) -> Vec { + let mut pats_to_process = std::collections::VecDeque::::new(); pats_to_process.push_back(root_pat); let mut leaf_pats = Vec::new(); while let Some(maybe_leaf_pat) = pats_to_process.pop_front() { - match maybe_leaf_pat.kind() { - PatKind::BindPat(bind_pat) => { + match &maybe_leaf_pat { + ast::Pat::BindPat(bind_pat) => { if let Some(pat) = bind_pat.pat() { pats_to_process.push_back(pat); } else { leaf_pats.push(maybe_leaf_pat); } } - PatKind::TuplePat(tuple_pat) => { + ast::Pat::TuplePat(tuple_pat) => { for arg_pat in tuple_pat.args() { pats_to_process.push_back(arg_pat); } } - PatKind::StructPat(struct_pat) => { + ast::Pat::StructPat(struct_pat) => { if let Some(pat_list) = struct_pat.field_pat_list() { pats_to_process.extend( pat_list @@ -139,12 +139,12 @@ fn get_leaf_pats(root_pat: Pat) -> Vec { .filter(|pat| pat.syntax().kind() != SyntaxKind::BIND_PAT) }) .chain(pat_list.bind_pats().map(|bind_pat| { - bind_pat.pat().unwrap_or_else(|| Pat::from(bind_pat)) + bind_pat.pat().unwrap_or_else(|| ast::Pat::from(bind_pat)) })), ); } } - PatKind::TupleStructPat(tuple_struct_pat) => { + ast::Pat::TupleStructPat(tuple_struct_pat) => { for arg_pat in tuple_struct_pat.args() { pats_to_process.push_back(arg_pat); } @@ -158,7 +158,7 @@ fn get_leaf_pats(root_pat: Pat) -> Vec { fn get_node_displayable_type( db: &RootDatabase, analyzer: &SourceAnalyzer, - node_pat: &Pat, + node_pat: &ast::Pat, ) -> Option { analyzer.type_of_pat(db, node_pat).and_then(|resolved_type| { if let Ty::Apply(_) = resolved_type { diff --git a/crates/ra_ide_api/src/references.rs b/crates/ra_ide_api/src/references.rs index 2118e7ad3..342e73fd3 100644 --- a/crates/ra_ide_api/src/references.rs +++ b/crates/ra_ide_api/src/references.rs @@ -75,7 +75,7 @@ pub(crate) fn find_all_refs( let analyzer = hir::SourceAnalyzer::new(db, position.file_id, name_ref.syntax(), None); let resolved = analyzer.resolve_local_name(&name_ref)?; if let Either::A(ptr) = resolved.ptr() { - if let ast::PatKind::BindPat(binding) = ptr.to_node(source_file.syntax()).kind() { + if let ast::Pat::BindPat(binding) = ptr.to_node(source_file.syntax()) { return Some((binding, analyzer)); } } diff --git a/crates/ra_ide_api/src/runnables.rs b/crates/ra_ide_api/src/runnables.rs index 09c082de9..9ea96909e 100644 --- a/crates/ra_ide_api/src/runnables.rs +++ b/crates/ra_ide_api/src/runnables.rs @@ -54,8 +54,8 @@ fn runnable_mod(db: &RootDatabase, file_id: FileId, module: ast::Module) -> Opti let has_test_function = module .item_list()? .items() - .filter_map(|it| match it.kind() { - ast::ModuleItemKind::FnDef(it) => Some(it), + .filter_map(|it| match it { + ast::ModuleItem::FnDef(it) => Some(it), _ => None, }) .any(|f| f.has_atom_attr("test")); -- cgit v1.2.3