blob: b22f361f36055f4b69d01926f3352fe0c0e045ba (
plain)
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
50
51
52
53
54
|
use rowan::{ast::AstNode, TextRange};
use syntax::latex;
use crate::util::cursor::CursorContext;
use super::builder::CompletionBuilder;
pub fn complete<'db>(
context: &'db CursorContext,
builder: &mut CompletionBuilder<'db>,
) -> Option<()> {
let token = context.cursor.as_tex()?;
let range = if token.kind() == latex::WORD {
latex::Key::cast(token.parent()?)
.map(|key| latex::small_range(&key))
.or_else(|| {
token
.parent()
.and_then(latex::Text::cast)
.map(|text| latex::small_range(&text))
})?
} else {
TextRange::empty(context.offset)
};
check_citation(context).or_else(|| check_acronym(context))?;
for document in &context.project.documents {
builder.citations(range, document);
}
Some(())
}
fn check_citation(context: &CursorContext) -> Option<()> {
let (_, _, group) = context.find_curly_group_word_list()?;
latex::Citation::cast(group.syntax().parent()?)?;
Some(())
}
fn check_acronym(context: &CursorContext) -> Option<()> {
let token = context.cursor.as_tex()?;
let pair = token
.parent_ancestors()
.find_map(latex::KeyValuePair::cast)?;
if pair.key()?.to_string() != "cite" {
return None;
}
latex::AcronymDeclaration::cast(pair.syntax().parent()?.parent()?.parent()?)?;
Some(())
}
|