Skip to content

Commit 0df59dc

Browse files
committed
refactor
1 parent 1e3067d commit 0df59dc

File tree

3 files changed

+19
-56
lines changed

3 files changed

+19
-56
lines changed

analysis/src/CompletionFrontEndNew.ml

Lines changed: 15 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -149,67 +149,38 @@ module CompletionContext = struct
149149
type t = {
150150
positionContext: PositionContext.t;
151151
scope: Scope.t;
152-
currentlyExpecting: currentlyExpecting list;
152+
currentlyExpecting: currentlyExpecting;
153153
ctxPath: ctxPath list;
154154
}
155155

156156
let make positionContext =
157157
{
158158
positionContext;
159159
scope = Scope.create ();
160-
currentlyExpecting = [];
160+
currentlyExpecting = Unit;
161161
ctxPath = [];
162162
}
163163

164164
let withResetCtx completionContext =
165-
{completionContext with currentlyExpecting = []; ctxPath = []}
165+
{completionContext with currentlyExpecting = Unit; ctxPath = []}
166166

167167
let withScope scope completionContext = {completionContext with scope}
168168

169-
let addCurrentlyExpecting currentlyExpecting completionContext =
170-
{
171-
completionContext with
172-
currentlyExpecting =
173-
currentlyExpecting :: completionContext.currentlyExpecting;
174-
}
175-
176-
let addCurrentlyExpectingOpt currentlyExpecting completionContext =
177-
match currentlyExpecting with
178-
| None -> completionContext
179-
| Some currentlyExpecting ->
180-
{
181-
completionContext with
182-
currentlyExpecting =
183-
currentlyExpecting :: completionContext.currentlyExpecting;
184-
}
169+
let setCurrentlyExpecting currentlyExpecting completionContext =
170+
{completionContext with currentlyExpecting}
185171

186172
let currentlyExpectingOrReset currentlyExpecting completionContext =
187173
match currentlyExpecting with
188-
| None -> {completionContext with currentlyExpecting = []}
189-
| Some currentlyExpecting ->
190-
{
191-
completionContext with
192-
currentlyExpecting =
193-
currentlyExpecting :: completionContext.currentlyExpecting;
194-
}
174+
| None -> {completionContext with currentlyExpecting = Unit}
175+
| Some currentlyExpecting -> {completionContext with currentlyExpecting}
195176

196177
let currentlyExpectingOrTypeAtLoc ~loc currentlyExpecting completionContext =
197178
match currentlyExpecting with
198-
| None ->
199-
{
200-
completionContext with
201-
currentlyExpecting =
202-
TypeAtLoc loc :: completionContext.currentlyExpecting;
203-
}
204-
| Some currentlyExpecting ->
205-
{
206-
completionContext with
207-
currentlyExpecting =
208-
currentlyExpecting :: completionContext.currentlyExpecting;
209-
}
179+
| None -> {completionContext with currentlyExpecting = TypeAtLoc loc}
180+
| Some currentlyExpecting -> {completionContext with currentlyExpecting}
210181

211182
let withResetCurrentlyExpecting completionContext =
212-
{completionContext with currentlyExpecting = [Unit]}
183+
{completionContext with currentlyExpecting = Unit}
213184

214185
let addCtxPathItem ctxPath completionContext =
215186
{completionContext with ctxPath = ctxPath :: completionContext.ctxPath}
@@ -247,21 +218,15 @@ module CompletionInstruction = struct
247218
Cpattern
248219
{
249220
prefix;
250-
rootType =
251-
(match completionContext.currentlyExpecting with
252-
| currentlyExpecting :: _ -> currentlyExpecting
253-
| _ -> Unit);
221+
rootType = completionContext.currentlyExpecting;
254222
ctxPath = completionContext.ctxPath;
255223
}
256224

257225
let expression ~(completionContext : CompletionContext.t) ~prefix =
258226
Cexpression
259227
{
260228
prefix;
261-
rootType =
262-
(match completionContext.currentlyExpecting with
263-
| currentlyExpecting :: _ -> currentlyExpecting
264-
| _ -> Unit);
229+
rootType = completionContext.currentlyExpecting;
265230
ctxPath = completionContext.ctxPath;
266231
}
267232

@@ -860,16 +825,16 @@ and completeExpr ~completionContext (expr : Parsetree.expression) :
860825
match fnReturnConstraint with
861826
| None -> (
862827
match completionContext.currentlyExpecting with
863-
| Type ctxPath :: _ ->
828+
| Type ctxPath ->
864829
(* Having a Type here already means the binding itself had a constraint on it. Since we're now moving into the function body,
865830
we'll need to ensure it's the function return type we use for completion, not the function type itself *)
866831
completionContext
867-
|> CompletionContext.addCurrentlyExpecting
832+
|> CompletionContext.setCurrentlyExpecting
868833
(FunctionReturnType ctxPath)
869834
| _ -> completionContext)
870835
| Some ctxPath ->
871836
completionContext
872-
|> CompletionContext.addCurrentlyExpecting (Type ctxPath)
837+
|> CompletionContext.setCurrentlyExpecting (Type ctxPath)
873838
in
874839
if locHasPos expr.pexp_loc then completeExpr ~completionContext expr
875840
else if checkIfExprHoleEmptyCursor ~completionContext expr then

analysis/src/Completions.ml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,5 @@ let getCompletions2 ~debug ~path ~pos ~currentFile ~forHover =
3939
(CompletionFrontEndNew.CompletionInstruction.toString res);
4040
Printf.printf "Scope: %i items\n" (List.length ctx.scope);
4141
Printf.printf "Looking for type: %s\n"
42-
(match ctx.currentlyExpecting with
43-
| currentlyExpecting :: _ ->
44-
CompletionFrontEndNew.currentlyExpectingToString currentlyExpecting
45-
| _ -> "")))
42+
(ctx.currentlyExpecting
43+
|> CompletionFrontEndNew.currentlyExpectingToString)))

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ Looking for type: Type<CId(Type)=someRecord>
6161
Complete2 src/CompletionNew.res 49:71
6262
Result: Cexpression: ctxPath: CId(Value)=x, rootType: Unit
6363
Scope: 1 items
64-
Looking for type:
64+
Looking for type: Unit
6565

6666
Complete2 src/CompletionNew.res 53:73
6767
Result: Cexpression: ctxPath: CRecordField=nested->CRecordField=maybeVariant->CId(Value)=, rootType: Type<CId(Type)=someRecord>
@@ -76,7 +76,7 @@ Looking for type: Type<CId(Type)=someRecord>
7676
Complete2 src/CompletionNew.res 61:58
7777
Result: Cexpression: ctxPath: CId(Value)=doStuff, rootType: Unit
7878
Scope: 0 items
79-
Looking for type:
79+
Looking for type: Unit
8080

8181
Complete2 src/CompletionNew.res 66:32
8282
Result: Cexpression: ctxPath: CId(Value)=, rootType: Type<bool>

0 commit comments

Comments
 (0)