mirror of
https://github.com/Myriad-Dreamin/tinymist.git
synced 2025-08-03 17:58:17 +00:00
feat: goto field definition of concrete values (#822)
This commit is contained in:
parent
f18ed7d1b2
commit
a2eb405430
3 changed files with 36 additions and 7 deletions
|
@ -121,9 +121,12 @@ fn find_field_definition(ctx: &Arc<SharedContext>, fa: ast::FieldAccess<'_>) ->
|
|||
log::debug!("field var: {:?} {:?}", v.def, v.def.span());
|
||||
Some(Definition::new(v.def.clone(), None))
|
||||
}
|
||||
_src @ (DocSource::Builtin(..) | DocSource::Ins(..)) => {
|
||||
todo!()
|
||||
DocSource::Ins(v) if !v.span().is_detached() => {
|
||||
let s = v.span();
|
||||
let source = ctx.source_by_id(s.id()?).ok()?;
|
||||
DefResolver::new(ctx, &source)?.of_span(s)
|
||||
}
|
||||
DocSource::Builtin(..) | DocSource::Ins(..) => None,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,10 @@ use super::*;
|
|||
pub fn term_value(ctx: &Arc<SharedContext>, value: &Value) -> Ty {
|
||||
match value {
|
||||
Value::Array(a) => {
|
||||
let values = a.iter().map(term_value_rec).collect::<Vec<_>>();
|
||||
let values = a
|
||||
.iter()
|
||||
.map(|v| term_value_rec(v, Span::detached()))
|
||||
.collect::<Vec<_>>();
|
||||
Ty::Tuple(values.into())
|
||||
}
|
||||
// todo: term arguments
|
||||
|
@ -19,7 +22,7 @@ pub fn term_value(ctx: &Arc<SharedContext>, value: &Value) -> Ty {
|
|||
Value::Dict(d) => {
|
||||
let values = d
|
||||
.iter()
|
||||
.map(|(k, v)| (k.as_str().into(), term_value_rec(v)))
|
||||
.map(|(k, v)| (k.as_str().into(), term_value_rec(v, Span::detached())))
|
||||
.collect();
|
||||
Ty::Dict(RecordTy::new(values))
|
||||
}
|
||||
|
@ -27,7 +30,7 @@ pub fn term_value(ctx: &Arc<SharedContext>, value: &Value) -> Ty {
|
|||
let values = m
|
||||
.scope()
|
||||
.iter()
|
||||
.map(|(k, v, _)| (k.into(), term_value_rec(v)))
|
||||
.map(|(k, v, s)| (k.into(), term_value_rec(v, s)))
|
||||
.collect();
|
||||
Ty::Dict(RecordTy::new(values))
|
||||
}
|
||||
|
@ -60,7 +63,7 @@ pub fn term_value(ctx: &Arc<SharedContext>, value: &Value) -> Ty {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn term_value_rec(value: &Value) -> Ty {
|
||||
pub fn term_value_rec(value: &Value, s: Span) -> Ty {
|
||||
match value {
|
||||
Value::Type(ty) => Ty::Builtin(BuiltinTy::Type(*ty)),
|
||||
Value::Dyn(v) => Ty::Builtin(BuiltinTy::Type(v.ty())),
|
||||
|
@ -92,6 +95,12 @@ pub fn term_value_rec(value: &Value) -> Ty {
|
|||
| Value::Datetime(..)
|
||||
| Value::Duration(..)
|
||||
| Value::Content(..)
|
||||
| Value::Styles(..) => Ty::Value(InsTy::new(value.clone())),
|
||||
| Value::Styles(..) => {
|
||||
if !s.is_detached() {
|
||||
Ty::Value(InsTy::new_at(value.clone(), s))
|
||||
} else {
|
||||
Ty::Value(InsTy::new(value.clone()))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -418,6 +418,23 @@ impl InsTy {
|
|||
})),
|
||||
})
|
||||
}
|
||||
|
||||
/// Get the span of the instance
|
||||
pub fn span(&self) -> Span {
|
||||
self.syntax
|
||||
.as_ref()
|
||||
.map(|s| s.name_node.span())
|
||||
.or_else(|| {
|
||||
Some(match &self.val {
|
||||
Value::Func(f) => f.span(),
|
||||
Value::Args(a) => a.span,
|
||||
Value::Content(c) => c.span(),
|
||||
// todo: module might have file id
|
||||
_ => return None,
|
||||
})
|
||||
})
|
||||
.unwrap_or_else(Span::detached)
|
||||
}
|
||||
}
|
||||
|
||||
/// A field type
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue