mirror of
https://github.com/Myriad-Dreamin/tinymist.git
synced 2025-07-24 05:05:00 +00:00
feat: support querying label with paper name in bib items (#365)
* feat: support querying label with paper name in bib items * dev: distinguish ref and bib title * dev: distinguish ref and bib title 2 --------- Co-authored-by: Myriad-Dreamin <camiyoru@gmail.com>
This commit is contained in:
parent
ff72962334
commit
7b8b3938a2
4 changed files with 34 additions and 7 deletions
|
@ -86,6 +86,8 @@ pub struct DynLabel {
|
||||||
pub label_desc: Option<EcoString>,
|
pub label_desc: Option<EcoString>,
|
||||||
/// Additional details about the label.
|
/// Additional details about the label.
|
||||||
pub detail: Option<EcoString>,
|
pub detail: Option<EcoString>,
|
||||||
|
/// The title of the bibliography entry. Not present for non-bibliography labels.
|
||||||
|
pub bib_title: Option<EcoString>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Find all labels and details for them.
|
/// Find all labels and details for them.
|
||||||
|
@ -119,6 +121,7 @@ pub fn analyze_labels(document: &Document) -> (Vec<DynLabel>, usize) {
|
||||||
eco_format!("{}(..)", elem.func().name())
|
eco_format!("{}(..)", elem.func().name())
|
||||||
}),
|
}),
|
||||||
detail: Some(details),
|
detail: Some(details),
|
||||||
|
bib_title: None,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,7 +132,8 @@ pub fn analyze_labels(document: &Document) -> (Vec<DynLabel>, usize) {
|
||||||
output.push(DynLabel {
|
output.push(DynLabel {
|
||||||
label: Label::new(&key),
|
label: Label::new(&key),
|
||||||
label_desc: detail.clone(),
|
label_desc: detail.clone(),
|
||||||
detail,
|
detail: detail.clone(),
|
||||||
|
bib_title: detail,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -215,6 +215,7 @@ impl StatefulRequest for CompletionRequest {
|
||||||
kind: Some(completion_kind(typst_completion.kind.clone())),
|
kind: Some(completion_kind(typst_completion.kind.clone())),
|
||||||
detail: typst_completion.detail.as_ref().map(String::from),
|
detail: typst_completion.detail.as_ref().map(String::from),
|
||||||
sort_text: typst_completion.sort_text.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| {
|
label_details: typst_completion.label_detail.as_ref().map(|e| {
|
||||||
CompletionItemLabelDetails {
|
CompletionItemLabelDetails {
|
||||||
detail: None,
|
detail: None,
|
||||||
|
@ -256,6 +257,7 @@ pub(crate) fn completion_kind(typst_completion_kind: TypstCompletionKind) -> Lsp
|
||||||
TypstCompletionKind::Field => LspCompletionKind::FIELD,
|
TypstCompletionKind::Field => LspCompletionKind::FIELD,
|
||||||
TypstCompletionKind::Variable => LspCompletionKind::VARIABLE,
|
TypstCompletionKind::Variable => LspCompletionKind::VARIABLE,
|
||||||
TypstCompletionKind::Constant => LspCompletionKind::CONSTANT,
|
TypstCompletionKind::Constant => LspCompletionKind::CONSTANT,
|
||||||
|
TypstCompletionKind::Reference => LspCompletionKind::REFERENCE,
|
||||||
TypstCompletionKind::Symbol(_) => LspCompletionKind::FIELD,
|
TypstCompletionKind::Symbol(_) => LspCompletionKind::FIELD,
|
||||||
TypstCompletionKind::Type => LspCompletionKind::CLASS,
|
TypstCompletionKind::Type => LspCompletionKind::CLASS,
|
||||||
TypstCompletionKind::Module => LspCompletionKind::MODULE,
|
TypstCompletionKind::Module => LspCompletionKind::MODULE,
|
||||||
|
|
|
@ -62,6 +62,8 @@ pub struct Completion {
|
||||||
pub label_detail: Option<EcoString>,
|
pub label_detail: Option<EcoString>,
|
||||||
/// The label the completion is shown with.
|
/// The label the completion is shown with.
|
||||||
pub sort_text: Option<EcoString>,
|
pub sort_text: Option<EcoString>,
|
||||||
|
/// The composed text used for filtering.
|
||||||
|
pub filter_text: Option<EcoString>,
|
||||||
/// The completed version of the input, possibly described with snippet
|
/// The completed version of the input, possibly described with snippet
|
||||||
/// syntax like `${lhs} + ${rhs}`.
|
/// syntax like `${lhs} + ${rhs}`.
|
||||||
///
|
///
|
||||||
|
@ -90,6 +92,8 @@ pub enum CompletionKind {
|
||||||
/// A constant.
|
/// A constant.
|
||||||
#[default]
|
#[default]
|
||||||
Constant,
|
Constant,
|
||||||
|
/// A reference.
|
||||||
|
Reference,
|
||||||
/// A symbol.
|
/// A symbol.
|
||||||
Symbol(char),
|
Symbol(char),
|
||||||
/// A variable.
|
/// A variable.
|
||||||
|
@ -1107,10 +1111,12 @@ impl<'a, 'w> CompletionContext<'a, 'w> {
|
||||||
label,
|
label,
|
||||||
label_desc,
|
label_desc,
|
||||||
detail,
|
detail,
|
||||||
|
bib_title,
|
||||||
} in labels.into_iter().skip(skip).take(take)
|
} in labels.into_iter().skip(skip).take(take)
|
||||||
{
|
{
|
||||||
self.completions.push(Completion {
|
let label: EcoString = label.as_str().into();
|
||||||
kind: CompletionKind::Constant,
|
let completion = Completion {
|
||||||
|
kind: CompletionKind::Reference,
|
||||||
apply: (open || close).then(|| {
|
apply: (open || close).then(|| {
|
||||||
eco_format!(
|
eco_format!(
|
||||||
"{}{}{}",
|
"{}{}{}",
|
||||||
|
@ -1119,11 +1125,25 @@ impl<'a, 'w> CompletionContext<'a, 'w> {
|
||||||
if close { ">" } else { "" }
|
if close { ">" } else { "" }
|
||||||
)
|
)
|
||||||
}),
|
}),
|
||||||
label_detail: label_desc,
|
label: label.clone(),
|
||||||
label: label.as_str().into(),
|
label_detail: label_desc.clone(),
|
||||||
detail,
|
filter_text: Some(label.clone()),
|
||||||
|
detail: detail.clone(),
|
||||||
..Completion::default()
|
..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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -165,6 +165,7 @@ fn label_tooltip(document: &Document, leaf: &LinkedNode) -> Option<Tooltip> {
|
||||||
label,
|
label,
|
||||||
label_desc: _,
|
label_desc: _,
|
||||||
detail,
|
detail,
|
||||||
|
..
|
||||||
} in analyze_labels(document).0
|
} in analyze_labels(document).0
|
||||||
{
|
{
|
||||||
if label.as_str() == target {
|
if label.as_str() == target {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue