Skip to content

Commit 1acf1ec

Browse files
committed
Allow autocomplete on blank.
Complete with anything in scope including open modules and pervasives.
1 parent d358f29 commit 1acf1ec

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

analysis/src/Commands.ml

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -271,10 +271,17 @@ let completionWithParser ~debug ~path ~posCursor ~currentFile ~text =
271271
(line, max 0 col - offset + offsetNoWhite)
272272
in
273273
let posBeforeCursor = (fst posCursor, max 0 (snd posCursor - 1)) in
274-
let charBeforeCursor, charAtCursor =
274+
let blankAfterCursor =
275275
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
278285
in
279286

280287
let found = ref false in
@@ -472,17 +479,10 @@ let completionWithParser ~debug ~path ~posCursor ~currentFile ~text =
472479
Printf.printf "Pexp_ident %s:%s\n"
473480
(Utils.flattenLongIdent id.txt |> String.concat ".")
474481
(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
482482
if id.loc |> Loc.hasPos ~pos:posBeforeCursor then
483483
let path_ = id.txt |> Utils.flattenLongIdent in
484484
let path =
485-
if idBreaksUp then (
485+
if blankAfterCursor = Some '.' then (
486486
(* Sometimes "Foo. " is followed by "bar" and the parser's
487487
behaviour is to parse as "Foo.bar".
488488
This gets back the intended path "Foo." *)
@@ -717,12 +717,16 @@ let completionWithParser ~debug ~path ~posCursor ~currentFile ~text =
717717
in
718718
let {Res_driver.parsetree = str} = parser ~filename:currentFile in
719719
iterator.structure iterator str |> ignore;
720+
if blankAfterCursor = Some ' ' || blankAfterCursor = Some '\n' then
721+
setResult (PartialParser.Cpath (CPId ([""], Value)));
720722
if !found = false then if debug then Printf.printf "XXX Not found!\n";
721723
!result)
722724
else if Filename.check_suffix path ".resi" then (
723725
let parser = Res_driver.parsingEngine.parseInterface ~forPrinter:false in
724726
let {Res_driver.parsetree = signature} = parser ~filename:currentFile in
725727
iterator.signature iterator signature |> ignore;
728+
if blankAfterCursor = Some ' ' || blankAfterCursor = Some '\n' then
729+
setResult (PartialParser.Cpath (CPId ([""], Type)));
726730
if !found = false then if debug then Printf.printf "XXX Not found!\n";
727731
!result)
728732
else None

0 commit comments

Comments
 (0)