Skip to content

Commit aedfc9e

Browse files
committed
Print pathFromEnv and whether the path was found.
1 parent f82ad64 commit aedfc9e

9 files changed

+48
-16
lines changed

analysis/src/CompletionBackEnd.ml

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -917,17 +917,18 @@ and getCompletionsForContextPath ~debug ~full ~opens ~rawOpens ~allFiles ~pos
917917
| _ :: pathRev ->
918918
(* type path is relative to the completion environment
919919
express it from the root of the file *)
920-
let pathFromEnv_ =
920+
let found, pathFromEnv =
921921
QueryEnv.pathFromEnv envFromCompletionItem (List.rev pathRev)
922922
in
923-
if pathFromEnv_ = [] then None
924-
else
925-
let pathFromEnv =
926-
if env.file.moduleName = envFromCompletionItem.file.moduleName
927-
then pathFromEnv_
928-
else envFromCompletionItem.file.moduleName :: pathFromEnv_
929-
in
930-
Some pathFromEnv
923+
if debug then
924+
Printf.printf "CPPipe pathFromEnv:%s found:%b\n"
925+
(pathFromEnv |> String.concat ".")
926+
found;
927+
if pathFromEnv = [] then None
928+
else if
929+
env.file.moduleName = envFromCompletionItem.file.moduleName
930+
then Some pathFromEnv
931+
else Some (envFromCompletionItem.file.moduleName :: pathFromEnv)
931932
| _ -> None)
932933
| _ -> None)
933934
in

analysis/src/SharedTypes.ml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ module QueryEnv : sig
266266
E.g. the env is at A.B.C and the path is D.
267267
The result is A.B.C.D if D is inside C.
268268
Or A.B.D or A.D or D if it's in one of its parents. *)
269-
val pathFromEnv : t -> path -> path
269+
val pathFromEnv : t -> path -> bool * path
270270

271271
val toString : t -> string
272272
end = struct
@@ -280,22 +280,22 @@ end = struct
280280

281281
(* Prune a path and find a parent environment that contains the module name *)
282282
let rec prunePath pathRev env name =
283-
if Exported.find env.exported Module name <> None then pathRev
283+
if Exported.find env.exported Module name <> None then (true, pathRev)
284284
else
285285
match (pathRev, env.parent) with
286286
| _ :: rest, Some env -> prunePath rest env name
287-
| _ -> []
287+
| _ -> (false, [])
288288

289289
let pathFromEnv env path =
290290
match path with
291-
| [] -> env.pathRev |> List.rev
291+
| [] -> (true, env.pathRev |> List.rev)
292292
| name :: _ ->
293-
let prunedPathRev = prunePath env.pathRev env name in
294-
List.rev_append prunedPathRev path
293+
let found, prunedPathRev = prunePath env.pathRev env name in
294+
(found, List.rev_append prunedPathRev path)
295295

296296
let enterStructure env (structure : Module.structure) =
297297
let name = structure.name in
298-
let pathRev = name :: prunePath env.pathRev env name in
298+
let pathRev = name :: snd (prunePath env.pathRev env name) in
299299
{env with exported = structure.exported; pathRev; parent = Some env}
300300
end
301301

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ ContextPath Value[a]
66
Path a
77
CPPipe env:CompletePrioritize1
88
CPPipe type path:Test.t
9+
CPPipe pathFromEnv:Test found:true
910
Path Test.
1011
[{
1112
"label": "Test.add",

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ ContextPath Value[ax]
66
Path ax
77
CPPipe env:CompletePrioritize2
88
CPPipe type path:Test.t
9+
CPPipe pathFromEnv:Test found:true
910
Path Test.
1011
[{
1112
"label": "Test.add",

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,7 @@ ContextPath Value[fa]
455455
Path fa
456456
CPPipe env:Completion
457457
CPPipe type path:ForAuto.t
458+
CPPipe pathFromEnv:ForAuto found:true
458459
Path ForAuto.
459460
[{
460461
"label": "ForAuto.abc",
@@ -1017,6 +1018,7 @@ ContextPath Value[FAO, forAutoObject]
10171018
Path FAO.forAutoObject
10181019
CPPipe env:Completion envFromCompletionItem:Completion.FAR
10191020
CPPipe type path:ForAuto.t
1021+
CPPipe pathFromEnv:ForAuto found:false
10201022
Path ForAuto.
10211023
[{
10221024
"label": "ForAuto.abc",

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,7 @@ ContextPath Value[thisGetsBrokenLoc]
351351
Path thisGetsBrokenLoc
352352
CPPipe env:CompletionFunctionArguments
353353
CPPipe type path:ReactEvent.Mouse.t
354+
CPPipe pathFromEnv:ReactEvent.Mouse found:false
354355
Path ReactEvent.Mouse.a
355356
[{
356357
"label": "ReactEvent.Mouse.altKey",
@@ -373,6 +374,7 @@ ContextPath Value[reassignedWorks]
373374
Path reassignedWorks
374375
CPPipe env:CompletionFunctionArguments
375376
CPPipe type path:ReactEvent.Mouse.t
377+
CPPipe pathFromEnv:ReactEvent.Mouse found:false
376378
Path ReactEvent.Mouse.a
377379
[{
378380
"label": "ReactEvent.Mouse.altKey",

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ ContextPath Value[reactEventFn]
150150
Path reactEventFn
151151
CPPipe env:CompletionInferValues
152152
CPPipe type path:ReactEvent.Mouse.t
153+
CPPipe pathFromEnv:ReactEvent.Mouse found:false
153154
Path ReactEvent.Mouse.pr
154155
[{
155156
"label": "ReactEvent.Mouse.preventDefault",
@@ -174,6 +175,7 @@ Path ReactDOM.domProps
174175
Path JsxDOM.domProps
175176
CPPipe env:CompletionInferValues
176177
CPPipe type path:JsxEvent.Mouse.t
178+
CPPipe pathFromEnv:JsxEvent.Mouse found:false
177179
Path JsxEvent.Mouse.pr
178180
[{
179181
"label": "JsxEvent.Mouse.preventDefault",
@@ -197,6 +199,7 @@ ContextPath CJsxPropValue [Div] onMouseEnter
197199
Path Div.make
198200
CPPipe env:CompletionInferValues envFromCompletionItem:CompletionInferValues.Div
199201
CPPipe type path:JsxEvent.Mouse.t
202+
CPPipe pathFromEnv:JsxEvent.Mouse found:false
200203
Path JsxEvent.Mouse.pr
201204
[{
202205
"label": "JsxEvent.Mouse.preventDefault",
@@ -666,6 +669,7 @@ ContextPath Value[fn2]
666669
Path fn2
667670
CPPipe env:CompletionInferValues
668671
CPPipe type path:ReactDOM.Client.Root.t
672+
CPPipe pathFromEnv:ReactDOM.Client.Root found:false
669673
Path ReactDOM.Client.Root.
670674
[{
671675
"label": "ReactDOM.Client.Root.unmount",
@@ -698,6 +702,7 @@ ContextPath Value[fn3]
698702
Path fn3
699703
CPPipe env:CompletionInferValues
700704
CPPipe type path:CompletionSupport.Test.t
705+
CPPipe pathFromEnv:CompletionSupport.Test found:false
701706
Path CompletionSupport.Test.
702707
[{
703708
"label": "CompletionSupport.Test.add",
@@ -793,6 +798,7 @@ ContextPath Value[CompletionSupport2, makeRenderer]
793798
Path CompletionSupport2.makeRenderer
794799
CPPipe env:CompletionInferValues envFromCompletionItem:CompletionSupport2.Internal
795800
CPPipe type path:ReactDOM.Client.Root.t
801+
CPPipe pathFromEnv:ReactDOM.Client.Root found:false
796802
Path CompletionSupport2.ReactDOM.Client.Root.
797803
[]
798804

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ ContextPath Value[int]
66
Path int
77
CPPipe env:CompletionPipeChain
88
CPPipe type path:Integer.t
9+
CPPipe pathFromEnv:Integer found:true
910
Path Integer.
1011
[{
1112
"label": "Integer.toInt",
@@ -42,6 +43,7 @@ ContextPath Value[toFlt]
4243
Path toFlt
4344
CPPipe env:CompletionPipeChain
4445
CPPipe type path:SuperFloat.t
46+
CPPipe pathFromEnv:SuperFloat found:true
4547
Path SuperFloat.
4648
[{
4749
"label": "SuperFloat.fromInteger",
@@ -66,6 +68,7 @@ ContextPath Value[Integer, increment]
6668
Path Integer.increment
6769
CPPipe env:CompletionPipeChain envFromCompletionItem:CompletionPipeChain.Integer
6870
CPPipe type path:t
71+
CPPipe pathFromEnv:Integer found:true
6972
Path Integer.
7073
[{
7174
"label": "Integer.toInt",
@@ -102,6 +105,7 @@ ContextPath Value[Integer, increment]
102105
Path Integer.increment
103106
CPPipe env:CompletionPipeChain envFromCompletionItem:CompletionPipeChain.Integer
104107
CPPipe type path:t
108+
CPPipe pathFromEnv:Integer found:true
105109
Path Integer.
106110
[{
107111
"label": "Integer.toInt",
@@ -138,6 +142,7 @@ ContextPath Value[Integer, decrement]
138142
Path Integer.decrement
139143
CPPipe env:CompletionPipeChain envFromCompletionItem:CompletionPipeChain.Integer
140144
CPPipe type path:t
145+
CPPipe pathFromEnv:Integer found:true
141146
Path Integer.
142147
[{
143148
"label": "Integer.toInt",
@@ -174,6 +179,7 @@ ContextPath Value[Integer, decrement]
174179
Path Integer.decrement
175180
CPPipe env:CompletionPipeChain envFromCompletionItem:CompletionPipeChain.Integer
176181
CPPipe type path:t
182+
CPPipe pathFromEnv:Integer found:true
177183
Path Integer.
178184
[{
179185
"label": "Integer.toInt",
@@ -210,6 +216,7 @@ ContextPath Value[SuperFloat, fromInteger]
210216
Path SuperFloat.fromInteger
211217
CPPipe env:CompletionPipeChain envFromCompletionItem:CompletionPipeChain.SuperFloat
212218
CPPipe type path:t
219+
CPPipe pathFromEnv:SuperFloat found:true
213220
Path SuperFloat.
214221
[{
215222
"label": "SuperFloat.fromInteger",
@@ -234,6 +241,7 @@ ContextPath Value[SuperFloat, fromInteger]
234241
Path SuperFloat.fromInteger
235242
CPPipe env:CompletionPipeChain envFromCompletionItem:CompletionPipeChain.SuperFloat
236243
CPPipe type path:t
244+
CPPipe pathFromEnv:SuperFloat found:true
237245
Path SuperFloat.t
238246
[{
239247
"label": "SuperFloat.toInteger",
@@ -252,6 +260,7 @@ ContextPath Value[CompletionSupport, Test, make]
252260
Path CompletionSupport.Test.make
253261
CPPipe env:CompletionPipeChain envFromCompletionItem:CompletionSupport.Test
254262
CPPipe type path:t
263+
CPPipe pathFromEnv:Test found:true
255264
Path CompletionSupport.Test.
256265
[{
257266
"label": "CompletionSupport.Test.add",
@@ -282,6 +291,7 @@ ContextPath Value[CompletionSupport, Test, addSelf]
282291
Path CompletionSupport.Test.addSelf
283292
CPPipe env:CompletionPipeChain envFromCompletionItem:CompletionSupport.Test
284293
CPPipe type path:t
294+
CPPipe pathFromEnv:Test found:true
285295
Path CompletionSupport.Test.
286296
[{
287297
"label": "CompletionSupport.Test.add",
@@ -312,6 +322,7 @@ ContextPath Value[Js, Array2, forEach]
312322
Path Js.Array2.forEach
313323
CPPipe env:CompletionPipeChain envFromCompletionItem:Js_array2
314324
CPPipe type path:unit
325+
CPPipe pathFromEnv: found:true
315326
[]
316327

317328
Complete src/CompletionPipeChain.res 62:6
@@ -345,6 +356,7 @@ ContextPath Value[aliased]
345356
Path aliased
346357
CPPipe env:CompletionPipeChain
347358
CPPipe type path:CompletionSupport.Test.t
359+
CPPipe pathFromEnv:CompletionSupport.Test found:false
348360
Path CompletionSupport.Test.
349361
[{
350362
"label": "CompletionSupport.Test.add",
@@ -374,6 +386,7 @@ ContextPath Value[notAliased]
374386
Path notAliased
375387
CPPipe env:CompletionPipeChain
376388
CPPipe type path:CompletionSupport.Test.t
389+
CPPipe pathFromEnv:CompletionSupport.Test found:false
377390
Path CompletionSupport.Test.
378391
[{
379392
"label": "CompletionSupport.Test.add",
@@ -410,6 +423,7 @@ ContextPath Value[props]
410423
Path props
411424
CPPipe env:CompletionPipeChain envFromCompletionItem:CompletionSupport.Nested
412425
CPPipe type path:ReactDOM.Client.Root.t
426+
CPPipe pathFromEnv:ReactDOM.Client.Root found:false
413427
Path CompletionSupport.ReactDOM.Client.Root.ren
414428
[]
415429

@@ -428,6 +442,7 @@ ContextPath Value[root]
428442
Path root
429443
CPPipe env:CompletionPipeChain
430444
CPPipe type path:ReactDOM.Client.Root.t
445+
CPPipe pathFromEnv:ReactDOM.Client.Root found:false
431446
Path ReactDOM.Client.Root.ren
432447
[{
433448
"label": "ReactDOM.Client.Root.render",

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ ContextPath Value[A, B1, xx]
66
Path A.B1.xx
77
CPPipe env:CompletionPipeSubmodules envFromCompletionItem:CompletionPipeSubmodules.A.B1
88
CPPipe type path:b1
9+
CPPipe pathFromEnv:A.B1 found:true
910
Path A.B1.
1011
[{
1112
"label": "A.B1.xx",
@@ -30,6 +31,7 @@ ContextPath Value[A, x]
3031
Path A.x
3132
CPPipe env:CompletionPipeSubmodules envFromCompletionItem:CompletionPipeSubmodules.A
3233
CPPipe type path:B1.b1
34+
CPPipe pathFromEnv:A.B1 found:true
3335
Path A.B1.
3436
[{
3537
"label": "A.B1.xx",
@@ -55,6 +57,7 @@ ContextPath Value[E, e]
5557
Path E.e
5658
CPPipe env:CompletionPipeSubmodules envFromCompletionItem:CompletionPipeSubmodules.D
5759
CPPipe type path:C.t
60+
CPPipe pathFromEnv:C found:false
5861
Path C.
5962
[{
6063
"label": "C.C",
@@ -74,6 +77,7 @@ ContextPath Value[E, e]
7477
Path E.e
7578
CPPipe env:CompletionPipeSubmodules envFromCompletionItem:CompletionPipeSubmodules.D
7679
CPPipe type path:C2.t2
80+
CPPipe pathFromEnv:D.C2 found:true
7781
Path D.C2.
7882
[{
7983
"label": "D.C2.C2",

0 commit comments

Comments
 (0)