Skip to content

Commit 8843b12

Browse files
committed
emit all available actions in a comment in applied file
1 parent ecbf9ee commit 8843b12

20 files changed

+105
-1
lines changed

compiler/ml/cmt_utils.ml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,31 @@ type action_type =
1515

1616
type cmt_action = {loc: Location.t; action: action_type; description: string}
1717

18+
let action_to_string = function
19+
| ApplyFunction {function_name} ->
20+
Printf.sprintf "ApplyFunction(%s)"
21+
(Longident.flatten function_name |> String.concat ".")
22+
| ApplyCoercion {coerce_to_name} ->
23+
Printf.sprintf "ApplyCoercion(%s)"
24+
(Longident.flatten coerce_to_name |> String.concat ".")
25+
| RemoveSwitchCase -> "RemoveSwitchCase"
26+
| RemoveOpen -> "RemoveOpen"
27+
| RemoveAwait -> "RemoveAwait"
28+
| AddAwait -> "AddAwait"
29+
| RewriteObjectToRecord -> "RewriteObjectToRecord"
30+
| RewriteArrayToTuple -> "RewriteArrayToTuple"
31+
| PrefixVariableWithUnderscore -> "PrefixVariableWithUnderscore"
32+
| RemoveUnusedVariable -> "RemoveUnusedVariable"
33+
| ReplaceWithVariantConstructor {constructor_name} ->
34+
Printf.sprintf "ReplaceWithVariantConstructor(%s)"
35+
(constructor_name |> Longident.flatten |> String.concat ".")
36+
| ReplaceWithPolymorphicVariantConstructor {constructor_name} ->
37+
Printf.sprintf "ReplaceWithPolymorphicVariantConstructor(%s)"
38+
constructor_name
39+
| RewriteIdent {new_ident} ->
40+
Printf.sprintf "RewriteIdent(%s)"
41+
(Longident.flatten new_ident |> String.concat ".")
42+
1843
let _add_possible_action : (cmt_action -> unit) ref = ref (fun _ -> ())
1944
let add_possible_action action = !_add_possible_action action
2045

tests/build_tests/actions/expected/Actions_AddAwait_applied.res

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,7 @@ let fn = async () => 12
33
let other = async (): int => {
44
await fn()
55
}
6+
7+
/* === AVAILABLE ACTIONS:
8+
- AddAwait - Await promise
9+
*/

tests/build_tests/actions/expected/Actions_ApplyCoercion_applied.res

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,7 @@ type x2 = | ...x1 | Two
33

44
let x1: x1 = One
55
let x2: x2 = (x1 :> x2)
6+
7+
/* === AVAILABLE ACTIONS:
8+
- ApplyCoercion(x2) - Coerce to x2
9+
*/
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
11
let x: int = Float.toInt(12.)
2+
3+
/* === AVAILABLE ACTIONS:
4+
- ApplyFunction(Float.toInt) - Convert to int with Float.toInt
5+
*/
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
\"Console".log(123)
2+
3+
/* === AVAILABLE ACTIONS:
4+
- RewriteIdent(Console) - Change to `Console`
5+
*/

tests/build_tests/actions/expected/Actions_JSXCustomComponentChildren_applied.res

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,7 @@ module CustomComponent = {
2222
}
2323

2424
let x = <CustomComponent> {React.float(1.)} </CustomComponent>
25+
26+
/* === AVAILABLE ACTIONS:
27+
- ApplyFunction(React.float) - Convert to float with React.float
28+
*/

tests/build_tests/actions/expected/Actions_PrefixUnusedVarUnderscore_applied.res

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,7 @@ let f = () => {
33
let _x = 1
44
12
55
}
6+
7+
/* === AVAILABLE ACTIONS:
8+
- PrefixVariableWithUnderscore - Prefix with `_`
9+
*/
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
let f = 12
22
let x = f
3+
4+
/* === AVAILABLE ACTIONS:
5+
- RemoveAwait - Remove await
6+
*/

tests/build_tests/actions/expected/Actions_RemoveUnusedVar_applied.res

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,7 @@
22
let f = () => {
33
12
44
}
5+
6+
/* === AVAILABLE ACTIONS:
7+
- RemoveUnusedVariable - Remove unused variable
8+
*/

tests/build_tests/actions/expected/Actions_RewriteArrayToTuple2_applied.res

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,7 @@ let doStuff = ((one, two)) => {
33
}
44

55
let x = doStuff(("hello", "world"))
6+
7+
/* === AVAILABLE ACTIONS:
8+
- RewriteArrayToTuple - Rewrite to tuple
9+
*/

0 commit comments

Comments
 (0)