Skip to content

Commit

Permalink
Make debug output consistent with path used for completion.
Browse files Browse the repository at this point in the history
  • Loading branch information
cristianoc committed Apr 28, 2022
1 parent 4dc4e7a commit f7998d7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 19 deletions.
34 changes: 18 additions & 16 deletions analysis/src/Completion.ml
Original file line number Diff line number Diff line change
Expand Up @@ -481,25 +481,26 @@ let completionWithParser ~debug ~path ~posCursor ~currentFile ~text =
match expr.pexp_desc with
| Pexp_constant _ -> setResult Cnone
| Pexp_ident lid ->
let lidPath = flattenLidCheckDot lid in
if debug then
Printf.printf "Pexp_ident %s:%s\n"
(Utils.flattenLongIdent lid.txt |> String.concat ".")
(lidPath |> String.concat ".")
(Loc.toString lid.loc);
if lid.loc |> Loc.hasPos ~pos:posBeforeCursor then
let path = flattenLidCheckDot lid in
setResult (Cpath (CPId (path, Value)))
setResult (Cpath (CPId (lidPath, Value)))
| Pexp_construct (lid, eOpt) ->
let lidPath = flattenLidCheckDot lid in
if debug then
Printf.printf "Pexp_construct %s:%s %s\n"
(Utils.flattenLongIdent lid.txt |> String.concat "\n")
(lidPath |> String.concat "\n")
(Loc.toString lid.loc)
(match eOpt with
| None -> "None"
| Some e -> Loc.toString e.pexp_loc);
if
eOpt = None && (not lid.loc.loc_ghost)
&& lid.loc |> Loc.hasPos ~pos:posBeforeCursor
then setResult (Cpath (CPId (flattenLidCheckDot lid, Value)))
then setResult (Cpath (CPId (lidPath, Value)))
| Pexp_field (e, fieldName) -> (
if debug then
Printf.printf "Pexp_field %s %s:%s\n" (Loc.toString e.pexp_loc)
Expand Down Expand Up @@ -532,11 +533,10 @@ let completionWithParser ~debug ~path ~posCursor ~currentFile ~text =
| Pexp_apply ({pexp_desc = Pexp_ident compName}, args)
when Res_parsetree_viewer.isJsxExpression expr ->
let jsxProps = extractJsxProps ~compName ~args in
let compNamePath = flattenLidCheckDot ~jsx:true compName in
if debug then
Printf.printf "JSX <%s:%s %s> _children:%s\n"
(jsxProps.compName.txt
|> Utils.flattenLongIdent ~jsx:true
|> String.concat ".")
(compNamePath |> String.concat ".")
(Loc.toString compName.loc)
(jsxProps.props
|> List.map (fun {name; posStart; posEnd; exp} ->
Expand All @@ -553,8 +553,7 @@ let completionWithParser ~debug ~path ~posCursor ~currentFile ~text =
in
if jsxCompletable <> None then setResultOpt jsxCompletable
else if compName.loc |> Loc.hasPos ~pos:posBeforeCursor then
setResult
(Cpath (CPId (flattenLidCheckDot ~jsx:true compName, Module)))
setResult (Cpath (CPId (compNamePath, Module)))
| Pexp_apply
( {pexp_desc = Pexp_ident {txt = Lident "|."}},
[
Expand Down Expand Up @@ -646,38 +645,41 @@ let completionWithParser ~debug ~path ~posCursor ~currentFile ~text =
(Loc.toString core_type.ptyp_loc);
match core_type.ptyp_desc with
| Ptyp_constr (lid, _args) ->
let lidPath = flattenLidCheckDot lid in
if debug then
Printf.printf "Ptyp_constr %s:%s\n"
(Utils.flattenLongIdent lid.txt |> String.concat ".")
(lidPath |> String.concat ".")
(Loc.toString lid.loc);
if lid.loc |> Loc.hasPos ~pos:posBeforeCursor then
setResult (Cpath (CPId (flattenLidCheckDot lid, Type)))
setResult (Cpath (CPId (lidPath, Type)))
| _ -> ());
Ast_iterator.default_iterator.typ iterator core_type
in
let module_expr (iterator : Ast_iterator.iterator)
(me : Parsetree.module_expr) =
(match me.pmod_desc with
| Pmod_ident lid when lid.loc |> Loc.hasPos ~pos:posBeforeCursor ->
let lidPath = flattenLidCheckDot lid in
if debug then
Printf.printf "Pmod_ident %s:%s\n"
(Utils.flattenLongIdent lid.txt |> String.concat ".")
(lidPath |> String.concat ".")
(Loc.toString lid.loc);
found := true;
setResult (Cpath (CPId (flattenLidCheckDot lid, Module)))
setResult (Cpath (CPId (lidPath, Module)))
| _ -> ());
Ast_iterator.default_iterator.module_expr iterator me
in
let module_type (iterator : Ast_iterator.iterator)
(mt : Parsetree.module_type) =
(match mt.pmty_desc with
| Pmty_ident lid when lid.loc |> Loc.hasPos ~pos:posBeforeCursor ->
let lidPath = flattenLidCheckDot lid in
if debug then
Printf.printf "Pmty_ident %s:%s\n"
(Utils.flattenLongIdent lid.txt |> String.concat ".")
(lidPath |> String.concat ".")
(Loc.toString lid.loc);
found := true;
setResult (Cpath (CPId (flattenLidCheckDot lid, Module)))
setResult (Cpath (CPId (lidPath, Module)))
| _ -> ());
Ast_iterator.default_iterator.module_type iterator mt
in
Expand Down
2 changes: 1 addition & 1 deletion analysis/tests/src/expected/Completion.res.txt
Original file line number Diff line number Diff line change
Expand Up @@ -997,7 +997,7 @@ Completable: Cpath Type[SomeLocalModule, ""]

Complete tests/src/Completion.res 261:33
posCursor:[261:33] posNoWhite:[261:32] Found type:[261:17->263:11]
Ptyp_constr SomeLocalModule.thirdProp:[261:17->263:11]
Ptyp_constr SomeLocalModule.:[261:17->263:11]
Completable: Cpath Type[SomeLocalModule, ""]
[{
"label": "zz",
Expand Down
4 changes: 2 additions & 2 deletions analysis/tests/src/expected/Jsx.res.txt
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ Complete tests/src/Jsx.res 129:19
posCursor:[129:19] posNoWhite:[129:18] Found expr:[128:3->131:9]
JSX <div:[128:3->128:6] x[129:5->129:6]=...[129:7->131:8]> _children:None
posCursor:[129:19] posNoWhite:[129:18] Found expr:[129:7->131:8]
Pexp_ident Outer.Inner.name:[129:7->131:8]
Pexp_ident Outer.Inner.:[129:7->131:8]
Completable: Cpath Value[Outer, Inner, ""]
[{
"label": "hello",
Expand Down Expand Up @@ -386,7 +386,7 @@ Completable: Cpath Module[Nested, Co]

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

0 comments on commit f7998d7

Please sign in to comment.