aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_hir/src/source_binder.rs64
-rw-r--r--crates/ra_ide_api/src/runnables.rs14
-rw-r--r--crates/ra_syntax/src/ast/traits.rs12
-rw-r--r--editors/code/src/extension.ts2
4 files changed, 51 insertions, 41 deletions
diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs
index 01f51ba5d..152bc71bd 100644
--- a/crates/ra_hir/src/source_binder.rs
+++ b/crates/ra_hir/src/source_binder.rs
@@ -12,7 +12,7 @@ use hir_expand::name::AsName;
12use ra_db::FileId; 12use ra_db::FileId;
13use ra_syntax::{ 13use ra_syntax::{
14 ast::{self, AstNode}, 14 ast::{self, AstNode},
15 AstPtr, 15 match_ast, AstPtr,
16 SyntaxKind::*, 16 SyntaxKind::*,
17 SyntaxNode, SyntaxNodePtr, TextRange, TextUnit, 17 SyntaxNode, SyntaxNodePtr, TextRange, TextUnit,
18}; 18};
@@ -37,24 +37,34 @@ fn try_get_resolver_for_node(
37 file_id: FileId, 37 file_id: FileId,
38 node: &SyntaxNode, 38 node: &SyntaxNode,
39) -> Option<Resolver> { 39) -> Option<Resolver> {
40 if let Some(module) = ast::Module::cast(node.clone()) { 40 match_ast! {
41 let src = crate::Source { file_id: file_id.into(), ast: module }; 41 match node {
42 Some(crate::Module::from_declaration(db, src)?.resolver(db)) 42 ast::Module(it) => {
43 } else if let Some(file) = ast::SourceFile::cast(node.clone()) { 43 let src = crate::Source { file_id: file_id.into(), ast: it };
44 let src = 44 Some(crate::Module::from_declaration(db, src)?.resolver(db))
45 crate::Source { file_id: file_id.into(), ast: crate::ModuleSource::SourceFile(file) }; 45 },
46 Some(crate::Module::from_definition(db, src)?.resolver(db)) 46 ast::SourceFile(it) => {
47 } else if let Some(s) = ast::StructDef::cast(node.clone()) { 47 let src =
48 let src = crate::Source { file_id: file_id.into(), ast: s }; 48 crate::Source { file_id: file_id.into(), ast: crate::ModuleSource::SourceFile(it) };
49 Some(Struct::from_source(db, src)?.resolver(db)) 49 Some(crate::Module::from_definition(db, src)?.resolver(db))
50 } else if let Some(e) = ast::EnumDef::cast(node.clone()) { 50 },
51 let src = crate::Source { file_id: file_id.into(), ast: e }; 51 ast::StructDef(it) => {
52 Some(Enum::from_source(db, src)?.resolver(db)) 52 let src = crate::Source { file_id: file_id.into(), ast: it };
53 } else if node.kind() == FN_DEF || node.kind() == CONST_DEF || node.kind() == STATIC_DEF { 53 Some(Struct::from_source(db, src)?.resolver(db))
54 Some(def_with_body_from_child_node(db, file_id, node)?.resolver(db)) 54 },
55 } else { 55 ast::EnumDef(it) => {
56 // FIXME add missing cases 56 let src = crate::Source { file_id: file_id.into(), ast: it };
57 None 57 Some(Enum::from_source(db, src)?.resolver(db))
58 },
59 _ => {
60 if node.kind() == FN_DEF || node.kind() == CONST_DEF || node.kind() == STATIC_DEF {
61 Some(def_with_body_from_child_node(db, file_id, node)?.resolver(db))
62 } else {
63 // FIXME add missing cases
64 None
65 }
66 },
67 }
58 } 68 }
59} 69}
60 70
@@ -68,16 +78,14 @@ fn def_with_body_from_child_node(
68 let ctx = LocationCtx::new(db, module.id, file_id.into()); 78 let ctx = LocationCtx::new(db, module.id, file_id.into());
69 79
70 node.ancestors().find_map(|node| { 80 node.ancestors().find_map(|node| {
71 if let Some(def) = ast::FnDef::cast(node.clone()) { 81 match_ast! {
72 return Some(Function { id: ctx.to_def(&def) }.into()); 82 match node {
73 } 83 ast::FnDef(def) => { Some(Function {id: ctx.to_def(&def) }.into()) },
74 if let Some(def) = ast::ConstDef::cast(node.clone()) { 84 ast::ConstDef(def) => { Some(Const { id: ctx.to_def(&def) }.into()) },
75 return Some(Const { id: ctx.to_def(&def) }.into()); 85 ast::StaticDef(def) => { Some(Static { id: ctx.to_def(&def) }.into()) },
76 } 86 _ => { None },
77 if let Some(def) = ast::StaticDef::cast(node) { 87 }
78 return Some(Static { id: ctx.to_def(&def) }.into());
79 } 88 }
80 None
81 }) 89 })
82} 90}
83 91
diff --git a/crates/ra_ide_api/src/runnables.rs b/crates/ra_ide_api/src/runnables.rs
index 910883da7..1b5c8deea 100644
--- a/crates/ra_ide_api/src/runnables.rs
+++ b/crates/ra_ide_api/src/runnables.rs
@@ -4,7 +4,7 @@ use itertools::Itertools;
4use ra_db::SourceDatabase; 4use ra_db::SourceDatabase;
5use ra_syntax::{ 5use ra_syntax::{
6 ast::{self, AstNode, AttrsOwner, ModuleItemOwner, NameOwner}, 6 ast::{self, AstNode, AttrsOwner, ModuleItemOwner, NameOwner},
7 SyntaxNode, TextRange, 7 match_ast, SyntaxNode, TextRange,
8}; 8};
9 9
10use crate::{db::RootDatabase, FileId}; 10use crate::{db::RootDatabase, FileId};
@@ -29,12 +29,12 @@ pub(crate) fn runnables(db: &RootDatabase, file_id: FileId) -> Vec<Runnable> {
29} 29}
30 30
31fn runnable(db: &RootDatabase, file_id: FileId, item: SyntaxNode) -> Option<Runnable> { 31fn runnable(db: &RootDatabase, file_id: FileId, item: SyntaxNode) -> Option<Runnable> {
32 if let Some(fn_def) = ast::FnDef::cast(item.clone()) { 32 match_ast! {
33 runnable_fn(fn_def) 33 match item {
34 } else if let Some(m) = ast::Module::cast(item) { 34 ast::FnDef(it) => { runnable_fn(it) },
35 runnable_mod(db, file_id, m) 35 ast::Module(it) => { runnable_mod(db, file_id, it) },
36 } else { 36 _ => { None },
37 None 37 }
38 } 38 }
39} 39}
40 40
diff --git a/crates/ra_syntax/src/ast/traits.rs b/crates/ra_syntax/src/ast/traits.rs
index 76313684e..c2b005886 100644
--- a/crates/ra_syntax/src/ast/traits.rs
+++ b/crates/ra_syntax/src/ast/traits.rs
@@ -6,6 +6,7 @@ use itertools::Itertools;
6 6
7use crate::{ 7use crate::{
8 ast::{self, child_opt, children, AstChildren, AstNode, AstToken}, 8 ast::{self, child_opt, children, AstChildren, AstNode, AstToken},
9 match_ast,
9 syntax_node::{SyntaxElementChildren, SyntaxNodeChildren}, 10 syntax_node::{SyntaxElementChildren, SyntaxNodeChildren},
10}; 11};
11 12
@@ -68,11 +69,12 @@ impl Iterator for ItemOrMacroIter {
68 fn next(&mut self) -> Option<ItemOrMacro> { 69 fn next(&mut self) -> Option<ItemOrMacro> {
69 loop { 70 loop {
70 let n = self.0.next()?; 71 let n = self.0.next()?;
71 if let Some(item) = ast::ModuleItem::cast(n.clone()) { 72 match_ast! {
72 return Some(ItemOrMacro::Item(item)); 73 match n {
73 } 74 ast::ModuleItem(it) => { return Some(ItemOrMacro::Item(it)) },
74 if let Some(call) = ast::MacroCall::cast(n) { 75 ast::MacroCall(it) => { return Some(ItemOrMacro::Macro(it)) },
75 return Some(ItemOrMacro::Macro(call)); 76 _ => {},
77 }
76 } 78 }
77 } 79 }
78 } 80 }
diff --git a/editors/code/src/extension.ts b/editors/code/src/extension.ts
index 39fe6efd8..c06928d12 100644
--- a/editors/code/src/extension.ts
+++ b/editors/code/src/extension.ts
@@ -45,7 +45,7 @@ export function activate(context: vscode.ExtensionContext) {
45 }); 45 });
46 } catch (_) { 46 } catch (_) {
47 vscode.window.showWarningMessage( 47 vscode.window.showWarningMessage(
48 'Enhanced typing feature is disabled because of incompatibility with VIM extension' 48 'Enhanced typing feature is disabled because of incompatibility with VIM extension, consider turning off rust-analyzer.enableEnhancedTyping: https://github.com/rust-analyzer/rust-analyzer/blob/master/docs/user/README.md#settings'
49 ); 49 );
50 } 50 }
51 } 51 }