@@ -271,10 +271,17 @@ let completionWithParser ~debug ~path ~posCursor ~currentFile ~text =
271
271
(line, max 0 col - offset + offsetNoWhite)
272
272
in
273
273
let posBeforeCursor = (fst posCursor, max 0 (snd posCursor - 1 )) in
274
- let charBeforeCursor, charAtCursor =
274
+ let blankAfterCursor =
275
275
match PartialParser. positionToOffset text posCursor with
276
- | Some offset when offset > 0 -> (Some text.[offset - 1 ], Some text.[offset])
277
- | _ -> (None , None )
276
+ | Some offset when offset > 0 -> (
277
+ let charBeforeCursor = text.[offset - 1 ] in
278
+ let charAtCursor =
279
+ if offset < String. length text then text.[offset] else '\n'
280
+ in
281
+ match charAtCursor with
282
+ | ' ' | '\t' | '\r' | '\n' -> Some charBeforeCursor
283
+ | _ -> None )
284
+ | _ -> None
278
285
in
279
286
280
287
let found = ref false in
@@ -472,17 +479,10 @@ let completionWithParser ~debug ~path ~posCursor ~currentFile ~text =
472
479
Printf. printf " Pexp_ident %s:%s\n "
473
480
(Utils. flattenLongIdent id.txt |> String. concat " ." )
474
481
(Loc. toString id.loc);
475
- let idBreaksUp =
476
- charBeforeCursor = Some '.'
477
- &&
478
- match charAtCursor with
479
- | Some (' ' | '\t' | '\n' | '\r' ) -> true
480
- | _ -> false
481
- in
482
482
if id.loc |> Loc. hasPos ~pos: posBeforeCursor then
483
483
let path_ = id.txt |> Utils. flattenLongIdent in
484
484
let path =
485
- if idBreaksUp then (
485
+ if blankAfterCursor = Some '.' then (
486
486
(* Sometimes "Foo. " is followed by "bar" and the parser's
487
487
behaviour is to parse as "Foo.bar".
488
488
This gets back the intended path "Foo." *)
@@ -717,12 +717,16 @@ let completionWithParser ~debug ~path ~posCursor ~currentFile ~text =
717
717
in
718
718
let {Res_driver. parsetree = str} = parser ~filename: currentFile in
719
719
iterator.structure iterator str |> ignore;
720
+ if blankAfterCursor = Some ' ' || blankAfterCursor = Some '\n' then
721
+ setResult (PartialParser. Cpath (CPId ([" " ], Value )));
720
722
if ! found = false then if debug then Printf. printf " XXX Not found!\n " ;
721
723
! result)
722
724
else if Filename. check_suffix path " .resi" then (
723
725
let parser = Res_driver. parsingEngine.parseInterface ~for Printer:false in
724
726
let {Res_driver. parsetree = signature} = parser ~filename: currentFile in
725
727
iterator.signature iterator signature |> ignore;
728
+ if blankAfterCursor = Some ' ' || blankAfterCursor = Some '\n' then
729
+ setResult (PartialParser. Cpath (CPId ([" " ], Type )));
726
730
if ! found = false then if debug then Printf. printf " XXX Not found!\n " ;
727
731
! result)
728
732
else None
0 commit comments