From 63b31c6186ac7e8080d4ef347d77d7718ae11ca3 Mon Sep 17 00:00:00 2001 From: Myriad-Dreamin <35292584+Myriad-Dreamin@users.noreply.github.com> Date: Sat, 30 Nov 2024 23:05:00 +0800 Subject: [PATCH] feat: convert values in builtin modules to definition (#919) --- .../tinymist-query/src/analysis/definition.rs | 32 +++---------------- .../snaps/test@builtin.typ.snap | 23 ++++++++++++- crates/tinymist-query/src/signature_help.rs | 2 +- 3 files changed, 28 insertions(+), 29 deletions(-) diff --git a/crates/tinymist-query/src/analysis/definition.rs b/crates/tinymist-query/src/analysis/definition.rs index 34625338..17e9cb65 100644 --- a/crates/tinymist-query/src/analysis/definition.rs +++ b/crates/tinymist-query/src/analysis/definition.rs @@ -126,7 +126,8 @@ fn find_field_definition(ctx: &Arc, fa: ast::FieldAccess<'_>) -> let source = ctx.source_by_id(s.id()?).ok()?; DefResolver::new(ctx, &source)?.of_span(s) } - DocSource::Builtin(..) | DocSource::Ins(..) => None, + DocSource::Ins(ins) => value_to_def(ins.val.clone(), || Some(fa.field().get().into())), + DocSource::Builtin(..) => None, } } @@ -294,27 +295,8 @@ static WHERE_FUNC: LazyLock> = LazyLock::new(|| { Some(f) }); -fn value_to_def( - value: Value, - name: impl FnOnce() -> Option>, - name_range: Option>, -) -> Option { +fn value_to_def(value: Value, name: impl FnOnce() -> Option>) -> Option { let val = Ty::Value(InsTy::new(value.clone())); - // DefKind::Closure | DefKind::Func => { - // let value = def_fid.and_then(|fid| { - // let def_source = ctx.source_by_id(fid).ok()?; - // let root = LinkedNode::new(def_source.root()); - // let def_name = root.find(def?.span()?)?; - - // log::info!("def_name for function: {def_name:?}"); - // let values = ctx.analyze_expr(def_name.get()); - // let func = values - // .into_iter() - // .find(|v| matches!(v.0, Value::Func(..)))?; - // log::info!("okay for function: {func:?}"); - // Some(func.0) - // }); - Some(match value { Value::Func(func) => { let name = func.name().map(|e| e.into()).or_else(name)?; @@ -325,11 +307,7 @@ fn value_to_def( Definition::new(decl.into(), Some(val)) } Value::Module(module) => Definition::new_var(module.name().into(), val), - _v => { - // todo name_range - let _ = name_range; - Definition::new_var(name()?, val) - } + _v => Definition::new_var(name()?, val), }) } @@ -371,7 +349,7 @@ impl DefResolver { // Get the type of the type node let better_def = match term { - Ty::Value(v) => value_to_def(v.val.clone(), || None, None), + Ty::Value(v) => value_to_def(v.val.clone(), || None), // Ty::Var(..) => DeclKind::Var, // Ty::Func(..) => DeclKind::Func, // Ty::With(..) => DeclKind::Func, diff --git a/crates/tinymist-query/src/fixtures/signature_help/snaps/test@builtin.typ.snap b/crates/tinymist-query/src/fixtures/signature_help/snaps/test@builtin.typ.snap index 5545ce0b..323b34d8 100644 --- a/crates/tinymist-query/src/fixtures/signature_help/snaps/test@builtin.typ.snap +++ b/crates/tinymist-query/src/fixtures/signature_help/snaps/test@builtin.typ.snap @@ -4,4 +4,25 @@ expression: "JsonRepr::new_redacted(result, &REDACT_LOC)" input_file: crates/tinymist-query/src/fixtures/signature_help/builtin.typ snapshot_kind: text --- -null +{ + "activeSignature": 0, + "signatures": [ + { + "activeParameter": 0, + "documentation": { + "kind": "markdown", + "value": "A horizontal line under content.\n\n```example\n$ underline(1 + 2 + ... + 5) $\n```" + }, + "label": "underline(body: content) -> underline", + "parameters": [ + { + "documentation": { + "kind": "markdown", + "value": "The content above the line." + }, + "label": "body:" + } + ] + } + ] +} diff --git a/crates/tinymist-query/src/signature_help.rs b/crates/tinymist-query/src/signature_help.rs index cfbba684..d3102a5a 100644 --- a/crates/tinymist-query/src/signature_help.rs +++ b/crates/tinymist-query/src/signature_help.rs @@ -111,7 +111,7 @@ impl SemanticRequest for SignatureHelpRequest { active_parameter.map(|x| x.min(sig.primary().pos_size().saturating_sub(1))); } - log::trace!("got signature info {label} {params:?}"); + crate::log_debug_ct!("got signature info {label} {params:?}"); Some(SignatureHelp { signatures: vec![SignatureInformation {