aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/ids.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-05-13 23:42:59 +0100
committerAleksey Kladov <[email protected]>2019-05-14 07:03:43 +0100
commit16c740526233b01980efdbb680b55718a71bb0e1 (patch)
treef68886b41ccc4134ad0dc038ed88005be50eee8d /crates/ra_hir/src/ids.rs
parent101b3abfd70cc988b24f30a610d46a3986df54d3 (diff)
expand to syntax node
Diffstat (limited to 'crates/ra_hir/src/ids.rs')
-rw-r--r--crates/ra_hir/src/ids.rs24
1 files changed, 12 insertions, 12 deletions
diff --git a/crates/ra_hir/src/ids.rs b/crates/ra_hir/src/ids.rs
index 357ef2a80..659b21f72 100644
--- a/crates/ra_hir/src/ids.rs
+++ b/crates/ra_hir/src/ids.rs
@@ -4,7 +4,7 @@ use std::{
4}; 4};
5 5
6use ra_db::{FileId, salsa}; 6use ra_db::{FileId, salsa};
7use ra_syntax::{TreeArc, SourceFile, AstNode, ast}; 7use ra_syntax::{TreeArc, AstNode, ast, SyntaxNode};
8use mbe::MacroRules; 8use mbe::MacroRules;
9 9
10use crate::{ 10use crate::{
@@ -56,17 +56,17 @@ impl HirFileId {
56 } 56 }
57 } 57 }
58 58
59 pub(crate) fn hir_parse_query( 59 pub(crate) fn parse_or_expand_query(
60 db: &impl DefDatabase, 60 db: &impl DefDatabase,
61 file_id: HirFileId, 61 file_id: HirFileId,
62 ) -> TreeArc<SourceFile> { 62 ) -> Option<TreeArc<SyntaxNode>> {
63 match file_id.0 { 63 match file_id.0 {
64 HirFileIdRepr::File(file_id) => db.parse(file_id), 64 HirFileIdRepr::File(file_id) => Some(db.parse(file_id).syntax().to_owned()),
65 HirFileIdRepr::Macro(macro_file) => { 65 HirFileIdRepr::Macro(macro_file) => {
66 let macro_call_id = macro_file.macro_call_id; 66 let macro_call_id = macro_file.macro_call_id;
67 let tt = match db.macro_expand(macro_call_id) { 67 let tt = db
68 Ok(it) => it, 68 .macro_expand(macro_call_id)
69 Err(err) => { 69 .map_err(|err| {
70 // Note: 70 // Note:
71 // The final goal we would like to make all parse_macro success, 71 // The final goal we would like to make all parse_macro success,
72 // such that the following log will not call anyway. 72 // such that the following log will not call anyway.
@@ -75,12 +75,12 @@ impl HirFileId {
75 err, 75 err,
76 macro_call_id.debug_dump(db) 76 macro_call_id.debug_dump(db)
77 ); 77 );
78 // returning an empty string looks fishy... 78 })
79 return SourceFile::parse(""); 79 .ok()?;
80 }
81 };
82 match macro_file.macro_file_kind { 80 match macro_file.macro_file_kind {
83 MacroFileKind::Items => mbe::token_tree_to_ast_item_list(&tt), 81 MacroFileKind::Items => {
82 Some(mbe::token_tree_to_ast_item_list(&tt).syntax().to_owned())
83 }
84 } 84 }
85 } 85 }
86 } 86 }