-
Notifications
You must be signed in to change notification settings - Fork 11.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[move-format] Added support for function definitions (#16699)
## Description This PR adds support for formatting functions definitions, including native ones, but excluding macros (to make these PRs more incremental - macros are a bit more subtle). It also fixes an omission from the support for formatting structs (phantom type parameters). ## Test Plan A new test has been added.
- Loading branch information
Showing
7 changed files
with
202 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
external-crates/move/crates/move-analyzer/prettier-plugin/tests/functions/movefmt.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
run_spec(__dirname); |
57 changes: 57 additions & 0 deletions
57
external-crates/move/crates/move-analyzer/prettier-plugin/tests/functions/test.exp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
module test::functions { | ||
|
||
fun empty() {} | ||
|
||
public fun pub() {} | ||
|
||
public entry fun pub_entry() {} | ||
|
||
public entry fun entry_pub() {} | ||
|
||
fun simple(p: u64): u64 {} | ||
|
||
fun simple_generic<T1: key, T2: store + drop + key>() {} | ||
|
||
fun long_type_list( | ||
p1: SomeStructWithALongName, | ||
p2: SomeStructWithALongName, | ||
p3: SomeStructWithALongName, | ||
p1: SomeStructWithALongName, | ||
): u64 {} | ||
|
||
fun long_type_list_and_generics< | ||
TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT1: key, | ||
TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT2: store, | ||
TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT3: drop, | ||
>( | ||
p1: SomeStructWithALongName, | ||
p2: SomeStructWithALongName, | ||
p3: SomeStructWithALongName, | ||
p1: SomeStructWithALongName, | ||
): u64 {} | ||
|
||
fun long_type_list_generics_and_body< | ||
TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT1: key, | ||
TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT2: store, | ||
TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT3: drop, | ||
>( | ||
p1: SomeStructWithALongName, | ||
p2: SomeStructWithALongName, | ||
p3: SomeStructWithALongName, | ||
p1: SomeStructWithALongName, | ||
): u64 { | ||
some_long_function_name(); | ||
some_long_function_name(); | ||
some_long_function_name(); | ||
some_long_function_name(); | ||
some_long_function_name(); | ||
some_long_function_name(); | ||
some_long_function_name(); | ||
} | ||
|
||
native fun simple_native(p: u64): u64; | ||
|
||
public native fun public_native(p: u64): u64; | ||
|
||
native fun simple_native_generic<T1: key, T2: store + drop + key>(): u64; | ||
} |
74 changes: 74 additions & 0 deletions
74
external-crates/move/crates/move-analyzer/prettier-plugin/tests/functions/test.move
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
module test::functions { | ||
|
||
fun empty() { | ||
} | ||
|
||
public fun pub() { | ||
} | ||
|
||
public entry fun pub_entry() { | ||
} | ||
|
||
entry public fun entry_pub() { | ||
} | ||
|
||
|
||
fun simple(p: u64): u64 { | ||
} | ||
|
||
fun simple_generic<T1 : key, | ||
T2 | ||
: | ||
store | ||
+ drop + key | ||
, | ||
>( | ||
) | ||
{ | ||
} | ||
|
||
fun long_type_list(p1: SomeStructWithALongName, | ||
p2: SomeStructWithALongName, p3: | ||
|
||
|
||
SomeStructWithALongName, p1: SomeStructWithALongName): u64 { | ||
} | ||
|
||
fun long_type_list_and_generics<TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT1 : key, TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT2 : store, TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT3 : drop> | ||
|
||
(p1: SomeStructWithALongName, | ||
p2: SomeStructWithALongName, p3: | ||
|
||
|
||
SomeStructWithALongName, p1: SomeStructWithALongName): u64 { | ||
} | ||
|
||
fun long_type_list_generics_and_body<TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT1 : key, TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT2 : store, TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT3 : drop> | ||
|
||
(p1: SomeStructWithALongName, | ||
p2: SomeStructWithALongName, p3: | ||
|
||
|
||
SomeStructWithALongName, p1: SomeStructWithALongName): u64 { | ||
some_long_function_name(); | ||
some_long_function_name(); | ||
some_long_function_name(); some_long_function_name(); | ||
some_long_function_name(); | ||
some_long_function_name(); | ||
some_long_function_name(); | ||
} | ||
|
||
native fun simple_native(p: u64): u64; | ||
|
||
public native fun public_native(p: u64): u64; | ||
|
||
native fun simple_native_generic<T1 : key, | ||
T2 | ||
: | ||
store | ||
+ drop + key | ||
, | ||
>( | ||
): u64; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
-1.86 KB
(99%)
external-crates/move/crates/move-analyzer/prettier-plugin/tree-sitter-move.wasm
Binary file not shown.