diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_analysis/src/completion/completion_item.rs | 10 | ||||
-rw-r--r-- | crates/ra_arena/src/lib.rs | 3 | ||||
-rw-r--r-- | crates/ra_db/Cargo.toml | 1 | ||||
-rw-r--r-- | crates/ra_db/src/lib.rs | 16 | ||||
-rw-r--r-- | crates/ra_db/src/loc2id.rs | 34 | ||||
-rw-r--r-- | crates/ra_hir/src/ids.rs | 8 |
6 files changed, 26 insertions, 46 deletions
diff --git a/crates/ra_analysis/src/completion/completion_item.rs b/crates/ra_analysis/src/completion/completion_item.rs index cd4d529f9..a25b87bee 100644 --- a/crates/ra_analysis/src/completion/completion_item.rs +++ b/crates/ra_analysis/src/completion/completion_item.rs | |||
@@ -150,12 +150,10 @@ impl Builder { | |||
150 | fn from_function(mut self, ctx: &CompletionContext, function: hir::Function) -> Builder { | 150 | fn from_function(mut self, ctx: &CompletionContext, function: hir::Function) -> Builder { |
151 | // If not an import, add parenthesis automatically. | 151 | // If not an import, add parenthesis automatically. |
152 | if ctx.use_item_syntax.is_none() { | 152 | if ctx.use_item_syntax.is_none() { |
153 | if let Some(sig_info) = function.signature_info(ctx.db) { | 153 | if function.signature(ctx.db).args().is_empty() { |
154 | if sig_info.params.is_empty() { | 154 | self.snippet = Some(format!("{}()$0", self.label)); |
155 | self.snippet = Some(format!("{}()$0", self.label)); | 155 | } else { |
156 | } else { | 156 | self.snippet = Some(format!("{}($0)", self.label)); |
157 | self.snippet = Some(format!("{}($0)", self.label)); | ||
158 | } | ||
159 | } | 157 | } |
160 | } | 158 | } |
161 | self.kind = Some(CompletionItemKind::Function); | 159 | self.kind = Some(CompletionItemKind::Function); |
diff --git a/crates/ra_arena/src/lib.rs b/crates/ra_arena/src/lib.rs index 040977dc4..43bfa925a 100644 --- a/crates/ra_arena/src/lib.rs +++ b/crates/ra_arena/src/lib.rs | |||
@@ -61,6 +61,9 @@ pub trait ArenaId { | |||
61 | } | 61 | } |
62 | 62 | ||
63 | impl<ID: ArenaId, T> Arena<ID, T> { | 63 | impl<ID: ArenaId, T> Arena<ID, T> { |
64 | pub fn len(&self) -> usize { | ||
65 | self.data.len() | ||
66 | } | ||
64 | pub fn alloc(&mut self, value: T) -> ID { | 67 | pub fn alloc(&mut self, value: T) -> ID { |
65 | let id = RawId(self.data.len() as u32); | 68 | let id = RawId(self.data.len() as u32); |
66 | self.data.push(value); | 69 | self.data.push(value); |
diff --git a/crates/ra_db/Cargo.toml b/crates/ra_db/Cargo.toml index c0e83a140..c43e65051 100644 --- a/crates/ra_db/Cargo.toml +++ b/crates/ra_db/Cargo.toml | |||
@@ -9,6 +9,7 @@ relative-path = "0.4.0" | |||
9 | salsa = "0.9.1" | 9 | salsa = "0.9.1" |
10 | rustc-hash = "1.0" | 10 | rustc-hash = "1.0" |
11 | parking_lot = "0.7.0" | 11 | parking_lot = "0.7.0" |
12 | ra_arena = { path = "../ra_arena" } | ||
12 | ra_syntax = { path = "../ra_syntax" } | 13 | ra_syntax = { path = "../ra_syntax" } |
13 | ra_editor = { path = "../ra_editor" } | 14 | ra_editor = { path = "../ra_editor" } |
14 | test_utils = { path = "../test_utils" } | 15 | test_utils = { path = "../test_utils" } |
diff --git a/crates/ra_db/src/lib.rs b/crates/ra_db/src/lib.rs index 3c41ee56d..732899718 100644 --- a/crates/ra_db/src/lib.rs +++ b/crates/ra_db/src/lib.rs | |||
@@ -18,23 +18,9 @@ pub use crate::{ | |||
18 | FileTextQuery, FileSourceRootQuery, SourceRootQuery, LocalRootsQuery, LibraryRootsQuery, CrateGraphQuery, | 18 | FileTextQuery, FileSourceRootQuery, SourceRootQuery, LocalRootsQuery, LibraryRootsQuery, CrateGraphQuery, |
19 | FileRelativePathQuery | 19 | FileRelativePathQuery |
20 | }, | 20 | }, |
21 | loc2id::{LocationIntener, NumericId}, | 21 | loc2id::LocationIntener, |
22 | }; | 22 | }; |
23 | 23 | ||
24 | #[macro_export] | ||
25 | macro_rules! impl_numeric_id { | ||
26 | ($id:ident) => { | ||
27 | impl $crate::NumericId for $id { | ||
28 | fn from_u32(id: u32) -> Self { | ||
29 | $id(id) | ||
30 | } | ||
31 | fn to_u32(self) -> u32 { | ||
32 | self.0 | ||
33 | } | ||
34 | } | ||
35 | }; | ||
36 | } | ||
37 | |||
38 | pub trait BaseDatabase: salsa::Database { | 24 | pub trait BaseDatabase: salsa::Database { |
39 | fn check_canceled(&self) -> Cancelable<()> { | 25 | fn check_canceled(&self) -> Cancelable<()> { |
40 | if self.salsa_runtime().is_current_revision_canceled() { | 26 | if self.salsa_runtime().is_current_revision_canceled() { |
diff --git a/crates/ra_db/src/loc2id.rs b/crates/ra_db/src/loc2id.rs index 2dc7930d8..1d6761897 100644 --- a/crates/ra_db/src/loc2id.rs +++ b/crates/ra_db/src/loc2id.rs | |||
@@ -1,8 +1,8 @@ | |||
1 | use parking_lot::Mutex; | ||
2 | |||
3 | use std::hash::Hash; | 1 | use std::hash::Hash; |
4 | 2 | ||
3 | use parking_lot::Mutex; | ||
5 | use rustc_hash::FxHashMap; | 4 | use rustc_hash::FxHashMap; |
5 | use ra_arena::{Arena, ArenaId}; | ||
6 | 6 | ||
7 | /// There are two principle ways to refer to things: | 7 | /// There are two principle ways to refer to things: |
8 | /// - by their locatinon (module in foo/bar/baz.rs at line 42) | 8 | /// - by their locatinon (module in foo/bar/baz.rs at line 42) |
@@ -17,33 +17,33 @@ use rustc_hash::FxHashMap; | |||
17 | #[derive(Debug)] | 17 | #[derive(Debug)] |
18 | struct Loc2IdMap<LOC, ID> | 18 | struct Loc2IdMap<LOC, ID> |
19 | where | 19 | where |
20 | ID: NumericId, | 20 | ID: ArenaId + Clone, |
21 | LOC: Clone + Eq + Hash, | 21 | LOC: Clone + Eq + Hash, |
22 | { | 22 | { |
23 | id2loc: Arena<ID, LOC>, | ||
23 | loc2id: FxHashMap<LOC, ID>, | 24 | loc2id: FxHashMap<LOC, ID>, |
24 | id2loc: FxHashMap<ID, LOC>, | ||
25 | } | 25 | } |
26 | 26 | ||
27 | impl<LOC, ID> Default for Loc2IdMap<LOC, ID> | 27 | impl<LOC, ID> Default for Loc2IdMap<LOC, ID> |
28 | where | 28 | where |
29 | ID: NumericId, | 29 | ID: ArenaId + Clone, |
30 | LOC: Clone + Eq + Hash, | 30 | LOC: Clone + Eq + Hash, |
31 | { | 31 | { |
32 | fn default() -> Self { | 32 | fn default() -> Self { |
33 | Loc2IdMap { | 33 | Loc2IdMap { |
34 | id2loc: Arena::default(), | ||
34 | loc2id: FxHashMap::default(), | 35 | loc2id: FxHashMap::default(), |
35 | id2loc: FxHashMap::default(), | ||
36 | } | 36 | } |
37 | } | 37 | } |
38 | } | 38 | } |
39 | 39 | ||
40 | impl<LOC, ID> Loc2IdMap<LOC, ID> | 40 | impl<LOC, ID> Loc2IdMap<LOC, ID> |
41 | where | 41 | where |
42 | ID: NumericId, | 42 | ID: ArenaId + Clone, |
43 | LOC: Clone + Eq + Hash, | 43 | LOC: Clone + Eq + Hash, |
44 | { | 44 | { |
45 | pub fn len(&self) -> usize { | 45 | pub fn len(&self) -> usize { |
46 | self.loc2id.len() | 46 | self.id2loc.len() |
47 | } | 47 | } |
48 | 48 | ||
49 | pub fn loc2id(&mut self, loc: &LOC) -> ID { | 49 | pub fn loc2id(&mut self, loc: &LOC) -> ID { |
@@ -51,28 +51,20 @@ where | |||
51 | Some(id) => return id.clone(), | 51 | Some(id) => return id.clone(), |
52 | None => (), | 52 | None => (), |
53 | } | 53 | } |
54 | let id = self.loc2id.len(); | 54 | let id = self.id2loc.alloc(loc.clone()); |
55 | assert!(id < u32::max_value() as usize); | ||
56 | let id = ID::from_u32(id as u32); | ||
57 | self.loc2id.insert(loc.clone(), id.clone()); | 55 | self.loc2id.insert(loc.clone(), id.clone()); |
58 | self.id2loc.insert(id.clone(), loc.clone()); | ||
59 | id | 56 | id |
60 | } | 57 | } |
61 | 58 | ||
62 | pub fn id2loc(&self, id: ID) -> LOC { | 59 | pub fn id2loc(&self, id: ID) -> LOC { |
63 | self.id2loc[&id].clone() | 60 | self.id2loc[id].clone() |
64 | } | 61 | } |
65 | } | 62 | } |
66 | 63 | ||
67 | pub trait NumericId: Clone + Eq + Hash { | ||
68 | fn from_u32(id: u32) -> Self; | ||
69 | fn to_u32(self) -> u32; | ||
70 | } | ||
71 | |||
72 | #[derive(Debug)] | 64 | #[derive(Debug)] |
73 | pub struct LocationIntener<LOC, ID> | 65 | pub struct LocationIntener<LOC, ID> |
74 | where | 66 | where |
75 | ID: NumericId, | 67 | ID: ArenaId + Clone, |
76 | LOC: Clone + Eq + Hash, | 68 | LOC: Clone + Eq + Hash, |
77 | { | 69 | { |
78 | map: Mutex<Loc2IdMap<LOC, ID>>, | 70 | map: Mutex<Loc2IdMap<LOC, ID>>, |
@@ -80,7 +72,7 @@ where | |||
80 | 72 | ||
81 | impl<LOC, ID> Default for LocationIntener<LOC, ID> | 73 | impl<LOC, ID> Default for LocationIntener<LOC, ID> |
82 | where | 74 | where |
83 | ID: NumericId, | 75 | ID: ArenaId + Clone, |
84 | LOC: Clone + Eq + Hash, | 76 | LOC: Clone + Eq + Hash, |
85 | { | 77 | { |
86 | fn default() -> Self { | 78 | fn default() -> Self { |
@@ -92,7 +84,7 @@ where | |||
92 | 84 | ||
93 | impl<LOC, ID> LocationIntener<LOC, ID> | 85 | impl<LOC, ID> LocationIntener<LOC, ID> |
94 | where | 86 | where |
95 | ID: NumericId, | 87 | ID: ArenaId + Clone, |
96 | LOC: Clone + Eq + Hash, | 88 | LOC: Clone + Eq + Hash, |
97 | { | 89 | { |
98 | pub fn len(&self) -> usize { | 90 | pub fn len(&self) -> usize { |
diff --git a/crates/ra_hir/src/ids.rs b/crates/ra_hir/src/ids.rs index bc8d4f3a8..3db757778 100644 --- a/crates/ra_hir/src/ids.rs +++ b/crates/ra_hir/src/ids.rs | |||
@@ -96,8 +96,8 @@ impl From<MacroCallId> for HirFileId { | |||
96 | /// `MacroCallId` identifies a particular macro invocation, like | 96 | /// `MacroCallId` identifies a particular macro invocation, like |
97 | /// `println!("Hello, {}", world)`. | 97 | /// `println!("Hello, {}", world)`. |
98 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 98 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
99 | pub struct MacroCallId(u32); | 99 | pub struct MacroCallId(RawId); |
100 | ra_db::impl_numeric_id!(MacroCallId); | 100 | impl_arena_id!(MacroCallId); |
101 | 101 | ||
102 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 102 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
103 | pub struct MacroCallLoc { | 103 | pub struct MacroCallLoc { |
@@ -128,8 +128,8 @@ impl MacroCallLoc { | |||
128 | /// Def's are a core concept of hir. A `Def` is an Item (function, module, etc) | 128 | /// Def's are a core concept of hir. A `Def` is an Item (function, module, etc) |
129 | /// in a specific module. | 129 | /// in a specific module. |
130 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 130 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
131 | pub struct DefId(u32); | 131 | pub struct DefId(RawId); |
132 | ra_db::impl_numeric_id!(DefId); | 132 | impl_arena_id!(DefId); |
133 | 133 | ||
134 | #[derive(Clone, Debug, PartialEq, Eq, Hash)] | 134 | #[derive(Clone, Debug, PartialEq, Eq, Hash)] |
135 | pub struct DefLoc { | 135 | pub struct DefLoc { |