mirror of
https://github.com/typst/typst
synced 2025-08-20 09:49:02 +08:00
Merge d2747b457f271bf867fcd0012a9d788c37b9bd37 into d1deb80bb8b4d5fad348c23a3e079e4854aa57e4
This commit is contained in:
commit
9d52dcaaa6
@ -1,3 +1,5 @@
|
||||
use std::collections::HashSet;
|
||||
|
||||
use comemo::Track;
|
||||
use ecow::{eco_vec, EcoString, EcoVec};
|
||||
use typst::foundations::{Label, Styles, Value};
|
||||
@ -66,14 +68,22 @@ pub fn analyze_import(world: &dyn IdeWorld, source: &LinkedNode) -> Option<Value
|
||||
/// - All labels and descriptions for them, if available
|
||||
/// - A split offset: All labels before this offset belong to nodes, all after
|
||||
/// belong to a bibliography.
|
||||
///
|
||||
/// Note: When multiple labels in the document have the same identifier,
|
||||
/// this only returns the first one.
|
||||
pub fn analyze_labels(
|
||||
document: &PagedDocument,
|
||||
) -> (Vec<(Label, Option<EcoString>)>, usize) {
|
||||
let mut output = vec![];
|
||||
let mut seen_labels = HashSet::new();
|
||||
|
||||
// Labels in the document.
|
||||
for elem in document.introspector.all() {
|
||||
let Some(label) = elem.label() else { continue };
|
||||
if !seen_labels.insert(label) {
|
||||
continue;
|
||||
}
|
||||
|
||||
let details = elem
|
||||
.get_by_name("caption")
|
||||
.or_else(|_| elem.get_by_name("body"))
|
||||
|
@ -1709,6 +1709,27 @@ mod tests {
|
||||
.must_exclude(["bib"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_autocomplete_ref_function() {
|
||||
let mut world = TestWorld::new("x<test>");
|
||||
let doc = typst::compile(&world).output.ok();
|
||||
|
||||
let end = world.main.text().len();
|
||||
world.main.edit(end..end, " #ref(<)");
|
||||
|
||||
test_with_doc(&world, -2, doc.as_ref()).must_include(["test"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_autocomplete_ref_shorthand() {
|
||||
let mut world = TestWorld::new("x<test>");
|
||||
let doc = typst::compile(&world).output.ok();
|
||||
|
||||
let end = world.main.text().len();
|
||||
world.main.edit(end..end, " @");
|
||||
|
||||
test_with_doc(&world, -1, doc.as_ref()).must_include(["test"]);
|
||||
}
|
||||
/// Test what kind of brackets we autocomplete for function calls depending
|
||||
/// on the function and existing parens.
|
||||
#[test]
|
||||
|
Loading…
x
Reference in New Issue
Block a user