Skip to content

Pipe complete more builtins #664

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 14 additions & 0 deletions analysis/src/CompletionBackEnd.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions analysis/src/CompletionFrontEnd.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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}) -> (
Expand Down
4 changes: 4 additions & 0 deletions analysis/src/SharedTypes.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -534,6 +536,8 @@ module Completable = struct
in
let rec contextPathToString = function
| CPString -> "string"
| CPInt -> "int"
| CPFloat -> "float"
| CPApply (cp, labels) ->
contextPathToString cp ^ "("
^ (labels
Expand Down
8 changes: 7 additions & 1 deletion analysis/tests/src/Completion.res
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ let header2 = `
background-color: ${red}; `
// ^com

// let _ = `color: ${r
// let _ = `color: ${r
// ^com

let onClick = evt => {
Expand All @@ -414,3 +414,9 @@ let onClick = evt => {
// ^com
Js.log("Hello")
}

// let _ = 123->t
// ^com

// let _ = 123.0->t
// ^com
42 changes: 40 additions & 2 deletions analysis/tests/src/expected/Completion.res.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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"}
}]