aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_analysis/src/loc2id.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_analysis/src/loc2id.rs')
-rw-r--r--crates/ra_analysis/src/loc2id.rs25
1 files changed, 25 insertions, 0 deletions
diff --git a/crates/ra_analysis/src/loc2id.rs b/crates/ra_analysis/src/loc2id.rs
index 8c297156a..e4b55f9b0 100644
--- a/crates/ra_analysis/src/loc2id.rs
+++ b/crates/ra_analysis/src/loc2id.rs
@@ -8,7 +8,9 @@ use std::{
8use rustc_hash::FxHashMap; 8use rustc_hash::FxHashMap;
9 9
10use crate::{ 10use crate::{
11 descriptors::module::ModuleId,
11 syntax_ptr::SyntaxPtr, 12 syntax_ptr::SyntaxPtr,
13 input::SourceRootId,
12}; 14};
13 15
14/// There are two principle ways to refer to things: 16/// There are two principle ways to refer to things:
@@ -89,6 +91,21 @@ macro_rules! impl_numeric_id {
89pub(crate) struct FnId(u32); 91pub(crate) struct FnId(u32);
90impl_numeric_id!(FnId); 92impl_numeric_id!(FnId);
91 93
94#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
95pub(crate) struct DefId(u32);
96impl_numeric_id!(DefId);
97
98#[derive(Clone, Debug, PartialEq, Eq, Hash)]
99pub(crate) enum DefLoc {
100 Module {
101 id: ModuleId,
102 source_root: SourceRootId,
103 },
104 Item {
105 ptr: SyntaxPtr,
106 },
107}
108
92pub(crate) trait IdDatabase: salsa::Database { 109pub(crate) trait IdDatabase: salsa::Database {
93 fn id_maps(&self) -> &IdMaps; 110 fn id_maps(&self) -> &IdMaps;
94} 111}
@@ -105,9 +122,17 @@ impl IdMaps {
105 pub(crate) fn fn_ptr(&self, fn_id: FnId) -> SyntaxPtr { 122 pub(crate) fn fn_ptr(&self, fn_id: FnId) -> SyntaxPtr {
106 self.inner.fns.lock().id2loc(fn_id) 123 self.inner.fns.lock().id2loc(fn_id)
107 } 124 }
125
126 pub(crate) fn def_id(&self, loc: DefLoc) -> DefId {
127 self.inner.defs.lock().loc2id(&loc)
128 }
129 pub(crate) fn def_loc(&self, def_id: DefId) -> DefLoc {
130 self.inner.defs.lock().id2loc(def_id)
131 }
108} 132}
109 133
110#[derive(Debug, Default)] 134#[derive(Debug, Default)]
111struct IdMapsInner { 135struct IdMapsInner {
112 fns: Mutex<Loc2IdMap<SyntaxPtr, FnId>>, 136 fns: Mutex<Loc2IdMap<SyntaxPtr, FnId>>,
137 defs: Mutex<Loc2IdMap<DefLoc, DefId>>,
113} 138}