1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
use base_db::{
semantics::{bib, tex, Span},
util::queries::{self},
DocumentData,
};
use crate::{RenameBuilder, RenameParams};
pub(super) fn prepare_rename(params: &RenameParams) -> Option<Span> {
match ¶ms.feature.document.data {
DocumentData::Tex(data) => {
let result = queries::object_at_cursor(
&data.semantics.citations,
params.offset,
queries::SearchMode::Name,
)?;
Some(Span::new(result.object.name.text.clone(), result.range))
}
DocumentData::Bib(data) => {
let result = queries::object_at_cursor(
&data.semantics.entries,
params.offset,
queries::SearchMode::Name,
)?;
Some(Span::new(result.object.name.text.clone(), result.range))
}
_ => None,
}
}
pub(super) fn rename(builder: &mut RenameBuilder) -> Option<()> {
let name = prepare_rename(&builder.params)?;
let project = &builder.params.feature.project;
let citations = queries::objects_with_name::<tex::Citation>(project, &name.text)
.map(|(doc, obj)| (doc, obj.name.range));
let entries = queries::objects_with_name::<bib::Entry>(project, &name.text)
.map(|(doc, obj)| (doc, obj.name.range));
for (document, range) in citations.chain(entries) {
let entry = builder.result.changes.entry(document);
entry.or_default().push(range);
}
Some(())
}
|