diff --git a/crates/tinymist-query/src/analysis/signature.rs b/crates/tinymist-query/src/analysis/signature.rs index 0719a9b2..d1169b4d 100644 --- a/crates/tinymist-query/src/analysis/signature.rs +++ b/crates/tinymist-query/src/analysis/signature.rs @@ -61,7 +61,7 @@ impl ParamSpec { name: p.name.into(), docs: Cow::Borrowed(p.docs), input: p.input.clone(), - base_type: Ty::from_param_site(f, p, &p.input), + base_type: Ty::from_param_site(f, p), type_repr: Some(eco_format!("{}", TypeExpr(&p.input))), expr: None, default: p.default, diff --git a/crates/tinymist-query/src/ty/builtin.rs b/crates/tinymist-query/src/ty/builtin.rs index 0fa5a672..096b9521 100644 --- a/crates/tinymist-query/src/ty/builtin.rs +++ b/crates/tinymist-query/src/ty/builtin.rs @@ -21,6 +21,7 @@ pub enum PathPreference { Yaml, Xml, Toml, + Csl, Bibliography, RawTheme, RawSyntax, @@ -45,6 +46,7 @@ impl PathPreference { static CSV_REGSET: Lazy = Lazy::new(|| RegexSet::new([r"^csv$"]).unwrap()); static BIB_REGSET: Lazy = Lazy::new(|| RegexSet::new([r"^yaml$", r"^yml$", r"^bib$"]).unwrap()); + static CSL_REGSET: Lazy = Lazy::new(|| RegexSet::new([r"^csl$"]).unwrap()); static RAW_THEME_REGSET: Lazy = Lazy::new(|| RegexSet::new([r"^tmTheme$", r"^xml$"]).unwrap()); static RAW_SYNTAX_REGSET: Lazy = @@ -60,6 +62,7 @@ impl PathPreference { let patterns = patterns.chain(TOML_REGSET.patterns()); let patterns = patterns.chain(CSV_REGSET.patterns()); let patterns = patterns.chain(BIB_REGSET.patterns()); + let patterns = patterns.chain(CSL_REGSET.patterns()); let patterns = patterns.chain(RAW_THEME_REGSET.patterns()); patterns.chain(RAW_SYNTAX_REGSET.patterns()) }) @@ -76,6 +79,7 @@ impl PathPreference { PathPreference::Yaml => &YAML_REGSET, PathPreference::Xml => &XML_REGSET, PathPreference::Toml => &TOML_REGSET, + PathPreference::Csl => &CSL_REGSET, PathPreference::Bibliography => &BIB_REGSET, PathPreference::RawTheme => &RAW_THEME_REGSET, PathPreference::RawSyntax => &RAW_SYNTAX_REGSET, @@ -84,6 +88,32 @@ impl PathPreference { } impl Ty { + pub(crate) fn from_cast_info(s: &CastInfo) -> Ty { + match &s { + CastInfo::Any => Ty::Any, + CastInfo::Value(v, doc) => Ty::Value(InsTy::new_doc(v.clone(), *doc)), + CastInfo::Type(ty) => Ty::Builtin(BuiltinTy::Type(*ty)), + CastInfo::Union(e) => { + Ty::iter_union(UnionIter(vec![e.as_slice().iter()]).map(Self::from_cast_info)) + } + } + } + + pub(crate) fn from_param_site(f: &Func, p: &ParamInfo) -> Option { + use typst::foundations::func::Repr; + match f.inner() { + Repr::Element(..) | Repr::Native(..) => { + if let Some(ty) = param_mapping(f, p) { + return Some(ty); + } + } + Repr::Closure(_) => {} + Repr::With(w) => return Ty::from_param_site(&w.0, p), + }; + + Some(Self::from_cast_info(&p.input)) + } + pub(crate) fn from_return_site(f: &Func, c: &'_ CastInfo) -> Option { use typst::foundations::func::Repr; match f.inner() { @@ -93,46 +123,7 @@ impl Ty { Repr::Native(_) => {} }; - let ty = match c { - CastInfo::Any => Ty::Any, - CastInfo::Value(v, doc) => Ty::Value(InsTy::new_doc(v.clone(), *doc)), - CastInfo::Type(ty) => Ty::Builtin(BuiltinTy::Type(*ty)), - CastInfo::Union(e) => { - // flat union - let e = UnionIter(vec![e.as_slice().iter()]); - - Ty::iter_union(e.flat_map(|e| Self::from_return_site(f, e))) - } - }; - - Some(ty) - } - - pub(crate) fn from_param_site(f: &Func, p: &ParamInfo, s: &CastInfo) -> Option { - use typst::foundations::func::Repr; - match f.inner() { - Repr::Element(..) | Repr::Native(..) => { - if let Some(ty) = param_mapping(f, p) { - return Some(ty); - } - } - Repr::Closure(_) => {} - Repr::With(w) => return Ty::from_param_site(&w.0, p, s), - }; - - let ty = match &s { - CastInfo::Any => Ty::Any, - CastInfo::Value(v, doc) => Ty::Value(InsTy::new_doc(v.clone(), *doc)), - CastInfo::Type(ty) => Ty::Builtin(BuiltinTy::Type(*ty)), - CastInfo::Union(e) => { - // flat union - let e = UnionIter(vec![e.as_slice().iter()]); - - Ty::iter_union(e.flat_map(|e| Self::from_param_site(f, p, e))) - } - }; - - Some(ty) + Some(Self::from_cast_info(c)) } } @@ -296,6 +287,7 @@ impl BuiltinTy { PathPreference::Yaml => "[yaml]", PathPreference::Xml => "[xml]", PathPreference::Toml => "[toml]", + PathPreference::Csl => "[csl]", PathPreference::Bibliography => "[bib]", PathPreference::RawTheme => "[theme]", PathPreference::RawSyntax => "[syntax]", @@ -378,6 +370,10 @@ pub(super) fn param_mapping(f: &Func, p: &ParamInfo) -> Option { ("toml", "path") => Some(literally(Path(PathPreference::Toml))), ("raw", "theme") => Some(literally(Path(PathPreference::RawTheme))), ("raw", "syntaxes") => Some(literally(Path(PathPreference::RawSyntax))), + ("bibliography" | "cite", "style") => Some(Ty::iter_union([ + literally(Path(PathPreference::Csl)), + Ty::from_cast_info(&p.input), + ])), ("bibliography", "path") => Some(literally(Path(PathPreference::Bibliography))), ("text", "size") => Some(literally(TextSize)), ("text", "font") => { diff --git a/tests/e2e/main.rs b/tests/e2e/main.rs index eedefd4d..fcad6bf6 100644 --- a/tests/e2e/main.rs +++ b/tests/e2e/main.rs @@ -374,7 +374,7 @@ fn e2e() { }); let hash = replay_log(&tinymist_binary, &root.join("neovim")); - insta::assert_snapshot!(hash, @"siphash128_13:d2a8dcc163ddbb5e204818aeb4c21b66"); + insta::assert_snapshot!(hash, @"siphash128_13:dcea50b5683ee4fcb2ed84578c6a0250"); } { @@ -385,7 +385,7 @@ fn e2e() { }); let hash = replay_log(&tinymist_binary, &root.join("vscode")); - insta::assert_snapshot!(hash, @"siphash128_13:32c954951f57dc40af56d3557fb15e5e"); + insta::assert_snapshot!(hash, @"siphash128_13:d8da3e31bea7c9cf4743c8f80c497242"); } }