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
55
56
57
58
59
60
61
|
mod citation;
mod entry_type;
mod field_type;
mod label;
mod package;
mod string_ref;
use base_db::{
data::{BibtexEntryType, BibtexFieldType},
util::RenderedLabel,
Document, Project, Workspace,
};
use rowan::{TextRange, TextSize};
#[derive(Debug)]
pub struct HoverParams<'db> {
pub document: &'db Document,
pub project: Project<'db>,
pub workspace: &'db Workspace,
pub offset: TextSize,
}
impl<'db> HoverParams<'db> {
pub fn new(workspace: &'db Workspace, document: &'db Document, offset: TextSize) -> Self {
let project = workspace.project(document);
Self {
document,
project,
workspace,
offset,
}
}
}
#[derive(Debug, Clone)]
pub struct Hover<'db> {
pub range: TextRange,
pub data: HoverData<'db>,
}
#[derive(Debug, Clone)]
pub enum HoverData<'db> {
Citation(String),
Package(&'db str),
EntryType(BibtexEntryType<'db>),
FieldType(BibtexFieldType<'db>),
Label(RenderedLabel<'db>),
StringRef(String),
}
pub fn find<'db>(params: &'db HoverParams<'db>) -> Option<Hover<'db>> {
citation::find_hover(¶ms)
.or_else(|| package::find_hover(¶ms))
.or_else(|| entry_type::find_hover(¶ms))
.or_else(|| field_type::find_hover(¶ms))
.or_else(|| label::find_hover(¶ms))
.or_else(|| string_ref::find_hover(¶ms))
}
#[cfg(test)]
mod tests;
|