Skip to content
This repository was archived by the owner on Dec 29, 2022. It is now read-only.

Commit 7db736d

Browse files
committed
Address review comments
Signed-off-by: Nick Cameron <nrc@ncameron.org>
1 parent 554ef1f commit 7db736d

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

rls-analysis/src/analysis.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ pub struct PerCrateAnalysis {
4848
pub ref_spans: HashMap<Id, Vec<Span>>,
4949
pub globs: HashMap<Span, Glob>,
5050
pub impls: HashMap<Id, Vec<Span>>,
51-
pub idents: Idents,
51+
pub idents: HashMap<PathBuf, IdentsByLine>,
5252

5353
pub root_id: Option<Id>,
5454
pub timestamp: SystemTime,
@@ -107,6 +107,12 @@ pub type Idents = HashMap<PathBuf, IdentsByLine>;
107107
pub type IdentsByLine = BTreeMap<Row<ZeroIndexed>, IdentsByColumn>;
108108
pub type IdentsByColumn = BTreeMap<Column<ZeroIndexed>, IdentBound>;
109109

110+
/// We store the identifiers for a file in a BTreeMap ordered by starting index.
111+
/// This struct contains the rest of the information we need to create an `Ident`.
112+
///
113+
/// We're optimising for space, rather than speed (of getting an Ident), because
114+
/// we have to build the whole index for every file (which is a lot for a large
115+
/// project), whereas we only get idents a few at a time and not very often.
110116
#[derive(new, Clone, Debug)]
111117
pub struct IdentBound {
112118
pub column_end: Column<ZeroIndexed>,
@@ -167,7 +173,7 @@ impl PerCrateAnalysis {
167173
ref_spans: HashMap::new(),
168174
globs: HashMap::new(),
169175
impls: HashMap::new(),
170-
idents: Idents::new(),
176+
idents: HashMap::new(),
171177
root_id: None,
172178
timestamp,
173179
path,
@@ -224,7 +230,7 @@ impl PerCrateAnalysis {
224230
})
225231
.collect::<Vec<Ident>>()
226232
})
227-
.unwrap_or_else(|| Vec::new())
233+
.unwrap_or_else(Vec::new)
228234
}
229235
}
230236

rls-analysis/src/lowering.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,12 +244,12 @@ impl<'a> CrateReader<'a> {
244244
ve.insert(Ref::Id(def_id));
245245
}
246246
}
247-
analysis.ref_spans.entry(def_id).or_insert_with(Vec::new).push(span.clone());
248247

249248
#[cfg(feature = "idents")]
250249
{
251250
Self::record_ident(analysis, &span, def_id, IdentKind::Ref);
252251
}
252+
analysis.ref_spans.entry(def_id).or_insert_with(Vec::new).push(span);
253253
}
254254
}
255255

0 commit comments

Comments
 (0)