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: show doc comments in LSP #5968

Merged
merged 20 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
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
103 changes: 6 additions & 97 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions aztec_macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@

// Usage -> mut ast -> aztec_library::transform(&mut ast)
// Covers all functions in the ast
for submodule in ast.submodules.iter_mut().filter(|submodule| submodule.is_contract) {
for submodule in
ast.submodules.iter_mut().map(|m| &mut m.item).filter(|submodule| submodule.is_contract)
{
if transform_module(
&file_id,
&mut submodule.contents,
Expand Down Expand Up @@ -111,7 +113,8 @@
}

let has_initializer = module.functions.iter().any(|func| {
func.def
func.item
.def
.attributes
.secondary
.iter()
Expand All @@ -121,6 +124,7 @@
let mut stubs: Vec<_> = vec![];

for func in module.functions.iter_mut() {
let func = &mut func.item;
let mut is_private = false;
let mut is_public = false;
let mut is_initializer = false;
Expand All @@ -134,7 +138,7 @@
} else if is_custom_attribute(&secondary_attribute, "aztec(initializer)") {
is_initializer = true;
insert_init_check = false;
} else if is_custom_attribute(&secondary_attribute, "aztec(noinitcheck)") {

Check warning on line 141 in aztec_macros/src/lib.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (noinitcheck)
insert_init_check = false;
} else if is_custom_attribute(&secondary_attribute, "aztec(internal)") {
is_internal = true;
Expand Down Expand Up @@ -175,6 +179,7 @@
let private_functions: Vec<_> = module
.functions
.iter()
.map(|t| &t.item)
.filter(|func| {
func.def
.attributes
Expand All @@ -187,6 +192,7 @@
let public_functions: Vec<_> = module
.functions
.iter()
.map(|func| &func.item)
.filter(|func| {
func.def
.attributes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
errors::AztecMacroError,
hir_utils::{
collect_crate_functions, collect_traits, fetch_notes, get_contract_module_data,
get_global_numberic_const, get_serialized_length, inject_fn,

Check warning on line 14 in aztec_macros/src/transforms/compute_note_hash_and_optionally_a_nullifier.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (numberic)
},
};

Expand All @@ -20,9 +20,9 @@
crate_id: &CrateId,
context: &HirContext,
) -> bool {
collect_crate_functions(crate_id, context).iter().any(|funct_id| {

Check warning on line 23 in aztec_macros/src/transforms/compute_note_hash_and_optionally_a_nullifier.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (funct)
let func_data = context.def_interner.function_meta(funct_id);

Check warning on line 24 in aztec_macros/src/transforms/compute_note_hash_and_optionally_a_nullifier.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (funct)
let func_name = context.def_interner.function_name(funct_id);

Check warning on line 25 in aztec_macros/src/transforms/compute_note_hash_and_optionally_a_nullifier.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (funct)
func_name == "compute_note_hash_and_optionally_a_nullifier"
&& func_data.parameters.len() == 6
&& func_data.parameters.0.first().is_some_and(| (_, typ, _) | match typ {
Expand Down Expand Up @@ -68,7 +68,7 @@
let traits: Vec<_> = collect_traits(context);

// Get MAX_NOTE_FIELDS_LENGTH global to check if the notes in our contract are too long.
let max_note_length_const = get_global_numberic_const(context, "MAX_NOTE_FIELDS_LENGTH")

Check warning on line 71 in aztec_macros/src/transforms/compute_note_hash_and_optionally_a_nullifier.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (numberic)
.map_err(|err| {
(
AztecMacroError::CouldNotImplementComputeNoteHashAndOptionallyANullifier {
Expand Down Expand Up @@ -166,7 +166,7 @@
assert_eq!(errors.len(), 0, "Failed to parse Noir macro code. This is either a bug in the compiler or the Noir macro code");

let mut function_ast = function_ast.into_sorted();
function_ast.functions.remove(0)
function_ast.functions.remove(0).item
}

fn generate_compute_note_hash_and_optionally_a_nullifier_source(
Expand Down
9 changes: 5 additions & 4 deletions aztec_macros/src/transforms/contract_interface.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use acvm::acir::AcirField;

use noirc_errors::Location;
use noirc_frontend::ast::{Ident, NoirFunction, UnresolvedTypeData};
use noirc_frontend::ast::{Documented, Ident, NoirFunction, UnresolvedTypeData};
use noirc_frontend::{
graph::CrateId,
macros_api::{FieldElement, FileId, HirContext, HirExpression, HirLiteral, HirStatement},
Expand Down Expand Up @@ -267,15 +267,16 @@ pub fn generate_contract_interface(
.methods
.iter()
.enumerate()
.map(|(i, (method, orig_span))| {
.map(|(i, (documented_method, orig_span))| {
let method = &documented_method.item;
if method.name() == "at" || method.name() == "interface" || method.name() == "storage" {
(method.clone(), *orig_span)
(documented_method.clone(), *orig_span)
} else {
let (_, new_location) = stubs[i];
let mut modified_method = method.clone();
modified_method.def.name =
Ident::new(modified_method.name().to_string(), new_location.span);
(modified_method, *orig_span)
(Documented::not_documented(modified_method), *orig_span)
}
})
.collect();
Expand Down
53 changes: 34 additions & 19 deletions aztec_macros/src/transforms/events.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use noirc_frontend::ast::{ItemVisibility, NoirFunction, NoirTraitImpl, TraitImplItem};
use noirc_frontend::ast::{Documented, ItemVisibility, NoirFunction, NoirTraitImpl, TraitImplItem};
use noirc_frontend::macros_api::{NodeInterner, StructId};
use noirc_frontend::token::SecondaryAttribute;
use noirc_frontend::{
Expand Down Expand Up @@ -34,10 +34,11 @@ pub fn generate_event_impls(
// print!("\ngenerate_event_interface_impl COUNT: {}\n", event_struct.name.0.contents);
// }

for submodule in module.submodules.iter_mut() {
let annotated_event_structs = submodule.contents.types.iter_mut().filter(|typ| {
typ.attributes.iter().any(|attr| is_custom_attribute(attr, "aztec(event)"))
});
for submodule in module.submodules.iter_mut().map(|m| &mut m.item) {
let annotated_event_structs =
submodule.contents.types.iter_mut().map(|typ| &mut typ.item).filter(|typ| {
typ.attributes.iter().any(|attr| is_custom_attribute(attr, "aztec(event)"))
});

for event_struct in annotated_event_structs {
// event_struct.attributes.push(SecondaryAttribute::Abi("events".to_string()));
Expand All @@ -52,7 +53,9 @@ pub fn generate_event_impls(

let mut event_fields = vec![];

for (field_ident, field_type) in event_struct.fields.iter() {
for field in event_struct.fields.iter() {
let field_ident = &field.item.name;
let field_type = &field.item.typ;
event_fields.push((
field_ident.0.contents.to_string(),
field_type.typ.to_string().replace("plain::", ""),
Expand All @@ -64,18 +67,30 @@ pub fn generate_event_impls(
event_byte_len,
empty_spans,
)?;
event_interface_trait_impl.items.push(TraitImplItem::Function(
generate_fn_get_event_type_id(event_type.as_str(), event_len, empty_spans)?,
event_interface_trait_impl.items.push(Documented::not_documented(
TraitImplItem::Function(generate_fn_get_event_type_id(
event_type.as_str(),
event_len,
empty_spans,
)?),
));
event_interface_trait_impl.items.push(Documented::not_documented(
TraitImplItem::Function(generate_fn_private_to_be_bytes(
event_type.as_str(),
event_byte_len,
empty_spans,
)?),
));
event_interface_trait_impl.items.push(TraitImplItem::Function(
generate_fn_private_to_be_bytes(event_type.as_str(), event_byte_len, empty_spans)?,
event_interface_trait_impl.items.push(Documented::not_documented(
TraitImplItem::Function(generate_fn_to_be_bytes(
event_type.as_str(),
event_byte_len,
empty_spans,
)?),
));
event_interface_trait_impl.items.push(TraitImplItem::Function(
generate_fn_to_be_bytes(event_type.as_str(), event_byte_len, empty_spans)?,
event_interface_trait_impl.items.push(Documented::not_documented(
TraitImplItem::Function(generate_fn_emit(event_type.as_str(), empty_spans)?),
));
event_interface_trait_impl
.items
.push(TraitImplItem::Function(generate_fn_emit(event_type.as_str(), empty_spans)?));
submodule.contents.trait_impls.push(event_interface_trait_impl);

let serialize_trait_impl = generate_trait_impl_serialize(
Expand Down Expand Up @@ -245,7 +260,7 @@ fn generate_fn_get_event_type_id(
}

let mut function_ast = function_ast.into_sorted();
let mut noir_fn = function_ast.functions.remove(0);
let mut noir_fn = function_ast.functions.remove(0).item;
noir_fn.def.visibility = ItemVisibility::Public;
Ok(noir_fn)
}
Expand Down Expand Up @@ -292,7 +307,7 @@ fn generate_fn_private_to_be_bytes(
}

let mut function_ast = function_ast.into_sorted();
let mut noir_fn = function_ast.functions.remove(0);
let mut noir_fn = function_ast.functions.remove(0).item;
noir_fn.def.visibility = ItemVisibility::Public;
Ok(noir_fn)
}
Expand Down Expand Up @@ -337,7 +352,7 @@ fn generate_fn_to_be_bytes(
}

let mut function_ast = function_ast.into_sorted();
let mut noir_fn = function_ast.functions.remove(0);
let mut noir_fn = function_ast.functions.remove(0).item;
noir_fn.def.visibility = ItemVisibility::Public;
Ok(noir_fn)
}
Expand All @@ -361,7 +376,7 @@ fn generate_fn_emit(event_type: &str, empty_spans: bool) -> Result<NoirFunction,
}

let mut function_ast = function_ast.into_sorted();
let mut noir_fn = function_ast.functions.remove(0);
let mut noir_fn = function_ast.functions.remove(0).item;
noir_fn.def.visibility = ItemVisibility::Public;
Ok(noir_fn)
}
Expand Down
Loading
Loading