aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-11-27 22:45:36 +0000
committerAleksey Kladov <[email protected]>2018-11-27 22:45:36 +0000
commit5e7f4202cf4d64f565d6d035cd2e854acfc336ab (patch)
treebc76e79dd732fecc217dbb1a2109e5ae1a1803fc
parentb9100d769a043c55f83b709de2714dac935e333f (diff)
Move FileItems up
-rw-r--r--crates/ra_analysis/src/hir/db.rs3
-rw-r--r--crates/ra_analysis/src/hir/mod.rs38
-rw-r--r--crates/ra_analysis/src/hir/module/nameres.rs36
-rw-r--r--crates/ra_analysis/src/hir/query_definitions.rs3
4 files changed, 43 insertions, 37 deletions
diff --git a/crates/ra_analysis/src/hir/db.rs b/crates/ra_analysis/src/hir/db.rs
index c6dbde79b..a226e8205 100644
--- a/crates/ra_analysis/src/hir/db.rs
+++ b/crates/ra_analysis/src/hir/db.rs
@@ -8,11 +8,12 @@ use ra_syntax::{
8use crate::{ 8use crate::{
9 FileId, 9 FileId,
10 db::SyntaxDatabase, 10 db::SyntaxDatabase,
11 hir::{FileItems, FileItemId},
11 hir::query_definitions, 12 hir::query_definitions,
12 hir::function::{FnId, FnScopes}, 13 hir::function::{FnId, FnScopes},
13 hir::module::{ 14 hir::module::{
14 ModuleId, ModuleTree, ModuleSource, 15 ModuleId, ModuleTree, ModuleSource,
15 nameres::{ItemMap, InputModuleItems, FileItems, FileItemId} 16 nameres::{ItemMap, InputModuleItems}
16 }, 17 },
17 input::SourceRootId, 18 input::SourceRootId,
18 Cancelable, 19 Cancelable,
diff --git a/crates/ra_analysis/src/hir/mod.rs b/crates/ra_analysis/src/hir/mod.rs
index 863ffd919..3d4a55ca4 100644
--- a/crates/ra_analysis/src/hir/mod.rs
+++ b/crates/ra_analysis/src/hir/mod.rs
@@ -11,15 +11,20 @@ mod function;
11mod module; 11mod module;
12mod path; 12mod path;
13 13
14use std::ops::Index;
15
16use ra_syntax::{SyntaxNodeRef, SyntaxNode};
17
14use crate::{ 18use crate::{
15 hir::db::HirDatabase, 19 hir::db::HirDatabase,
16 loc2id::{DefId, DefLoc}, 20 loc2id::{DefId, DefLoc},
17 Cancelable, 21 Cancelable,
22 arena::{Arena, Id},
18}; 23};
19 24
20pub(crate) use self::{ 25pub(crate) use self::{
21 path::{Path, PathKind}, 26 path::{Path, PathKind},
22 module::{Module, ModuleId, Problem, nameres::FileItemId}, 27 module::{Module, ModuleId, Problem},
23 function::{Function, FnScopes}, 28 function::{Function, FnScopes},
24}; 29};
25 30
@@ -43,3 +48,34 @@ impl DefId {
43 Ok(res) 48 Ok(res)
44 } 49 }
45} 50}
51
52/// Identifier of item within a specific file. This is stable over reparses, so
53/// it's OK to use it as a salsa key/value.
54pub(crate) type FileItemId = Id<SyntaxNode>;
55
56/// Maps item's `SyntaxNode`s to `FileItemId` and back.
57#[derive(Debug, PartialEq, Eq, Default)]
58pub(crate) struct FileItems {
59 arena: Arena<SyntaxNode>,
60}
61
62impl FileItems {
63 fn alloc(&mut self, item: SyntaxNode) -> FileItemId {
64 self.arena.alloc(item)
65 }
66 fn id_of(&self, item: SyntaxNodeRef) -> FileItemId {
67 let (id, _item) = self
68 .arena
69 .iter()
70 .find(|(_id, i)| i.borrowed() == item)
71 .unwrap();
72 id
73 }
74}
75
76impl Index<FileItemId> for FileItems {
77 type Output = SyntaxNode;
78 fn index(&self, idx: FileItemId) -> &SyntaxNode {
79 &self.arena[idx]
80 }
81}
diff --git a/crates/ra_analysis/src/hir/module/nameres.rs b/crates/ra_analysis/src/hir/module/nameres.rs
index d38940085..f7d8c8e8c 100644
--- a/crates/ra_analysis/src/hir/module/nameres.rs
+++ b/crates/ra_analysis/src/hir/module/nameres.rs
@@ -16,13 +16,12 @@
16//! structure itself is modified. 16//! structure itself is modified.
17use std::{ 17use std::{
18 sync::Arc, 18 sync::Arc,
19 ops::Index,
20}; 19};
21 20
22use rustc_hash::FxHashMap; 21use rustc_hash::FxHashMap;
23 22
24use ra_syntax::{ 23use ra_syntax::{
25 SyntaxNode, SyntaxNodeRef, TextRange, 24 TextRange,
26 SmolStr, SyntaxKind::{self, *}, 25 SmolStr, SyntaxKind::{self, *},
27 ast::{self, AstNode} 26 ast::{self, AstNode}
28}; 27};
@@ -31,45 +30,14 @@ use crate::{
31 Cancelable, FileId, 30 Cancelable, FileId,
32 loc2id::{DefId, DefLoc}, 31 loc2id::{DefId, DefLoc},
33 hir::{ 32 hir::{
33 FileItemId, FileItems,
34 Path, PathKind, 34 Path, PathKind,
35 HirDatabase, 35 HirDatabase,
36 module::{ModuleId, ModuleTree}, 36 module::{ModuleId, ModuleTree},
37 }, 37 },
38 input::SourceRootId, 38 input::SourceRootId,
39 arena::{Arena, Id}
40}; 39};
41 40
42/// Identifier of item within a specific file. This is stable over reparses, so
43/// it's OK to use it as a salsa key/value.
44pub(crate) type FileItemId = Id<SyntaxNode>;
45
46/// Maps item's `SyntaxNode`s to `FileItemId` and back.
47#[derive(Debug, PartialEq, Eq, Default)]
48pub(crate) struct FileItems {
49 arena: Arena<SyntaxNode>,
50}
51
52impl FileItems {
53 pub(crate) fn alloc(&mut self, item: SyntaxNode) -> FileItemId {
54 self.arena.alloc(item)
55 }
56 fn id_of(&self, item: SyntaxNodeRef) -> FileItemId {
57 let (id, _item) = self
58 .arena
59 .iter()
60 .find(|(_id, i)| i.borrowed() == item)
61 .unwrap();
62 id
63 }
64}
65
66impl Index<FileItemId> for FileItems {
67 type Output = SyntaxNode;
68 fn index(&self, idx: FileItemId) -> &SyntaxNode {
69 &self.arena[idx]
70 }
71}
72
73/// Item map is the result of the name resolution. Item map contains, for each 41/// Item map is the result of the name resolution. Item map contains, for each
74/// module, the set of visible items. 42/// module, the set of visible items.
75#[derive(Default, Debug, PartialEq, Eq)] 43#[derive(Default, Debug, PartialEq, Eq)]
diff --git a/crates/ra_analysis/src/hir/query_definitions.rs b/crates/ra_analysis/src/hir/query_definitions.rs
index 8584a8d64..e6bfbc6cf 100644
--- a/crates/ra_analysis/src/hir/query_definitions.rs
+++ b/crates/ra_analysis/src/hir/query_definitions.rs
@@ -12,12 +12,13 @@ use ra_syntax::{
12use crate::{ 12use crate::{
13 FileId, Cancelable, 13 FileId, Cancelable,
14 hir::{ 14 hir::{
15 FileItems, FileItemId,
15 db::HirDatabase, 16 db::HirDatabase,
16 function::{FnId, FnScopes}, 17 function::{FnId, FnScopes},
17 module::{ 18 module::{
18 ModuleSource, ModuleSourceNode, ModuleId, 19 ModuleSource, ModuleSourceNode, ModuleId,
19 imp::Submodule, 20 imp::Submodule,
20 nameres::{FileItems, FileItemId, InputModuleItems, ItemMap, Resolver}, 21 nameres::{InputModuleItems, ItemMap, Resolver},
21 }, 22 },
22 }, 23 },
23 input::SourceRootId, 24 input::SourceRootId,