aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide_api')
-rw-r--r--crates/ra_ide_api/src/call_info.rs6
-rw-r--r--crates/ra_ide_api/src/change.rs4
-rw-r--r--crates/ra_ide_api/src/completion/completion_context.rs7
-rw-r--r--crates/ra_ide_api/src/goto_type_definition.rs3
-rw-r--r--crates/ra_ide_api/src/hover.rs3
-rw-r--r--crates/ra_ide_api/src/inlay_hints.rs7
-rw-r--r--crates/ra_ide_api/src/references.rs15
-rw-r--r--crates/ra_ide_api/src/references/classify.rs35
-rw-r--r--crates/ra_ide_api/src/runnables.rs6
9 files changed, 57 insertions, 29 deletions
diff --git a/crates/ra_ide_api/src/call_info.rs b/crates/ra_ide_api/src/call_info.rs
index 3572825b5..41ee81511 100644
--- a/crates/ra_ide_api/src/call_info.rs
+++ b/crates/ra_ide_api/src/call_info.rs
@@ -19,7 +19,11 @@ pub(crate) fn call_info(db: &RootDatabase, position: FilePosition) -> Option<Cal
19 let calling_node = FnCallNode::with_node(&syntax, position.offset)?; 19 let calling_node = FnCallNode::with_node(&syntax, position.offset)?;
20 let name_ref = calling_node.name_ref()?; 20 let name_ref = calling_node.name_ref()?;
21 21
22 let analyzer = hir::SourceAnalyzer::new(db, position.file_id, name_ref.syntax(), None); 22 let analyzer = hir::SourceAnalyzer::new(
23 db,
24 hir::Source::new(position.file_id.into(), name_ref.syntax()),
25 None,
26 );
23 let (mut call_info, has_self) = match &calling_node { 27 let (mut call_info, has_self) = match &calling_node {
24 FnCallNode::CallExpr(expr) => { 28 FnCallNode::CallExpr(expr) => {
25 //FIXME: apply subst 29 //FIXME: apply subst
diff --git a/crates/ra_ide_api/src/change.rs b/crates/ra_ide_api/src/change.rs
index 010b45141..5c9dec13e 100644
--- a/crates/ra_ide_api/src/change.rs
+++ b/crates/ra_ide_api/src/change.rs
@@ -271,7 +271,6 @@ impl RootDatabase {
271 self.query(hir::db::AstIdMapQuery).sweep(sweep); 271 self.query(hir::db::AstIdMapQuery).sweep(sweep);
272 272
273 self.query(hir::db::RawItemsWithSourceMapQuery).sweep(sweep); 273 self.query(hir::db::RawItemsWithSourceMapQuery).sweep(sweep);
274 self.query(hir::db::ImplsInModuleWithSourceMapQuery).sweep(sweep);
275 self.query(hir::db::BodyWithSourceMapQuery).sweep(sweep); 274 self.query(hir::db::BodyWithSourceMapQuery).sweep(sweep);
276 275
277 self.query(hir::db::ExprScopesQuery).sweep(sweep); 276 self.query(hir::db::ExprScopesQuery).sweep(sweep);
@@ -314,8 +313,6 @@ impl RootDatabase {
314 hir::db::RawItemsWithSourceMapQuery 313 hir::db::RawItemsWithSourceMapQuery
315 hir::db::RawItemsQuery 314 hir::db::RawItemsQuery
316 hir::db::CrateDefMapQuery 315 hir::db::CrateDefMapQuery
317 hir::db::ImplsInModuleWithSourceMapQuery
318 hir::db::ImplsInModuleQuery
319 hir::db::GenericParamsQuery 316 hir::db::GenericParamsQuery
320 hir::db::FnDataQuery 317 hir::db::FnDataQuery
321 hir::db::TypeAliasDataQuery 318 hir::db::TypeAliasDataQuery
@@ -340,6 +337,7 @@ impl RootDatabase {
340 hir::db::TraitDatumQuery 337 hir::db::TraitDatumQuery
341 hir::db::StructDatumQuery 338 hir::db::StructDatumQuery
342 hir::db::ImplDatumQuery 339 hir::db::ImplDatumQuery
340 hir::db::ImplDataQuery
343 hir::db::TraitSolveQuery 341 hir::db::TraitSolveQuery
344 ]; 342 ];
345 acc.sort_by_key(|it| std::cmp::Reverse(it.1)); 343 acc.sort_by_key(|it| std::cmp::Reverse(it.1));
diff --git a/crates/ra_ide_api/src/completion/completion_context.rs b/crates/ra_ide_api/src/completion/completion_context.rs
index 64cbc0f98..0906a4e1b 100644
--- a/crates/ra_ide_api/src/completion/completion_context.rs
+++ b/crates/ra_ide_api/src/completion/completion_context.rs
@@ -58,8 +58,11 @@ impl<'a> CompletionContext<'a> {
58 ); 58 );
59 let token = 59 let token =
60 original_parse.tree().syntax().token_at_offset(position.offset).left_biased()?; 60 original_parse.tree().syntax().token_at_offset(position.offset).left_biased()?;
61 let analyzer = 61 let analyzer = hir::SourceAnalyzer::new(
62 hir::SourceAnalyzer::new(db, position.file_id, &token.parent(), Some(position.offset)); 62 db,
63 hir::Source::new(position.file_id.into(), &token.parent()),
64 Some(position.offset),
65 );
63 let mut ctx = CompletionContext { 66 let mut ctx = CompletionContext {
64 db, 67 db,
65 analyzer, 68 analyzer,
diff --git a/crates/ra_ide_api/src/goto_type_definition.rs b/crates/ra_ide_api/src/goto_type_definition.rs
index 71146591d..2327cb1e7 100644
--- a/crates/ra_ide_api/src/goto_type_definition.rs
+++ b/crates/ra_ide_api/src/goto_type_definition.rs
@@ -18,7 +18,8 @@ pub(crate) fn goto_type_definition(
18 .find(|n| ast::Expr::cast(n.clone()).is_some() || ast::Pat::cast(n.clone()).is_some()) 18 .find(|n| ast::Expr::cast(n.clone()).is_some() || ast::Pat::cast(n.clone()).is_some())
19 })?; 19 })?;
20 20
21 let analyzer = hir::SourceAnalyzer::new(db, position.file_id, &node, None); 21 let analyzer =
22 hir::SourceAnalyzer::new(db, hir::Source::new(position.file_id.into(), &node), None);
22 23
23 let ty: hir::Ty = if let Some(ty) = 24 let ty: hir::Ty = if let Some(ty) =
24 ast::Expr::cast(node.clone()).and_then(|e| analyzer.type_of(db, &e)) 25 ast::Expr::cast(node.clone()).and_then(|e| analyzer.type_of(db, &e))
diff --git a/crates/ra_ide_api/src/hover.rs b/crates/ra_ide_api/src/hover.rs
index 07d511fb3..92b4b1f79 100644
--- a/crates/ra_ide_api/src/hover.rs
+++ b/crates/ra_ide_api/src/hover.rs
@@ -230,7 +230,8 @@ pub(crate) fn type_of(db: &RootDatabase, frange: FileRange) -> Option<String> {
230 .ancestors() 230 .ancestors()
231 .take_while(|it| it.text_range() == leaf_node.text_range()) 231 .take_while(|it| it.text_range() == leaf_node.text_range())
232 .find(|it| ast::Expr::cast(it.clone()).is_some() || ast::Pat::cast(it.clone()).is_some())?; 232 .find(|it| ast::Expr::cast(it.clone()).is_some() || ast::Pat::cast(it.clone()).is_some())?;
233 let analyzer = hir::SourceAnalyzer::new(db, frange.file_id, &node, None); 233 let analyzer =
234 hir::SourceAnalyzer::new(db, hir::Source::new(frange.file_id.into(), &node), None);
234 let ty = if let Some(ty) = ast::Expr::cast(node.clone()).and_then(|e| analyzer.type_of(db, &e)) 235 let ty = if let Some(ty) = ast::Expr::cast(node.clone()).and_then(|e| analyzer.type_of(db, &e))
235 { 236 {
236 ty 237 ty
diff --git a/crates/ra_ide_api/src/inlay_hints.rs b/crates/ra_ide_api/src/inlay_hints.rs
index 2ff10b89a..0cd959848 100644
--- a/crates/ra_ide_api/src/inlay_hints.rs
+++ b/crates/ra_ide_api/src/inlay_hints.rs
@@ -32,6 +32,7 @@ fn get_inlay_hints(
32 file_id: FileId, 32 file_id: FileId,
33 node: &SyntaxNode, 33 node: &SyntaxNode,
34) -> Option<Vec<InlayHint>> { 34) -> Option<Vec<InlayHint>> {
35 let analyzer = SourceAnalyzer::new(db, hir::Source::new(file_id.into(), node), None);
35 match_ast! { 36 match_ast! {
36 match node { 37 match node {
37 ast::LetStmt(it) => { 38 ast::LetStmt(it) => {
@@ -39,11 +40,9 @@ fn get_inlay_hints(
39 return None; 40 return None;
40 } 41 }
41 let pat = it.pat()?; 42 let pat = it.pat()?;
42 let analyzer = SourceAnalyzer::new(db, file_id, it.syntax(), None);
43 Some(get_pat_type_hints(db, &analyzer, pat, false)) 43 Some(get_pat_type_hints(db, &analyzer, pat, false))
44 }, 44 },
45 ast::LambdaExpr(it) => { 45 ast::LambdaExpr(it) => {
46 let analyzer = SourceAnalyzer::new(db, file_id, it.syntax(), None);
47 it.param_list().map(|param_list| { 46 it.param_list().map(|param_list| {
48 param_list 47 param_list
49 .params() 48 .params()
@@ -56,21 +55,17 @@ fn get_inlay_hints(
56 }, 55 },
57 ast::ForExpr(it) => { 56 ast::ForExpr(it) => {
58 let pat = it.pat()?; 57 let pat = it.pat()?;
59 let analyzer = SourceAnalyzer::new(db, file_id, it.syntax(), None);
60 Some(get_pat_type_hints(db, &analyzer, pat, false)) 58 Some(get_pat_type_hints(db, &analyzer, pat, false))
61 }, 59 },
62 ast::IfExpr(it) => { 60 ast::IfExpr(it) => {
63 let pat = it.condition()?.pat()?; 61 let pat = it.condition()?.pat()?;
64 let analyzer = SourceAnalyzer::new(db, file_id, it.syntax(), None);
65 Some(get_pat_type_hints(db, &analyzer, pat, true)) 62 Some(get_pat_type_hints(db, &analyzer, pat, true))
66 }, 63 },
67 ast::WhileExpr(it) => { 64 ast::WhileExpr(it) => {
68 let pat = it.condition()?.pat()?; 65 let pat = it.condition()?.pat()?;
69 let analyzer = SourceAnalyzer::new(db, file_id, it.syntax(), None);
70 Some(get_pat_type_hints(db, &analyzer, pat, true)) 66 Some(get_pat_type_hints(db, &analyzer, pat, true))
71 }, 67 },
72 ast::MatchArmList(it) => { 68 ast::MatchArmList(it) => {
73 let analyzer = SourceAnalyzer::new(db, file_id, it.syntax(), None);
74 Some( 69 Some(
75 it 70 it
76 .arms() 71 .arms()
diff --git a/crates/ra_ide_api/src/references.rs b/crates/ra_ide_api/src/references.rs
index 9cb9433e7..faa88d988 100644
--- a/crates/ra_ide_api/src/references.rs
+++ b/crates/ra_ide_api/src/references.rs
@@ -369,6 +369,21 @@ mod tests {
369 assert_eq!(refs.len(), 2); 369 assert_eq!(refs.len(), 2);
370 } 370 }
371 371
372 #[test]
373 fn test_find_all_refs_macro_def() {
374 let code = r#"
375 #[macro_export]
376 macro_rules! m1<|> { () => (()) }
377
378 fn foo() {
379 m1();
380 m1();
381 }"#;
382
383 let refs = get_all_refs(code);
384 assert_eq!(refs.len(), 3);
385 }
386
372 fn get_all_refs(text: &str) -> ReferenceSearchResult { 387 fn get_all_refs(text: &str) -> ReferenceSearchResult {
373 let (analysis, position) = single_file_with_position(text); 388 let (analysis, position) = single_file_with_position(text);
374 analysis.find_all_refs(position, None).unwrap().unwrap() 389 analysis.find_all_refs(position, None).unwrap().unwrap()
diff --git a/crates/ra_ide_api/src/references/classify.rs b/crates/ra_ide_api/src/references/classify.rs
index 217f9951e..f12b58cb9 100644
--- a/crates/ra_ide_api/src/references/classify.rs
+++ b/crates/ra_ide_api/src/references/classify.rs
@@ -21,7 +21,6 @@ pub(crate) fn classify_name(
21 let parent = name.syntax().parent()?; 21 let parent = name.syntax().parent()?;
22 let file_id = file_id.into(); 22 let file_id = file_id.into();
23 23
24 // FIXME: add ast::MacroCall(it)
25 match_ast! { 24 match_ast! {
26 match parent { 25 match parent {
27 ast::BindPat(it) => { 26 ast::BindPat(it) => {
@@ -104,6 +103,19 @@ pub(crate) fn classify_name(
104 Some(from_module_def(db, def.into(), None)) 103 Some(from_module_def(db, def.into(), None))
105 } 104 }
106 }, 105 },
106 ast::MacroCall(it) => {
107 let src = hir::Source { file_id, ast: it};
108 let def = hir::MacroDef::from_source(db, src.clone())?;
109
110 let module_src = ModuleSource::from_child_node(db, src.as_ref().map(|it| it.syntax()));
111 let module = Module::from_definition(db, Source::new(file_id, module_src))?;
112
113 Some(NameDefinition {
114 visibility: None,
115 container: module,
116 kind: NameKind::Macro(def),
117 })
118 },
107 _ => None, 119 _ => None,
108 } 120 }
109 } 121 }
@@ -114,12 +126,11 @@ pub(crate) fn classify_name_ref(
114 file_id: FileId, 126 file_id: FileId,
115 name_ref: &ast::NameRef, 127 name_ref: &ast::NameRef,
116) -> Option<NameDefinition> { 128) -> Option<NameDefinition> {
117 use PathResolution::*;
118
119 let _p = profile("classify_name_ref"); 129 let _p = profile("classify_name_ref");
120 130
121 let parent = name_ref.syntax().parent()?; 131 let parent = name_ref.syntax().parent()?;
122 let analyzer = SourceAnalyzer::new(db, file_id, name_ref.syntax(), None); 132 let analyzer =
133 SourceAnalyzer::new(db, hir::Source::new(file_id.into(), name_ref.syntax()), None);
123 134
124 if let Some(method_call) = ast::MethodCallExpr::cast(parent.clone()) { 135 if let Some(method_call) = ast::MethodCallExpr::cast(parent.clone()) {
125 tested_by!(goto_definition_works_for_methods); 136 tested_by!(goto_definition_works_for_methods);
@@ -146,8 +157,8 @@ pub(crate) fn classify_name_ref(
146 } 157 }
147 } 158 }
148 159
149 let ast = ModuleSource::from_child_node(db, file_id, &parent);
150 let file_id = file_id.into(); 160 let file_id = file_id.into();
161 let ast = ModuleSource::from_child_node(db, Source::new(file_id, &parent));
151 // FIXME: find correct container and visibility for each case 162 // FIXME: find correct container and visibility for each case
152 let container = Module::from_definition(db, Source { file_id, ast })?; 163 let container = Module::from_definition(db, Source { file_id, ast })?;
153 let visibility = None; 164 let visibility = None;
@@ -163,26 +174,26 @@ pub(crate) fn classify_name_ref(
163 let path = name_ref.syntax().ancestors().find_map(ast::Path::cast)?; 174 let path = name_ref.syntax().ancestors().find_map(ast::Path::cast)?;
164 let resolved = analyzer.resolve_path(db, &path)?; 175 let resolved = analyzer.resolve_path(db, &path)?;
165 match resolved { 176 match resolved {
166 Def(def) => Some(from_module_def(db, def, Some(container))), 177 PathResolution::Def(def) => Some(from_module_def(db, def, Some(container))),
167 AssocItem(item) => Some(from_assoc_item(db, item)), 178 PathResolution::AssocItem(item) => Some(from_assoc_item(db, item)),
168 Local(local) => { 179 PathResolution::Local(local) => {
169 let container = local.module(db); 180 let container = local.module(db);
170 let kind = NameKind::Local(local); 181 let kind = NameKind::Local(local);
171 Some(NameDefinition { kind, container, visibility: None }) 182 Some(NameDefinition { kind, container, visibility: None })
172 } 183 }
173 GenericParam(par) => { 184 PathResolution::GenericParam(par) => {
174 // FIXME: get generic param def 185 // FIXME: get generic param def
175 let kind = NameKind::GenericParam(par); 186 let kind = NameKind::GenericParam(par);
176 Some(NameDefinition { kind, container, visibility }) 187 Some(NameDefinition { kind, container, visibility })
177 } 188 }
178 Macro(def) => { 189 PathResolution::Macro(def) => {
179 let kind = NameKind::Macro(def); 190 let kind = NameKind::Macro(def);
180 Some(NameDefinition { kind, container, visibility }) 191 Some(NameDefinition { kind, container, visibility })
181 } 192 }
182 SelfType(impl_block) => { 193 PathResolution::SelfType(impl_block) => {
183 let ty = impl_block.target_ty(db); 194 let ty = impl_block.target_ty(db);
184 let kind = NameKind::SelfType(ty); 195 let kind = NameKind::SelfType(ty);
185 let container = impl_block.module(); 196 let container = impl_block.module(db);
186 Some(NameDefinition { kind, container, visibility }) 197 Some(NameDefinition { kind, container, visibility })
187 } 198 }
188 } 199 }
diff --git a/crates/ra_ide_api/src/runnables.rs b/crates/ra_ide_api/src/runnables.rs
index 366ac8048..8039a5164 100644
--- a/crates/ra_ide_api/src/runnables.rs
+++ b/crates/ra_ide_api/src/runnables.rs
@@ -1,5 +1,6 @@
1//! FIXME: write short doc here 1//! FIXME: write short doc here
2 2
3use hir::Source;
3use itertools::Itertools; 4use itertools::Itertools;
4use ra_db::SourceDatabase; 5use ra_db::SourceDatabase;
5use ra_syntax::{ 6use ra_syntax::{
@@ -65,9 +66,8 @@ fn runnable_mod(db: &RootDatabase, file_id: FileId, module: ast::Module) -> Opti
65 return None; 66 return None;
66 } 67 }
67 let range = module.syntax().text_range(); 68 let range = module.syntax().text_range();
68 let src = hir::ModuleSource::from_child_node(db, file_id, &module.syntax()); 69 let src = hir::ModuleSource::from_child_node(db, Source::new(file_id.into(), &module.syntax()));
69 let module = 70 let module = hir::Module::from_definition(db, Source::new(file_id.into(), src))?;
70 hir::Module::from_definition(db, hir::Source { file_id: file_id.into(), ast: src })?;
71 71
72 let path = module.path_to_root(db).into_iter().rev().filter_map(|it| it.name(db)).join("::"); 72 let path = module.path_to_root(db).into_iter().rev().filter_map(|it| it.name(db)).join("::");
73 Some(Runnable { range, kind: RunnableKind::TestMod { path } }) 73 Some(Runnable { range, kind: RunnableKind::TestMod { path } })