Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 4 commits into from
Jan 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading