From 77ed270fde1c91f15593ba3c3e81dc6a3ee992ae Mon Sep 17 00:00:00 2001 From: Maxim Vezenov Date: Thu, 20 Jun 2024 20:40:45 +0000 Subject: [PATCH 1/2] look for span before Less sign rather than looking at the name when formatting a func --- tooling/nargo_fmt/src/visitor/item.rs | 4 ++-- tooling/nargo_fmt/tests/expected/fn.nr | 4 ++++ tooling/nargo_fmt/tests/input/fn.nr | 5 +++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/tooling/nargo_fmt/src/visitor/item.rs b/tooling/nargo_fmt/src/visitor/item.rs index a5d042dc71e..02afcb045ee 100644 --- a/tooling/nargo_fmt/src/visitor/item.rs +++ b/tooling/nargo_fmt/src/visitor/item.rs @@ -44,9 +44,9 @@ impl super::FmtVisitor<'_> { if !func.def.generics.is_empty() { let full_span = name_span.end()..params_open; - let start = name_span.end(); - let end = self.span_after(full_span, Token::Greater).start(); + let start = self.span_before(full_span.clone(), Token::Less).start(); + let end = self.span_after(full_span, Token::Greater).start(); let generics = func.def.generics; let span = (start..end).into(); let generics = format_seq( diff --git a/tooling/nargo_fmt/tests/expected/fn.nr b/tooling/nargo_fmt/tests/expected/fn.nr index 3d231cd3f7f..961e67faf1c 100644 --- a/tooling/nargo_fmt/tests/expected/fn.nr +++ b/tooling/nargo_fmt/tests/expected/fn.nr @@ -61,3 +61,7 @@ fn main( ) {} pub fn from_baz(x: [Field; crate::foo::MAGIC_NUMBER]) {} + +fn whitespace_before_generics(foo: T) {} + +fn more_whitespace_before_generics(foo: T) {} diff --git a/tooling/nargo_fmt/tests/input/fn.nr b/tooling/nargo_fmt/tests/input/fn.nr index 1c6d201fa39..03806b0fef9 100644 --- a/tooling/nargo_fmt/tests/input/fn.nr +++ b/tooling/nargo_fmt/tests/input/fn.nr @@ -44,3 +44,8 @@ fn main( ) {} pub fn from_baz(x: [Field; crate::foo::MAGIC_NUMBER]) {} + +fn whitespace_before_generics < T > (foo: T) {} + +fn more_whitespace_before_generics < +T > (foo: T) {} From fef05155c23ac9c78cf7faefbf09b61a8ddeead3 Mon Sep 17 00:00:00 2001 From: Maxim Vezenov Date: Thu, 20 Jun 2024 20:46:26 +0000 Subject: [PATCH 2/2] reduce diff --- tooling/nargo_fmt/src/visitor/item.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tooling/nargo_fmt/src/visitor/item.rs b/tooling/nargo_fmt/src/visitor/item.rs index 02afcb045ee..3cfee4f46ad 100644 --- a/tooling/nargo_fmt/src/visitor/item.rs +++ b/tooling/nargo_fmt/src/visitor/item.rs @@ -44,9 +44,9 @@ impl super::FmtVisitor<'_> { if !func.def.generics.is_empty() { let full_span = name_span.end()..params_open; - let start = self.span_before(full_span.clone(), Token::Less).start(); let end = self.span_after(full_span, Token::Greater).start(); + let generics = func.def.generics; let span = (start..end).into(); let generics = format_seq(