feat: implement hover info for tuple, list, and contructor pattern elements
This commit is contained in:
parent
6ce30bd949
commit
f7dd2de17b
|
@ -449,7 +449,7 @@ impl TypedDefinition {
|
|||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub enum Located<'a> {
|
||||
Expression(&'a TypedExpr),
|
||||
Pattern(&'a TypedPattern, &'a TypedExpr),
|
||||
Pattern(&'a TypedPattern, Rc<Type>),
|
||||
Definition(&'a TypedDefinition),
|
||||
}
|
||||
|
||||
|
@ -964,7 +964,7 @@ impl<A, B> Pattern<A, B> {
|
|||
}
|
||||
|
||||
impl TypedPattern {
|
||||
pub fn find_node<'a>(&'a self, byte_index: usize, value: &'a TypedExpr) -> Option<Located<'a>> {
|
||||
pub fn find_node<'a>(&'a self, byte_index: usize, value: &Rc<Type>) -> Option<Located<'a>> {
|
||||
if !self.location().contains(byte_index) {
|
||||
return None;
|
||||
}
|
||||
|
@ -973,20 +973,41 @@ impl TypedPattern {
|
|||
Pattern::Int { .. }
|
||||
| Pattern::Var { .. }
|
||||
| Pattern::Assign { .. }
|
||||
| Pattern::Discard { .. } => Some(Located::Pattern(self, value)),
|
||||
| Pattern::Discard { .. } => Some(Located::Pattern(self, value.clone())),
|
||||
|
||||
Pattern::List { elements, .. }
|
||||
| Pattern::Tuple {
|
||||
elems: elements, ..
|
||||
} => elements
|
||||
} => match &**value {
|
||||
Type::Tuple { elems } => elements
|
||||
.iter()
|
||||
.find_map(|e| e.find_node(byte_index, value))
|
||||
.or(Some(Located::Pattern(self, value))),
|
||||
.zip(elems.iter())
|
||||
.find_map(|(e, t)| e.find_node(byte_index, t))
|
||||
.or(Some(Located::Pattern(self, value.clone()))),
|
||||
Type::App {
|
||||
module, name, args, ..
|
||||
} if module.is_empty() && name == "List" => elements
|
||||
.iter()
|
||||
// this is the same as above but this uses
|
||||
// cycle to repeat the single type arg for a list
|
||||
// there's probably a cleaner way to re-use the code
|
||||
// from this branch and the above.
|
||||
.zip(args.iter().cycle())
|
||||
.find_map(|(e, t)| e.find_node(byte_index, t))
|
||||
.or(Some(Located::Pattern(self, value.clone()))),
|
||||
_ => None,
|
||||
},
|
||||
|
||||
Pattern::Constructor { arguments, .. } => arguments
|
||||
Pattern::Constructor {
|
||||
arguments, tipo, ..
|
||||
} => match &**tipo {
|
||||
Type::Fn { args, .. } => arguments
|
||||
.iter()
|
||||
.find_map(|e| e.value.find_node(byte_index, value))
|
||||
.or(Some(Located::Pattern(self, value))),
|
||||
.zip(args.iter())
|
||||
.find_map(|(e, t)| e.value.find_node(byte_index, t))
|
||||
.or(Some(Located::Pattern(self, value.clone()))),
|
||||
_ => None,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -368,7 +368,7 @@ impl TypedExpr {
|
|||
.or_else(|| right.find_node(byte_index)),
|
||||
|
||||
TypedExpr::Assignment { value, pattern, .. } => pattern
|
||||
.find_node(byte_index, value)
|
||||
.find_node(byte_index, &value.tipo())
|
||||
.or_else(|| value.find_node(byte_index)),
|
||||
|
||||
TypedExpr::When {
|
||||
|
|
|
@ -516,7 +516,7 @@ impl Server {
|
|||
expression.definition_location(),
|
||||
Some(expression.tipo()),
|
||||
),
|
||||
Located::Pattern(pattern, value) => (pattern.location(), None, pattern.tipo(value)),
|
||||
Located::Pattern(pattern, tipo) => (pattern.location(), None, Some(tipo)),
|
||||
Located::Definition(_) => return Ok(None),
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue