Skip to content
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
53 changes: 50 additions & 3 deletions tooling/lsp/src/requests/code_action/implement_missing_members.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::collections::HashMap;
use lsp_types::TextEdit;
use noirc_errors::{Location, Span};
use noirc_frontend::{
Kind,
ast::{NoirTraitImpl, TraitImplItemKind, UnresolvedTypeData},
node_interner::ReferenceId,
};
Expand Down Expand Up @@ -47,7 +48,9 @@ impl CodeActionFinder<'_> {
TraitImplItemKind::Function(noir_function) => {
method_ids.remove(noir_function.name());
}
TraitImplItemKind::Constant(..) => (),
TraitImplItemKind::Constant(name, ..) => {
associated_types.remove(name.as_string());
}
TraitImplItemKind::Type { name, alias } => {
if let UnresolvedTypeData::Unspecified = alias.typ {
continue;
Expand Down Expand Up @@ -99,8 +102,12 @@ impl CodeActionFinder<'_> {

let mut stubs = Vec::new();

for (name, _) in associated_types {
stubs.push(format!("{}type {};\n", indent_string, name));
for (name, generic) in associated_types {
if let Kind::Numeric(typ) = generic.kind() {
stubs.push(format!("{}let {}: {};\n", indent_string, name, typ));
} else {
stubs.push(format!("{}type {};\n", indent_string, name));
}
}

for (name, func_id) in method_ids {
Expand Down Expand Up @@ -366,6 +373,46 @@ impl Trait for Foo {
assert_code_action(title, src, expected).await;
}

#[test]
async fn test_add_missing_impl_members_associated_constant() {
let title = "Implement missing members";

let src = r#"
trait Trait {
let N: u32;
let M: u32;

fn foo(x: [Field; Self::N]) -> [Field; Self::N];
}

struct Foo {}

impl Trait>|< for Foo {
let M: u32 = 1;
}"#;

let expected = r#"
trait Trait {
let N: u32;
let M: u32;

fn foo(x: [Field; Self::N]) -> [Field; Self::N];
}

struct Foo {}

impl Trait for Foo {
let M: u32 = 1;
let N: u32;

fn foo(x: [Field; Self::N]) -> [Field; Self::N] {
panic(f"Implement foo")
}
}"#;

assert_code_action(title, src, expected).await;
}

#[test]
async fn test_add_missing_impl_members_nested() {
let title = "Implement missing members";
Expand Down
Loading