Skip to content

add broken completion case for result #674

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
Jan 5, 2023
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
2 changes: 2 additions & 0 deletions analysis/src/CompletionBackEnd.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1373,6 +1373,8 @@ let rec getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env
| Path.Pident id when Ident.name id = "result" -> Some resultModulePath
| Path.Pident id when Ident.name id = "lazy_t" -> Some ["Lazy"]
| Path.Pident id when Ident.name id = "char" -> Some ["Char"]
| Pdot (Pident id, "result", _) when Ident.name id = "Pervasives" ->
Some resultModulePath
| _ -> None
in
let rec expandPath (path : Path.t) =
Expand Down
5 changes: 5 additions & 0 deletions analysis/tests/src/Completion.res
Original file line number Diff line number Diff line change
Expand Up @@ -420,3 +420,8 @@ let onClick = evt => {

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

let ok = Ok(true)

// ok->g
// ^com
29 changes: 24 additions & 5 deletions analysis/tests/src/expected/Completion.res.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1623,11 +1623,11 @@ Resolved opens 2 Completion.res Completion.res
}]

Complete src/Completion.res 405:22
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]
posCursor:[405:22] posNoWhite:[405:21] Found expr:[405:11->428:0]
Pexp_apply ...__ghost__[0:-1->0:-1] (...[405:11->423:17], ...[428:0->428:0])
posCursor:[405:22] posNoWhite:[405:21] Found expr:[405:11->423:17]
Pexp_apply ...__ghost__[0:-1->0:-1] (...[405:11->405:19], ...[405:21->423:17])
posCursor:[405:22] posNoWhite:[405:21] Found expr:[405:21->423:17]
posCursor:[405:22] posNoWhite:[405:21] Found expr:[405:21->405:22]
Pexp_ident r:[405:21->405:22]
Completable: Cpath Value[r]
Expand Down Expand Up @@ -1738,3 +1738,22 @@ Resolved opens 2 Completion.res Completion.res
"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"}
}]

Complete src/Completion.res 425:8
posCursor:[425:8] posNoWhite:[425:7] Found expr:[425:3->425:8]
Completable: Cpath Value[ok]->g
Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder
Resolved opens 2 Completion.res Completion.res
[{
"label": "Belt.Result.getExn",
"kind": 12,
"tags": [],
"detail": "t<'a, 'b> => 'a",
"documentation": {"kind": "markdown", "value": "\n `getExn(res)`: when `res` is `Ok(n)`, returns `n` when `res` is `Error(m)`, raise an exception\n\n ```res example\n Belt.Result.getExn(Belt.Result.Ok(42)) == 42\n\n Belt.Result.getExn(Belt.Result.Error(\"Invalid data\")) /* raises exception */\n ```\n"}
}, {
"label": "Belt.Result.getWithDefault",
"kind": 12,
"tags": [],
"detail": "(t<'a, 'b>, 'a) => 'a",
"documentation": {"kind": "markdown", "value": "\n `getWithDefault(res, defaultValue)`: If `res` is `Ok(n)`, returns `n`,\n otherwise `default`\n\n ```res example\n Belt.Result.getWithDefault(Ok(42), 0) == 42\n\n Belt.Result.getWithDefault(Error(\"Invalid Data\"), 0) == 0\n ```\n"}
}]