mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-26 13:29:12 +00:00
Go-to-definition basic support
This commit is contained in:
parent
e954e074fb
commit
886a367026
10 changed files with 465 additions and 313 deletions
|
@ -727,6 +727,17 @@ pub fn find_closest_type_at(
|
|||
visitor.region_typ
|
||||
}
|
||||
|
||||
/// Given an ability Foo has foo : ..., returns (T, foo1) if the symbol at the given region is a
|
||||
/// symbol foo1 that specializes foo for T. Otherwise if the symbol is foo but the specialization
|
||||
/// is unknown, (Foo, foo) is returned. Otherwise [None] is returned.
|
||||
pub fn find_closest_symbol_at(
|
||||
position: Position,
|
||||
decls: &Declarations,
|
||||
abilities_store: &AbilitiesStore,
|
||||
) -> Option<FoundSymbol> {
|
||||
find_symbol_at_impl(Region::from_pos(position), decls, abilities_store, true)
|
||||
}
|
||||
|
||||
/// Given an ability Foo has foo : ..., returns (T, foo1) if the symbol at the given region is a
|
||||
/// symbol foo1 that specializes foo for T. Otherwise if the symbol is foo but the specialization
|
||||
/// is unknown, (Foo, foo) is returned. Otherwise [None] is returned.
|
||||
|
@ -734,11 +745,21 @@ pub fn find_symbol_at(
|
|||
region: Region,
|
||||
decls: &Declarations,
|
||||
abilities_store: &AbilitiesStore,
|
||||
) -> Option<FoundSymbol> {
|
||||
find_symbol_at_impl(region, decls, abilities_store, false)
|
||||
}
|
||||
|
||||
pub fn find_symbol_at_impl(
|
||||
region: Region,
|
||||
decls: &Declarations,
|
||||
abilities_store: &AbilitiesStore,
|
||||
allow_subregion: bool,
|
||||
) -> Option<FoundSymbol> {
|
||||
let mut visitor = Finder {
|
||||
region,
|
||||
found: None,
|
||||
abilities_store,
|
||||
allow_subregion,
|
||||
};
|
||||
visitor.visit_decls(decls);
|
||||
return visitor.found;
|
||||
|
@ -747,6 +768,17 @@ pub fn find_symbol_at(
|
|||
region: Region,
|
||||
abilities_store: &'a AbilitiesStore,
|
||||
found: Option<FoundSymbol>,
|
||||
allow_subregion: bool,
|
||||
}
|
||||
|
||||
impl<'a> Finder<'a> {
|
||||
fn is_at_wanted_region(&self, region: Region) -> bool {
|
||||
if self.allow_subregion {
|
||||
region.contains(&self.region)
|
||||
} else {
|
||||
region == self.region
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Visitor for Finder<'_> {
|
||||
|
@ -755,7 +787,7 @@ pub fn find_symbol_at(
|
|||
}
|
||||
|
||||
fn visit_pattern(&mut self, pattern: &Pattern, region: Region, _opt_var: Option<Variable>) {
|
||||
if region == self.region {
|
||||
if self.is_at_wanted_region(region) {
|
||||
match pattern {
|
||||
Pattern::AbilityMemberSpecialization {
|
||||
ident: spec_symbol,
|
||||
|
@ -776,7 +808,7 @@ pub fn find_symbol_at(
|
|||
}
|
||||
|
||||
fn visit_expr(&mut self, expr: &Expr, region: Region, var: Variable) {
|
||||
if region == self.region {
|
||||
if self.is_at_wanted_region(region) {
|
||||
match expr {
|
||||
&Expr::AbilityMember(member_symbol, specialization_id, _var) => {
|
||||
debug_assert!(self.found.is_none());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue