diff options
author | Aleksey Kladov <[email protected]> | 2018-11-27 22:45:36 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-11-27 22:45:36 +0000 |
commit | 5e7f4202cf4d64f565d6d035cd2e854acfc336ab (patch) | |
tree | bc76e79dd732fecc217dbb1a2109e5ae1a1803fc /crates/ra_analysis/src/hir/module | |
parent | b9100d769a043c55f83b709de2714dac935e333f (diff) |
Move FileItems up
Diffstat (limited to 'crates/ra_analysis/src/hir/module')
-rw-r--r-- | crates/ra_analysis/src/hir/module/nameres.rs | 36 |
1 files changed, 2 insertions, 34 deletions
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. |
17 | use std::{ | 17 | use std::{ |
18 | sync::Arc, | 18 | sync::Arc, |
19 | ops::Index, | ||
20 | }; | 19 | }; |
21 | 20 | ||
22 | use rustc_hash::FxHashMap; | 21 | use rustc_hash::FxHashMap; |
23 | 22 | ||
24 | use ra_syntax::{ | 23 | use 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. | ||
44 | pub(crate) type FileItemId = Id<SyntaxNode>; | ||
45 | |||
46 | /// Maps item's `SyntaxNode`s to `FileItemId` and back. | ||
47 | #[derive(Debug, PartialEq, Eq, Default)] | ||
48 | pub(crate) struct FileItems { | ||
49 | arena: Arena<SyntaxNode>, | ||
50 | } | ||
51 | |||
52 | impl 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 | |||
66 | impl 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)] |