diff --git a/CHANGELOG.md b/CHANGELOG.md index 039035e02..4d2683c10 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ - Make pipe completion work in pipe chains, not just on the first pipe. https://github.com/rescript-lang/rescript-vscode/pull/656 - Make pipe completion work reliably when the path resolution needs to traverse submodules https://github.com/rescript-lang/rescript-vscode/pull/663 - Make pipe completion work (after saving/compiling) when the return type of a function call is unknown until compilation https://github.com/rescript-lang/rescript-vscode/pull/662 +- Add pipe completion for `int` and `float` constants https://github.com/rescript-lang/rescript-vscode/pull/664 #### :bug: Bug Fix diff --git a/analysis/src/CompletionBackEnd.ml b/analysis/src/CompletionBackEnd.ml index 0e463e91e..e1ace9947 100644 --- a/analysis/src/CompletionBackEnd.ml +++ b/analysis/src/CompletionBackEnd.ml @@ -1176,6 +1176,20 @@ let rec getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env (Completion.Value (Ctype.newconstr (Path.Pident (Ident.create "string")) [])); ] + | CPInt -> + [ + Completion.create ~name:"int" ~env + ~kind: + (Completion.Value + (Ctype.newconstr (Path.Pident (Ident.create "int")) [])); + ] + | CPFloat -> + [ + Completion.create ~name:"float" ~env + ~kind: + (Completion.Value + (Ctype.newconstr (Path.Pident (Ident.create "float")) [])); + ] | CPArray -> [ Completion.create ~name:"array" ~env diff --git a/analysis/src/CompletionFrontEnd.ml b/analysis/src/CompletionFrontEnd.ml index d9509abde..953163b60 100644 --- a/analysis/src/CompletionFrontEnd.ml +++ b/analysis/src/CompletionFrontEnd.ml @@ -138,6 +138,8 @@ let findNamedArgCompletable ~(args : arg list) ~endPos ~posBeforeCursor let rec exprToContextPath (e : Parsetree.expression) = match e.pexp_desc with | Pexp_constant (Pconst_string _) -> Some Completable.CPString + | Pexp_constant (Pconst_integer _) -> Some CPInt + | Pexp_constant (Pconst_float _) -> Some CPFloat | Pexp_array _ -> Some CPArray | Pexp_ident {txt} -> Some (CPId (Utils.flattenLongIdent txt, Value)) | Pexp_field (e1, {txt = Lident name}) -> ( diff --git a/analysis/src/SharedTypes.ml b/analysis/src/SharedTypes.ml index 3d4878583..358e25856 100644 --- a/analysis/src/SharedTypes.ml +++ b/analysis/src/SharedTypes.ml @@ -505,6 +505,8 @@ module Completable = struct type contextPath = | CPString | CPArray + | CPInt + | CPFloat | CPApply of contextPath * Asttypes.arg_label list | CPId of string list * completionContext | CPField of contextPath * string @@ -534,6 +536,8 @@ module Completable = struct in let rec contextPathToString = function | CPString -> "string" + | CPInt -> "int" + | CPFloat -> "float" | CPApply (cp, labels) -> contextPathToString cp ^ "(" ^ (labels diff --git a/analysis/tests/src/Completion.res b/analysis/tests/src/Completion.res index 39b57c138..c79bed175 100644 --- a/analysis/tests/src/Completion.res +++ b/analysis/tests/src/Completion.res @@ -403,7 +403,7 @@ let header2 = ` background-color: ${red}; ` // ^com -// let _ = `color: ${r +// let _ = `color: ${r // ^com let onClick = evt => { @@ -414,3 +414,9 @@ let onClick = evt => { // ^com Js.log("Hello") } + +// let _ = 123->t +// ^com + +// let _ = 123.0->t +// ^com diff --git a/analysis/tests/src/expected/Completion.res.txt b/analysis/tests/src/expected/Completion.res.txt index 1f0c66e56..9ee0144ed 100644 --- a/analysis/tests/src/expected/Completion.res.txt +++ b/analysis/tests/src/expected/Completion.res.txt @@ -1625,8 +1625,8 @@ Resolved opens 2 Completion.res Completion.res }] Complete src/Completion.res 405:22 -posCursor:[405:22] posNoWhite:[405:21] Found expr:[405:11->417:0] -Pexp_apply ...__ghost__[0:-1->0:-1] (...[405:11->415:1], ...[417:0->417:0]) +posCursor:[405:22] posNoWhite:[405:21] Found expr:[405:11->423:0] +Pexp_apply ...__ghost__[0:-1->0:-1] (...[405:11->415:1], ...[423:0->423:0]) posCursor:[405:22] posNoWhite:[405:21] Found expr:[405:11->415:1] Pexp_apply ...__ghost__[0:-1->0:-1] (...[405:11->405:19], ...[405:21->415:1]) posCursor:[405:22] posNoWhite:[405:21] Found expr:[405:21->415:1] @@ -1702,3 +1702,41 @@ Resolved opens 2 Completion.res Completion.res "documentation": null }] +Complete src/Completion.res 417:17 +posCursor:[417:17] posNoWhite:[417:16] Found expr:[417:11->417:17] +Completable: Cpath int->t +Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder +Resolved opens 2 Completion.res Completion.res +[{ + "label": "Belt.Int.toString", + "kind": 12, + "tags": [], + "detail": "int => string", + "documentation": {"kind": "markdown", "value": "\n Converts a given `int` to a `string`. Uses the JavaScript `String` constructor under the hood.\n\n ```res example\n Js.log(Belt.Int.toString(1) === \"1\") /* true */\n ```\n"} + }, { + "label": "Belt.Int.toFloat", + "kind": 12, + "tags": [], + "detail": "int => float", + "documentation": {"kind": "markdown", "value": "\n Converts a given `int` to a `float`.\n\n ```res example\n Js.log(Belt.Int.toFloat(1) === 1.0) /* true */\n ```\n"} + }] + +Complete src/Completion.res 420:19 +posCursor:[420:19] posNoWhite:[420:18] Found expr:[420:11->420:19] +Completable: Cpath float->t +Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder +Resolved opens 2 Completion.res Completion.res +[{ + "label": "Belt.Float.toInt", + "kind": 12, + "tags": [], + "detail": "float => int", + "documentation": {"kind": "markdown", "value": "\nConverts a given `float` to an `int`.\n\n```res example\nJs.log(Belt.Float.toInt(1.0) === 1) /* true */\n```\n"} + }, { + "label": "Belt.Float.toString", + "kind": 12, + "tags": [], + "detail": "float => string", + "documentation": {"kind": "markdown", "value": "\n Converts a given `float` to a `string`. Uses the JavaScript `String` constructor under the hood.\n\n ```res example\n Js.log(Belt.Float.toString(1.0) === \"1.0\") /* true */\n ```\n"} + }] +