Skip to content
This repository was archived by the owner on Mar 1, 2019. It is now read-only.

Commit 3b94e92

Browse files
committed
Handle aliasing imports for renaming
1 parent 7d63c01 commit 3b94e92

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

src/analysis.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@ pub struct Analysis {
2222
/// Contains lowered data with global inter-crate `Id`s per each crate.
2323
pub per_crate: HashMap<CrateId, PerCrateAnalysis>,
2424

25+
// This is a bit of a hack and should be considered temporary. A def has an
26+
// entry if there exists an import of the def which aliases it. We use this
27+
// for find_all_refs with unique spans to ensure that clients don't rename a
28+
// definition when they only mean to rename an alias.
29+
//
30+
// In the future we should handle imports, in particular aliasing ones, more
31+
// explicitly and then this can be removed.
32+
pub(crate) aliased_imports: HashSet<Id>,
33+
2534
pub doc_url_base: String,
2635
pub src_url_base: String,
2736
}
@@ -135,6 +144,7 @@ impl Analysis {
135144
pub fn new() -> Analysis {
136145
Analysis {
137146
per_crate: HashMap::new(),
147+
aliased_imports: HashSet::new(),
138148
// TODO don't hardcode these
139149
doc_url_base: "https://doc.rust-lang.org/nightly".to_owned(),
140150
src_url_base: "https://github.com/rust-lang/rust/blob/master".to_owned(),

src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,9 @@ impl<L: AnalysisLoader> AnalysisHost<L> {
307307
let t_start = Instant::now();
308308
let result = self.with_analysis(|a| {
309309
a.def_id_for_span(span).map(|id| {
310+
if force_unique_spans && a.aliased_imports.contains(&id) {
311+
return vec![];
312+
}
310313
let decl = if include_decl {
311314
def_span!(a, id)
312315
} else {

src/lowering.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,8 @@ impl CrateReader {
190190
if let Some(alias_span) = i.alias_span {
191191
let alias_span = lower_span(&alias_span, &self.base_dir, &self.path_rewrite);
192192
self.record_ref(def_id, alias_span, analysis, project_analysis);
193+
let mut analysis = project_analysis.analysis.lock().unwrap();
194+
analysis.as_mut().unwrap().aliased_imports.insert(def_id);
193195
}
194196
}
195197
}

0 commit comments

Comments
 (0)