remove ast::*Kind from ra_ide_api

This commit is contained in:
Aleksey Kladov 2019-08-19 14:13:58 +03:00
parent 3bec812258
commit df6dce23a7
5 changed files with 19 additions and 21 deletions

View File

@ -91,8 +91,8 @@ fn with_node(syntax: &SyntaxNode, offset: TextUnit) -> Option<FnCallNode> {
fn name_ref(&self) -> Option<ast::NameRef> {
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,
}),

View File

@ -33,13 +33,11 @@ fn impls_for_def(
node: &ast::NominalDef,
module: hir::Module,
) -> Option<Vec<NavigationTarget>> {
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)?;

View File

@ -3,7 +3,7 @@
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<InlayHint> {
let original_pat = &root_pat.clone();
@ -108,27 +108,27 @@ fn get_pat_type_hints(
.collect()
}
fn get_leaf_pats(root_pat: Pat) -> Vec<Pat> {
let mut pats_to_process = std::collections::VecDeque::<Pat>::new();
fn get_leaf_pats(root_pat: ast::Pat) -> Vec<ast::Pat> {
let mut pats_to_process = std::collections::VecDeque::<ast::Pat>::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<Pat> {
.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<Pat> {
fn get_node_displayable_type(
db: &RootDatabase,
analyzer: &SourceAnalyzer,
node_pat: &Pat,
node_pat: &ast::Pat,
) -> Option<Ty> {
analyzer.type_of_pat(db, node_pat).and_then(|resolved_type| {
if let Ty::Apply(_) = resolved_type {

View File

@ -75,7 +75,7 @@ fn find_binding<'a>(
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));
}
}

View File

@ -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"));