From cc49271c64d107c839a761ad7c745a96c6413ac2 Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Tue, 31 May 2022 06:22:27 +0200 Subject: [PATCH 1/5] Add examples of hovering on arity0 --- analysis/tests/src/Hover.res | 14 +++++++++++++- analysis/tests/src/expected/Hover.res.txt | 6 ++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/analysis/tests/src/Hover.res b/analysis/tests/src/Hover.res index 8a4075084..95e4f364a 100644 --- a/analysis/tests/src/Hover.res +++ b/analysis/tests/src/Hover.res @@ -111,4 +111,16 @@ let typeDuplicate = AA.fnnxx // ^hov @live let dd = 34 -// ^hov \ No newline at end of file +// ^hov + +let arity0a = (. ()) => { + // ^hov + let f = () => 3 + f +} + +let arity0b = (. ()) => { + // ^hov + let f = (. ()) => 3 + f +} diff --git a/analysis/tests/src/expected/Hover.res.txt b/analysis/tests/src/expected/Hover.res.txt index 2824a102a..7492dcdf4 100644 --- a/analysis/tests/src/expected/Hover.res.txt +++ b/analysis/tests/src/expected/Hover.res.txt @@ -70,3 +70,9 @@ Attribute id:live:[112:0->112:5] label:live Completable: Cdecorator(live) {"contents": "The `@live` decorator is for reanalyze, a static analysis tool for ReScript that can do dead code analysis.\n\n`@live` tells the dead code analysis that the value should be considered live, even though it might appear to be dead. This is typically used in case of FFI where there are indirect ways to access values. It can be added to everything that could otherwise be considered unused by the dead code analysis - values, functions, arguments, records, individual record fields, and so on.\n\n[Read more and see examples in the documentation](https://rescript-lang.org/syntax-lookup#live-decorator).\n\nHint: Did you know you can run an interactive code analysis in your project by running the command `> ReScript: Start Code Analyzer`? Try it!"} +Hover tests/src/Hover.res 115:5 +{"contents": "```rescript\n(. unit) => int\n```"} + +Hover tests/src/Hover.res 121:5 +{"contents": "```rescript\nJs.Fn.arity0<(. ()) => int>\n```"} + From c4f320296b9e42d1176f0f6e750ed124eb169e2a Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Tue, 31 May 2022 06:44:15 +0200 Subject: [PATCH 2/5] More examples --- analysis/tests/src/Hover.res | 12 ++++++------ analysis/tests/src/expected/Hover.res.txt | 7 +++++-- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/analysis/tests/src/Hover.res b/analysis/tests/src/Hover.res index 95e4f364a..b91760348 100644 --- a/analysis/tests/src/Hover.res +++ b/analysis/tests/src/Hover.res @@ -114,13 +114,13 @@ let typeDuplicate = AA.fnnxx // ^hov let arity0a = (. ()) => { - // ^hov + //^hov let f = () => 3 f } -let arity0b = (. ()) => { - // ^hov - let f = (. ()) => 3 - f -} +let arity0b = (. (), . ()) => 3 +// ^hov + +let arity0c = (. (), . ()) => [3] +// ^hov diff --git a/analysis/tests/src/expected/Hover.res.txt b/analysis/tests/src/expected/Hover.res.txt index 7492dcdf4..036449026 100644 --- a/analysis/tests/src/expected/Hover.res.txt +++ b/analysis/tests/src/expected/Hover.res.txt @@ -70,9 +70,12 @@ Attribute id:live:[112:0->112:5] label:live Completable: Cdecorator(live) {"contents": "The `@live` decorator is for reanalyze, a static analysis tool for ReScript that can do dead code analysis.\n\n`@live` tells the dead code analysis that the value should be considered live, even though it might appear to be dead. This is typically used in case of FFI where there are indirect ways to access values. It can be added to everything that could otherwise be considered unused by the dead code analysis - values, functions, arguments, records, individual record fields, and so on.\n\n[Read more and see examples in the documentation](https://rescript-lang.org/syntax-lookup#live-decorator).\n\nHint: Did you know you can run an interactive code analysis in your project by running the command `> ReScript: Start Code Analyzer`? Try it!"} -Hover tests/src/Hover.res 115:5 +Hover tests/src/Hover.res 115:4 {"contents": "```rescript\n(. unit) => int\n```"} -Hover tests/src/Hover.res 121:5 +Hover tests/src/Hover.res 121:4 {"contents": "```rescript\nJs.Fn.arity0<(. ()) => int>\n```"} +Hover tests/src/Hover.res 124:4 +{"contents": "```rescript\nJs.Fn.arity0>>\n```"} + From 4426c2191e267c76057dad1599ea55a8072fa930 Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Tue, 31 May 2022 12:56:22 +0200 Subject: [PATCH 3/5] Sync outcome printer from syntax repo. --- analysis/tests/src/expected/Hover.res.txt | 6 +++--- .../res_outcome_printer/res_outcome_printer.ml | 14 ++++++-------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/analysis/tests/src/expected/Hover.res.txt b/analysis/tests/src/expected/Hover.res.txt index 036449026..3563518da 100644 --- a/analysis/tests/src/expected/Hover.res.txt +++ b/analysis/tests/src/expected/Hover.res.txt @@ -71,11 +71,11 @@ Completable: Cdecorator(live) {"contents": "The `@live` decorator is for reanalyze, a static analysis tool for ReScript that can do dead code analysis.\n\n`@live` tells the dead code analysis that the value should be considered live, even though it might appear to be dead. This is typically used in case of FFI where there are indirect ways to access values. It can be added to everything that could otherwise be considered unused by the dead code analysis - values, functions, arguments, records, individual record fields, and so on.\n\n[Read more and see examples in the documentation](https://rescript-lang.org/syntax-lookup#live-decorator).\n\nHint: Did you know you can run an interactive code analysis in your project by running the command `> ReScript: Start Code Analyzer`? Try it!"} Hover tests/src/Hover.res 115:4 -{"contents": "```rescript\n(. unit) => int\n```"} +{"contents": "```rescript\n(.) => unit => int\n```"} Hover tests/src/Hover.res 121:4 -{"contents": "```rescript\nJs.Fn.arity0<(. ()) => int>\n```"} +{"contents": "```rescript\n(.) => (.) => int\n```"} Hover tests/src/Hover.res 124:4 -{"contents": "```rescript\nJs.Fn.arity0>>\n```"} +{"contents": "```rescript\n(.) => (.) => array\n```"} diff --git a/analysis/vendor/res_outcome_printer/res_outcome_printer.ml b/analysis/vendor/res_outcome_printer/res_outcome_printer.ml index f88a15c4e..12503c115 100644 --- a/analysis/vendor/res_outcome_printer/res_outcome_printer.ml +++ b/analysis/vendor/res_outcome_printer/res_outcome_printer.ml @@ -233,20 +233,18 @@ let printPolyVarIdent txt = ) | Otyp_alias (typ, aliasTxt) -> Doc.concat [ - Doc.lparen; printOutTypeDoc typ; Doc.text " as '"; - Doc.text aliasTxt; - Doc.rparen + Doc.text aliasTxt ] | Otyp_constr ( Oide_dot (Oide_dot (Oide_ident "Js", "Fn") , "arity0"), (* Js.Fn.arity0 *) - [Otyp_constr (Oide_ident ident, [])] (* int or unit or string *) + [typ] ) -> - (* Js.Fn.arity0 -> (.) => int*) + (* Js.Fn.arity0 -> (.) => t *) Doc.concat [ - Doc.text "(. ()) => "; - Doc.text ident; + Doc.text "(.) => "; + printOutTypeDoc typ; ] | Otyp_constr ( Oide_dot (Oide_dot (Oide_ident "Js", "Fn") , ident), (* Js.Fn.arity2 *) @@ -352,7 +350,7 @@ let printPolyVarIdent txt = let i = ref 0 in let package = Doc.join ~sep:Doc.line ((List.map2 [@doesNotRaise]) (fun lbl typ -> Doc.concat [ - Doc.text (if i.contents > 0 then "and type " else "with type "); + Doc.text (if i.contents > 0 then "and " else "with "); Doc.text lbl; Doc.text " = "; printOutTypeDoc typ; From 2efed32c5f4f2ccb91ed0f5927f9e872e76bb22c Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Tue, 31 May 2022 12:58:09 +0200 Subject: [PATCH 4/5] Tweak test. --- analysis/tests/src/Hover.res | 2 +- analysis/tests/src/expected/Hover.res.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/analysis/tests/src/Hover.res b/analysis/tests/src/Hover.res index b91760348..24730270b 100644 --- a/analysis/tests/src/Hover.res +++ b/analysis/tests/src/Hover.res @@ -122,5 +122,5 @@ let arity0a = (. ()) => { let arity0b = (. (), . ()) => 3 // ^hov -let arity0c = (. (), . ()) => [3] +let arity0c = (. (), ()) => 3 // ^hov diff --git a/analysis/tests/src/expected/Hover.res.txt b/analysis/tests/src/expected/Hover.res.txt index 3563518da..795551f4c 100644 --- a/analysis/tests/src/expected/Hover.res.txt +++ b/analysis/tests/src/expected/Hover.res.txt @@ -77,5 +77,5 @@ Hover tests/src/Hover.res 121:4 {"contents": "```rescript\n(.) => (.) => int\n```"} Hover tests/src/Hover.res 124:4 -{"contents": "```rescript\n(.) => (.) => array\n```"} +{"contents": "```rescript\n(. unit, unit) => int\n```"} From cbf16ec8f462c0168f933b278fc9a6e92fc9a079 Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Tue, 31 May 2022 13:05:59 +0200 Subject: [PATCH 5/5] One more example. --- analysis/tests/src/Hover.res | 6 ++++++ analysis/tests/src/expected/Hover.res.txt | 3 +++ 2 files changed, 9 insertions(+) diff --git a/analysis/tests/src/Hover.res b/analysis/tests/src/Hover.res index 24730270b..2da1a17fd 100644 --- a/analysis/tests/src/Hover.res +++ b/analysis/tests/src/Hover.res @@ -124,3 +124,9 @@ let arity0b = (. (), . ()) => 3 let arity0c = (. (), ()) => 3 // ^hov + +let arity0d = (. ()) => { + // ^hov + let f = () => 3 + f +} diff --git a/analysis/tests/src/expected/Hover.res.txt b/analysis/tests/src/expected/Hover.res.txt index 795551f4c..afc35fb6a 100644 --- a/analysis/tests/src/expected/Hover.res.txt +++ b/analysis/tests/src/expected/Hover.res.txt @@ -79,3 +79,6 @@ Hover tests/src/Hover.res 121:4 Hover tests/src/Hover.res 124:4 {"contents": "```rescript\n(. unit, unit) => int\n```"} +Hover tests/src/Hover.res 127:5 +{"contents": "```rescript\n(.) => unit => int\n```"} +