Skip to content

Commit f7998d7

Browse files
committed
Make debug output consistent with path used for completion.
1 parent 4dc4e7a commit f7998d7

File tree

3 files changed

+21
-19
lines changed

3 files changed

+21
-19
lines changed

analysis/src/Completion.ml

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -481,25 +481,26 @@ let completionWithParser ~debug ~path ~posCursor ~currentFile ~text =
481481
match expr.pexp_desc with
482482
| Pexp_constant _ -> setResult Cnone
483483
| Pexp_ident lid ->
484+
let lidPath = flattenLidCheckDot lid in
484485
if debug then
485486
Printf.printf "Pexp_ident %s:%s\n"
486-
(Utils.flattenLongIdent lid.txt |> String.concat ".")
487+
(lidPath |> String.concat ".")
487488
(Loc.toString lid.loc);
488489
if lid.loc |> Loc.hasPos ~pos:posBeforeCursor then
489-
let path = flattenLidCheckDot lid in
490-
setResult (Cpath (CPId (path, Value)))
490+
setResult (Cpath (CPId (lidPath, Value)))
491491
| Pexp_construct (lid, eOpt) ->
492+
let lidPath = flattenLidCheckDot lid in
492493
if debug then
493494
Printf.printf "Pexp_construct %s:%s %s\n"
494-
(Utils.flattenLongIdent lid.txt |> String.concat "\n")
495+
(lidPath |> String.concat "\n")
495496
(Loc.toString lid.loc)
496497
(match eOpt with
497498
| None -> "None"
498499
| Some e -> Loc.toString e.pexp_loc);
499500
if
500501
eOpt = None && (not lid.loc.loc_ghost)
501502
&& lid.loc |> Loc.hasPos ~pos:posBeforeCursor
502-
then setResult (Cpath (CPId (flattenLidCheckDot lid, Value)))
503+
then setResult (Cpath (CPId (lidPath, Value)))
503504
| Pexp_field (e, fieldName) -> (
504505
if debug then
505506
Printf.printf "Pexp_field %s %s:%s\n" (Loc.toString e.pexp_loc)
@@ -532,11 +533,10 @@ let completionWithParser ~debug ~path ~posCursor ~currentFile ~text =
532533
| Pexp_apply ({pexp_desc = Pexp_ident compName}, args)
533534
when Res_parsetree_viewer.isJsxExpression expr ->
534535
let jsxProps = extractJsxProps ~compName ~args in
536+
let compNamePath = flattenLidCheckDot ~jsx:true compName in
535537
if debug then
536538
Printf.printf "JSX <%s:%s %s> _children:%s\n"
537-
(jsxProps.compName.txt
538-
|> Utils.flattenLongIdent ~jsx:true
539-
|> String.concat ".")
539+
(compNamePath |> String.concat ".")
540540
(Loc.toString compName.loc)
541541
(jsxProps.props
542542
|> List.map (fun {name; posStart; posEnd; exp} ->
@@ -553,8 +553,7 @@ let completionWithParser ~debug ~path ~posCursor ~currentFile ~text =
553553
in
554554
if jsxCompletable <> None then setResultOpt jsxCompletable
555555
else if compName.loc |> Loc.hasPos ~pos:posBeforeCursor then
556-
setResult
557-
(Cpath (CPId (flattenLidCheckDot ~jsx:true compName, Module)))
556+
setResult (Cpath (CPId (compNamePath, Module)))
558557
| Pexp_apply
559558
( {pexp_desc = Pexp_ident {txt = Lident "|."}},
560559
[
@@ -646,38 +645,41 @@ let completionWithParser ~debug ~path ~posCursor ~currentFile ~text =
646645
(Loc.toString core_type.ptyp_loc);
647646
match core_type.ptyp_desc with
648647
| Ptyp_constr (lid, _args) ->
648+
let lidPath = flattenLidCheckDot lid in
649649
if debug then
650650
Printf.printf "Ptyp_constr %s:%s\n"
651-
(Utils.flattenLongIdent lid.txt |> String.concat ".")
651+
(lidPath |> String.concat ".")
652652
(Loc.toString lid.loc);
653653
if lid.loc |> Loc.hasPos ~pos:posBeforeCursor then
654-
setResult (Cpath (CPId (flattenLidCheckDot lid, Type)))
654+
setResult (Cpath (CPId (lidPath, Type)))
655655
| _ -> ());
656656
Ast_iterator.default_iterator.typ iterator core_type
657657
in
658658
let module_expr (iterator : Ast_iterator.iterator)
659659
(me : Parsetree.module_expr) =
660660
(match me.pmod_desc with
661661
| Pmod_ident lid when lid.loc |> Loc.hasPos ~pos:posBeforeCursor ->
662+
let lidPath = flattenLidCheckDot lid in
662663
if debug then
663664
Printf.printf "Pmod_ident %s:%s\n"
664-
(Utils.flattenLongIdent lid.txt |> String.concat ".")
665+
(lidPath |> String.concat ".")
665666
(Loc.toString lid.loc);
666667
found := true;
667-
setResult (Cpath (CPId (flattenLidCheckDot lid, Module)))
668+
setResult (Cpath (CPId (lidPath, Module)))
668669
| _ -> ());
669670
Ast_iterator.default_iterator.module_expr iterator me
670671
in
671672
let module_type (iterator : Ast_iterator.iterator)
672673
(mt : Parsetree.module_type) =
673674
(match mt.pmty_desc with
674675
| Pmty_ident lid when lid.loc |> Loc.hasPos ~pos:posBeforeCursor ->
676+
let lidPath = flattenLidCheckDot lid in
675677
if debug then
676678
Printf.printf "Pmty_ident %s:%s\n"
677-
(Utils.flattenLongIdent lid.txt |> String.concat ".")
679+
(lidPath |> String.concat ".")
678680
(Loc.toString lid.loc);
679681
found := true;
680-
setResult (Cpath (CPId (flattenLidCheckDot lid, Module)))
682+
setResult (Cpath (CPId (lidPath, Module)))
681683
| _ -> ());
682684
Ast_iterator.default_iterator.module_type iterator mt
683685
in

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -997,7 +997,7 @@ Completable: Cpath Type[SomeLocalModule, ""]
997997

998998
Complete tests/src/Completion.res 261:33
999999
posCursor:[261:33] posNoWhite:[261:32] Found type:[261:17->263:11]
1000-
Ptyp_constr SomeLocalModule.thirdProp:[261:17->263:11]
1000+
Ptyp_constr SomeLocalModule.:[261:17->263:11]
10011001
Completable: Cpath Type[SomeLocalModule, ""]
10021002
[{
10031003
"label": "zz",

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ Complete tests/src/Jsx.res 129:19
357357
posCursor:[129:19] posNoWhite:[129:18] Found expr:[128:3->131:9]
358358
JSX <div:[128:3->128:6] x[129:5->129:6]=...[129:7->131:8]> _children:None
359359
posCursor:[129:19] posNoWhite:[129:18] Found expr:[129:7->131:8]
360-
Pexp_ident Outer.Inner.name:[129:7->131:8]
360+
Pexp_ident Outer.Inner.:[129:7->131:8]
361361
Completable: Cpath Value[Outer, Inner, ""]
362362
[{
363363
"label": "hello",
@@ -386,7 +386,7 @@ Completable: Cpath Module[Nested, Co]
386386

387387
Complete tests/src/Jsx.res 153:19
388388
posCursor:[153:19] posNoWhite:[153:18] Found expr:[153:12->153:25]
389-
JSX <Nested.name:[153:12->153:24] > _children:None
389+
JSX <Nested.:[153:12->153:24] > _children:None
390390
Completable: Cpath Module[Nested, ""]
391391
[{
392392
"label": "Comp",

0 commit comments

Comments
 (0)