aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_analysis/src/hir/module/nameres.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_analysis/src/hir/module/nameres.rs')
-rw-r--r--crates/ra_analysis/src/hir/module/nameres.rs36
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.
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)]