Go-to-definition basic support

This commit is contained in:
Ayaz Hafiz 2023-10-22 12:45:11 -04:00
parent e954e074fb
commit 886a367026
No known key found for this signature in database
GPG key ID: 0E2A37416A25EF58
10 changed files with 465 additions and 313 deletions

View file

@ -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());