aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_analysis/src/completion/completion_item.rs10
-rw-r--r--crates/ra_arena/src/lib.rs3
-rw-r--r--crates/ra_db/Cargo.toml1
-rw-r--r--crates/ra_db/src/lib.rs16
-rw-r--r--crates/ra_db/src/loc2id.rs34
-rw-r--r--crates/ra_hir/src/ids.rs8
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
63impl<ID: ArenaId, T> Arena<ID, T> { 63impl<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"
9salsa = "0.9.1" 9salsa = "0.9.1"
10rustc-hash = "1.0" 10rustc-hash = "1.0"
11parking_lot = "0.7.0" 11parking_lot = "0.7.0"
12ra_arena = { path = "../ra_arena" }
12ra_syntax = { path = "../ra_syntax" } 13ra_syntax = { path = "../ra_syntax" }
13ra_editor = { path = "../ra_editor" } 14ra_editor = { path = "../ra_editor" }
14test_utils = { path = "../test_utils" } 15test_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]
25macro_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
38pub trait BaseDatabase: salsa::Database { 24pub 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 @@
1use parking_lot::Mutex;
2
3use std::hash::Hash; 1use std::hash::Hash;
4 2
3use parking_lot::Mutex;
5use rustc_hash::FxHashMap; 4use rustc_hash::FxHashMap;
5use 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)]
18struct Loc2IdMap<LOC, ID> 18struct Loc2IdMap<LOC, ID>
19where 19where
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
27impl<LOC, ID> Default for Loc2IdMap<LOC, ID> 27impl<LOC, ID> Default for Loc2IdMap<LOC, ID>
28where 28where
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
40impl<LOC, ID> Loc2IdMap<LOC, ID> 40impl<LOC, ID> Loc2IdMap<LOC, ID>
41where 41where
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
67pub 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)]
73pub struct LocationIntener<LOC, ID> 65pub struct LocationIntener<LOC, ID>
74where 66where
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
81impl<LOC, ID> Default for LocationIntener<LOC, ID> 73impl<LOC, ID> Default for LocationIntener<LOC, ID>
82where 74where
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
93impl<LOC, ID> LocationIntener<LOC, ID> 85impl<LOC, ID> LocationIntener<LOC, ID>
94where 86where
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)]
99pub struct MacroCallId(u32); 99pub struct MacroCallId(RawId);
100ra_db::impl_numeric_id!(MacroCallId); 100impl_arena_id!(MacroCallId);
101 101
102#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 102#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
103pub struct MacroCallLoc { 103pub 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)]
131pub struct DefId(u32); 131pub struct DefId(RawId);
132ra_db::impl_numeric_id!(DefId); 132impl_arena_id!(DefId);
133 133
134#[derive(Clone, Debug, PartialEq, Eq, Hash)] 134#[derive(Clone, Debug, PartialEq, Eq, Hash)]
135pub struct DefLoc { 135pub struct DefLoc {