Skip to content

Commit 7869ce5

Browse files
committed
illustrate new issue with pipe completion paths
1 parent 29b5b95 commit 7869ce5

5 files changed

+55
-1
lines changed

analysis/src/CompletionBackEnd.ml

+6-1
Original file line numberDiff line numberDiff line change
@@ -857,9 +857,14 @@ and getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env
857857
with
858858
| None -> []
859859
| Some (typ, envFromCompletionItem) -> (
860+
(* Passing `envFromCompletionItem` into `resolveTypeForPipeCompletion`
861+
fixes the issue in `CompletionInferValues.res`, but breaks other pipe
862+
chains. Change it and see what breaks instead. *)
860863
let env, typ =
861864
typ
862-
|> TypeUtils.resolveTypeForPipeCompletion ~env ~package ~full ~lhsLoc
865+
|> TypeUtils.resolveTypeForPipeCompletion
866+
(* by doing this ~env:envFromCompletionItem*)
867+
~env ~package ~full ~lhsLoc
863868
in
864869
let completionPath =
865870
match typ with

analysis/tests/src/CompletionInferValues.res

+8
Original file line numberDiff line numberDiff line change
@@ -154,3 +154,11 @@ let fn3 = (~cb: sameFileRecord => unit) => {
154154
// Handles pipe chains as input for switch
155155
// let x = 123; switch x->Belt.Int.toString->Js.String2.split("/") { | }
156156
// ^com
157+
158+
// Regular completion works
159+
// let renderer = CompletionSupport2.makeRenderer(~prepare=() => "hello",~render=({support}) => {support.},())
160+
// ^com
161+
162+
// But pipe completion gets the wrong completion path. Should be `ReactDOM.Client.Root.t`, but ends up being `CompletionSupport2.ReactDOM.Client.Root.t`.
163+
// let renderer = CompletionSupport2.makeRenderer(~prepare=() => "hello",~render=({support:{root}}) => {root->},())
164+
// ^com
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module Internal = {
2+
type prepareProps<'prepared> = {
3+
someName: string,
4+
support: CompletionSupport.Nested.config,
5+
prepared: 'prepared,
6+
}
7+
}
8+
9+
let makeRenderer = (
10+
~prepare: unit => 'prepared,
11+
~render: Internal.prepareProps<'prepared> => React.element,
12+
(),
13+
) => {
14+
let _ = prepare
15+
let _ = render
16+
"123"
17+
}

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

+24
Original file line numberDiff line numberDiff line change
@@ -508,3 +508,27 @@ Completable: Cpattern Value[Js, String2, split](Nolabel, Nolabel)
508508
"insertTextFormat": 2
509509
}]
510510

511+
Complete src/CompletionInferValues.res 158:105
512+
posCursor:[158:105] posNoWhite:[158:104] Found expr:[158:18->158:110]
513+
Pexp_apply ...[158:18->158:49] (~prepare158:51->158:58=...[158:59->158:72], ~render158:74->158:80=...[158:81->158:106], ...[158:107->158:109])
514+
posCursor:[158:105] posNoWhite:[158:104] Found expr:[158:81->158:106]
515+
posCursor:[158:105] posNoWhite:[158:104] Found expr:[158:97->158:105]
516+
Pexp_field [158:97->158:104] _:[158:105->158:105]
517+
Completable: Cpath Value[support].""
518+
[{
519+
"label": "root",
520+
"kind": 5,
521+
"tags": [],
522+
"detail": "root: ReactDOM.Client.Root.t\n\ntype config = {root: ReactDOM.Client.Root.t}",
523+
"documentation": null
524+
}]
525+
526+
Complete src/CompletionInferValues.res 162:110
527+
posCursor:[162:110] posNoWhite:[162:109] Found expr:[162:18->162:115]
528+
Pexp_apply ...[162:18->162:49] (~prepare162:51->162:58=...[162:59->162:72], ~render162:74->162:80=...[162:81->162:111], ...[162:112->162:114])
529+
posCursor:[162:110] posNoWhite:[162:109] Found expr:[162:81->162:111]
530+
posCursor:[162:110] posNoWhite:[162:109] Found expr:[162:104->0:-1]
531+
posCursor:[162:110] posNoWhite:[162:109] Found expr:[162:104->0:-1]
532+
Completable: Cpath Value[root]->
533+
[]
534+

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

Whitespace-only changes.

0 commit comments

Comments
 (0)