Skip to content

Commit

Permalink
Iterate objects (#1065)
Browse files Browse the repository at this point in the history
* iterate objects

* changelog
  • Loading branch information
zth authored Jan 5, 2025
1 parent 85a72dc commit ddc23b0
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#### :bug: Bug fix

- Fix bug where type args stopped working in some completions when passed through inline records. https://github.com/rescript-lang/rescript-vscode/pull/1064
- Fix bug where objects weren't actually iterated on, making completions inside of them not work. https://github.com/rescript-lang/rescript-vscode/pull/1065

## 1.60.0

Expand Down
2 changes: 2 additions & 0 deletions analysis/src/CompletionFrontEnd.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1106,6 +1106,8 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
if expr.pexp_loc |> Loc.hasPos ~pos:posNoWhite && !result = None then (
setFound ();
match expr.pexp_desc with
| Pexp_extension ({txt = "obj"}, PStr [str_item]) ->
Ast_iterator.default_iterator.structure_item iterator str_item
| Pexp_extension ({txt}, _) -> setResult (CextensionNode txt)
| Pexp_constant _ -> setResult Cnone
| Pexp_ident lid ->
Expand Down
10 changes: 10 additions & 0 deletions analysis/tests/src/CompletionObjects.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
let x = Some(true)

let _ff = {
"one": switch x {
| Some(true) => "hello"
// |
// ^com
| _ => ""
},
}
38 changes: 38 additions & 0 deletions analysis/tests/src/expected/CompletionObjects.res.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
Complete src/CompletionObjects.res 5:7
posCursor:[5:7] posNoWhite:[5:5] Found expr:[2:10->9:1]
posCursor:[5:7] posNoWhite:[5:5] Found expr:[2:10->9:1]
posCursor:[5:7] posNoWhite:[5:5] Found pattern:__ghost__[0:-1->7:5]
posCursor:[5:7] posNoWhite:[5:5] Found pattern:__ghost__[0:-1->7:5]
Completable: Cpattern Value[x]
Package opens Pervasives.JsxModules.place holder
Resolved opens 1 pervasives
ContextPath Value[x]
Path x
[{
"label": "None",
"kind": 12,
"tags": [],
"detail": "bool",
"documentation": null
}, {
"label": "Some(_)",
"kind": 12,
"tags": [],
"detail": "bool",
"documentation": null,
"insertText": "Some(${1:_})",
"insertTextFormat": 2
}, {
"label": "Some(true)",
"kind": 4,
"tags": [],
"detail": "bool",
"documentation": null
}, {
"label": "Some(false)",
"kind": 4,
"tags": [],
"detail": "bool",
"documentation": null
}]

0 comments on commit ddc23b0

Please sign in to comment.