Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
fix case in expr record field completion where the record body contex…
…t was not picked up
  • Loading branch information
zth committed May 29, 2024
commit 85e9e868c2568c8291f322a37be6753cd1211a57
4 changes: 4 additions & 0 deletions analysis/src/CompletionExpressions.ml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ let rec traverseExpr (exp : Parsetree.expression) ~exprPath ~pos
(* An expression hole means for example `{someField: <com>}`. We want to complete for the type of `someField`. *)
someIfHasCursor
("", [Completable.NFollowRecordField {fieldName = fname}] @ exprPath)
| Pexp_ident {txt = Lident txt} when fname = txt ->
(* This is a heuristic for catching writing field names. ReScript has punning for record fields, but the AST doesn't,
so punning is represented as the record field name and identifier being the same: {someField}. *)
someIfHasCursor (txt, [Completable.NRecordBody {seenFields}] @ exprPath)
| Pexp_ident {txt = Lident txt} ->
(* A var means `{someField: s}` or similar. Complete for identifiers or values. *)
someIfHasCursor (txt, exprPath)
Expand Down
22 changes: 22 additions & 0 deletions analysis/tests/src/CompletionExpressions.res
Original file line number Diff line number Diff line change
Expand Up @@ -362,3 +362,25 @@ let someTyp: someTyp = {test: true}

// switch someTyp. { | _ => () }
// ^com

type config = {
includeName: bool,
operator?: [#"and" | #or],
showMore: bool,
}

type hookReturn = {name: string}

let hook = (config: config) => {
ignore(config)
{
name: "tester",
}
}

let {name} = hook({
// ope
// ^com
includeName: true,
showMore: true,
})
18 changes: 18 additions & 0 deletions analysis/tests/src/expected/CompletionExpressions.res.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1423,3 +1423,21 @@ Path someTyp
"documentation": {"kind": "markdown", "value": "```rescript\ntest: bool\n```\n\n```rescript\ntype someTyp = {test: bool}\n```"}
}]

Complete src/CompletionExpressions.res 381:8
posCursor:[381:8] posNoWhite:[381:7] Found expr:[380:13->385:2]
Pexp_apply ...[380:13->380:17] (...[380:18->385:1])
Completable: Cexpression CArgument Value[hook]($0)=ope->recordBody
Raw opens: 1 CompletionSupport.place holder
Package opens Pervasives.JsxModules.place holder
Resolved opens 2 pervasives CompletionSupport.res
ContextPath CArgument Value[hook]($0)
ContextPath Value[hook]
Path hook
[{
"label": "operator",
"kind": 5,
"tags": [],
"detail": "[#\"and\" | #or]",
"documentation": {"kind": "markdown", "value": "```rescript\noperator?: [#\"and\" | #or]\n```\n\n```rescript\ntype config = {includeName: bool, operator: option<[#\"and\" | #or]>, showMore: bool}\n```"}
}]