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)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
pub enum Located<'a> {
|
pub enum Located<'a> {
|
||||||
Expression(&'a TypedExpr),
|
Expression(&'a TypedExpr),
|
||||||
Pattern(&'a TypedPattern, &'a TypedExpr),
|
Pattern(&'a TypedPattern, Rc<Type>),
|
||||||
Definition(&'a TypedDefinition),
|
Definition(&'a TypedDefinition),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -964,7 +964,7 @@ impl<A, B> Pattern<A, B> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TypedPattern {
|
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) {
|
if !self.location().contains(byte_index) {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
@ -973,20 +973,41 @@ impl TypedPattern {
|
||||||
Pattern::Int { .. }
|
Pattern::Int { .. }
|
||||||
| Pattern::Var { .. }
|
| Pattern::Var { .. }
|
||||||
| Pattern::Assign { .. }
|
| Pattern::Assign { .. }
|
||||||
| Pattern::Discard { .. } => Some(Located::Pattern(self, value)),
|
| Pattern::Discard { .. } => Some(Located::Pattern(self, value.clone())),
|
||||||
|
|
||||||
Pattern::List { elements, .. }
|
Pattern::List { elements, .. }
|
||||||
| Pattern::Tuple {
|
| Pattern::Tuple {
|
||||||
elems: elements, ..
|
elems: elements, ..
|
||||||
} => elements
|
} => match &**value {
|
||||||
.iter()
|
Type::Tuple { elems } => elements
|
||||||
.find_map(|e| e.find_node(byte_index, value))
|
.iter()
|
||||||
.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 {
|
||||||
.iter()
|
arguments, tipo, ..
|
||||||
.find_map(|e| e.value.find_node(byte_index, value))
|
} => match &**tipo {
|
||||||
.or(Some(Located::Pattern(self, value))),
|
Type::Fn { args, .. } => arguments
|
||||||
|
.iter()
|
||||||
|
.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)),
|
.or_else(|| right.find_node(byte_index)),
|
||||||
|
|
||||||
TypedExpr::Assignment { value, pattern, .. } => pattern
|
TypedExpr::Assignment { value, pattern, .. } => pattern
|
||||||
.find_node(byte_index, value)
|
.find_node(byte_index, &value.tipo())
|
||||||
.or_else(|| value.find_node(byte_index)),
|
.or_else(|| value.find_node(byte_index)),
|
||||||
|
|
||||||
TypedExpr::When {
|
TypedExpr::When {
|
||||||
|
|
|
@ -516,7 +516,7 @@ impl Server {
|
||||||
expression.definition_location(),
|
expression.definition_location(),
|
||||||
Some(expression.tipo()),
|
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),
|
Located::Definition(_) => return Ok(None),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue