@@ -149,67 +149,38 @@ module CompletionContext = struct
149
149
type t = {
150
150
positionContext : PositionContext .t ;
151
151
scope : Scope .t ;
152
- currentlyExpecting : currentlyExpecting list ;
152
+ currentlyExpecting : currentlyExpecting ;
153
153
ctxPath : ctxPath list ;
154
154
}
155
155
156
156
let make positionContext =
157
157
{
158
158
positionContext;
159
159
scope = Scope. create () ;
160
- currentlyExpecting = [] ;
160
+ currentlyExpecting = Unit ;
161
161
ctxPath = [] ;
162
162
}
163
163
164
164
let withResetCtx completionContext =
165
- {completionContext with currentlyExpecting = [] ; ctxPath = [] }
165
+ {completionContext with currentlyExpecting = Unit ; ctxPath = [] }
166
166
167
167
let withScope scope completionContext = {completionContext with scope}
168
168
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}
185
171
186
172
let currentlyExpectingOrReset currentlyExpecting completionContext =
187
173
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}
195
176
196
177
let currentlyExpectingOrTypeAtLoc ~loc currentlyExpecting completionContext =
197
178
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}
210
181
211
182
let withResetCurrentlyExpecting completionContext =
212
- {completionContext with currentlyExpecting = [ Unit ] }
183
+ {completionContext with currentlyExpecting = Unit }
213
184
214
185
let addCtxPathItem ctxPath completionContext =
215
186
{completionContext with ctxPath = ctxPath :: completionContext .ctxPath}
@@ -247,21 +218,15 @@ module CompletionInstruction = struct
247
218
Cpattern
248
219
{
249
220
prefix;
250
- rootType =
251
- (match completionContext.currentlyExpecting with
252
- | currentlyExpecting :: _ -> currentlyExpecting
253
- | _ -> Unit );
221
+ rootType = completionContext.currentlyExpecting;
254
222
ctxPath = completionContext.ctxPath;
255
223
}
256
224
257
225
let expression ~(completionContext : CompletionContext.t ) ~prefix =
258
226
Cexpression
259
227
{
260
228
prefix;
261
- rootType =
262
- (match completionContext.currentlyExpecting with
263
- | currentlyExpecting :: _ -> currentlyExpecting
264
- | _ -> Unit );
229
+ rootType = completionContext.currentlyExpecting;
265
230
ctxPath = completionContext.ctxPath;
266
231
}
267
232
@@ -860,16 +825,16 @@ and completeExpr ~completionContext (expr : Parsetree.expression) :
860
825
match fnReturnConstraint with
861
826
| None -> (
862
827
match completionContext.currentlyExpecting with
863
- | Type ctxPath :: _ ->
828
+ | Type ctxPath ->
864
829
(* Having a Type here already means the binding itself had a constraint on it. Since we're now moving into the function body,
865
830
we'll need to ensure it's the function return type we use for completion, not the function type itself *)
866
831
completionContext
867
- |> CompletionContext. addCurrentlyExpecting
832
+ |> CompletionContext. setCurrentlyExpecting
868
833
(FunctionReturnType ctxPath)
869
834
| _ -> completionContext)
870
835
| Some ctxPath ->
871
836
completionContext
872
- |> CompletionContext. addCurrentlyExpecting (Type ctxPath)
837
+ |> CompletionContext. setCurrentlyExpecting (Type ctxPath)
873
838
in
874
839
if locHasPos expr.pexp_loc then completeExpr ~completion Context expr
875
840
else if checkIfExprHoleEmptyCursor ~completion Context expr then
0 commit comments