Skip to content

Commit 205a1b2

Browse files
committed
complete float
1 parent 0597a6e commit 205a1b2

File tree

5 files changed

+34
-2
lines changed

5 files changed

+34
-2
lines changed

analysis/src/CompletionBackEnd.ml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,6 +1183,13 @@ let rec getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env
11831183
(Completion.Value
11841184
(Ctype.newconstr (Path.Pident (Ident.create "int")) []));
11851185
]
1186+
| CPFloat ->
1187+
[
1188+
Completion.create ~name:"float" ~env
1189+
~kind:
1190+
(Completion.Value
1191+
(Ctype.newconstr (Path.Pident (Ident.create "float")) []));
1192+
]
11861193
| CPArray ->
11871194
[
11881195
Completion.create ~name:"array" ~env

analysis/src/CompletionFrontEnd.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ let rec exprToContextPath (e : Parsetree.expression) =
139139
match e.pexp_desc with
140140
| Pexp_constant (Pconst_string _) -> Some Completable.CPString
141141
| Pexp_constant (Pconst_integer _) -> Some CPInt
142+
| Pexp_constant (Pconst_float _) -> Some CPFloat
142143
| Pexp_array _ -> Some CPArray
143144
| Pexp_ident {txt} -> Some (CPId (Utils.flattenLongIdent txt, Value))
144145
| Pexp_field (e1, {txt = Lident name}) -> (

analysis/src/SharedTypes.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,7 @@ module Completable = struct
506506
| CPString
507507
| CPArray
508508
| CPInt
509+
| CPFloat
509510
| CPApply of contextPath * Asttypes.arg_label list
510511
| CPId of string list * completionContext
511512
| CPField of contextPath * string
@@ -536,6 +537,7 @@ module Completable = struct
536537
let rec contextPathToString = function
537538
| CPString -> "string"
538539
| CPInt -> "int"
540+
| CPFloat -> "float"
539541
| CPApply (cp, labels) ->
540542
contextPathToString cp ^ "("
541543
^ (labels

analysis/tests/src/Completion.res

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,3 +417,6 @@ let onClick = evt => {
417417

418418
// let _ = 123->t
419419
// ^com
420+
421+
// let _ = 123.0->t
422+
// ^com

analysis/tests/src/expected/Completion.res.txt

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1625,8 +1625,8 @@ Resolved opens 2 Completion.res Completion.res
16251625
}]
16261626

16271627
Complete src/Completion.res 405:22
1628-
posCursor:[405:22] posNoWhite:[405:21] Found expr:[405:11->420:0]
1629-
Pexp_apply ...__ghost__[0:-1->0:-1] (...[405:11->415:1], ...[420:0->420:0])
1628+
posCursor:[405:22] posNoWhite:[405:21] Found expr:[405:11->423:0]
1629+
Pexp_apply ...__ghost__[0:-1->0:-1] (...[405:11->415:1], ...[423:0->423:0])
16301630
posCursor:[405:22] posNoWhite:[405:21] Found expr:[405:11->415:1]
16311631
Pexp_apply ...__ghost__[0:-1->0:-1] (...[405:11->405:19], ...[405:21->415:1])
16321632
posCursor:[405:22] posNoWhite:[405:21] Found expr:[405:21->415:1]
@@ -1721,3 +1721,22 @@ Resolved opens 2 Completion.res Completion.res
17211721
"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"}
17221722
}]
17231723

1724+
Complete src/Completion.res 420:19
1725+
posCursor:[420:19] posNoWhite:[420:18] Found expr:[420:11->420:19]
1726+
Completable: Cpath float->t
1727+
Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder
1728+
Resolved opens 2 Completion.res Completion.res
1729+
[{
1730+
"label": "Belt.Float.toInt",
1731+
"kind": 12,
1732+
"tags": [],
1733+
"detail": "float => int",
1734+
"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"}
1735+
}, {
1736+
"label": "Belt.Float.toString",
1737+
"kind": 12,
1738+
"tags": [],
1739+
"detail": "float => string",
1740+
"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"}
1741+
}]
1742+

0 commit comments

Comments
 (0)