Skip to content

Commit aebde4a

Browse files
committed
wip
1 parent 0ed7b7f commit aebde4a

File tree

3 files changed

+40
-27
lines changed

3 files changed

+40
-27
lines changed

analysis/src/CompletionFrontEndNew.ml

+9-13
Original file line numberDiff line numberDiff line change
@@ -506,17 +506,8 @@ and completeExpr ~completionContext (expr : Parsetree.expression) :
506506
(CId (flattenLidCheckDot ~completionContext fieldName, Value))
507507
completionContext
508508
else
509-
completeExpr
510-
~completionContext:
511-
(CompletionContext.addCtxPathItem
512-
(CRecordFieldFollow
513-
{
514-
fieldName = fieldName.txt |> Longident.last;
515-
recordCtxPath =
516-
ctxPathFromCompletionContext completionContext;
517-
})
518-
completionContext)
519-
fieldExpr)
509+
(* TODO: Only follow if we can follow, otherwise set context appropriately. *)
510+
completeExpr ~completionContext fieldExpr)
520511
in
521512
match fieldToComplete with
522513
| None -> (
@@ -598,7 +589,12 @@ and completeExpr ~completionContext (expr : Parsetree.expression) :
598589
completeExpr
599590
~completionContext:(CompletionContext.resetCtx completionContext)
600591
condition
601-
else if locHasPos then_.pexp_loc then completeExpr ~completionContext then_
592+
else if locHasPos then_.pexp_loc then
593+
completeExpr
594+
~completionContext:
595+
(completionContext
596+
|> CompletionContext.setCurrentlyExpecting completionContext.ctxPath)
597+
then_
602598
else
603599
match maybeElse with
604600
| Some else_ ->
@@ -615,7 +611,7 @@ and completeExpr ~completionContext (expr : Parsetree.expression) :
615611
if checkIfExprHoleEmptyCursor ~completionContext then_ then
616612
let completionContext =
617613
completionContext
618-
|> CompletionContext.addCtxPathItem (CId ([], Value))
614+
|> CompletionContext.setCurrentlyExpecting completionContext.ctxPath
619615
in
620616
CompletionResult.expression ~completionContext ~prefix:""
621617
else None)

analysis/tests/src/CompletionNew.res

+4-4
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@ type someRecord = {nested: option<nestedRecord>, variant: someVariant, someStrin
5050
// let myFunc: someRecord = {nested: {maybeVariant: {let x = true; if x {}}}, }
5151
// ^co2
5252

53-
// This is the last expression
53+
// This is the last expression - NOTE: This should work but it's doing a follow
5454
// let myFunc: someRecord = {nested: {maybeVariant: {let x = true; if x {}}}, }
5555
// ^co2
5656

57-
// Complete as the last expression (looking for the record field type)
58-
// let myFunc: someRecord = {nested: {maybeVariant: {doStuff(); let x = true; if x {v}}}, }
59-
// ^co2
57+
// Complete as the last expression (looking for the record field type) - NOTE: This should work but it's doing a follow
58+
// let myFunc: someRecord = {nested: {maybeVariant: {doStuff(); let x = true; if x {So}}}, }
59+
// ^co2
6060

6161
// Complete on the identifier, no context
6262
// let myFunc: someRecord = {nested: {maybeVariant: {doStuff(); let x = true; if x {v}}}, }

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

+27-10
Original file line numberDiff line numberDiff line change
@@ -286,21 +286,29 @@ Resolved opens 1 pervasives
286286

287287
Complete2 src/CompletionNew.res 53:73
288288
Scope: 106 items
289-
Completable: Cexpression: ctxPath: Value(prefix=)
289+
Completable: Cexpression: ctxPath: ((Type(prefix=someRecord))->followRecordField{nested})->followRecordField{maybeVariant}
290290
Package opens Pervasives.JsxModules.place holder
291291
Resolved opens 1 pervasives
292-
Path
292+
Path someRecord
293+
CRecordFieldFollow: type of field ("nested") to follow: option<nestedRecord>
294+
CRecordFieldFollow: found type at record ctx path, but it's not a record: option<nestedRecord>
293295
[]
294296

295-
Complete2 src/CompletionNew.res 57:85
297+
Complete2 src/CompletionNew.res 57:86
296298
Scope: 106 items
297-
Completable: Cexpression: ctxPath: ((Type(prefix=someRecord))->followRecordField{nested})->followRecordField{maybeVariant} , prefix: "v"
299+
Completable: Cexpression: ctxPath: ((Type(prefix=someRecord))->followRecordField{nested})->followRecordField{maybeVariant} , prefix: "So"
298300
Package opens Pervasives.JsxModules.place holder
299301
Resolved opens 1 pervasives
300302
Path someRecord
301303
CRecordFieldFollow: type of field ("nested") to follow: option<nestedRecord>
302304
CRecordFieldFollow: found type at record ctx path, but it's not a record: option<nestedRecord>
303-
[]
305+
[{
306+
"label": "Sort",
307+
"kind": 9,
308+
"tags": [],
309+
"detail": "file module",
310+
"documentation": null
311+
}]
304312

305313
Complete2 src/CompletionNew.res 61:58
306314
Scope: 105 items
@@ -328,11 +336,20 @@ CRecordField: found something that's not a record at the record ctx path: (~name
328336

329337
Complete2 src/CompletionNew.res 72:72
330338
Scope: 109 items
331-
Completable: Cexpression: ctxPath: Value(prefix=)
339+
Completable: Cexpression: ctxPath: Type(prefix=fn)
332340
Package opens Pervasives.JsxModules.place holder
333341
Resolved opens 1 pervasives
334-
Path
335-
[]
342+
Path fn
343+
[{
344+
"label": "(~name=?, v1) => {}",
345+
"kind": 12,
346+
"tags": [],
347+
"detail": "(~name: string=?, string) => bool",
348+
"documentation": null,
349+
"sortText": "A",
350+
"insertText": "(~name=?, ${1:v1}) => {$0}",
351+
"insertTextFormat": 2
352+
}]
336353

337354
Complete2 src/CompletionNew.res 76:60
338355
Scope: 108 items
@@ -547,10 +564,10 @@ CTypeAtLoc: found no type at loc
547564

548565
Complete2 src/CompletionNew.res 158:40
549566
Scope: 107 items
550-
Completable: Cexpression: ctxPath: Value(prefix=)
567+
Completable: Cexpression: ctxPath: CTypeAtLoc: [158:7->158:10]
551568
Package opens Pervasives.JsxModules.place holder
552569
Resolved opens 1 pervasives
553-
Path
570+
CTypeAtLoc: found no type at loc
554571
[]
555572

556573
Complete2 src/CompletionNew.res 161:35

0 commit comments

Comments
 (0)