diff --git a/crates/tinymist-query/src/analysis/track_values.rs b/crates/tinymist-query/src/analysis/track_values.rs index 5b01e4d1..6de82384 100644 --- a/crates/tinymist-query/src/analysis/track_values.rs +++ b/crates/tinymist-query/src/analysis/track_values.rs @@ -86,6 +86,8 @@ pub struct DynLabel { pub label_desc: Option, /// Additional details about the label. pub detail: Option, + /// The title of the bibliography entry. Not present for non-bibliography labels. + pub bib_title: Option, } /// Find all labels and details for them. @@ -119,6 +121,7 @@ pub fn analyze_labels(document: &Document) -> (Vec, usize) { eco_format!("{}(..)", elem.func().name()) }), detail: Some(details), + bib_title: None, }); } @@ -129,7 +132,8 @@ pub fn analyze_labels(document: &Document) -> (Vec, usize) { output.push(DynLabel { label: Label::new(&key), label_desc: detail.clone(), - detail, + detail: detail.clone(), + bib_title: detail, }); } diff --git a/crates/tinymist-query/src/completion.rs b/crates/tinymist-query/src/completion.rs index 93dadae2..d7996674 100644 --- a/crates/tinymist-query/src/completion.rs +++ b/crates/tinymist-query/src/completion.rs @@ -215,6 +215,7 @@ impl StatefulRequest for CompletionRequest { kind: Some(completion_kind(typst_completion.kind.clone())), detail: typst_completion.detail.as_ref().map(String::from), sort_text: typst_completion.sort_text.as_ref().map(String::from), + filter_text: typst_completion.filter_text.as_ref().map(String::from), label_details: typst_completion.label_detail.as_ref().map(|e| { CompletionItemLabelDetails { detail: None, @@ -256,6 +257,7 @@ pub(crate) fn completion_kind(typst_completion_kind: TypstCompletionKind) -> Lsp TypstCompletionKind::Field => LspCompletionKind::FIELD, TypstCompletionKind::Variable => LspCompletionKind::VARIABLE, TypstCompletionKind::Constant => LspCompletionKind::CONSTANT, + TypstCompletionKind::Reference => LspCompletionKind::REFERENCE, TypstCompletionKind::Symbol(_) => LspCompletionKind::FIELD, TypstCompletionKind::Type => LspCompletionKind::CLASS, TypstCompletionKind::Module => LspCompletionKind::MODULE, diff --git a/crates/tinymist-query/src/upstream/complete.rs b/crates/tinymist-query/src/upstream/complete.rs index 9db691b8..7afebded 100644 --- a/crates/tinymist-query/src/upstream/complete.rs +++ b/crates/tinymist-query/src/upstream/complete.rs @@ -62,6 +62,8 @@ pub struct Completion { pub label_detail: Option, /// The label the completion is shown with. pub sort_text: Option, + /// The composed text used for filtering. + pub filter_text: Option, /// The completed version of the input, possibly described with snippet /// syntax like `${lhs} + ${rhs}`. /// @@ -90,6 +92,8 @@ pub enum CompletionKind { /// A constant. #[default] Constant, + /// A reference. + Reference, /// A symbol. Symbol(char), /// A variable. @@ -1107,10 +1111,12 @@ impl<'a, 'w> CompletionContext<'a, 'w> { label, label_desc, detail, + bib_title, } in labels.into_iter().skip(skip).take(take) { - self.completions.push(Completion { - kind: CompletionKind::Constant, + let label: EcoString = label.as_str().into(); + let completion = Completion { + kind: CompletionKind::Reference, apply: (open || close).then(|| { eco_format!( "{}{}{}", @@ -1119,11 +1125,25 @@ impl<'a, 'w> CompletionContext<'a, 'w> { if close { ">" } else { "" } ) }), - label_detail: label_desc, - label: label.as_str().into(), - detail, + label: label.clone(), + label_detail: label_desc.clone(), + filter_text: Some(label.clone()), + detail: detail.clone(), ..Completion::default() - }); + }; + + if let Some(bib_title) = bib_title { + self.completions.push(Completion { + kind: CompletionKind::Constant, + label: bib_title.clone(), + label_detail: Some(label), + filter_text: Some(bib_title), + detail, + ..completion.clone() + }); + } + + self.completions.push(completion); } } diff --git a/crates/tinymist-query/src/upstream/tooltip.rs b/crates/tinymist-query/src/upstream/tooltip.rs index aaf0b4fa..93882a5d 100644 --- a/crates/tinymist-query/src/upstream/tooltip.rs +++ b/crates/tinymist-query/src/upstream/tooltip.rs @@ -165,6 +165,7 @@ fn label_tooltip(document: &Document, leaf: &LinkedNode) -> Option { label, label_desc: _, detail, + .. } in analyze_labels(document).0 { if label.as_str() == target {