aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_hir/src/db.rs6
-rw-r--r--crates/ra_hir/src/diagnostics.rs6
-rw-r--r--crates/ra_hir/src/ids.rs24
-rw-r--r--crates/ra_hir/src/nameres/raw.rs7
-rw-r--r--crates/ra_hir/src/source_id.rs14
-rw-r--r--crates/ra_ide_api/src/change.rs2
6 files changed, 33 insertions, 26 deletions
diff --git a/crates/ra_hir/src/db.rs b/crates/ra_hir/src/db.rs
index 8f98ca3a5..8e827d4f5 100644
--- a/crates/ra_hir/src/db.rs
+++ b/crates/ra_hir/src/db.rs
@@ -1,6 +1,6 @@
1use std::sync::{Arc, Mutex}; 1use std::sync::{Arc, Mutex};
2 2
3use ra_syntax::{SyntaxNode, TreeArc, SourceFile, SmolStr, ast}; 3use ra_syntax::{SyntaxNode, TreeArc, SmolStr, ast};
4use ra_db::{SourceDatabase, salsa}; 4use ra_db::{SourceDatabase, salsa};
5 5
6use crate::{ 6use crate::{
@@ -54,8 +54,8 @@ pub trait DefDatabase: SourceDatabase {
54 #[salsa::invoke(crate::ids::macro_expand_query)] 54 #[salsa::invoke(crate::ids::macro_expand_query)]
55 fn macro_expand(&self, macro_call: ids::MacroCallId) -> Result<Arc<tt::Subtree>, String>; 55 fn macro_expand(&self, macro_call: ids::MacroCallId) -> Result<Arc<tt::Subtree>, String>;
56 56
57 #[salsa::invoke(crate::ids::HirFileId::hir_parse_query)] 57 #[salsa::invoke(crate::ids::HirFileId::parse_or_expand_query)]
58 fn hir_parse(&self, file_id: HirFileId) -> TreeArc<SourceFile>; 58 fn parse_or_expand(&self, file_id: HirFileId) -> Option<TreeArc<SyntaxNode>>;
59 59
60 #[salsa::invoke(crate::adt::StructData::struct_data_query)] 60 #[salsa::invoke(crate::adt::StructData::struct_data_query)]
61 fn struct_data(&self, s: Struct) -> Arc<StructData>; 61 fn struct_data(&self, s: Struct) -> Arc<StructData>;
diff --git a/crates/ra_hir/src/diagnostics.rs b/crates/ra_hir/src/diagnostics.rs
index d41525779..4b7b2dbee 100644
--- a/crates/ra_hir/src/diagnostics.rs
+++ b/crates/ra_hir/src/diagnostics.rs
@@ -1,6 +1,6 @@
1use std::{fmt, any::Any}; 1use std::{fmt, any::Any};
2 2
3use ra_syntax::{SyntaxNodePtr, TreeArc, AstPtr, TextRange, ast, SyntaxNode, AstNode}; 3use ra_syntax::{SyntaxNodePtr, TreeArc, AstPtr, TextRange, ast, SyntaxNode};
4use relative_path::RelativePathBuf; 4use relative_path::RelativePathBuf;
5 5
6use crate::{HirFileId, HirDatabase, Name}; 6use crate::{HirFileId, HirDatabase, Name};
@@ -29,8 +29,8 @@ pub trait Diagnostic: Any + Send + Sync + fmt::Debug + 'static {
29 29
30impl dyn Diagnostic { 30impl dyn Diagnostic {
31 pub fn syntax_node(&self, db: &impl HirDatabase) -> TreeArc<SyntaxNode> { 31 pub fn syntax_node(&self, db: &impl HirDatabase) -> TreeArc<SyntaxNode> {
32 let source_file = db.hir_parse(self.file()); 32 let node = db.parse_or_expand(self.file()).unwrap();
33 self.syntax_node_ptr().to_node(source_file.syntax()).to_owned() 33 self.syntax_node_ptr().to_node(&*node).to_owned()
34 } 34 }
35 pub fn downcast_ref<D: Diagnostic>(&self) -> Option<&D> { 35 pub fn downcast_ref<D: Diagnostic>(&self) -> Option<&D> {
36 self.as_any().downcast_ref() 36 self.as_any().downcast_ref()
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 }
diff --git a/crates/ra_hir/src/nameres/raw.rs b/crates/ra_hir/src/nameres/raw.rs
index 211e02068..bd32b264b 100644
--- a/crates/ra_hir/src/nameres/raw.rs
+++ b/crates/ra_hir/src/nameres/raw.rs
@@ -75,8 +75,11 @@ impl RawItems {
75 source_ast_id_map: db.ast_id_map(file_id.into()), 75 source_ast_id_map: db.ast_id_map(file_id.into()),
76 source_map: ImportSourceMap::default(), 76 source_map: ImportSourceMap::default(),
77 }; 77 };
78 let source_file = db.hir_parse(file_id); 78 if let Some(node) = db.parse_or_expand(file_id) {
79 collector.process_module(None, &*source_file); 79 if let Some(source_file) = ast::SourceFile::cast(&node) {
80 collector.process_module(None, &*source_file);
81 }
82 }
80 (Arc::new(collector.raw_items), Arc::new(collector.source_map)) 83 (Arc::new(collector.raw_items), Arc::new(collector.source_map))
81 } 84 }
82 85
diff --git a/crates/ra_hir/src/source_id.rs b/crates/ra_hir/src/source_id.rs
index 7a39be779..13f548eaf 100644
--- a/crates/ra_hir/src/source_id.rs
+++ b/crates/ra_hir/src/source_id.rs
@@ -81,15 +81,19 @@ pub struct ErasedFileAstId(RawId);
81impl_arena_id!(ErasedFileAstId); 81impl_arena_id!(ErasedFileAstId);
82 82
83/// Maps items' `SyntaxNode`s to `ErasedFileAstId`s and back. 83/// Maps items' `SyntaxNode`s to `ErasedFileAstId`s and back.
84#[derive(Debug, PartialEq, Eq)] 84#[derive(Debug, PartialEq, Eq, Default)]
85pub struct AstIdMap { 85pub struct AstIdMap {
86 arena: Arena<ErasedFileAstId, SyntaxNodePtr>, 86 arena: Arena<ErasedFileAstId, SyntaxNodePtr>,
87} 87}
88 88
89impl AstIdMap { 89impl AstIdMap {
90 pub(crate) fn ast_id_map_query(db: &impl DefDatabase, file_id: HirFileId) -> Arc<AstIdMap> { 90 pub(crate) fn ast_id_map_query(db: &impl DefDatabase, file_id: HirFileId) -> Arc<AstIdMap> {
91 let source_file = db.hir_parse(file_id); 91 let map = if let Some(node) = db.parse_or_expand(file_id) {
92 Arc::new(AstIdMap::from_source(source_file.syntax())) 92 AstIdMap::from_source(&*node)
93 } else {
94 AstIdMap::default()
95 };
96 Arc::new(map)
93 } 97 }
94 98
95 pub(crate) fn file_item_query( 99 pub(crate) fn file_item_query(
@@ -97,8 +101,8 @@ impl AstIdMap {
97 file_id: HirFileId, 101 file_id: HirFileId,
98 ast_id: ErasedFileAstId, 102 ast_id: ErasedFileAstId,
99 ) -> TreeArc<SyntaxNode> { 103 ) -> TreeArc<SyntaxNode> {
100 let source_file = db.hir_parse(file_id); 104 let node = db.parse_or_expand(file_id).unwrap();
101 db.ast_id_map(file_id).arena[ast_id].to_node(source_file.syntax()).to_owned() 105 db.ast_id_map(file_id).arena[ast_id].to_node(&*node).to_owned()
102 } 106 }
103 107
104 pub(crate) fn ast_id<N: AstNode>(&self, item: &N) -> FileAstId<N> { 108 pub(crate) fn ast_id<N: AstNode>(&self, item: &N) -> FileAstId<N> {
diff --git a/crates/ra_ide_api/src/change.rs b/crates/ra_ide_api/src/change.rs
index dc6a433c4..2434f428f 100644
--- a/crates/ra_ide_api/src/change.rs
+++ b/crates/ra_ide_api/src/change.rs
@@ -222,7 +222,7 @@ impl RootDatabase {
222 222
223 self.query(ra_db::ParseQuery).sweep(sweep); 223 self.query(ra_db::ParseQuery).sweep(sweep);
224 224
225 self.query(hir::db::HirParseQuery).sweep(sweep); 225 self.query(hir::db::ParseOrExpandQuery).sweep(sweep);
226 self.query(hir::db::AstIdMapQuery).sweep(sweep); 226 self.query(hir::db::AstIdMapQuery).sweep(sweep);
227 self.query(hir::db::AstIdToNodeQuery).sweep(sweep); 227 self.query(hir::db::AstIdToNodeQuery).sweep(sweep);
228 228