diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_analysis/src/completion/complete_scope.rs | 2 | ||||
-rw-r--r-- | crates/ra_analysis/src/db.rs | 2 | ||||
-rw-r--r-- | crates/ra_analysis/src/imp.rs | 4 | ||||
-rw-r--r-- | crates/ra_hir/src/db.rs | 10 | ||||
-rw-r--r-- | crates/ra_hir/src/ids.rs | 52 | ||||
-rw-r--r-- | crates/ra_hir/src/krate.rs | 3 | ||||
-rw-r--r-- | crates/ra_hir/src/lib.rs | 16 | ||||
-rw-r--r-- | crates/ra_hir/src/mock.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir/src/module.rs | 40 | ||||
-rw-r--r-- | crates/ra_hir/src/module/imp.rs | 6 | ||||
-rw-r--r-- | crates/ra_hir/src/module/nameres.rs | 31 | ||||
-rw-r--r-- | crates/ra_hir/src/query_definitions.rs | 46 | ||||
-rw-r--r-- | crates/ra_hir/src/source_binder.rs | 20 |
13 files changed, 135 insertions, 99 deletions
diff --git a/crates/ra_analysis/src/completion/complete_scope.rs b/crates/ra_analysis/src/completion/complete_scope.rs index daf666505..4dead3689 100644 --- a/crates/ra_analysis/src/completion/complete_scope.rs +++ b/crates/ra_analysis/src/completion/complete_scope.rs | |||
@@ -27,7 +27,7 @@ pub(super) fn complete_scope(acc: &mut Completions, ctx: &CompletionContext) -> | |||
27 | match res.import { | 27 | match res.import { |
28 | None => true, | 28 | None => true, |
29 | Some(import) => { | 29 | Some(import) => { |
30 | let range = import.range(ctx.db, module.source().file_id()); | 30 | let range = import.range(ctx.db, module.file_id()); |
31 | !range.is_subrange(&ctx.leaf.range()) | 31 | !range.is_subrange(&ctx.leaf.range()) |
32 | } | 32 | } |
33 | } | 33 | } |
diff --git a/crates/ra_analysis/src/db.rs b/crates/ra_analysis/src/db.rs index adfec56d8..d7740f0c4 100644 --- a/crates/ra_analysis/src/db.rs +++ b/crates/ra_analysis/src/db.rs | |||
@@ -91,7 +91,7 @@ salsa::database_storage! { | |||
91 | fn library_symbols() for symbol_index::LibrarySymbolsQuery; | 91 | fn library_symbols() for symbol_index::LibrarySymbolsQuery; |
92 | } | 92 | } |
93 | impl hir::db::HirDatabase { | 93 | impl hir::db::HirDatabase { |
94 | fn m_source_file() for hir::db::MSourceFileQuery; | 94 | fn hir_source_file() for hir::db::HirSourceFileQuery; |
95 | fn expand_macro_invocation() for hir::db::ExpandMacroCallQuery; | 95 | fn expand_macro_invocation() for hir::db::ExpandMacroCallQuery; |
96 | fn module_tree() for hir::db::ModuleTreeQuery; | 96 | fn module_tree() for hir::db::ModuleTreeQuery; |
97 | fn fn_scopes() for hir::db::FnScopesQuery; | 97 | fn fn_scopes() for hir::db::FnScopesQuery; |
diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs index 5669aa94d..ec7da437a 100644 --- a/crates/ra_analysis/src/imp.rs +++ b/crates/ra_analysis/src/imp.rs | |||
@@ -230,7 +230,7 @@ impl AnalysisImpl { | |||
230 | Some(it) => it, | 230 | Some(it) => it, |
231 | }; | 231 | }; |
232 | let root = descr.crate_root(); | 232 | let root = descr.crate_root(); |
233 | let file_id = root.source().file_id(); | 233 | let file_id = root.file_id(); |
234 | 234 | ||
235 | let crate_graph = self.db.crate_graph(); | 235 | let crate_graph = self.db.crate_graph(); |
236 | let crate_id = crate_graph.crate_id_for_crate_root(file_id); | 236 | let crate_id = crate_graph.crate_id_for_crate_root(file_id); |
@@ -283,7 +283,7 @@ impl AnalysisImpl { | |||
283 | if let Some(child_module) = | 283 | if let Some(child_module) = |
284 | source_binder::module_from_declaration(&*self.db, position.file_id, module)? | 284 | source_binder::module_from_declaration(&*self.db, position.file_id, module)? |
285 | { | 285 | { |
286 | let file_id = child_module.source().file_id(); | 286 | let file_id = child_module.file_id(); |
287 | let name = match child_module.name() { | 287 | let name = match child_module.name() { |
288 | Some(name) => name.to_string().into(), | 288 | Some(name) => name.to_string().into(), |
289 | None => "".into(), | 289 | None => "".into(), |
diff --git a/crates/ra_hir/src/db.rs b/crates/ra_hir/src/db.rs index ba0423d64..c0b56f30a 100644 --- a/crates/ra_hir/src/db.rs +++ b/crates/ra_hir/src/db.rs | |||
@@ -4,7 +4,7 @@ use ra_syntax::{SyntaxNode, SourceFileNode}; | |||
4 | use ra_db::{SourceRootId, LocationIntener, SyntaxDatabase, Cancelable}; | 4 | use ra_db::{SourceRootId, LocationIntener, SyntaxDatabase, Cancelable}; |
5 | 5 | ||
6 | use crate::{ | 6 | use crate::{ |
7 | DefLoc, DefId, Name, MFileId, | 7 | DefLoc, DefId, Name, HirFileId, |
8 | SourceFileItems, SourceItemId, | 8 | SourceFileItems, SourceItemId, |
9 | query_definitions, | 9 | query_definitions, |
10 | FnScopes, | 10 | FnScopes, |
@@ -21,9 +21,9 @@ pub trait HirDatabase: SyntaxDatabase | |||
21 | + AsRef<LocationIntener<DefLoc, DefId>> | 21 | + AsRef<LocationIntener<DefLoc, DefId>> |
22 | + AsRef<LocationIntener<MacroCallLoc, MacroCallId>> | 22 | + AsRef<LocationIntener<MacroCallLoc, MacroCallId>> |
23 | { | 23 | { |
24 | fn m_source_file(mfile_id: MFileId) -> SourceFileNode { | 24 | fn hir_source_file(file_id: HirFileId) -> SourceFileNode { |
25 | type MSourceFileQuery; | 25 | type HirSourceFileQuery; |
26 | use fn crate::query_definitions::m_source_file; | 26 | use fn HirFileId::source_file_query; |
27 | } | 27 | } |
28 | fn expand_macro_invocation(invoc: MacroCallId) -> Option<Arc<MacroExpansion>> { | 28 | fn expand_macro_invocation(invoc: MacroCallId) -> Option<Arc<MacroExpansion>> { |
29 | type ExpandMacroCallQuery; | 29 | type ExpandMacroCallQuery; |
@@ -60,7 +60,7 @@ pub trait HirDatabase: SyntaxDatabase | |||
60 | use fn crate::ty::type_for_field; | 60 | use fn crate::ty::type_for_field; |
61 | } | 61 | } |
62 | 62 | ||
63 | fn file_items(mfile_id: MFileId) -> Arc<SourceFileItems> { | 63 | fn file_items(file_id: HirFileId) -> Arc<SourceFileItems> { |
64 | type SourceFileItemsQuery; | 64 | type SourceFileItemsQuery; |
65 | use fn query_definitions::file_items; | 65 | use fn query_definitions::file_items; |
66 | } | 66 | } |
diff --git a/crates/ra_hir/src/ids.rs b/crates/ra_hir/src/ids.rs index 881303861..3eba35a24 100644 --- a/crates/ra_hir/src/ids.rs +++ b/crates/ra_hir/src/ids.rs | |||
@@ -1,4 +1,6 @@ | |||
1 | use crate::{FileId, MacroCallId}; | 1 | use crate::{FileId, MacroCallId, HirDatabase}; |
2 | |||
3 | use ra_syntax::SourceFileNode; | ||
2 | 4 | ||
3 | /// hir makes a heavy use of ids: integer (u32) handlers to various things. You | 5 | /// hir makes a heavy use of ids: integer (u32) handlers to various things. You |
4 | /// can think of id as a pointer (but without a lifetime) or a file descriptor | 6 | /// can think of id as a pointer (but without a lifetime) or a file descriptor |
@@ -20,13 +22,53 @@ use crate::{FileId, MacroCallId}; | |||
20 | /// (because everything bottoms out at the real `FileId`) and small | 22 | /// (because everything bottoms out at the real `FileId`) and small |
21 | /// (`MacroCallId` uses location interner). | 23 | /// (`MacroCallId` uses location interner). |
22 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 24 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
23 | pub enum MFileId { | 25 | pub struct HirFileId(HirFileIdRepr); |
26 | |||
27 | impl HirFileId { | ||
28 | pub(crate) fn original_file_id(self, db: &impl HirDatabase) -> FileId { | ||
29 | match self.0 { | ||
30 | HirFileIdRepr::File(file_id) => file_id, | ||
31 | HirFileIdRepr::Macro(macro_call_id) => { | ||
32 | let loc = macro_call_id.loc(db); | ||
33 | loc.source_item_id.file_id.original_file_id(db) | ||
34 | } | ||
35 | } | ||
36 | } | ||
37 | |||
38 | pub(crate) fn as_original_file(self) -> FileId { | ||
39 | match self.0 { | ||
40 | HirFileIdRepr::File(file_id) => file_id, | ||
41 | HirFileIdRepr::Macro(_r) => panic!("macro generated file: {:?}", self), | ||
42 | } | ||
43 | } | ||
44 | pub(crate) fn source_file_query(db: &impl HirDatabase, file_id: HirFileId) -> SourceFileNode { | ||
45 | match file_id.0 { | ||
46 | HirFileIdRepr::File(file_id) => db.source_file(file_id), | ||
47 | HirFileIdRepr::Macro(m) => { | ||
48 | if let Some(exp) = db.expand_macro_invocation(m) { | ||
49 | return exp.file(); | ||
50 | } | ||
51 | // returning an empty string looks fishy... | ||
52 | SourceFileNode::parse("") | ||
53 | } | ||
54 | } | ||
55 | } | ||
56 | } | ||
57 | |||
58 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
59 | enum HirFileIdRepr { | ||
24 | File(FileId), | 60 | File(FileId), |
25 | Macro(MacroCallId), | 61 | Macro(MacroCallId), |
26 | } | 62 | } |
27 | 63 | ||
28 | impl From<FileId> for MFileId { | 64 | impl From<FileId> for HirFileId { |
29 | fn from(file_id: FileId) -> MFileId { | 65 | fn from(file_id: FileId) -> HirFileId { |
30 | MFileId::File(file_id) | 66 | HirFileId(HirFileIdRepr::File(file_id)) |
67 | } | ||
68 | } | ||
69 | |||
70 | impl From<MacroCallId> for HirFileId { | ||
71 | fn from(macro_call_id: MacroCallId) -> HirFileId { | ||
72 | HirFileId(HirFileIdRepr::Macro(macro_call_id)) | ||
31 | } | 73 | } |
32 | } | 74 | } |
diff --git a/crates/ra_hir/src/krate.rs b/crates/ra_hir/src/krate.rs index 89b1e639e..4d4f59949 100644 --- a/crates/ra_hir/src/krate.rs +++ b/crates/ra_hir/src/krate.rs | |||
@@ -1,6 +1,6 @@ | |||
1 | pub use ra_db::CrateId; | 1 | pub use ra_db::CrateId; |
2 | 2 | ||
3 | use crate::{HirDatabase, Module, Cancelable, Name, AsName}; | 3 | use crate::{HirDatabase, Module, Cancelable, Name, AsName, HirFileId}; |
4 | 4 | ||
5 | /// hir::Crate describes a single crate. It's the main inteface with which | 5 | /// hir::Crate describes a single crate. It's the main inteface with which |
6 | /// crate's dependencies interact. Mostly, it should be just a proxy for the | 6 | /// crate's dependencies interact. Mostly, it should be just a proxy for the |
@@ -35,6 +35,7 @@ impl Crate { | |||
35 | let crate_graph = db.crate_graph(); | 35 | let crate_graph = db.crate_graph(); |
36 | let file_id = crate_graph.crate_root(self.crate_id); | 36 | let file_id = crate_graph.crate_root(self.crate_id); |
37 | let source_root_id = db.file_source_root(file_id); | 37 | let source_root_id = db.file_source_root(file_id); |
38 | let file_id = HirFileId::from(file_id); | ||
38 | let module_tree = db.module_tree(source_root_id)?; | 39 | let module_tree = db.module_tree(source_root_id)?; |
39 | // FIXME: teach module tree about crate roots instead of guessing | 40 | // FIXME: teach module tree about crate roots instead of guessing |
40 | let (module_id, _) = ctry!(module_tree | 41 | let (module_id, _) = ctry!(module_tree |
diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs index 8d3a026d5..c1386601d 100644 --- a/crates/ra_hir/src/lib.rs +++ b/crates/ra_hir/src/lib.rs | |||
@@ -47,7 +47,7 @@ pub use self::{ | |||
47 | path::{Path, PathKind}, | 47 | path::{Path, PathKind}, |
48 | name::Name, | 48 | name::Name, |
49 | krate::Crate, | 49 | krate::Crate, |
50 | ids::MFileId, | 50 | ids::HirFileId, |
51 | macros::{MacroDef, MacroInput, MacroExpansion, MacroCallId, MacroCallLoc}, | 51 | macros::{MacroDef, MacroInput, MacroExpansion, MacroCallId, MacroCallLoc}, |
52 | module::{Module, ModuleId, Problem, nameres::{ItemMap, PerNs, Namespace}, ModuleScope, Resolution}, | 52 | module::{Module, ModuleId, Problem, nameres::{ItemMap, PerNs, Namespace}, ModuleScope, Resolution}, |
53 | function::{Function, FnScopes}, | 53 | function::{Function, FnScopes}, |
@@ -158,7 +158,7 @@ pub(crate) type SourceFileItemId = Id<SyntaxNode>; | |||
158 | 158 | ||
159 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 159 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
160 | pub struct SourceItemId { | 160 | pub struct SourceItemId { |
161 | mfile_id: MFileId, | 161 | file_id: HirFileId, |
162 | /// None for the whole file. | 162 | /// None for the whole file. |
163 | item_id: Option<SourceFileItemId>, | 163 | item_id: Option<SourceFileItemId>, |
164 | } | 164 | } |
@@ -166,14 +166,14 @@ pub struct SourceItemId { | |||
166 | /// Maps item's `SyntaxNode`s to `SourceFileItemId` and back. | 166 | /// Maps item's `SyntaxNode`s to `SourceFileItemId` and back. |
167 | #[derive(Debug, PartialEq, Eq)] | 167 | #[derive(Debug, PartialEq, Eq)] |
168 | pub struct SourceFileItems { | 168 | pub struct SourceFileItems { |
169 | mfile_id: MFileId, | 169 | file_id: HirFileId, |
170 | arena: Arena<SyntaxNode>, | 170 | arena: Arena<SyntaxNode>, |
171 | } | 171 | } |
172 | 172 | ||
173 | impl SourceFileItems { | 173 | impl SourceFileItems { |
174 | fn new(mfile_id: MFileId, source_file: SourceFile) -> SourceFileItems { | 174 | fn new(file_id: HirFileId, source_file: SourceFile) -> SourceFileItems { |
175 | let mut res = SourceFileItems { | 175 | let mut res = SourceFileItems { |
176 | mfile_id, | 176 | file_id, |
177 | arena: Arena::default(), | 177 | arena: Arena::default(), |
178 | }; | 178 | }; |
179 | res.init(source_file); | 179 | res.init(source_file); |
@@ -193,11 +193,11 @@ impl SourceFileItems { | |||
193 | fn alloc(&mut self, item: SyntaxNode) -> SourceFileItemId { | 193 | fn alloc(&mut self, item: SyntaxNode) -> SourceFileItemId { |
194 | self.arena.alloc(item) | 194 | self.arena.alloc(item) |
195 | } | 195 | } |
196 | pub fn id_of(&self, mfile_id: MFileId, item: SyntaxNodeRef) -> SourceFileItemId { | 196 | pub fn id_of(&self, file_id: HirFileId, item: SyntaxNodeRef) -> SourceFileItemId { |
197 | assert_eq!( | 197 | assert_eq!( |
198 | self.mfile_id, mfile_id, | 198 | self.file_id, file_id, |
199 | "SourceFileItems: wrong file, expected {:?}, got {:?}", | 199 | "SourceFileItems: wrong file, expected {:?}, got {:?}", |
200 | self.mfile_id, mfile_id | 200 | self.file_id, file_id |
201 | ); | 201 | ); |
202 | self.id_of_unchecked(item) | 202 | self.id_of_unchecked(item) |
203 | } | 203 | } |
diff --git a/crates/ra_hir/src/mock.rs b/crates/ra_hir/src/mock.rs index 19bc426f6..89b18194a 100644 --- a/crates/ra_hir/src/mock.rs +++ b/crates/ra_hir/src/mock.rs | |||
@@ -189,7 +189,7 @@ salsa::database_storage! { | |||
189 | fn file_lines() for ra_db::FileLinesQuery; | 189 | fn file_lines() for ra_db::FileLinesQuery; |
190 | } | 190 | } |
191 | impl db::HirDatabase { | 191 | impl db::HirDatabase { |
192 | fn m_source_file() for db::MSourceFileQuery; | 192 | fn hir_source_file() for db::HirSourceFileQuery; |
193 | fn expand_macro_invocation() for db::ExpandMacroCallQuery; | 193 | fn expand_macro_invocation() for db::ExpandMacroCallQuery; |
194 | fn module_tree() for db::ModuleTreeQuery; | 194 | fn module_tree() for db::ModuleTreeQuery; |
195 | fn fn_scopes() for db::FnScopesQuery; | 195 | fn fn_scopes() for db::FnScopesQuery; |
diff --git a/crates/ra_hir/src/module.rs b/crates/ra_hir/src/module.rs index dde036f2c..26171d27c 100644 --- a/crates/ra_hir/src/module.rs +++ b/crates/ra_hir/src/module.rs | |||
@@ -15,7 +15,7 @@ use relative_path::RelativePathBuf; | |||
15 | use crate::{ | 15 | use crate::{ |
16 | Def, DefKind, DefLoc, DefId, | 16 | Def, DefKind, DefLoc, DefId, |
17 | Name, Path, PathKind, HirDatabase, SourceItemId, SourceFileItemId, Crate, | 17 | Name, Path, PathKind, HirDatabase, SourceItemId, SourceFileItemId, Crate, |
18 | MFileId, | 18 | HirFileId, |
19 | arena::{Arena, Id}, | 19 | arena::{Arena, Id}, |
20 | }; | 20 | }; |
21 | 21 | ||
@@ -49,13 +49,17 @@ impl Module { | |||
49 | /// Returns `None` for the root module | 49 | /// Returns `None` for the root module |
50 | pub fn parent_link_source(&self, db: &impl HirDatabase) -> Option<(FileId, ast::ModuleNode)> { | 50 | pub fn parent_link_source(&self, db: &impl HirDatabase) -> Option<(FileId, ast::ModuleNode)> { |
51 | let link = self.module_id.parent_link(&self.tree)?; | 51 | let link = self.module_id.parent_link(&self.tree)?; |
52 | let file_id = link.owner(&self.tree).source(&self.tree).file_id(); | 52 | let file_id = link |
53 | .owner(&self.tree) | ||
54 | .source(&self.tree) | ||
55 | .file_id() | ||
56 | .as_original_file(); | ||
53 | let src = link.bind_source(&self.tree, db); | 57 | let src = link.bind_source(&self.tree, db); |
54 | Some((file_id, src)) | 58 | Some((file_id, src)) |
55 | } | 59 | } |
56 | 60 | ||
57 | pub fn source(&self) -> ModuleSource { | 61 | pub fn file_id(&self) -> FileId { |
58 | self.module_id.source(&self.tree) | 62 | self.source().file_id().as_original_file() |
59 | } | 63 | } |
60 | 64 | ||
61 | /// Parent module. Returns `None` if this is a root module. | 65 | /// Parent module. Returns `None` if this is a root module. |
@@ -70,7 +74,7 @@ impl Module { | |||
70 | /// Returns the crate this module is part of. | 74 | /// Returns the crate this module is part of. |
71 | pub fn krate(&self, db: &impl HirDatabase) -> Option<Crate> { | 75 | pub fn krate(&self, db: &impl HirDatabase) -> Option<Crate> { |
72 | let root_id = self.module_id.crate_root(&self.tree); | 76 | let root_id = self.module_id.crate_root(&self.tree); |
73 | let file_id = root_id.source(&self.tree).file_id(); | 77 | let file_id = root_id.source(&self.tree).file_id().as_original_file(); |
74 | let crate_graph = db.crate_graph(); | 78 | let crate_graph = db.crate_graph(); |
75 | let crate_id = crate_graph.crate_id_for_crate_root(file_id)?; | 79 | let crate_id = crate_graph.crate_id_for_crate_root(file_id)?; |
76 | Some(Crate::new(crate_id)) | 80 | Some(Crate::new(crate_id)) |
@@ -163,6 +167,10 @@ impl Module { | |||
163 | pub fn problems(&self, db: &impl HirDatabase) -> Vec<(SyntaxNode, Problem)> { | 167 | pub fn problems(&self, db: &impl HirDatabase) -> Vec<(SyntaxNode, Problem)> { |
164 | self.module_id.problems(&self.tree, db) | 168 | self.module_id.problems(&self.tree, db) |
165 | } | 169 | } |
170 | |||
171 | pub(crate) fn source(&self) -> ModuleSource { | ||
172 | self.module_id.source(&self.tree) | ||
173 | } | ||
166 | } | 174 | } |
167 | 175 | ||
168 | /// Physically, rust source is organized as a set of files, but logically it is | 176 | /// Physically, rust source is organized as a set of files, but logically it is |
@@ -292,34 +300,28 @@ pub struct ModuleData { | |||
292 | 300 | ||
293 | impl ModuleSource { | 301 | impl ModuleSource { |
294 | // precondition: item_id **must** point to module | 302 | // precondition: item_id **must** point to module |
295 | fn new(file_id: FileId, item_id: Option<SourceFileItemId>) -> ModuleSource { | 303 | fn new(file_id: HirFileId, item_id: Option<SourceFileItemId>) -> ModuleSource { |
296 | let source_item_id = SourceItemId { | 304 | let source_item_id = SourceItemId { file_id, item_id }; |
297 | mfile_id: file_id.into(), | ||
298 | item_id, | ||
299 | }; | ||
300 | ModuleSource(source_item_id) | 305 | ModuleSource(source_item_id) |
301 | } | 306 | } |
302 | 307 | ||
303 | pub(crate) fn new_file(file_id: FileId) -> ModuleSource { | 308 | pub(crate) fn new_file(file_id: HirFileId) -> ModuleSource { |
304 | ModuleSource::new(file_id, None) | 309 | ModuleSource::new(file_id, None) |
305 | } | 310 | } |
306 | 311 | ||
307 | pub(crate) fn new_inline( | 312 | pub(crate) fn new_inline( |
308 | db: &impl HirDatabase, | 313 | db: &impl HirDatabase, |
309 | file_id: FileId, | 314 | file_id: HirFileId, |
310 | m: ast::Module, | 315 | m: ast::Module, |
311 | ) -> ModuleSource { | 316 | ) -> ModuleSource { |
312 | assert!(!m.has_semi()); | 317 | assert!(!m.has_semi()); |
313 | let file_items = db.file_items(file_id.into()); | 318 | let file_items = db.file_items(file_id); |
314 | let item_id = file_items.id_of(file_id.into(), m.syntax()); | 319 | let item_id = file_items.id_of(file_id, m.syntax()); |
315 | ModuleSource::new(file_id, Some(item_id)) | 320 | ModuleSource::new(file_id, Some(item_id)) |
316 | } | 321 | } |
317 | 322 | ||
318 | pub fn file_id(self) -> FileId { | 323 | pub(crate) fn file_id(self) -> HirFileId { |
319 | match self.0.mfile_id { | 324 | self.0.file_id |
320 | MFileId::File(file_id) => file_id, | ||
321 | MFileId::Macro(_) => unreachable!(), | ||
322 | } | ||
323 | } | 325 | } |
324 | 326 | ||
325 | pub(crate) fn resolve(self, db: &impl HirDatabase) -> ModuleSourceNode { | 327 | pub(crate) fn resolve(self, db: &impl HirDatabase) -> ModuleSourceNode { |
diff --git a/crates/ra_hir/src/module/imp.rs b/crates/ra_hir/src/module/imp.rs index eded85a63..d1498a646 100644 --- a/crates/ra_hir/src/module/imp.rs +++ b/crates/ra_hir/src/module/imp.rs | |||
@@ -64,7 +64,7 @@ fn create_module_tree<'a>( | |||
64 | 64 | ||
65 | let source_root = db.source_root(source_root); | 65 | let source_root = db.source_root(source_root); |
66 | for &file_id in source_root.files.values() { | 66 | for &file_id in source_root.files.values() { |
67 | let source = ModuleSource::new_file(file_id); | 67 | let source = ModuleSource::new_file(file_id.into()); |
68 | if visited.contains(&source) { | 68 | if visited.contains(&source) { |
69 | continue; // TODO: use explicit crate_roots here | 69 | continue; // TODO: use explicit crate_roots here |
70 | } | 70 | } |
@@ -123,7 +123,7 @@ fn build_subtree( | |||
123 | visited, | 123 | visited, |
124 | roots, | 124 | roots, |
125 | Some(link), | 125 | Some(link), |
126 | ModuleSource::new_file(file_id), | 126 | ModuleSource::new_file(file_id.into()), |
127 | ), | 127 | ), |
128 | }) | 128 | }) |
129 | .collect::<Cancelable<Vec<_>>>()?; | 129 | .collect::<Cancelable<Vec<_>>>()?; |
@@ -155,7 +155,7 @@ fn resolve_submodule( | |||
155 | name: &Name, | 155 | name: &Name, |
156 | ) -> (Vec<FileId>, Option<Problem>) { | 156 | ) -> (Vec<FileId>, Option<Problem>) { |
157 | // FIXME: handle submodules of inline modules properly | 157 | // FIXME: handle submodules of inline modules properly |
158 | let file_id = source.file_id(); | 158 | let file_id = source.file_id().original_file_id(db); |
159 | let source_root_id = db.file_source_root(file_id); | 159 | let source_root_id = db.file_source_root(file_id); |
160 | let path = db.file_relative_path(file_id); | 160 | let path = db.file_relative_path(file_id); |
161 | let root = RelativePathBuf::default(); | 161 | let root = RelativePathBuf::default(); |
diff --git a/crates/ra_hir/src/module/nameres.rs b/crates/ra_hir/src/module/nameres.rs index 27a76a293..cc60ba077 100644 --- a/crates/ra_hir/src/module/nameres.rs +++ b/crates/ra_hir/src/module/nameres.rs | |||
@@ -25,7 +25,7 @@ use ra_syntax::{ | |||
25 | use ra_db::SourceRootId; | 25 | use ra_db::SourceRootId; |
26 | 26 | ||
27 | use crate::{ | 27 | use crate::{ |
28 | Cancelable, MFileId, FileId, | 28 | Cancelable, HirFileId, FileId, |
29 | DefId, DefLoc, DefKind, | 29 | DefId, DefLoc, DefKind, |
30 | SourceItemId, SourceFileItemId, SourceFileItems, | 30 | SourceItemId, SourceFileItemId, SourceFileItems, |
31 | Path, PathKind, | 31 | Path, PathKind, |
@@ -95,9 +95,11 @@ pub struct NamedImport { | |||
95 | } | 95 | } |
96 | 96 | ||
97 | impl NamedImport { | 97 | impl NamedImport { |
98 | // FIXME: this is only here for one use-case in completion. Seems like a | ||
99 | // pretty gross special case. | ||
98 | pub fn range(&self, db: &impl HirDatabase, file_id: FileId) -> TextRange { | 100 | pub fn range(&self, db: &impl HirDatabase, file_id: FileId) -> TextRange { |
99 | let source_item_id = SourceItemId { | 101 | let source_item_id = SourceItemId { |
100 | mfile_id: file_id.into(), | 102 | file_id: file_id.into(), |
101 | item_id: Some(self.file_item_id), | 103 | item_id: Some(self.file_item_id), |
102 | }; | 104 | }; |
103 | let syntax = db.file_item(source_item_id); | 105 | let syntax = db.file_item(source_item_id); |
@@ -211,25 +213,25 @@ impl<T> PerNs<T> { | |||
211 | impl InputModuleItems { | 213 | impl InputModuleItems { |
212 | pub(crate) fn add_item( | 214 | pub(crate) fn add_item( |
213 | &mut self, | 215 | &mut self, |
214 | mfile_id: MFileId, | 216 | file_id: HirFileId, |
215 | file_items: &SourceFileItems, | 217 | file_items: &SourceFileItems, |
216 | item: ast::ModuleItem, | 218 | item: ast::ModuleItem, |
217 | ) -> Option<()> { | 219 | ) -> Option<()> { |
218 | match item { | 220 | match item { |
219 | ast::ModuleItem::StructDef(it) => { | 221 | ast::ModuleItem::StructDef(it) => { |
220 | self.items.push(ModuleItem::new(mfile_id, file_items, it)?) | 222 | self.items.push(ModuleItem::new(file_id, file_items, it)?) |
221 | } | 223 | } |
222 | ast::ModuleItem::EnumDef(it) => { | 224 | ast::ModuleItem::EnumDef(it) => { |
223 | self.items.push(ModuleItem::new(mfile_id, file_items, it)?) | 225 | self.items.push(ModuleItem::new(file_id, file_items, it)?) |
224 | } | 226 | } |
225 | ast::ModuleItem::FnDef(it) => { | 227 | ast::ModuleItem::FnDef(it) => { |
226 | self.items.push(ModuleItem::new(mfile_id, file_items, it)?) | 228 | self.items.push(ModuleItem::new(file_id, file_items, it)?) |
227 | } | 229 | } |
228 | ast::ModuleItem::TraitDef(it) => { | 230 | ast::ModuleItem::TraitDef(it) => { |
229 | self.items.push(ModuleItem::new(mfile_id, file_items, it)?) | 231 | self.items.push(ModuleItem::new(file_id, file_items, it)?) |
230 | } | 232 | } |
231 | ast::ModuleItem::TypeDef(it) => { | 233 | ast::ModuleItem::TypeDef(it) => { |
232 | self.items.push(ModuleItem::new(mfile_id, file_items, it)?) | 234 | self.items.push(ModuleItem::new(file_id, file_items, it)?) |
233 | } | 235 | } |
234 | ast::ModuleItem::ImplItem(_) => { | 236 | ast::ModuleItem::ImplItem(_) => { |
235 | // impls don't define items | 237 | // impls don't define items |
@@ -239,13 +241,13 @@ impl InputModuleItems { | |||
239 | // TODO | 241 | // TODO |
240 | } | 242 | } |
241 | ast::ModuleItem::ConstDef(it) => { | 243 | ast::ModuleItem::ConstDef(it) => { |
242 | self.items.push(ModuleItem::new(mfile_id, file_items, it)?) | 244 | self.items.push(ModuleItem::new(file_id, file_items, it)?) |
243 | } | 245 | } |
244 | ast::ModuleItem::StaticDef(it) => { | 246 | ast::ModuleItem::StaticDef(it) => { |
245 | self.items.push(ModuleItem::new(mfile_id, file_items, it)?) | 247 | self.items.push(ModuleItem::new(file_id, file_items, it)?) |
246 | } | 248 | } |
247 | ast::ModuleItem::Module(it) => { | 249 | ast::ModuleItem::Module(it) => { |
248 | self.items.push(ModuleItem::new(mfile_id, file_items, it)?) | 250 | self.items.push(ModuleItem::new(file_id, file_items, it)?) |
249 | } | 251 | } |
250 | } | 252 | } |
251 | Some(()) | 253 | Some(()) |
@@ -269,7 +271,7 @@ impl InputModuleItems { | |||
269 | 271 | ||
270 | impl ModuleItem { | 272 | impl ModuleItem { |
271 | fn new<'a>( | 273 | fn new<'a>( |
272 | mfile_id: MFileId, | 274 | file_id: HirFileId, |
273 | file_items: &SourceFileItems, | 275 | file_items: &SourceFileItems, |
274 | item: impl ast::NameOwner<'a>, | 276 | item: impl ast::NameOwner<'a>, |
275 | ) -> Option<ModuleItem> { | 277 | ) -> Option<ModuleItem> { |
@@ -277,7 +279,7 @@ impl ModuleItem { | |||
277 | let kind = item.syntax().kind(); | 279 | let kind = item.syntax().kind(); |
278 | let vis = Vis::Other; | 280 | let vis = Vis::Other; |
279 | let item_id = Some(file_items.id_of_unchecked(item.syntax())); | 281 | let item_id = Some(file_items.id_of_unchecked(item.syntax())); |
280 | let id = SourceItemId { mfile_id, item_id }; | 282 | let id = SourceItemId { file_id, item_id }; |
281 | let res = ModuleItem { | 283 | let res = ModuleItem { |
282 | id, | 284 | id, |
283 | name, | 285 | name, |
@@ -339,7 +341,8 @@ where | |||
339 | let root_id = module_id.crate_root(&self.module_tree); | 341 | let root_id = module_id.crate_root(&self.module_tree); |
340 | let file_id = root_id.source(&self.module_tree).file_id(); | 342 | let file_id = root_id.source(&self.module_tree).file_id(); |
341 | let crate_graph = self.db.crate_graph(); | 343 | let crate_graph = self.db.crate_graph(); |
342 | if let Some(crate_id) = crate_graph.crate_id_for_crate_root(file_id) { | 344 | if let Some(crate_id) = crate_graph.crate_id_for_crate_root(file_id.as_original_file()) |
345 | { | ||
343 | let krate = Crate::new(crate_id); | 346 | let krate = Crate::new(crate_id); |
344 | for dep in krate.dependencies(self.db) { | 347 | for dep in krate.dependencies(self.db) { |
345 | if let Some(module) = dep.krate.root_module(self.db)? { | 348 | if let Some(module) = dep.krate.root_module(self.db)? { |
diff --git a/crates/ra_hir/src/query_definitions.rs b/crates/ra_hir/src/query_definitions.rs index 3b73208e6..bc1f91938 100644 --- a/crates/ra_hir/src/query_definitions.rs +++ b/crates/ra_hir/src/query_definitions.rs | |||
@@ -5,13 +5,13 @@ use std::{ | |||
5 | 5 | ||
6 | use rustc_hash::FxHashMap; | 6 | use rustc_hash::FxHashMap; |
7 | use ra_syntax::{ | 7 | use ra_syntax::{ |
8 | AstNode, SyntaxNode, SourceFileNode, | 8 | AstNode, SyntaxNode, |
9 | ast::{self, NameOwner, ModuleItemOwner} | 9 | ast::{self, NameOwner, ModuleItemOwner} |
10 | }; | 10 | }; |
11 | use ra_db::{SourceRootId, FileId, Cancelable,}; | 11 | use ra_db::{SourceRootId, Cancelable,}; |
12 | 12 | ||
13 | use crate::{ | 13 | use crate::{ |
14 | SourceFileItems, SourceItemId, DefKind, Function, DefId, Name, AsName, MFileId, | 14 | SourceFileItems, SourceItemId, DefKind, Function, DefId, Name, AsName, HirFileId, |
15 | macros::MacroCallLoc, | 15 | macros::MacroCallLoc, |
16 | db::HirDatabase, | 16 | db::HirDatabase, |
17 | function::FnScopes, | 17 | function::FnScopes, |
@@ -48,29 +48,17 @@ pub(super) fn enum_data(db: &impl HirDatabase, def_id: DefId) -> Cancelable<Arc< | |||
48 | Ok(Arc::new(EnumData::new(enum_def.borrowed()))) | 48 | Ok(Arc::new(EnumData::new(enum_def.borrowed()))) |
49 | } | 49 | } |
50 | 50 | ||
51 | pub(super) fn m_source_file(db: &impl HirDatabase, mfile_id: MFileId) -> SourceFileNode { | 51 | pub(super) fn file_items(db: &impl HirDatabase, file_id: HirFileId) -> Arc<SourceFileItems> { |
52 | match mfile_id { | 52 | let source_file = db.hir_source_file(file_id); |
53 | MFileId::File(file_id) => db.source_file(file_id), | ||
54 | MFileId::Macro(m) => { | ||
55 | if let Some(exp) = db.expand_macro_invocation(m) { | ||
56 | return exp.file(); | ||
57 | } | ||
58 | SourceFileNode::parse("") | ||
59 | } | ||
60 | } | ||
61 | } | ||
62 | |||
63 | pub(super) fn file_items(db: &impl HirDatabase, mfile_id: MFileId) -> Arc<SourceFileItems> { | ||
64 | let source_file = db.m_source_file(mfile_id); | ||
65 | let source_file = source_file.borrowed(); | 53 | let source_file = source_file.borrowed(); |
66 | let res = SourceFileItems::new(mfile_id, source_file); | 54 | let res = SourceFileItems::new(file_id, source_file); |
67 | Arc::new(res) | 55 | Arc::new(res) |
68 | } | 56 | } |
69 | 57 | ||
70 | pub(super) fn file_item(db: &impl HirDatabase, source_item_id: SourceItemId) -> SyntaxNode { | 58 | pub(super) fn file_item(db: &impl HirDatabase, source_item_id: SourceItemId) -> SyntaxNode { |
71 | match source_item_id.item_id { | 59 | match source_item_id.item_id { |
72 | Some(id) => db.file_items(source_item_id.mfile_id)[id].clone(), | 60 | Some(id) => db.file_items(source_item_id.file_id)[id].clone(), |
73 | None => db.m_source_file(source_item_id.mfile_id).syntax().owned(), | 61 | None => db.hir_source_file(source_item_id.file_id).syntax().owned(), |
74 | } | 62 | } |
75 | } | 63 | } |
76 | 64 | ||
@@ -92,7 +80,7 @@ pub(crate) fn submodules( | |||
92 | 80 | ||
93 | fn collect_submodules<'a>( | 81 | fn collect_submodules<'a>( |
94 | db: &impl HirDatabase, | 82 | db: &impl HirDatabase, |
95 | file_id: FileId, | 83 | file_id: HirFileId, |
96 | root: impl ast::ModuleItemOwner<'a>, | 84 | root: impl ast::ModuleItemOwner<'a>, |
97 | ) -> Vec<Submodule> { | 85 | ) -> Vec<Submodule> { |
98 | modules(root) | 86 | modules(root) |
@@ -129,13 +117,13 @@ pub(super) fn input_module_items( | |||
129 | ) -> Cancelable<Arc<InputModuleItems>> { | 117 | ) -> Cancelable<Arc<InputModuleItems>> { |
130 | let module_tree = db.module_tree(source_root_id)?; | 118 | let module_tree = db.module_tree(source_root_id)?; |
131 | let source = module_id.source(&module_tree); | 119 | let source = module_id.source(&module_tree); |
132 | let mfile_id = source.file_id().into(); | 120 | let file_id = source.file_id(); |
133 | let file_items = db.file_items(mfile_id); | 121 | let file_items = db.file_items(file_id); |
134 | let fill = |acc: &mut InputModuleItems, items: &mut Iterator<Item = ast::ItemOrMacro>| { | 122 | let fill = |acc: &mut InputModuleItems, items: &mut Iterator<Item = ast::ItemOrMacro>| { |
135 | for item in items { | 123 | for item in items { |
136 | match item { | 124 | match item { |
137 | ast::ItemOrMacro::Item(it) => { | 125 | ast::ItemOrMacro::Item(it) => { |
138 | acc.add_item(mfile_id, &file_items, it); | 126 | acc.add_item(file_id, &file_items, it); |
139 | } | 127 | } |
140 | ast::ItemOrMacro::Macro(macro_call) => { | 128 | ast::ItemOrMacro::Macro(macro_call) => { |
141 | let item_id = file_items.id_of_unchecked(macro_call.syntax()); | 129 | let item_id = file_items.id_of_unchecked(macro_call.syntax()); |
@@ -143,16 +131,16 @@ pub(super) fn input_module_items( | |||
143 | source_root_id, | 131 | source_root_id, |
144 | module_id, | 132 | module_id, |
145 | source_item_id: SourceItemId { | 133 | source_item_id: SourceItemId { |
146 | mfile_id, | 134 | file_id, |
147 | item_id: Some(item_id), | 135 | item_id: Some(item_id), |
148 | }, | 136 | }, |
149 | }; | 137 | }; |
150 | let id = loc.id(db); | 138 | let id = loc.id(db); |
151 | let mfile_id = MFileId::Macro(id); | 139 | let file_id = HirFileId::from(id); |
152 | let file_items = db.file_items(mfile_id); | 140 | let file_items = db.file_items(file_id); |
153 | //FIXME: expand recursively | 141 | //FIXME: expand recursively |
154 | for item in db.m_source_file(mfile_id).borrowed().items() { | 142 | for item in db.hir_source_file(file_id).borrowed().items() { |
155 | acc.add_item(mfile_id, &file_items, item); | 143 | acc.add_item(file_id, &file_items, item); |
156 | } | 144 | } |
157 | } | 145 | } |
158 | } | 146 | } |
diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs index 4a99dff84..24490d119 100644 --- a/crates/ra_hir/src/source_binder.rs +++ b/crates/ra_hir/src/source_binder.rs | |||
@@ -20,7 +20,7 @@ use crate::{ | |||
20 | 20 | ||
21 | /// Locates the module by `FileId`. Picks topmost module in the file. | 21 | /// Locates the module by `FileId`. Picks topmost module in the file. |
22 | pub fn module_from_file_id(db: &impl HirDatabase, file_id: FileId) -> Cancelable<Option<Module>> { | 22 | pub fn module_from_file_id(db: &impl HirDatabase, file_id: FileId) -> Cancelable<Option<Module>> { |
23 | let module_source = ModuleSource::new_file(file_id); | 23 | let module_source = ModuleSource::new_file(file_id.into()); |
24 | module_from_source(db, module_source) | 24 | module_from_source(db, module_source) |
25 | } | 25 | } |
26 | 26 | ||
@@ -50,8 +50,8 @@ pub fn module_from_position( | |||
50 | ) -> Cancelable<Option<Module>> { | 50 | ) -> Cancelable<Option<Module>> { |
51 | let file = db.source_file(position.file_id); | 51 | let file = db.source_file(position.file_id); |
52 | let module_source = match find_node_at_offset::<ast::Module>(file.syntax(), position.offset) { | 52 | let module_source = match find_node_at_offset::<ast::Module>(file.syntax(), position.offset) { |
53 | Some(m) if !m.has_semi() => ModuleSource::new_inline(db, position.file_id, m), | 53 | Some(m) if !m.has_semi() => ModuleSource::new_inline(db, position.file_id.into(), m), |
54 | _ => ModuleSource::new_file(position.file_id), | 54 | _ => ModuleSource::new_file(position.file_id.into()), |
55 | }; | 55 | }; |
56 | module_from_source(db, module_source) | 56 | module_from_source(db, module_source) |
57 | } | 57 | } |
@@ -67,9 +67,9 @@ pub fn module_from_child_node( | |||
67 | .filter_map(ast::Module::cast) | 67 | .filter_map(ast::Module::cast) |
68 | .find(|it| !it.has_semi()) | 68 | .find(|it| !it.has_semi()) |
69 | { | 69 | { |
70 | ModuleSource::new_inline(db, file_id, m) | 70 | ModuleSource::new_inline(db, file_id.into(), m) |
71 | } else { | 71 | } else { |
72 | ModuleSource::new_file(file_id) | 72 | ModuleSource::new_file(file_id.into()) |
73 | }; | 73 | }; |
74 | module_from_source(db, module_source) | 74 | module_from_source(db, module_source) |
75 | } | 75 | } |
@@ -78,7 +78,7 @@ fn module_from_source( | |||
78 | db: &impl HirDatabase, | 78 | db: &impl HirDatabase, |
79 | module_source: ModuleSource, | 79 | module_source: ModuleSource, |
80 | ) -> Cancelable<Option<Module>> { | 80 | ) -> Cancelable<Option<Module>> { |
81 | let source_root_id = db.file_source_root(module_source.file_id()); | 81 | let source_root_id = db.file_source_root(module_source.file_id().as_original_file()); |
82 | let module_tree = db.module_tree(source_root_id)?; | 82 | let module_tree = db.module_tree(source_root_id)?; |
83 | let m = module_tree | 83 | let m = module_tree |
84 | .modules_with_sources() | 84 | .modules_with_sources() |
@@ -102,11 +102,11 @@ pub fn function_from_module( | |||
102 | module: &Module, | 102 | module: &Module, |
103 | fn_def: ast::FnDef, | 103 | fn_def: ast::FnDef, |
104 | ) -> Function { | 104 | ) -> Function { |
105 | let mfile_id = module.source().file_id().into(); | 105 | let file_id = module.source().file_id(); |
106 | let file_items = db.file_items(mfile_id); | 106 | let file_items = db.file_items(file_id); |
107 | let item_id = file_items.id_of(mfile_id, fn_def.syntax()); | 107 | let item_id = file_items.id_of(file_id, fn_def.syntax()); |
108 | let source_item_id = SourceItemId { | 108 | let source_item_id = SourceItemId { |
109 | mfile_id, | 109 | file_id, |
110 | item_id: Some(item_id), | 110 | item_id: Some(item_id), |
111 | }; | 111 | }; |
112 | let def_loc = DefLoc { | 112 | let def_loc = DefLoc { |