Skip to content

Commit

Permalink
feat(lsp): goto struct member inside Impl method (#3918)
Browse files Browse the repository at this point in the history
# Description

## Problem\*

Resolves 
feat(lsp): goto struct member inside Impl method #3719

## Summary\*



## Additional Context



## Documentation\*

Check one:
- [x] No documentation needed.
- [ ] Documentation included in this PR.
- [ ] **[Exceptional Case]** Documentation to be submitted in a separate
PR.

# PR Checklist\*

- [x] I have tested the changes locally.
- [x] I have formatted the changes with [Prettier](https://prettier.io/)
and/or `cargo fmt` on default settings.
  • Loading branch information
kobyhallx committed Jan 3, 2024
1 parent 6b078b4 commit 99c2c5a
Showing 1 changed file with 6 additions and 25 deletions.
31 changes: 6 additions & 25 deletions compiler/noirc_frontend/src/node_interner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1295,8 +1295,6 @@ impl NodeInterner {
HirExpression::Constructor(expr) => {
let struct_type = &expr.r#type.borrow();

eprintln!("\n -> Resolve Constructor {struct_type:?}\n");

Some(struct_type.location)
}
HirExpression::MemberAccess(expr_member_access) => {
Expand All @@ -1322,34 +1320,17 @@ impl NodeInterner {
let expr_lhs = &expr_member_access.lhs;
let expr_rhs = &expr_member_access.rhs;

let found_ident = self.nodes.get(expr_lhs.into())?;

let ident = match found_ident {
Node::Expression(HirExpression::Ident(ident)) => ident,
_ => return None,
};

let definition_info = self.definition(ident.id);

let local_id = match definition_info.kind {
DefinitionKind::Local(Some(local_id)) => local_id,
let lhs_self_struct = match self.id_type(expr_lhs) {
Type::Struct(struct_type, _) => struct_type,
_ => return None,
};

let constructor_expression = match self.nodes.get(local_id.into()) {
Some(Node::Expression(HirExpression::Constructor(constructor_expression))) => {
constructor_expression
}
_ => return None,
};

let struct_type = constructor_expression.r#type.borrow();
let struct_type = lhs_self_struct.borrow();
let field_names = struct_type.field_names();

match field_names.iter().find(|field_name| field_name.0 == expr_rhs.0) {
Some(found) => Some(Location::new(found.span(), struct_type.location.file)),
None => None,
}
field_names.iter().find(|field_name| field_name.0 == expr_rhs.0).map(|found_field_name| {
Location::new(found_field_name.span(), struct_type.location.file)
})
}
}

Expand Down

0 comments on commit 99c2c5a

Please sign in to comment.