@@ -2,13 +2,6 @@ open SharedTypes
2
2
3
3
let modulePathFromEnv env = env.QueryEnv. file.moduleName :: List. rev env.pathRev
4
4
5
- let completionPathFromEnvAndPath env ~path =
6
- modulePathFromEnv env @ List. rev (Utils. expandPath path)
7
- |> List. rev |> List. tl |> List. rev
8
-
9
- let getFullTypeId ~env (path : Path.t ) =
10
- modulePathFromEnv env @ List. rev (Utils. expandPath path) |> String. concat " ."
11
-
12
5
let fullTypeIdFromDecl ~env ~name ~modulePath =
13
6
env.QueryEnv. file.moduleName :: ModulePath. toPath modulePath name
14
7
|> String. concat " ."
@@ -506,45 +499,6 @@ let findReturnTypeOfFunctionAtLoc loc ~(env : QueryEnv.t) ~full ~debug =
506
499
| _ -> None )
507
500
| _ -> None
508
501
509
- type builtinType =
510
- | Array
511
- | Option
512
- | String
513
- | Int
514
- | Float
515
- | Promise
516
- | List
517
- | Result
518
- | Lazy
519
- | Char
520
- | RegExp
521
-
522
- type pipeCompletionType =
523
- | Builtin of builtinType * Types .type_expr
524
- | TypExpr of Types .type_expr
525
-
526
- let getBuiltinFromTypePath path =
527
- match path with
528
- | Path. Pident _ -> (
529
- match Path. name path with
530
- | "array" -> Some Array
531
- | "option" -> Some Option
532
- | "string" -> Some String
533
- | "int" -> Some Int
534
- | "float" -> Some Float
535
- | "promise" -> Some Promise
536
- | "list" -> Some List
537
- | "result" -> Some Result
538
- | "lazy_t" -> Some Lazy
539
- | "char" -> Some Char
540
- | _ -> None )
541
- | Pdot (Pdot (Pident m , "Re" , _ ), "t" , _ ) when Ident. name m = " Js" ->
542
- Some RegExp
543
- | Pdot (Pident id, " result" , _)
544
- when Ident. name id = " Pervasives" || Ident. name id = " PervasivesU" ->
545
- Some Result
546
- | _ -> None
547
-
548
502
let rec digToRelevantTemplateNameType ~env ~package ?(suffix = " " )
549
503
(t : Types.type_expr ) =
550
504
match t.desc with
@@ -563,47 +517,6 @@ let rec digToRelevantTemplateNameType ~env ~package ?(suffix = "")
563
517
564
518
let rec resolveTypeForPipeCompletion ~env ~package ~lhsLoc ~full
565
519
(t : Types.type_expr ) =
566
- let builtin =
567
- match t |> pathFromTypeExpr with
568
- | Some path -> path |> getBuiltinFromTypePath
569
- | None -> None
570
- in
571
- match builtin with
572
- | Some builtin -> (env, Builtin (builtin, t))
573
- | None -> (
574
- (* If the type we're completing on is a type parameter, we won't be able to
575
- do completion unless we know what that type parameter is compiled as.
576
- This attempts to look up the compiled type for that type parameter by
577
- looking for compiled information at the loc of that expression. *)
578
- let typFromLoc =
579
- match t with
580
- | {Types. desc = Tvar _ } -> (
581
- match findReturnTypeOfFunctionAtLoc lhsLoc ~env ~full ~debug: false with
582
- | None -> None
583
- | Some typFromLoc -> Some typFromLoc)
584
- | _ -> None
585
- in
586
- match typFromLoc with
587
- | Some typFromLoc ->
588
- typFromLoc |> resolveTypeForPipeCompletion ~lhs Loc ~env ~package ~full
589
- | None ->
590
- let rec digToRelevantType ~env ~package (t : Types.type_expr ) =
591
- match t.desc with
592
- | Tlink t1 | Tsubst t1 | Tpoly (t1 , [] ) ->
593
- digToRelevantType ~env ~package t1
594
- (* Don't descend into types named "t". Type t is a convention in the ReScript ecosystem. *)
595
- | Tconstr (path , _ , _ ) when path |> Path. last = " t" -> (env, TypExpr t)
596
- | Tconstr (path , _ , _ ) -> (
597
- match References. digConstructor ~env ~package path with
598
- | Some (env , {item = {decl = {type_manifest = Some typ } } } ) ->
599
- digToRelevantType ~env ~package typ
600
- | _ -> (env, TypExpr t))
601
- | _ -> (env, TypExpr t)
602
- in
603
- digToRelevantType ~env ~package t)
604
-
605
- let rec resolveTypeForPipeCompletion2 ~env ~package ~lhsLoc ~full
606
- (t : Types.type_expr ) =
607
520
(* If the type we're completing on is a type parameter, we won't be able to
608
521
do completion unless we know what that type parameter is compiled as.
609
522
This attempts to look up the compiled type for that type parameter by
@@ -616,7 +529,7 @@ let rec resolveTypeForPipeCompletion2 ~env ~package ~lhsLoc ~full
616
529
in
617
530
match typFromLoc with
618
531
| Some typFromLoc ->
619
- typFromLoc |> resolveTypeForPipeCompletion2 ~lhs Loc ~env ~package ~full
532
+ typFromLoc |> resolveTypeForPipeCompletion ~lhs Loc ~env ~package ~full
620
533
| None ->
621
534
let rec digToRelevantType ~env ~package (t : Types.type_expr ) =
622
535
match t.desc with
@@ -1190,21 +1103,9 @@ let pathToElementProps package =
1190
1103
| None -> [" ReactDOM" ; " domProps" ]
1191
1104
| Some g -> (g |> String. split_on_char '.' ) @ [" Elements" ; " props" ]
1192
1105
1193
- (* * Extracts module to draw extra completions from for the type, if it has been annotated with @editor.completeFrom. *)
1194
- let rec getExtraModuleToCompleteFromForType ~env ~full (t : Types.type_expr ) =
1195
- match t |> Shared. digConstructor with
1196
- | Some path -> (
1197
- match References. digConstructor ~env ~package: full.package path with
1198
- | None -> None
1199
- | Some (env , {item = {decl = {type_manifest = Some t } } } ) ->
1200
- getExtraModuleToCompleteFromForType ~env ~full t
1201
- | Some (_ , {item = {attributes} } ) ->
1202
- ProcessAttributes. findEditorCompleteFromAttribute attributes)
1203
- | None -> None
1204
-
1205
1106
module StringSet = Set. Make (String )
1206
1107
1207
- let rec getExtraModuleTosCompleteFromForType ~env ~full (t : Types.type_expr ) =
1108
+ let getExtraModulesToCompleteFromForType ~env ~full (t : Types.type_expr ) =
1208
1109
let foundModulePaths = ref StringSet. empty in
1209
1110
let addToModulePaths attributes =
1210
1111
ProcessAttributes. findEditorCompleteFromAttribute2 attributes
@@ -1227,39 +1128,6 @@ let rec getExtraModuleTosCompleteFromForType ~env ~full (t : Types.type_expr) =
1227
1128
! foundModulePaths |> StringSet. elements
1228
1129
|> List. map (fun l -> String. split_on_char '.' l)
1229
1130
1230
- (* * Checks whether the provided type represents a function that takes the provided path
1231
- as the first argument (meaning it's pipeable). *)
1232
- let rec fnTakesTypeAsFirstArg ~env ~full ~targetTypeId t =
1233
- (* if Debug.verbose () then
1234
- Printf.printf "[fnTakesTypeAsFirstArg] start env: %s\n"
1235
- env.QueryEnv.file.moduleName;*)
1236
- match t.Types. desc with
1237
- | Tlink t1
1238
- | Tsubst t1
1239
- | Tpoly (t1, [] )
1240
- | Tconstr (Pident {name = "function$" } , [t1 ; _ ], _ ) ->
1241
- fnTakesTypeAsFirstArg ~env ~full ~target TypeId t1
1242
- | Tarrow _ -> (
1243
- match extractFunctionTypeWithEnv ~env ~package: full.package t with
1244
- | (Nolabel, t ) :: _ , _ , env -> (
1245
- (* if Debug.verbose () then
1246
- Printf.printf "[fnTakesTypeAsFirstArg] extracted env: %s\n"
1247
- env.QueryEnv.file.moduleName;*)
1248
- let mainTypeId =
1249
- match pathFromTypeExpr t with
1250
- | None -> None
1251
- | Some tPath -> Some (getFullTypeId ~env tPath)
1252
- in
1253
- (* if Debug.verbose () then
1254
- Printf.printf "[filterPipeableFunctions]--> targetTypeId:%s = %s\n"
1255
- targetTypeId
1256
- (Option.value ~default:"None" mainTypeId);*)
1257
- match mainTypeId with
1258
- | None -> false
1259
- | Some mainTypeId -> mainTypeId = targetTypeId)
1260
- | _ -> false )
1261
- | _ -> false
1262
-
1263
1131
let getFirstFnUnlabelledArgType ~env ~full t =
1264
1132
let labels, _, env =
1265
1133
extractFunctionTypeWithEnv ~env ~package: full.package t
0 commit comments