From a0b4361604b9f683a62a131e92de164c3ffea83f Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Tue, 24 Jan 2023 20:21:58 +0100 Subject: [PATCH 01/41] setup + minimum needed to understand aliases --- analysis/src/Cfg.ml | 2 + analysis/src/CompletionBackEnd.ml | 60 +++-- analysis/src/CompletionFrontEnd.ml | 40 +-- analysis/src/Scope.ml | 23 +- analysis/src/SharedTypes.ml | 241 +++++++++--------- analysis/tests/src/CompletionInferValues.res | 23 ++ .../expected/CompletionInferValues.res.txt | 53 ++++ 7 files changed, 282 insertions(+), 160 deletions(-) create mode 100644 analysis/tests/src/CompletionInferValues.res create mode 100644 analysis/tests/src/expected/CompletionInferValues.res.txt diff --git a/analysis/src/Cfg.ml b/analysis/src/Cfg.ml index 28b92aaf7..0ca7d35ab 100644 --- a/analysis/src/Cfg.ml +++ b/analysis/src/Cfg.ml @@ -1 +1,3 @@ let supportsSnippets = ref false + +let debugFollowCtxPath = false diff --git a/analysis/src/CompletionBackEnd.ml b/analysis/src/CompletionBackEnd.ml index 421986ddb..eddfb4f17 100644 --- a/analysis/src/CompletionBackEnd.ml +++ b/analysis/src/CompletionBackEnd.ml @@ -243,6 +243,7 @@ let kindToDetail name (kind : Completion.kind) = ^ ")") ^ "\n\n" ^ s | Snippet s -> s + | FollowContextPath _ -> "" | ExtractedType (extractedType, _) -> TypeUtils.extractedTypeToString extractedType @@ -262,7 +263,7 @@ let findAllCompletions ~(env : QueryEnv.t) ~prefix ~exact ~namesUsed completionForExportedFields ~env ~prefix ~exact ~namesUsed @ completionForExportedModules ~env ~prefix ~exact ~namesUsed -let processLocalValue name loc ~prefix ~exact ~env +let processLocalValue name loc contextPath ~prefix ~exact ~env ~(localTables : LocalTables.t) = if Utils.checkName name ~prefix ~exact then match Hashtbl.find_opt localTables.valueTable (name, Loc.start loc) with @@ -284,10 +285,13 @@ let processLocalValue name loc ~prefix ~exact ~env localTables.resultRev <- Completion.create name ~env ~kind: - (Value - (Ctype.newconstr - (Path.Pident (Ident.create "Type Not Known")) - [])) + (match contextPath with + | Some contextPath -> FollowContextPath contextPath + | None -> + Value + (Ctype.newconstr + (Path.Pident (Ident.create "Type Not Known")) + [])) :: localTables.resultRev let processLocalConstructor name loc ~prefix ~exact ~env @@ -616,27 +620,47 @@ let completionsGetCompletionType ~full = function type getCompletionsForContextPathMode = Regular | Pipe -let rec getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env +let rec completionsGetTypeEnv2 (completions : Completion.t list) ~full ~opens + ~rawOpens ~allFiles ~pos ~scope = + match completions with + | {Completion.kind = Value typ; env} :: _ -> Some (typ, env) + | {Completion.kind = ObjLabel typ; env} :: _ -> Some (typ, env) + | {Completion.kind = Field ({typ}, _); env} :: _ -> Some (typ, env) + | {Completion.kind = FollowContextPath ctxPath; env} :: _ -> + ctxPath + |> getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env + ~exact:true ~scope + |> completionsGetTypeEnv2 ~full ~opens ~rawOpens ~allFiles ~pos ~scope + | _ -> None + +and getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env ~exact ~scope ?(mode = Regular) (contextPath : Completable.contextPath) = let package = full.package in match contextPath with | CPString -> [ - Completion.create "string" ~env + Completion.create "dummy" ~env ~kind: (Completion.Value (Ctype.newconstr (Path.Pident (Ident.create "string")) [])); ] + | CPBool -> + [ + Completion.create "dummy" ~env + ~kind: + (Completion.Value + (Ctype.newconstr (Path.Pident (Ident.create "bool")) [])); + ] | CPInt -> [ - Completion.create "int" ~env + Completion.create "dummy" ~env ~kind: (Completion.Value (Ctype.newconstr (Path.Pident (Ident.create "int")) [])); ] | CPFloat -> [ - Completion.create "float" ~env + Completion.create "dummy" ~env ~kind: (Completion.Value (Ctype.newconstr (Path.Pident (Ident.create "float")) [])); @@ -694,7 +718,7 @@ let rec getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env cp |> getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env ~exact:true ~scope - |> completionsGetTypeEnv + |> completionsGetTypeEnv2 ~full ~opens ~rawOpens ~allFiles ~pos ~scope with | Some (typ, env) -> ( let rec reconstructFunctionType args tRet = @@ -740,7 +764,7 @@ let rec getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env cp |> getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env ~exact:true ~scope - |> completionsGetTypeEnv + |> completionsGetTypeEnv2 ~full ~opens ~rawOpens ~allFiles ~pos ~scope with | Some (typ, env) -> ( match typ |> TypeUtils.extractRecordType ~env ~package with @@ -764,7 +788,7 @@ let rec getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env cp |> getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env ~exact:true ~scope - |> completionsGetTypeEnv + |> completionsGetTypeEnv2 ~full ~opens ~rawOpens ~allFiles ~pos ~scope with | Some (typ, env) -> ( match typ |> TypeUtils.extractObjectType ~env ~package with @@ -791,7 +815,7 @@ let rec getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env cp |> getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env ~exact:true ~scope ~mode:Pipe - |> completionsGetTypeEnv + |> completionsGetTypeEnv2 ~full ~opens ~rawOpens ~allFiles ~pos ~scope with | None -> [] | Some (typ, envFromCompletionItem) -> ( @@ -945,7 +969,7 @@ let rec getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env path |> getCompletionsForPath ~completionContext:Value ~exact:true ~package ~opens ~allFiles ~pos ~env ~scope - |> completionsGetTypeEnv + |> completionsGetTypeEnv2 ~full ~opens ~rawOpens ~allFiles ~pos ~scope in let lowercaseComponent = match pathToComponent with @@ -991,7 +1015,7 @@ let rec getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env functionContextPath |> getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env ~exact:true ~scope - |> completionsGetTypeEnv + |> completionsGetTypeEnv2 ~full ~opens ~rawOpens ~allFiles ~pos ~scope with | Some (typ, env) -> (typ |> TypeUtils.getArgs ~full ~env, env) | None -> ([], env) @@ -1314,7 +1338,7 @@ let rec processCompletable ~debug ~full ~scope ~env ~pos ~forHover path |> getCompletionsForPath ~completionContext:Value ~exact:true ~package ~opens ~allFiles ~pos ~env ~scope - |> completionsGetTypeEnv + |> completionsGetTypeEnv2 ~full ~opens ~rawOpens ~allFiles ~pos ~scope in match completable with | Cnone -> [] @@ -1380,7 +1404,7 @@ let rec processCompletable ~debug ~full ~scope ~env ~pos ~forHover cp |> getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env ~exact:true ~scope - |> completionsGetTypeEnv + |> completionsGetTypeEnv2 ~full ~opens ~rawOpens ~allFiles ~pos ~scope with | Some (typ, _env) -> if debug then @@ -1416,7 +1440,7 @@ let rec processCompletable ~debug ~full ~scope ~env ~pos ~forHover contextPath |> getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env ~exact:true ~scope - |> completionsGetTypeEnv + |> completionsGetTypeEnv2 ~full ~opens ~rawOpens ~allFiles ~pos ~scope with | Some (typ, env) -> ( match diff --git a/analysis/src/CompletionFrontEnd.ml b/analysis/src/CompletionFrontEnd.ml index e0d79bccf..2ebe91915 100644 --- a/analysis/src/CompletionFrontEnd.ml +++ b/analysis/src/CompletionFrontEnd.ml @@ -141,6 +141,7 @@ let rec exprToContextPath (e : Parsetree.expression) = | Pexp_constant (Pconst_string _) -> Some Completable.CPString | Pexp_constant (Pconst_integer _) -> Some CPInt | Pexp_constant (Pconst_float _) -> Some CPFloat + | Pexp_construct ({txt = Lident ("true" | "false")}, None) -> Some CPBool | Pexp_array exprs -> Some (CPArray @@ -271,30 +272,38 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor ~text = scope := !scope |> Scope.addValue ~name:vd.pval_name.txt ~loc:vd.pval_name.loc in - let rec scopePattern (pat : Parsetree.pattern) = + let rec scopePattern ?contextPath (pat : Parsetree.pattern) = match pat.ppat_desc with | Ppat_any -> () - | Ppat_var {txt; loc} -> scope := !scope |> Scope.addValue ~name:txt ~loc + | Ppat_var {txt; loc} -> + scope := !scope |> Scope.addValue ~name:txt ~loc ?contextPath | Ppat_alias (p, asA) -> scopePattern p; - scope := !scope |> Scope.addValue ~name:asA.txt ~loc:asA.loc + scope := + !scope + |> Scope.addValue ~name:asA.txt ~loc:asA.loc + ?contextPath: + (match p with + | {ppat_desc = Ppat_var {txt}} -> Some (CPId ([txt], Value)) + | _ -> None) | Ppat_constant _ | Ppat_interval _ -> () - | Ppat_tuple pl -> pl |> List.iter scopePattern + | Ppat_tuple pl -> pl |> List.iter (scopePattern ?contextPath) | Ppat_construct (_, None) -> () - | Ppat_construct (_, Some p) -> scopePattern p + | Ppat_construct (_, Some p) -> scopePattern ?contextPath p | Ppat_variant (_, None) -> () - | Ppat_variant (_, Some p) -> scopePattern p + | Ppat_variant (_, Some p) -> scopePattern ?contextPath p | Ppat_record (fields, _) -> - fields |> List.iter (fun (_, p) -> scopePattern p) - | Ppat_array pl -> pl |> List.iter scopePattern - | Ppat_or (p1, _) -> scopePattern p1 - | Ppat_constraint (p, _) -> scopePattern p + fields |> List.iter (fun (_, p) -> scopePattern ?contextPath p) + | Ppat_array pl -> pl |> List.iter (scopePattern ?contextPath) + | Ppat_or (p1, _) -> scopePattern ?contextPath p1 + | Ppat_constraint (p, _) -> scopePattern ?contextPath p | Ppat_type _ -> () - | Ppat_lazy p -> scopePattern p - | Ppat_unpack {txt; loc} -> scope := !scope |> Scope.addValue ~name:txt ~loc - | Ppat_exception p -> scopePattern p + | Ppat_lazy p -> scopePattern ?contextPath p + | Ppat_unpack {txt; loc} -> + scope := !scope |> Scope.addValue ~name:txt ~loc ?contextPath + | Ppat_exception p -> scopePattern ?contextPath p | Ppat_extension _ -> () - | Ppat_open (_, p) -> scopePattern p + | Ppat_open (_, p) -> scopePattern ?contextPath p in let lookingForPat = ref None in @@ -322,7 +331,8 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor ~text = | _ -> () in let scopeValueBinding (vb : Parsetree.value_binding) = - scopePattern vb.pvb_pat + let contextPath = exprToContextPath vb.pvb_expr in + scopePattern ?contextPath vb.pvb_pat in let scopeTypeKind (tk : Parsetree.type_kind) = match tk with diff --git a/analysis/src/Scope.ml b/analysis/src/Scope.ml index abd44a360..8fb6a594b 100644 --- a/analysis/src/Scope.ml +++ b/analysis/src/Scope.ml @@ -4,7 +4,7 @@ type item = | Module of string * Location.t | Open of string list | Type of string * Location.t - | Value of string * Location.t + | Value of string * Location.t * SharedTypes.Completable.contextPath option type t = item list @@ -16,7 +16,7 @@ let itemToString item = | Field (s, loc) -> "Field " ^ s ^ " " ^ Loc.toString loc | Open sl -> "Open " ^ list sl | Module (s, loc) -> "Module " ^ s ^ " " ^ Loc.toString loc - | Value (s, loc) -> "Value " ^ s ^ " " ^ Loc.toString loc + | Value (s, loc, _) -> "Value " ^ s ^ " " ^ Loc.toString loc | Type (s, loc) -> "Type " ^ s ^ " " ^ Loc.toString loc [@@live] @@ -25,14 +25,23 @@ let addConstructor ~name ~loc x = Constructor (name, loc) :: x let addField ~name ~loc x = Field (name, loc) :: x let addModule ~name ~loc x = Module (name, loc) :: x let addOpen ~lid x = Open (Utils.flattenLongIdent lid @ ["place holder"]) :: x -let addValue ~name ~loc x = Value (name, loc) :: x +let addValue ~name ~loc ?contextPath x = + let showDebug = Cfg.debugFollowCtxPath in + (if showDebug then + match contextPath with + | None -> Printf.printf "adding value '%s', no ctxPath\n" name + | Some contextPath -> + if showDebug then + Printf.printf "adding value '%s' with ctxPath: %s\n" name + (SharedTypes.Completable.contextPathToString contextPath)); + Value (name, loc, contextPath) :: x let addType ~name ~loc x = Type (name, loc) :: x let iterValuesBeforeFirstOpen f x = let rec loop items = match items with - | Value (s, loc) :: rest -> - f s loc; + | Value (s, loc, contextPath) :: rest -> + f s loc contextPath; loop rest | Open _ :: _ -> () | _ :: rest -> loop rest @@ -43,8 +52,8 @@ let iterValuesBeforeFirstOpen f x = let iterValuesAfterFirstOpen f x = let rec loop foundOpen items = match items with - | Value (s, loc) :: rest -> - if foundOpen then f s loc; + | Value (s, loc, contextPath) :: rest -> + if foundOpen then f s loc contextPath; loop foundOpen rest | Open _ :: rest -> loop true rest | _ :: rest -> loop foundOpen rest diff --git a/analysis/src/SharedTypes.ml b/analysis/src/SharedTypes.ml index 524661503..39b41aae9 100644 --- a/analysis/src/SharedTypes.ml +++ b/analysis/src/SharedTypes.ml @@ -327,77 +327,6 @@ type completionType = | TinlineRecord of {env: QueryEnv.t; fields: field list} | Tfunction of {env: QueryEnv.t; args: typedFnArg list; typ: Types.type_expr} -module Completion = struct - type kind = - | Module of Module.t - | Value of Types.type_expr - | ObjLabel of Types.type_expr - | Label of string - | Type of Type.t - | Constructor of Constructor.t * string - | PolyvariantConstructor of polyVariantConstructor * string - | Field of field * string - | FileModule of string - | Snippet of string - | ExtractedType of completionType * [`Value | `Type] - - type t = { - name: string; - sortText: string option; - insertText: string option; - filterText: string option; - insertTextFormat: Protocol.insertTextFormat option; - env: QueryEnv.t; - deprecated: string option; - docstring: string list; - kind: kind; - detail: string option; - } - - let create ~kind ~env ?(docstring = []) ?insertText ?deprecated ?detail name = - { - name; - env; - deprecated; - docstring; - kind; - sortText = None; - insertText; - insertTextFormat = None; - filterText = None; - detail; - } - - let createWithSnippet ~name ?insertText ~kind ~env ?sortText ?deprecated - ?(docstring = []) () = - { - name; - env; - deprecated; - docstring; - kind; - sortText; - insertText; - insertTextFormat = Some Protocol.Snippet; - filterText = None; - detail = None; - } - - (* https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_completion *) - (* https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#completionItemKind *) - let kindToInt kind = - match kind with - | Module _ -> 9 - | FileModule _ -> 9 - | Constructor (_, _) | PolyvariantConstructor (_, _) -> 4 - | ObjLabel _ -> 4 - | Label _ -> 4 - | Field (_, _) -> 5 - | Type _ | ExtractedType (_, `Type) -> 22 - | Value _ | ExtractedType (_, `Value) -> 12 - | Snippet _ -> 15 -end - module Env = struct type t = {stamps: Stamps.t; modulePath: ModulePath.t} let addExportedModule ~name ~isType env = @@ -596,6 +525,7 @@ module Completable = struct | CPArray of contextPath option | CPInt | CPFloat + | CPBool | CPOption of contextPath | CPApply of contextPath * Asttypes.arg_label list | CPId of string list * completionContext @@ -663,56 +593,54 @@ module Completable = struct | CexhaustiveSwitch of {contextPath: contextPath; exprLoc: Location.t} | ChtmlElement of {prefix: string} - let toString = - let completionContextToString = function - | Value -> "Value" - | Type -> "Type" - | Module -> "Module" - | Field -> "Field" - in - let rec contextPathToString = function - | CPString -> "string" - | CPInt -> "int" - | CPFloat -> "float" - | CPOption ctxPath -> "option<" ^ contextPathToString ctxPath ^ ">" - | CPApply (cp, labels) -> - contextPathToString cp ^ "(" - ^ (labels - |> List.map (function - | Asttypes.Nolabel -> "Nolabel" - | Labelled s -> "~" ^ s - | Optional s -> "?" ^ s) - |> String.concat ", ") - ^ ")" - | CPArray (Some ctxPath) -> "array<" ^ contextPathToString ctxPath ^ ">" - | CPArray None -> "array" - | CPId (sl, completionContext) -> - completionContextToString completionContext ^ list sl - | CPField (cp, s) -> contextPathToString cp ^ "." ^ str s - | CPObj (cp, s) -> contextPathToString cp ^ "[\"" ^ s ^ "\"]" - | CPPipe {contextPath; id; inJsx} -> - contextPathToString contextPath - ^ "->" ^ id - ^ if inJsx then " <>" else "" - | CTuple ctxPaths -> - "CTuple(" - ^ (ctxPaths |> List.map contextPathToString |> String.concat ", ") - ^ ")" - | CArgument {functionContextPath; argumentLabel} -> - "CArgument " - ^ contextPathToString functionContextPath - ^ "(" - ^ (match argumentLabel with - | Unlabelled {argumentPosition} -> - "$" ^ string_of_int argumentPosition - | Labelled name -> "~" ^ name - | Optional name -> "~" ^ name ^ "=?") - ^ ")" - | CJsxPropValue {pathToComponent; propName} -> - "CJsxPropValue " ^ (pathToComponent |> list) ^ " " ^ propName - in + let completionContextToString = function + | Value -> "Value" + | Type -> "Type" + | Module -> "Module" + | Field -> "Field" + + let rec contextPathToString = function + | CPString -> "string" + | CPInt -> "int" + | CPFloat -> "float" + | CPBool -> "bool" + | CPOption ctxPath -> "option<" ^ contextPathToString ctxPath ^ ">" + | CPApply (cp, labels) -> + contextPathToString cp ^ "(" + ^ (labels + |> List.map (function + | Asttypes.Nolabel -> "Nolabel" + | Labelled s -> "~" ^ s + | Optional s -> "?" ^ s) + |> String.concat ", ") + ^ ")" + | CPArray (Some ctxPath) -> "array<" ^ contextPathToString ctxPath ^ ">" + | CPArray None -> "array" + | CPId (sl, completionContext) -> + completionContextToString completionContext ^ list sl + | CPField (cp, s) -> contextPathToString cp ^ "." ^ str s + | CPObj (cp, s) -> contextPathToString cp ^ "[\"" ^ s ^ "\"]" + | CPPipe {contextPath; id; inJsx} -> + contextPathToString contextPath + ^ "->" ^ id + ^ if inJsx then " <>" else "" + | CTuple ctxPaths -> + "CTuple(" + ^ (ctxPaths |> List.map contextPathToString |> String.concat ", ") + ^ ")" + | CArgument {functionContextPath; argumentLabel} -> + "CArgument " + ^ contextPathToString functionContextPath + ^ "(" + ^ (match argumentLabel with + | Unlabelled {argumentPosition} -> "$" ^ string_of_int argumentPosition + | Labelled name -> "~" ^ name + | Optional name -> "~" ^ name ^ "=?") + ^ ")" + | CJsxPropValue {pathToComponent; propName} -> + "CJsxPropValue " ^ (pathToComponent |> list) ^ " " ^ propName - function + let toString = function | Cpath cp -> "Cpath " ^ contextPathToString cp | Cdecorator s -> "Cdecorator(" ^ str s ^ ")" | CnamedArg (cp, s, sl2) -> @@ -751,6 +679,79 @@ module Completable = struct | ChtmlElement {prefix} -> "ChtmlElement <" ^ prefix end +module Completion = struct + type kind = + | Module of Module.t + | Value of Types.type_expr + | ObjLabel of Types.type_expr + | Label of string + | Type of Type.t + | Constructor of Constructor.t * string + | PolyvariantConstructor of polyVariantConstructor * string + | Field of field * string + | FileModule of string + | Snippet of string + | ExtractedType of completionType * [`Value | `Type] + | FollowContextPath of Completable.contextPath + + type t = { + name: string; + sortText: string option; + insertText: string option; + filterText: string option; + insertTextFormat: Protocol.insertTextFormat option; + env: QueryEnv.t; + deprecated: string option; + docstring: string list; + kind: kind; + detail: string option; + } + + let create ~kind ~env ?(docstring = []) ?filterText ?detail ?deprecated + ?insertText name = + { + name; + env; + deprecated; + docstring; + kind; + sortText = None; + insertText; + insertTextFormat = None; + filterText; + detail; + } + + let createWithSnippet ~name ?insertText ~kind ~env ?sortText ?filterText + ?detail ?(docstring = []) () = + { + name; + env; + deprecated = None; + docstring; + kind; + sortText; + insertText; + insertTextFormat = Some Protocol.Snippet; + filterText; + detail; + } + + (* https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_completion *) + (* https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#completionItemKind *) + let kindToInt kind = + match kind with + | Module _ -> 9 + | FileModule _ -> 9 + | Constructor (_, _) | PolyvariantConstructor (_, _) -> 4 + | ObjLabel _ -> 4 + | Label _ -> 4 + | Field (_, _) -> 5 + | Type _ | ExtractedType (_, `Type) -> 22 + | Value _ | ExtractedType (_, `Value) -> 12 + | Snippet _ | FollowContextPath _ -> 15 +end + module CursorPosition = struct type t = NoCursor | HasCursor | EmptyLoc diff --git a/analysis/tests/src/CompletionInferValues.res b/analysis/tests/src/CompletionInferValues.res new file mode 100644 index 000000000..5dbba7b65 --- /dev/null +++ b/analysis/tests/src/CompletionInferValues.res @@ -0,0 +1,23 @@ +let getBool = () => true +let getInt = () => 123 + +type someRecord = {name: string, age: int} + +let someFnWithCallback = (cb: (~num: int, ~someRecord: someRecord, ~isOn: bool) => unit) => { + let _ = cb +} + +let reactEventFn = (cb: someRecord => unit) => { + let _ = cb +} + +@val external getSomeRecord: unit => someRecord = "getSomeRecord" + +// let x = 123; let aliased = x; aliased->f +// ^com + +// let x = getSomeRecord(); x. +// ^com + +// let x = getSomeRecord(); let aliased = x; aliased. +// ^com diff --git a/analysis/tests/src/expected/CompletionInferValues.res.txt b/analysis/tests/src/expected/CompletionInferValues.res.txt new file mode 100644 index 000000000..01d2583a9 --- /dev/null +++ b/analysis/tests/src/expected/CompletionInferValues.res.txt @@ -0,0 +1,53 @@ +Complete src/CompletionInferValues.res 15:43 +posCursor:[15:43] posNoWhite:[15:42] Found expr:[15:33->15:43] +Completable: Cpath Value[aliased]->f +[{ + "label": "Belt.Int.fromString", + "kind": 12, + "tags": [], + "detail": "string => option", + "documentation": {"kind": "markdown", "value": "\n Converts a given `string` to an `int`. Returns `Some(int)` when the input is a number, `None` otherwise.\n\n ```res example\n Js.log(Belt.Int.fromString(\"1\") === Some(1)) /* true */\n ```\n"} + }, { + "label": "Belt.Int.fromFloat", + "kind": 12, + "tags": [], + "detail": "float => int", + "documentation": {"kind": "markdown", "value": "\n Converts a given `float` to an `int`.\n\n ```res example\n Js.log(Belt.Int.fromFloat(1.0) === 1) /* true */\n ```\n"} + }] + +Complete src/CompletionInferValues.res 18:30 +posCursor:[18:30] posNoWhite:[18:29] Found expr:[18:28->18:30] +Pexp_field [18:28->18:29] _:[24:0->18:30] +Completable: Cpath Value[x]."" +[{ + "label": "name", + "kind": 5, + "tags": [], + "detail": "name: string\n\ntype someRecord = {name: string, age: int}", + "documentation": null + }, { + "label": "age", + "kind": 5, + "tags": [], + "detail": "age: int\n\ntype someRecord = {name: string, age: int}", + "documentation": null + }] + +Complete src/CompletionInferValues.res 21:53 +posCursor:[21:53] posNoWhite:[21:52] Found expr:[21:45->21:53] +Pexp_field [21:45->21:52] _:[24:0->21:53] +Completable: Cpath Value[aliased]."" +[{ + "label": "name", + "kind": 5, + "tags": [], + "detail": "name: string\n\ntype someRecord = {name: string, age: int}", + "documentation": null + }, { + "label": "age", + "kind": 5, + "tags": [], + "detail": "age: int\n\ntype someRecord = {name: string, age: int}", + "documentation": null + }] + From 0a1a7c7eb4c0ce0346b8168683bb1621bff404be Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Tue, 24 Jan 2023 21:55:17 +0100 Subject: [PATCH 02/41] add (mostly working) moving into function arguments --- analysis/src/Cfg.ml | 2 +- analysis/src/CompletionBackEnd.ml | 14 +-- analysis/src/CompletionFrontEnd.ml | 99 +++++++++++++++++-- analysis/src/Scope.ml | 2 +- analysis/tests/src/CompletionInferValues.res | 12 ++- .../expected/CompletionInferValues.res.txt | 52 +++++++++- analysis/tests/src/expected/Jsx2.res.txt | 6 ++ 7 files changed, 166 insertions(+), 21 deletions(-) diff --git a/analysis/src/Cfg.ml b/analysis/src/Cfg.ml index 0ca7d35ab..38b3e9aa7 100644 --- a/analysis/src/Cfg.ml +++ b/analysis/src/Cfg.ml @@ -1,3 +1,3 @@ let supportsSnippets = ref false -let debugFollowCtxPath = false +let debugFollowCtxPath = ref false diff --git a/analysis/src/CompletionBackEnd.ml b/analysis/src/CompletionBackEnd.ml index eddfb4f17..0c828199e 100644 --- a/analysis/src/CompletionBackEnd.ml +++ b/analysis/src/CompletionBackEnd.ml @@ -1023,12 +1023,14 @@ and getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env let targetLabel = labels |> List.find_opt (fun (label, _) -> - match argumentLabel with - | Unlabelled _ -> label = argumentLabel - | Labelled name | Optional name -> ( - match label with - | (Labelled n | Optional n) when name = n -> true - | _ -> false)) + match (argumentLabel, label) with + | ( Unlabelled {argumentPosition = pos1}, + Completable.Unlabelled {argumentPosition = pos2} ) -> + pos1 = pos2 + | ( (Labelled name1 | Optional name1), + (Labelled name2 | Optional name2) ) -> + name1 = name2 + | _ -> false) in let expandOption = match targetLabel with diff --git a/analysis/src/CompletionFrontEnd.ml b/analysis/src/CompletionFrontEnd.ml index 2ebe91915..b9783ee22 100644 --- a/analysis/src/CompletionFrontEnd.ml +++ b/analysis/src/CompletionFrontEnd.ml @@ -258,6 +258,25 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor ~text = Utils.flattenLongIdent ~cutAtOffset ~jsx lid.txt in + let currentCtxPath = ref None in + let setCurrentCtxPath ctxPath = + if !Cfg.debugFollowCtxPath then + Printf.printf "setting current ctxPath: %s\n" + (Completable.contextPathToString ctxPath); + currentCtxPath := Some ctxPath + in + let resetCurrentCtxPath ctxPath = + (match (!currentCtxPath, ctxPath) with + | None, None -> () + | _ -> + if !Cfg.debugFollowCtxPath then + Printf.printf "resetting current ctxPath to: %s\n" + (match ctxPath with + | None -> "None" + | Some ctxPath -> Completable.contextPathToString ctxPath)); + currentCtxPath := ctxPath + in + let found = ref false in let result = ref None in let scope = ref (Scope.create ()) in @@ -443,7 +462,7 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor ~text = let case (iterator : Ast_iterator.iterator) (case : Parsetree.case) = let oldScope = !scope in - scopePattern case.pc_lhs; + scopePattern ?contextPath:!currentCtxPath case.pc_lhs; completePattern case.pc_lhs; Ast_iterator.default_iterator.case iterator case; scope := oldScope @@ -619,7 +638,34 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor ~text = | _ -> ()); Ast_iterator.default_iterator.attribute iterator (id, payload) in - let expr (iterator : Ast_iterator.iterator) (expr : Parsetree.expression) = + let rec iterateFnArguments ~args ~iterator ~isPipe + (argCompletable : Completable.t option) = + match argCompletable with + | None -> ( + match !currentCtxPath with + | None -> () + | Some functionContextPath -> + let currentUnlabelledCount = ref (if isPipe then 1 else 0) in + args + |> List.iter (fun (arg : arg) -> + let previousCtxPath = !currentCtxPath in + setCurrentCtxPath + (CArgument + { + functionContextPath; + argumentLabel = + (match arg with + | {label = None} -> + let current = !currentUnlabelledCount in + currentUnlabelledCount := current + 1; + Unlabelled {argumentPosition = current} + | {label = Some {name; opt = true}} -> Optional name + | {label = Some {name; opt = false}} -> Labelled name); + }); + expr iterator arg.exp; + resetCurrentCtxPath previousCtxPath)) + | Some argCompletable -> setResult argCompletable + and expr (iterator : Ast_iterator.iterator) (expr : Parsetree.expression) = let oldInJsxContext = !inJsxContext in let processed = ref false in let setFound () = @@ -773,7 +819,7 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor ~text = But it should not fire in foo(~a)<---there *) not (Loc.end_ expr.pexp_loc = posCursor - && charBeforeCursor = Some ')') -> + && charBeforeCursor = Some ')') -> ( (* Complete fn argument values and named args when the fn call is piped. E.g. someVar->someFn(). *) let args = extractExpApplyArgs ~args in let argCompletable = @@ -786,15 +832,23 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor ~text = ~firstCharBeforeCursorNoWhite | None -> None in - - setResultOpt argCompletable + match argCompletable with + | None -> ( + match exprToContextPath funExpr with + | None -> () + | Some funCtxPath -> + let oldCtxPath = !currentCtxPath in + setCurrentCtxPath funCtxPath; + argCompletable |> iterateFnArguments ~isPipe:true ~args ~iterator; + resetCurrentCtxPath oldCtxPath) + | Some argCompletable -> setResult argCompletable) | Pexp_apply ({pexp_desc = Pexp_ident {txt = Lident "|."}}, [_; _]) -> (* Ignore any other pipe. *) () | Pexp_apply (funExpr, args) when not (Loc.end_ expr.pexp_loc = posCursor - && charBeforeCursor = Some ')') -> + && charBeforeCursor = Some ')') -> ( (* Complete fn argument values and named args when the fn call is _not_ piped. E.g. someFn(). *) let args = extractExpApplyArgs ~args in if debug then @@ -822,8 +876,16 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor ~text = ~firstCharBeforeCursorNoWhite | None -> None in - - setResultOpt argCompletable + match argCompletable with + | None -> ( + match exprToContextPath funExpr with + | None -> () + | Some funCtxPath -> + let oldCtxPath = !currentCtxPath in + setCurrentCtxPath funCtxPath; + argCompletable |> iterateFnArguments ~isPipe:false ~args ~iterator; + resetCurrentCtxPath oldCtxPath) + | Some argCompletable -> setResult argCompletable) | Pexp_send (lhs, {txt; loc}) -> ( (* e["txt"] If the string for txt is not closed, it could go over several lines. @@ -850,16 +912,33 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor ~text = match exprToContextPath lhs with | Some contextPath -> setResult (Cpath (CPObj (contextPath, label))) | None -> ()) - | Pexp_fun (_lbl, defaultExpOpt, pat, e) -> + | Pexp_fun (lbl, defaultExpOpt, pat, e) -> let oldScope = !scope in + let oldCtxPath = !currentCtxPath in + (* TODO: Haven't figured out how to count unlabelled args here yet... *) + (* TODO: This is broken *) + (match !currentCtxPath with + | None -> () + | Some ctxPath -> + setCurrentCtxPath + (CArgument + { + functionContextPath = ctxPath; + argumentLabel = + (match lbl with + | Nolabel -> Unlabelled {argumentPosition = 0} + | Optional name -> Optional name + | Labelled name -> Labelled name); + })); (match defaultExpOpt with | None -> () | Some defaultExp -> iterator.expr iterator defaultExp); - scopePattern pat; + scopePattern ?contextPath:!currentCtxPath pat; completePattern pat; iterator.pat iterator pat; iterator.expr iterator e; scope := oldScope; + resetCurrentCtxPath oldCtxPath; processed := true | Pexp_let (recFlag, bindings, e) -> let oldScope = !scope in diff --git a/analysis/src/Scope.ml b/analysis/src/Scope.ml index 8fb6a594b..5251486f8 100644 --- a/analysis/src/Scope.ml +++ b/analysis/src/Scope.ml @@ -26,7 +26,7 @@ let addField ~name ~loc x = Field (name, loc) :: x let addModule ~name ~loc x = Module (name, loc) :: x let addOpen ~lid x = Open (Utils.flattenLongIdent lid @ ["place holder"]) :: x let addValue ~name ~loc ?contextPath x = - let showDebug = Cfg.debugFollowCtxPath in + let showDebug = !Cfg.debugFollowCtxPath in (if showDebug then match contextPath with | None -> Printf.printf "adding value '%s', no ctxPath\n" name diff --git a/analysis/tests/src/CompletionInferValues.res b/analysis/tests/src/CompletionInferValues.res index 5dbba7b65..cb06a0256 100644 --- a/analysis/tests/src/CompletionInferValues.res +++ b/analysis/tests/src/CompletionInferValues.res @@ -7,7 +7,7 @@ let someFnWithCallback = (cb: (~num: int, ~someRecord: someRecord, ~isOn: bool) let _ = cb } -let reactEventFn = (cb: someRecord => unit) => { +let reactEventFn = (cb: ReactEvent.Mouse.t => unit) => { let _ = cb } @@ -21,3 +21,13 @@ let reactEventFn = (cb: someRecord => unit) => { // let x = getSomeRecord(); let aliased = x; aliased. // ^com + +// someFnWithCallback((~someRecord, ~num, ~isOn) => someRecord.) +// ^com + +// Broken because not using the first argument (argument context seems to pile on when they should be plucked off and new one added) +// let aliasedFn = someFnWithCallback; aliasedFn((~num, ~someRecord, ~isOn) => someRecord.) +// ^com + +// reactEventFn(event => { event->pr }); +// ^com diff --git a/analysis/tests/src/expected/CompletionInferValues.res.txt b/analysis/tests/src/expected/CompletionInferValues.res.txt index 01d2583a9..90d9c0693 100644 --- a/analysis/tests/src/expected/CompletionInferValues.res.txt +++ b/analysis/tests/src/expected/CompletionInferValues.res.txt @@ -17,7 +17,7 @@ Completable: Cpath Value[aliased]->f Complete src/CompletionInferValues.res 18:30 posCursor:[18:30] posNoWhite:[18:29] Found expr:[18:28->18:30] -Pexp_field [18:28->18:29] _:[24:0->18:30] +Pexp_field [18:28->18:29] _:[34:0->18:30] Completable: Cpath Value[x]."" [{ "label": "name", @@ -35,7 +35,7 @@ Completable: Cpath Value[x]."" Complete src/CompletionInferValues.res 21:53 posCursor:[21:53] posNoWhite:[21:52] Found expr:[21:45->21:53] -Pexp_field [21:45->21:52] _:[24:0->21:53] +Pexp_field [21:45->21:52] _:[34:0->21:53] Completable: Cpath Value[aliased]."" [{ "label": "name", @@ -51,3 +51,51 @@ Completable: Cpath Value[aliased]."" "documentation": null }] +Complete src/CompletionInferValues.res 24:63 +posCursor:[24:63] posNoWhite:[24:62] Found expr:[24:3->24:64] +Pexp_apply ...[24:3->24:21] (...[24:22->24:63]) +posCursor:[24:63] posNoWhite:[24:62] Found expr:[24:22->24:63] +posCursor:[24:63] posNoWhite:[24:62] Found expr:[24:36->24:63] +posCursor:[24:63] posNoWhite:[24:62] Found expr:[24:42->24:63] +posCursor:[24:63] posNoWhite:[24:62] Found expr:[24:52->24:63] +Pexp_field [24:52->24:62] _:[24:63->24:63] +Completable: Cpath Value[someRecord]."" +[{ + "label": "name", + "kind": 5, + "tags": [], + "detail": "name: string\n\ntype someRecord = {name: string, age: int}", + "documentation": null + }, { + "label": "age", + "kind": 5, + "tags": [], + "detail": "age: int\n\ntype someRecord = {name: string, age: int}", + "documentation": null + }] + +Complete src/CompletionInferValues.res 28:90 +posCursor:[28:90] posNoWhite:[28:89] Found expr:[28:39->28:91] +Pexp_apply ...[28:39->28:48] (...[28:49->28:90]) +posCursor:[28:90] posNoWhite:[28:89] Found expr:[28:49->28:90] +posCursor:[28:90] posNoWhite:[28:89] Found expr:[28:56->28:90] +posCursor:[28:90] posNoWhite:[28:89] Found expr:[28:69->28:90] +posCursor:[28:90] posNoWhite:[28:89] Found expr:[28:79->28:90] +Pexp_field [28:79->28:89] _:[28:90->28:90] +Completable: Cpath Value[someRecord]."" +[] + +Complete src/CompletionInferValues.res 31:36 +posCursor:[31:36] posNoWhite:[31:35] Found expr:[31:3->31:39] +Pexp_apply ...[31:3->31:15] (...[31:16->31:38]) +posCursor:[31:36] posNoWhite:[31:35] Found expr:[31:16->31:38] +posCursor:[31:36] posNoWhite:[31:35] Found expr:[31:27->31:36] +Completable: Cpath Value[event]->pr +[{ + "label": "ReactEvent.Mouse.preventDefault", + "kind": 12, + "tags": [], + "detail": "t => unit", + "documentation": null + }] + diff --git a/analysis/tests/src/expected/Jsx2.res.txt b/analysis/tests/src/expected/Jsx2.res.txt index 5cd54d307..412f41045 100644 --- a/analysis/tests/src/expected/Jsx2.res.txt +++ b/analysis/tests/src/expected/Jsx2.res.txt @@ -257,6 +257,12 @@ posCursor:[80:6] posNoWhite:[80:5] Found expr:[80:5->83:20] Pexp_construct :::[83:0->83:20] [83:0->83:20] posCursor:[80:6] posNoWhite:[80:5] Found expr:__ghost__[80:5->83:20] Pexp_construct []:__ghost__[80:5->83:20] None +posCursor:[80:6] posNoWhite:[80:5] Found expr:[80:4->83:19] +JSX 80:5] > _children:80:5 +posCursor:[80:6] posNoWhite:[80:5] Found expr:[80:5->83:20] +Pexp_construct :::[83:0->83:20] [83:0->83:20] +posCursor:[80:6] posNoWhite:[80:5] Found expr:__ghost__[80:5->83:20] +Pexp_construct []:__ghost__[80:5->83:20] None [] Complete src/Jsx2.res 89:16 From dc4b99958c43a5dc1d9bc346d865c9453cfe6b1b Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Tue, 24 Jan 2023 22:43:02 +0100 Subject: [PATCH 03/41] handle jsx context --- analysis/src/CompletionBackEnd.ml | 10 +++---- analysis/src/CompletionFrontEnd.ml | 14 ++++++++++ analysis/tests/src/CompletionInferValues.res | 14 ++++++++++ .../tests/src/expected/Completion.res.txt | 3 ++ .../expected/CompletionInferValues.res.txt | 28 +++++++++++++++++++ .../tests/src/expected/RecoveryOnProp.res.txt | 3 ++ 6 files changed, 67 insertions(+), 5 deletions(-) diff --git a/analysis/src/CompletionBackEnd.ml b/analysis/src/CompletionBackEnd.ml index 0c828199e..9d402f6c3 100644 --- a/analysis/src/CompletionBackEnd.ml +++ b/analysis/src/CompletionBackEnd.ml @@ -978,25 +978,25 @@ and getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env in let targetLabel = if lowercaseComponent then - let rec digToTypeForCompletion path ~env = + let rec digToTypeForCompletion path = match path |> getCompletionsForPath ~completionContext:Type ~exact:true ~package ~opens ~allFiles ~pos ~env ~scope with - | {kind = Type {kind = Abstract (Some (p, _))}; env} :: _ -> + | {kind = Type {kind = Abstract (Some (p, _))}} :: _ -> (* This case happens when what we're looking for is a type alias. This is the case in newer rescript-react versions where ReactDOM.domProps is an alias for JsxEvent.t. *) let pathRev = p |> Utils.expandPath in - pathRev |> List.rev |> digToTypeForCompletion ~env - | {kind = Type {kind = Record fields}; env} :: _ -> ( + pathRev |> List.rev |> digToTypeForCompletion + | {kind = Type {kind = Record fields}} :: _ -> ( match fields |> List.find_opt (fun f -> f.fname.txt = propName) with | None -> None | Some f -> Some (f.fname.txt, f.typ, env)) | _ -> None in - ["ReactDOM"; "domProps"] |> digToTypeForCompletion ~env + ["ReactDOM"; "domProps"] |> digToTypeForCompletion else CompletionJsx.getJsxLabels ~componentPath:pathToComponent ~findTypeOfValue ~package diff --git a/analysis/src/CompletionFrontEnd.ml b/analysis/src/CompletionFrontEnd.ml index b9783ee22..6b80fb3e2 100644 --- a/analysis/src/CompletionFrontEnd.ml +++ b/analysis/src/CompletionFrontEnd.ml @@ -665,6 +665,19 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor ~text = expr iterator arg.exp; resetCurrentCtxPath previousCtxPath)) | Some argCompletable -> setResult argCompletable + and iterateJsxProps ~iterator (props : CompletionJsx.jsxProps) = + props.props + |> List.iter (fun (prop : CompletionJsx.prop) -> + let previousCtxPath = !currentCtxPath in + setCurrentCtxPath + (CJsxPropValue + { + pathToComponent = + Utils.flattenLongIdent ~jsx:true props.compName.txt; + propName = prop.name; + }); + expr iterator prop.exp; + resetCurrentCtxPath previousCtxPath) and expr (iterator : Ast_iterator.iterator) (expr : Parsetree.expression) = let oldInJsxContext = !inJsxContext in let processed = ref false in @@ -796,6 +809,7 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor ~text = | [prefix] when Char.lowercase_ascii prefix.[0] = prefix.[0] -> ChtmlElement {prefix} | _ -> Cpath (CPId (compNamePath, Module))) + else iterateJsxProps ~iterator jsxProps | Pexp_apply ( {pexp_desc = Pexp_ident {txt = Lident "|."}}, [ diff --git a/analysis/tests/src/CompletionInferValues.res b/analysis/tests/src/CompletionInferValues.res index cb06a0256..41ab8efb3 100644 --- a/analysis/tests/src/CompletionInferValues.res +++ b/analysis/tests/src/CompletionInferValues.res @@ -31,3 +31,17 @@ let reactEventFn = (cb: ReactEvent.Mouse.t => unit) => { // reactEventFn(event => { event->pr }); // ^com + +module Div = { + @react.component + let make = (~onMouseEnter: option unit>=?) => { + let _ = onMouseEnter + React.null + } +} + +// let _ =
{ event->pr }} /> +// ^com + +// let _ =
{ event->pr }} /> +// ^com diff --git a/analysis/tests/src/expected/Completion.res.txt b/analysis/tests/src/expected/Completion.res.txt index c98e1a2c8..c7a4bce5e 100644 --- a/analysis/tests/src/expected/Completion.res.txt +++ b/analysis/tests/src/expected/Completion.res.txt @@ -1364,6 +1364,9 @@ posCursor:[336:26] posNoWhite:[336:25] Found expr:[336:16->338:5] posCursor:[336:26] posNoWhite:[336:25] Found pattern:[336:20->338:5] posCursor:[336:26] posNoWhite:[336:25] Found type:[336:23->338:5] Ptyp_constr Res:[336:23->338:5] +posCursor:[336:26] posNoWhite:[336:25] Found pattern:[336:20->338:5] +posCursor:[336:26] posNoWhite:[336:25] Found type:[336:23->338:5] +Ptyp_constr Res:[336:23->338:5] Completable: Cpath Type[Res] Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder Resolved opens 2 Completion.res Completion.res diff --git a/analysis/tests/src/expected/CompletionInferValues.res.txt b/analysis/tests/src/expected/CompletionInferValues.res.txt index 90d9c0693..b98d25657 100644 --- a/analysis/tests/src/expected/CompletionInferValues.res.txt +++ b/analysis/tests/src/expected/CompletionInferValues.res.txt @@ -99,3 +99,31 @@ Completable: Cpath Value[event]->pr "documentation": null }] +Complete src/CompletionInferValues.res 42:50 +posCursor:[42:50] posNoWhite:[42:49] Found expr:[42:12->42:56] +JSX 42:15] onMouseEnter[42:16->42:28]=...[42:36->42:52]> _children:42:54 +posCursor:[42:50] posNoWhite:[42:49] Found expr:[42:36->42:52] +posCursor:[42:50] posNoWhite:[42:49] Found expr:[42:41->42:50] +Completable: Cpath Value[event]->pr <> +[{ + "label": "JsxEvent.Mouse.preventDefault", + "kind": 12, + "tags": [], + "detail": "t => unit", + "documentation": null + }] + +Complete src/CompletionInferValues.res 45:50 +posCursor:[45:50] posNoWhite:[45:49] Found expr:[45:12->45:56] +JSX 45:15] onMouseEnter[45:16->45:28]=...[45:36->45:52]> _children:45:54 +posCursor:[45:50] posNoWhite:[45:49] Found expr:[45:36->45:52] +posCursor:[45:50] posNoWhite:[45:49] Found expr:[45:41->45:50] +Completable: Cpath Value[event]->pr <> +[{ + "label": "JsxEvent.Mouse.preventDefault", + "kind": 12, + "tags": [], + "detail": "t => unit", + "documentation": null + }] + diff --git a/analysis/tests/src/expected/RecoveryOnProp.res.txt b/analysis/tests/src/expected/RecoveryOnProp.res.txt index fe509d768..950a49bfc 100644 --- a/analysis/tests/src/expected/RecoveryOnProp.res.txt +++ b/analysis/tests/src/expected/RecoveryOnProp.res.txt @@ -7,6 +7,9 @@ posCursor:[6:26] posNoWhite:[6:25] Found expr:[6:16->8:5] posCursor:[6:26] posNoWhite:[6:25] Found pattern:[6:20->8:5] posCursor:[6:26] posNoWhite:[6:25] Found type:[6:23->8:5] Ptyp_constr Res:[6:23->8:5] +posCursor:[6:26] posNoWhite:[6:25] Found pattern:[6:20->8:5] +posCursor:[6:26] posNoWhite:[6:25] Found type:[6:23->8:5] +Ptyp_constr Res:[6:23->8:5] Completable: Cpath Type[Res] [{ "label": "RescriptReactErrorBoundary", From 709ab034eb0362d71f9873458c4711a2dd0f40a7 Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Tue, 24 Jan 2023 22:54:17 +0100 Subject: [PATCH 04/41] add broken example test --- analysis/src/CompletionFrontEnd.ml | 7 ++++++- analysis/tests/src/CompletionInferValues.res | 4 ++++ .../tests/src/expected/CompletionInferValues.res.txt | 10 ++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/analysis/src/CompletionFrontEnd.ml b/analysis/src/CompletionFrontEnd.ml index 6b80fb3e2..2fb474dd9 100644 --- a/analysis/src/CompletionFrontEnd.ml +++ b/analysis/src/CompletionFrontEnd.ml @@ -136,6 +136,7 @@ let findArgCompletables ~(args : arg list) ~endPos ~posBeforeCursor }) | _ -> loop args +(* TODO: Mimic pipe chain detection here? *) let rec exprToContextPath (e : Parsetree.expression) = match e.pexp_desc with | Pexp_constant (Pconst_string _) -> Some Completable.CPString @@ -930,7 +931,11 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor ~text = let oldScope = !scope in let oldCtxPath = !currentCtxPath in (* TODO: Haven't figured out how to count unlabelled args here yet... *) - (* TODO: This is broken *) + (* TODO: This is broken. I'm trying to set the CArgument context path + below here continuously for each argument as I traverse the expr + for the arg, but I end up piling them on each other. So what should + be Carg $0, then Carg $1, then Carg $3... is now (faulty) Carg $0, + then Carg Carg $0 $1, then Carg Carg Carg $0 $1 $2, and so on. *) (match !currentCtxPath with | None -> () | Some ctxPath -> diff --git a/analysis/tests/src/CompletionInferValues.res b/analysis/tests/src/CompletionInferValues.res index 41ab8efb3..8387b1369 100644 --- a/analysis/tests/src/CompletionInferValues.res +++ b/analysis/tests/src/CompletionInferValues.res @@ -45,3 +45,7 @@ module Div = { // let _ =
{ event->pr }} /> // ^com + +// Pipe are broken, need to fix +// let _ =
{ let btn = event->JsxEvent.Mouse.button; btn-> }} /> +// ^com diff --git a/analysis/tests/src/expected/CompletionInferValues.res.txt b/analysis/tests/src/expected/CompletionInferValues.res.txt index b98d25657..78496b472 100644 --- a/analysis/tests/src/expected/CompletionInferValues.res.txt +++ b/analysis/tests/src/expected/CompletionInferValues.res.txt @@ -127,3 +127,13 @@ Completable: Cpath Value[event]->pr <> "documentation": null }] +Complete src/CompletionInferValues.res 49:86 +posCursor:[49:86] posNoWhite:[49:85] Found expr:[49:12->49:92] +JSX 49:15] onMouseEnter[49:16->49:28]=...[49:36->49:88]> _children:49:90 +posCursor:[49:86] posNoWhite:[49:85] Found expr:[49:36->49:88] +posCursor:[49:86] posNoWhite:[49:85] Found expr:[49:41->49:86] +posCursor:[49:86] posNoWhite:[49:85] Found expr:[49:81->0:-1] +posCursor:[49:86] posNoWhite:[49:85] Found expr:[49:81->0:-1] +Completable: Cpath Value[btn]-> <> +[] + From 73cf40b7937b1dace800c56240a7b6d4cc5f67e5 Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Wed, 25 Jan 2023 09:43:11 +0100 Subject: [PATCH 05/41] handle pipe chains as assigned value --- analysis/src/CompletionFrontEnd.ml | 17 ++-- analysis/tests/src/CompletionInferValues.res | 11 ++- .../expected/CompletionInferValues.res.txt | 83 +++++++++++++++++-- 3 files changed, 94 insertions(+), 17 deletions(-) diff --git a/analysis/src/CompletionFrontEnd.ml b/analysis/src/CompletionFrontEnd.ml index 2fb474dd9..5bbecfdda 100644 --- a/analysis/src/CompletionFrontEnd.ml +++ b/analysis/src/CompletionFrontEnd.ml @@ -136,7 +136,6 @@ let findArgCompletables ~(args : arg list) ~endPos ~posBeforeCursor }) | _ -> loop args -(* TODO: Mimic pipe chain detection here? *) let rec exprToContextPath (e : Parsetree.expression) = match e.pexp_desc with | Pexp_constant (Pconst_string _) -> Some Completable.CPString @@ -149,6 +148,7 @@ let rec exprToContextPath (e : Parsetree.expression) = (match exprs with | [] -> None | exp :: _ -> exprToContextPath exp)) + | Pexp_ident {txt = Lident "|."} -> None | Pexp_ident {txt} -> Some (CPId (Utils.flattenLongIdent txt, Value)) | Pexp_field (e1, {txt = Lident name}) -> ( match exprToContextPath e1 with @@ -172,7 +172,7 @@ let rec exprToContextPath (e : Parsetree.expression) = else None | _ -> None -let completePipeChain ~(lhs : Parsetree.expression) = +let completePipeChain (exp : Parsetree.expression) = (* Complete the end of pipe chains by reconstructing the pipe chain as a single pipe, so it can be completed. Example: @@ -180,7 +180,7 @@ let completePipeChain ~(lhs : Parsetree.expression) = will complete as: Js.Array2.map(someArray->Js.Array2.filter(v => v > 10), v => v + 2)-> *) - match lhs.pexp_desc with + match exp.pexp_desc with (* When the left side of the pipe we're completing is a function application. Example: someArray->Js.Array2.map(v => v + 2)-> *) | Pexp_apply @@ -351,7 +351,14 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor ~text = | _ -> () in let scopeValueBinding (vb : Parsetree.value_binding) = - let contextPath = exprToContextPath vb.pvb_expr in + let contextPath = + (* Pipe chains get special treatment here, because when assigning values + we want the return of the entire pipe chain as a function call, rather + than as a pipe completion call. *) + match completePipeChain vb.pvb_expr with + | Some (ctxPath, _) -> Some ctxPath + | None -> exprToContextPath vb.pvb_expr + in scopePattern ?contextPath vb.pvb_pat in let scopeTypeKind (tk : Parsetree.type_kind) = @@ -690,7 +697,7 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor ~text = (Loc.toString expr.pexp_loc) in let setPipeResult ~(lhs : Parsetree.expression) ~id = - match completePipeChain ~lhs with + match completePipeChain lhs with | None -> ( match exprToContextPath lhs with | Some pipe -> diff --git a/analysis/tests/src/CompletionInferValues.res b/analysis/tests/src/CompletionInferValues.res index 8387b1369..fadd5c2fe 100644 --- a/analysis/tests/src/CompletionInferValues.res +++ b/analysis/tests/src/CompletionInferValues.res @@ -46,6 +46,11 @@ module Div = { // let _ =
{ event->pr }} /> // ^com -// Pipe are broken, need to fix -// let _ =
{ let btn = event->JsxEvent.Mouse.button; btn-> }} /> -// ^com +// let _ =
{ let btn = event->JsxEvent.Mouse.button; btn->t }} /> +// ^com + +// let _ =
{ let btn = event->JsxEvent.Mouse.button->Belt.Int.toString; btn->spl }} /> +// ^com + +// let _ =
{ let btn = event->JsxEvent.Mouse.button->Belt.Int.toString->Js.String2.split("/"); btn->ma }} /> +// ^com diff --git a/analysis/tests/src/expected/CompletionInferValues.res.txt b/analysis/tests/src/expected/CompletionInferValues.res.txt index 78496b472..24d6002fd 100644 --- a/analysis/tests/src/expected/CompletionInferValues.res.txt +++ b/analysis/tests/src/expected/CompletionInferValues.res.txt @@ -127,13 +127,78 @@ Completable: Cpath Value[event]->pr <> "documentation": null }] -Complete src/CompletionInferValues.res 49:86 -posCursor:[49:86] posNoWhite:[49:85] Found expr:[49:12->49:92] -JSX 49:15] onMouseEnter[49:16->49:28]=...[49:36->49:88]> _children:49:90 -posCursor:[49:86] posNoWhite:[49:85] Found expr:[49:36->49:88] -posCursor:[49:86] posNoWhite:[49:85] Found expr:[49:41->49:86] -posCursor:[49:86] posNoWhite:[49:85] Found expr:[49:81->0:-1] -posCursor:[49:86] posNoWhite:[49:85] Found expr:[49:81->0:-1] -Completable: Cpath Value[btn]-> <> -[] +Complete src/CompletionInferValues.res 48:87 +posCursor:[48:87] posNoWhite:[48:86] Found expr:[48:12->48:93] +JSX 48:15] onMouseEnter[48:16->48:28]=...[48:36->48:89]> _children:48:91 +posCursor:[48:87] posNoWhite:[48:86] Found expr:[48:36->48:89] +posCursor:[48:87] posNoWhite:[48:86] Found expr:[48:41->48:87] +posCursor:[48:87] posNoWhite:[48:86] Found expr:[48:81->48:87] +Completable: Cpath Value[btn]->t <> +[{ + "label": "Belt.Int.toString", + "kind": 12, + "tags": [], + "detail": "int => string", + "documentation": {"kind": "markdown", "value": "\n Converts a given `int` to a `string`. Uses the JavaScript `String` constructor under the hood.\n\n ```res example\n Js.log(Belt.Int.toString(1) === \"1\") /* true */\n ```\n"} + }, { + "label": "Belt.Int.toFloat", + "kind": 12, + "tags": [], + "detail": "int => float", + "documentation": {"kind": "markdown", "value": "\n Converts a given `int` to a `float`.\n\n ```res example\n Js.log(Belt.Int.toFloat(1) === 1.0) /* true */\n ```\n"} + }] + +Complete src/CompletionInferValues.res 51:108 +posCursor:[51:108] posNoWhite:[51:107] Found expr:[51:12->51:114] +JSX 51:15] onMouseEnter[51:16->51:28]=...[51:36->51:110]> _children:51:112 +posCursor:[51:108] posNoWhite:[51:107] Found expr:[51:36->51:110] +posCursor:[51:108] posNoWhite:[51:107] Found expr:[51:41->51:108] +posCursor:[51:108] posNoWhite:[51:107] Found expr:[51:100->51:108] +Completable: Cpath Value[btn]->spl <> +[{ + "label": "Js.String2.splitAtMost", + "kind": 12, + "tags": [], + "detail": "(t, t, ~limit: int) => array", + "documentation": {"kind": "markdown", "value": "\n `splitAtMost delimiter ~limit: n str` splits the given `str` at every occurrence of `delimiter` and returns an array of the first `n` resulting substrings. If `n` is negative or greater than the number of substrings, the array will contain all the substrings.\n\n```\nsplitAtMost \"ant/bee/cat/dog/elk\" \"/\" ~limit: 3 = [|\"ant\"; \"bee\"; \"cat\"|];;\nsplitAtMost \"ant/bee/cat/dog/elk\" \"/\" ~limit: 0 = [| |];;\nsplitAtMost \"ant/bee/cat/dog/elk\" \"/\" ~limit: 9 = [|\"ant\"; \"bee\"; \"cat\"; \"dog\"; \"elk\"|];;\n```\n"} + }, { + "label": "Js.String2.splitByRe", + "kind": 12, + "tags": [], + "detail": "(t, Js_re.t) => array>", + "documentation": {"kind": "markdown", "value": "\n`splitByRe(str, regex)` splits the given `str` at every occurrence of `regex`\nand returns an array of the resulting substrings.\n\nSee [`String.split`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split)\non MDN.\n\n```res example\nJs.String2.splitByRe(\"art; bed , cog ;dad\", %re(\"/\\s*[,;]\\s*/\")) == [\n Some(\"art\"),\n Some(\"bed\"),\n Some(\"cog\"),\n Some(\"dad\"),\n ]\n```\n"} + }, { + "label": "Js.String2.split", + "kind": 12, + "tags": [], + "detail": "(t, t) => array", + "documentation": {"kind": "markdown", "value": "\n`split(str, delimiter)` splits the given `str` at every occurrence of\n`delimiter` and returns an array of the resulting substrings.\n\nSee [`String.split`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split)\non MDN.\n\n```res example\nJs.String2.split(\"2018-01-02\", \"-\") == [\"2018\", \"01\", \"02\"]\nJs.String2.split(\"a,b,,c\", \",\") == [\"a\", \"b\", \"\", \"c\"]\nJs.String2.split(\"good::bad as great::awful\", \"::\") == [\"good\", \"bad as great\", \"awful\"]\nJs.String2.split(\"has-no-delimiter\", \";\") == [\"has-no-delimiter\"]\n```\n"} + }, { + "label": "Js.String2.splitByReAtMost", + "kind": 12, + "tags": [], + "detail": "(t, Js_re.t, ~limit: int) => array>", + "documentation": {"kind": "markdown", "value": "\n`splitByReAtMost(str, regex, ~limit:n)` splits the given `str` at every\noccurrence of `regex` and returns an array of the first `n` resulting\nsubstrings. If `n` is negative or greater than the number of substrings, the\narray will contain all the substrings.\n\nSee [`String.split`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split)\non MDN.\n\n```res example\nJs.String2.splitByReAtMost(\"one: two: three: four\", %re(\"/\\s*:\\s*/\"), ~limit=3) == [\n Some(\"one\"),\n Some(\"two\"),\n Some(\"three\"),\n ]\n\nJs.String2.splitByReAtMost(\"one: two: three: four\", %re(\"/\\s*:\\s*/\"), ~limit=0) == []\n\nJs.String2.splitByReAtMost(\"one: two: three: four\", %re(\"/\\s*:\\s*/\"), ~limit=8) == [\n Some(\"one\"),\n Some(\"two\"),\n Some(\"three\"),\n Some(\"four\"),\n ]\n```\n"} + }] + +Complete src/CompletionInferValues.res 54:130 +posCursor:[54:130] posNoWhite:[54:129] Found expr:[54:12->54:136] +JSX 54:15] onMouseEnter[54:16->54:28]=...[54:36->54:132]> _children:54:134 +posCursor:[54:130] posNoWhite:[54:129] Found expr:[54:36->54:132] +posCursor:[54:130] posNoWhite:[54:129] Found expr:[54:41->54:130] +posCursor:[54:130] posNoWhite:[54:129] Found expr:[54:123->54:130] +Completable: Cpath Value[btn]->ma <> +[{ + "label": "Js.Array2.mapi", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ('a, int) => 'b) => t<'b>", + "documentation": {"kind": "markdown", "value": "\nApplies the function (the second argument) to each item in the array, returning\na new array. The function acceps two arguments: an item from the array and its\nindex number. The result array does not have to have elements of the same type\nas the input array. See\n[`Array.map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map)\non MDN.\n\n```res example\n// multiply each item in array by its position\nlet product = (item, index) => item * index\nJs.Array2.mapi([10, 11, 12], product) == [0, 11, 24]\n```\n"} + }, { + "label": "Js.Array2.map", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a => 'b) => t<'b>", + "documentation": {"kind": "markdown", "value": "\nApplies the function (the second argument) to each item in the array, returning\na new array. The result array does not have to have elements of the same type\nas the input array. See\n[`Array.map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map)\non MDN.\n\n```res example\nJs.Array2.map([12, 4, 8], x => x * x) == [144, 16, 64]\nJs.Array2.map([\"animal\", \"vegetable\", \"mineral\"], Js.String.length) == [6, 9, 7]\n```\n"} + }] From 83973e8e33fcfac2ace48763d87c484d4d2e986b Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Wed, 25 Jan 2023 12:51:04 +0100 Subject: [PATCH 06/41] support leveraging type annotations when inferring --- analysis/src/CompletionBackEnd.ml | 82 ++++++++++++++----- analysis/src/CompletionFrontEnd.ml | 3 +- analysis/tests/src/CompletionInferValues.res | 3 + .../expected/CompletionInferValues.res.txt | 18 ++++ 4 files changed, 83 insertions(+), 23 deletions(-) diff --git a/analysis/src/CompletionBackEnd.ml b/analysis/src/CompletionBackEnd.ml index 9d402f6c3..07bc91e6e 100644 --- a/analysis/src/CompletionBackEnd.ml +++ b/analysis/src/CompletionBackEnd.ml @@ -604,6 +604,12 @@ let completionsGetTypeEnv = function | {Completion.kind = Field ({typ}, _); env} :: _ -> Some (typ, env) | _ -> None +type getCompletionsForContextPathMode = Regular | Pipe + +type completionsTypeEnvTyp = + | TypeExpr of Types.type_expr + | ExtractedType of completionType + let completionsGetCompletionType ~full = function | {Completion.kind = Value typ; env} :: _ | {Completion.kind = ObjLabel typ; env} :: _ @@ -618,9 +624,27 @@ let completionsGetCompletionType ~full = function | {Completion.kind = ExtractedType (typ, _); env} :: _ -> Some (typ, env) | _ -> None -type getCompletionsForContextPathMode = Regular | Pipe +let rec completionsGetCompletionType2 ~full ~opens ~rawOpens ~allFiles ~pos + ~scope = function + | {Completion.kind = Value typ; env} :: _ + | {Completion.kind = ObjLabel typ; env} :: _ + | {Completion.kind = Field ({typ}, _); env} :: _ -> + Some (TypeExpr typ, env) + | {Completion.kind = FollowContextPath ctxPath; env} :: _ -> + ctxPath + |> getCompletionsForContextPath ~full ~env ~exact:true ~opens ~rawOpens + ~allFiles ~pos ~scope + |> completionsGetCompletionType2 ~full ~opens ~rawOpens ~allFiles ~pos + ~scope + | {Completion.kind = Type typ; env} :: _ -> ( + match TypeUtils.extractTypeFromResolvedType typ ~env ~full with + | None -> None + | Some extractedType -> Some (ExtractedType extractedType, env)) + | {Completion.kind = ExtractedType (typ, _); env} :: _ -> + Some (ExtractedType typ, env) + | _ -> None -let rec completionsGetTypeEnv2 (completions : Completion.t list) ~full ~opens +and completionsGetTypeEnv2 (completions : Completion.t list) ~full ~opens ~rawOpens ~allFiles ~pos ~scope = match completions with | {Completion.kind = Value typ; env} :: _ -> Some (typ, env) @@ -760,29 +784,43 @@ and getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env |> getCompletionsForPath ~package ~opens ~allFiles ~pos ~exact ~completionContext:Field ~env ~scope | CPField (cp, fieldName) -> ( - match + let completionsForCtxPath = cp |> getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env ~exact:true ~scope - |> completionsGetTypeEnv2 ~full ~opens ~rawOpens ~allFiles ~pos ~scope - with - | Some (typ, env) -> ( - match typ |> TypeUtils.extractRecordType ~env ~package with - | Some (env, fields, typDecl) -> - fields - |> Utils.filterMap (fun field -> - if Utils.checkName field.fname.txt ~prefix:fieldName ~exact then - Some - (Completion.create field.fname.txt ~env - ~docstring:field.docstring ?deprecated:field.deprecated - ~kind: - (Completion.Field - ( field, - typDecl.item.decl - |> Shared.declToString typDecl.name.txt ))) - else None) - | None -> []) - | None -> []) + in + let extracted = + match + completionsForCtxPath + |> completionsGetCompletionType2 ~full ~opens ~rawOpens ~allFiles ~pos + ~scope + with + | Some (TypeExpr typ, env) -> ( + match typ |> TypeUtils.extractRecordType ~env ~package with + | Some (env, fields, typDecl) -> + Some + ( env, + fields, + typDecl.item.decl |> Shared.declToString typDecl.name.txt ) + | None -> None) + | Some (ExtractedType typ, env) -> ( + match typ with + | Trecord {fields} -> + Some (env, fields, typ |> TypeUtils.extractedTypeToString) + | _ -> None) + | None -> None + in + match extracted with + | None -> [] + | Some (env, fields, recordAsString) -> + fields + |> Utils.filterMap (fun field -> + if Utils.checkName field.fname.txt ~prefix:fieldName ~exact then + Some + (Completion.create field.fname.txt ~env + ~docstring:field.docstring + ~kind:(Completion.Field (field, recordAsString))) + else None)) | CPObj (cp, label) -> ( match cp diff --git a/analysis/src/CompletionFrontEnd.ml b/analysis/src/CompletionFrontEnd.ml index 5bbecfdda..6e4e70d53 100644 --- a/analysis/src/CompletionFrontEnd.ml +++ b/analysis/src/CompletionFrontEnd.ml @@ -316,7 +316,8 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor ~text = fields |> List.iter (fun (_, p) -> scopePattern ?contextPath p) | Ppat_array pl -> pl |> List.iter (scopePattern ?contextPath) | Ppat_or (p1, _) -> scopePattern ?contextPath p1 - | Ppat_constraint (p, _) -> scopePattern ?contextPath p + | Ppat_constraint (p, coreType) -> + scopePattern ?contextPath:(TypeUtils.contextPathFromCoreType coreType) p | Ppat_type _ -> () | Ppat_lazy p -> scopePattern ?contextPath p | Ppat_unpack {txt; loc} -> diff --git a/analysis/tests/src/CompletionInferValues.res b/analysis/tests/src/CompletionInferValues.res index fadd5c2fe..e0bf0a0b6 100644 --- a/analysis/tests/src/CompletionInferValues.res +++ b/analysis/tests/src/CompletionInferValues.res @@ -54,3 +54,6 @@ module Div = { // let _ =
{ let btn = event->JsxEvent.Mouse.button->Belt.Int.toString->Js.String2.split("/"); btn->ma }} /> // ^com + +// let x: someRecord = {name: "Hello", age: 123}; x. +// ^com diff --git a/analysis/tests/src/expected/CompletionInferValues.res.txt b/analysis/tests/src/expected/CompletionInferValues.res.txt index 24d6002fd..ab9b0a469 100644 --- a/analysis/tests/src/expected/CompletionInferValues.res.txt +++ b/analysis/tests/src/expected/CompletionInferValues.res.txt @@ -202,3 +202,21 @@ Completable: Cpath Value[btn]->ma <> "documentation": {"kind": "markdown", "value": "\nApplies the function (the second argument) to each item in the array, returning\na new array. The result array does not have to have elements of the same type\nas the input array. See\n[`Array.map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map)\non MDN.\n\n```res example\nJs.Array2.map([12, 4, 8], x => x * x) == [144, 16, 64]\nJs.Array2.map([\"animal\", \"vegetable\", \"mineral\"], Js.String.length) == [6, 9, 7]\n```\n"} }] +Complete src/CompletionInferValues.res 57:52 +posCursor:[57:52] posNoWhite:[57:51] Found expr:[57:50->57:52] +Pexp_field [57:50->57:51] _:[60:0->57:52] +Completable: Cpath Value[x]."" +[{ + "label": "name", + "kind": 5, + "tags": [], + "detail": "name: string\n\ntype someRecord = {name: string, age: int}", + "documentation": null + }, { + "label": "age", + "kind": 5, + "tags": [], + "detail": "age: int\n\ntype someRecord = {name: string, age: int}", + "documentation": null + }] + From b80c5df9097761f37230b8dac2aa276f2052f57c Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Wed, 25 Jan 2023 14:00:34 +0100 Subject: [PATCH 07/41] start work on following pattern path --- analysis/src/CompletionBackEnd.ml | 30 ++++- analysis/src/CompletionFrontEnd.ml | 106 ++++++++++++++---- analysis/src/SharedTypes.ml | 54 +++++---- analysis/tests/src/CompletionInferValues.res | 21 ++++ .../expected/CompletionInferValues.res.txt | 48 ++++++++ 5 files changed, 215 insertions(+), 44 deletions(-) diff --git a/analysis/src/CompletionBackEnd.ml b/analysis/src/CompletionBackEnd.ml index 07bc91e6e..07298e4a8 100644 --- a/analysis/src/CompletionBackEnd.ml +++ b/analysis/src/CompletionBackEnd.ml @@ -715,7 +715,7 @@ and getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env (* Pipe completion with array just needs to know that it's an array, not what inner type it has. *) [ - Completion.create "array" ~env + Completion.create "dummy" ~env ~kind: (Completion.Value (Ctype.newconstr (Path.Pident (Ident.create "array")) [])); @@ -738,6 +738,7 @@ and getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env |> getCompletionsForPath ~package ~opens ~allFiles ~pos ~exact ~completionContext ~env ~scope | CPApply (cp, labels) -> ( + (* TODO: Also needs to support ExtractedType *) match cp |> getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env @@ -822,6 +823,7 @@ and getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env ~kind:(Completion.Field (field, recordAsString))) else None)) | CPObj (cp, label) -> ( + (* TODO: Also needs to support ExtractedType *) match cp |> getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env @@ -1048,6 +1050,7 @@ and getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env ~kind:(Completion.Value (Utils.unwrapIfOption typ)); ]) | CArgument {functionContextPath; argumentLabel} -> ( + (* TODO: Also needs to support ExtractedType *) let labels, env = match functionContextPath @@ -1084,6 +1087,31 @@ and getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env (Completion.Value (if expandOption then Utils.unwrapIfOption typ else typ)); ]) + | CPatternPath {rootCtxPath; nested} -> ( + match + rootCtxPath + |> getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env + ~exact:true ~scope + |> completionsGetCompletionType2 ~full ~opens ~rawOpens ~allFiles ~pos + ~scope + with + | Some (typ, env) -> ( + let typ = + match typ with + | ExtractedType typ -> Some typ + | TypeExpr typ -> typ |> TypeUtils.extractType ~env ~package + in + match typ with + | None -> [] + | Some typ -> ( + match typ |> TypeUtils.resolveNested ~env ~full ~nested with + | Some (typ, env, _completionContext) -> + [ + Completion.create "dummy" ~env + ~kind:(Completion.ExtractedType (typ, `Value)); + ] + | None -> [])) + | None -> []) let getOpens ~debug ~rawOpens ~package ~env = if debug && rawOpens <> [] then diff --git a/analysis/src/CompletionFrontEnd.ml b/analysis/src/CompletionFrontEnd.ml index 6e4e70d53..2ff72ed42 100644 --- a/analysis/src/CompletionFrontEnd.ml +++ b/analysis/src/CompletionFrontEnd.ml @@ -292,39 +292,105 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor ~text = scope := !scope |> Scope.addValue ~name:vd.pval_name.txt ~loc:vd.pval_name.loc in - let rec scopePattern ?contextPath (pat : Parsetree.pattern) = + let rec scopePattern ?contextPath + ?(patternPath : Completable.nestedPath list = []) + (pat : Parsetree.pattern) = + let contextPathToSave = + match (contextPath, patternPath) with + | maybeContextPath, [] -> maybeContextPath + | Some contextPath, patternPath -> + Some + (Completable.CPatternPath + {rootCtxPath = contextPath; nested = List.rev patternPath}) + | _ -> None + in match pat.ppat_desc with | Ppat_any -> () | Ppat_var {txt; loc} -> - scope := !scope |> Scope.addValue ~name:txt ~loc ?contextPath + scope := + !scope |> Scope.addValue ~name:txt ~loc ?contextPath:contextPathToSave | Ppat_alias (p, asA) -> - scopePattern p; + scopePattern p ~patternPath ?contextPath; + let ctxPath = + if contextPathToSave = None then + match p with + | {ppat_desc = Ppat_var {txt}} -> + Some (Completable.CPId ([txt], Value)) + | _ -> None + else None + in scope := - !scope - |> Scope.addValue ~name:asA.txt ~loc:asA.loc - ?contextPath: - (match p with - | {ppat_desc = Ppat_var {txt}} -> Some (CPId ([txt], Value)) - | _ -> None) + !scope |> Scope.addValue ~name:asA.txt ~loc:asA.loc ?contextPath:ctxPath | Ppat_constant _ | Ppat_interval _ -> () - | Ppat_tuple pl -> pl |> List.iter (scopePattern ?contextPath) + | Ppat_tuple pl -> + pl + |> List.iteri (fun index p -> + scopePattern p + ~patternPath:(NTupleItem {itemNum = index} :: patternPath) + ?contextPath) | Ppat_construct (_, None) -> () - | Ppat_construct (_, Some p) -> scopePattern ?contextPath p + | Ppat_construct ({txt}, Some {ppat_desc = Ppat_tuple pl}) -> + pl + |> List.iteri (fun index p -> + scopePattern p + ~patternPath: + (NVariantPayload + { + itemNum = index; + constructorName = Utils.getUnqualifiedName txt; + } + :: patternPath) + ?contextPath) + | Ppat_construct ({txt}, Some p) -> + scopePattern + ~patternPath: + (NVariantPayload + {itemNum = 0; constructorName = Utils.getUnqualifiedName txt} + :: patternPath) + ?contextPath p | Ppat_variant (_, None) -> () - | Ppat_variant (_, Some p) -> scopePattern ?contextPath p + | Ppat_variant (txt, Some {ppat_desc = Ppat_tuple pl}) -> + pl + |> List.iteri (fun index p -> + scopePattern p + ~patternPath: + (NPolyvariantPayload {itemNum = index; constructorName = txt} + :: patternPath) + ?contextPath) + | Ppat_variant (txt, Some p) -> + scopePattern + ~patternPath: + (NPolyvariantPayload {itemNum = 0; constructorName = txt} + :: patternPath) + ?contextPath p | Ppat_record (fields, _) -> - fields |> List.iter (fun (_, p) -> scopePattern ?contextPath p) - | Ppat_array pl -> pl |> List.iter (scopePattern ?contextPath) - | Ppat_or (p1, _) -> scopePattern ?contextPath p1 + fields + |> List.iter (fun (fname, p) -> + match fname with + | {Location.txt = Longident.Lident fname} -> + scopePattern + ~patternPath: + (Completable.NFollowRecordField {fieldName = fname} + :: patternPath) + ?contextPath p + | _ -> ()) + | Ppat_array pl -> + pl + |> List.iter + (scopePattern ~patternPath:(NArray :: patternPath) ?contextPath) + | Ppat_or (p1, _) -> scopePattern ~patternPath ?contextPath p1 | Ppat_constraint (p, coreType) -> - scopePattern ?contextPath:(TypeUtils.contextPathFromCoreType coreType) p + scopePattern ~patternPath + ?contextPath:(TypeUtils.contextPathFromCoreType coreType) + p | Ppat_type _ -> () - | Ppat_lazy p -> scopePattern ?contextPath p + | Ppat_lazy p -> scopePattern ~patternPath ?contextPath p | Ppat_unpack {txt; loc} -> - scope := !scope |> Scope.addValue ~name:txt ~loc ?contextPath - | Ppat_exception p -> scopePattern ?contextPath p + scope := + !scope |> Scope.addValue ~name:txt ~loc ?contextPath:contextPathToSave + | Ppat_exception p -> scopePattern ~patternPath ?contextPath p | Ppat_extension _ -> () - | Ppat_open (_, p) -> scopePattern ?contextPath p + | Ppat_open (_, p) -> scopePattern ~patternPath ?contextPath p in let lookingForPat = ref None in diff --git a/analysis/src/SharedTypes.ml b/analysis/src/SharedTypes.ml index 39b41aae9..c4a9e385e 100644 --- a/analysis/src/SharedTypes.ml +++ b/analysis/src/SharedTypes.ml @@ -520,6 +520,29 @@ module Completable = struct | Labelled of string | Optional of string + (** Additional context for nested completion where needed. *) + type nestedContext = RecordField of {seenFields: string list} + + type nestedPath = + | NTupleItem of {itemNum: int} + | NFollowRecordField of {fieldName: string} + | NRecordBody of {seenFields: string list} + | NVariantPayload of {constructorName: string; itemNum: int} + | NPolyvariantPayload of {constructorName: string; itemNum: int} + | NArray + + let nestedPathToString p = + match p with + | NTupleItem {itemNum} -> "tuple($" ^ string_of_int itemNum ^ ")" + | NFollowRecordField {fieldName} -> "recordField(" ^ fieldName ^ ")" + | NRecordBody _ -> "recordBody" + | NVariantPayload {constructorName; itemNum} -> + "variantPayload::" ^ constructorName ^ "($" ^ string_of_int itemNum ^ ")" + | NPolyvariantPayload {constructorName; itemNum} -> + "polyvariantPayload::" ^ constructorName ^ "($" ^ string_of_int itemNum + ^ ")" + | NArray -> "array" + type contextPath = | CPString | CPArray of contextPath option @@ -544,29 +567,7 @@ module Completable = struct argumentLabel: argumentLabel; } | CJsxPropValue of {pathToComponent: string list; propName: string} - - (** Additional context for nested completion where needed. *) - type nestedContext = RecordField of {seenFields: string list} - - type nestedPath = - | NTupleItem of {itemNum: int} - | NFollowRecordField of {fieldName: string} - | NRecordBody of {seenFields: string list} - | NVariantPayload of {constructorName: string; itemNum: int} - | NPolyvariantPayload of {constructorName: string; itemNum: int} - | NArray - - let nestedPathToString p = - match p with - | NTupleItem {itemNum} -> "tuple($" ^ string_of_int itemNum ^ ")" - | NFollowRecordField {fieldName} -> "recordField(" ^ fieldName ^ ")" - | NRecordBody _ -> "recordBody" - | NVariantPayload {constructorName; itemNum} -> - "variantPayload::" ^ constructorName ^ "($" ^ string_of_int itemNum ^ ")" - | NPolyvariantPayload {constructorName; itemNum} -> - "polyvariantPayload::" ^ constructorName ^ "($" ^ string_of_int itemNum - ^ ")" - | NArray -> "array" + | CPatternPath of {rootCtxPath: contextPath; nested: nestedPath list} type patternMode = Default | Destructuring @@ -639,6 +640,13 @@ module Completable = struct ^ ")" | CJsxPropValue {pathToComponent; propName} -> "CJsxPropValue " ^ (pathToComponent |> list) ^ " " ^ propName + | CPatternPath {rootCtxPath; nested} -> + "CPatternPath(" + ^ contextPathToString rootCtxPath + ^ ")" ^ "->" + ^ (nested + |> List.map (fun nestedPath -> nestedPathToString nestedPath) + |> String.concat "->") let toString = function | Cpath cp -> "Cpath " ^ contextPathToString cp diff --git a/analysis/tests/src/CompletionInferValues.res b/analysis/tests/src/CompletionInferValues.res index e0bf0a0b6..684723e85 100644 --- a/analysis/tests/src/CompletionInferValues.res +++ b/analysis/tests/src/CompletionInferValues.res @@ -57,3 +57,24 @@ module Div = { // let x: someRecord = {name: "Hello", age: 123}; x. // ^com + +type someVariant = One | Two | Three(int, string) +type someNestedRecord = {someRecord: someRecord} + +type someRecordWithNestedStuff = { + things: string, + srecord: someRecord, + nested: someNestedRecord, + someStuff: bool, +} + +type otherNestedRecord = {someRecord: someRecord, someTuple: (someVariant, int)} + +// let x: someRecordWithNestedStuff = {things: "", someRecord: {name: "Hello", age: 123}, someStuff: true}; let {srecord} = x; srecord. +// ^com + +// let x: someRecordWithNestedStuff = {things: "", someRecord: {name: "Hello", age: 123}, someStuff: true}; let {nested: aliased} = x; aliased. +// ^com + +// let x: someRecordWithNestedStuff = {things: "", someRecord: {name: "Hello", age: 123}, someStuff: true}; let {srecord, nested: {someRecord}} = x; someRecord. +// ^com diff --git a/analysis/tests/src/expected/CompletionInferValues.res.txt b/analysis/tests/src/expected/CompletionInferValues.res.txt index ab9b0a469..0ab90afc9 100644 --- a/analysis/tests/src/expected/CompletionInferValues.res.txt +++ b/analysis/tests/src/expected/CompletionInferValues.res.txt @@ -220,3 +220,51 @@ Completable: Cpath Value[x]."" "documentation": null }] +Complete src/CompletionInferValues.res 72:135 +posCursor:[72:135] posNoWhite:[72:134] Found expr:[72:127->72:135] +Pexp_field [72:127->72:134] _:[81:0->72:135] +Completable: Cpath Value[srecord]."" +[{ + "label": "name", + "kind": 5, + "tags": [], + "detail": "name: string\n\nsomeRecord", + "documentation": null + }, { + "label": "age", + "kind": 5, + "tags": [], + "detail": "age: int\n\nsomeRecord", + "documentation": null + }] + +Complete src/CompletionInferValues.res 75:143 +posCursor:[75:143] posNoWhite:[75:142] Found expr:[75:135->75:143] +Pexp_field [75:135->75:142] _:[81:0->75:143] +Completable: Cpath Value[aliased]."" +[{ + "label": "someRecord", + "kind": 5, + "tags": [], + "detail": "someRecord: someRecord\n\nsomeNestedRecord", + "documentation": null + }] + +Complete src/CompletionInferValues.res 78:160 +posCursor:[78:160] posNoWhite:[78:159] Found expr:[78:149->78:160] +Pexp_field [78:149->78:159] _:[81:0->78:160] +Completable: Cpath Value[someRecord]."" +[{ + "label": "name", + "kind": 5, + "tags": [], + "detail": "name: string\n\nsomeRecord", + "documentation": null + }, { + "label": "age", + "kind": 5, + "tags": [], + "detail": "age: int\n\nsomeRecord", + "documentation": null + }] + From c9d6bbcaa767b97b627af35df607ab5ee4ece311 Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Thu, 26 Jan 2023 18:02:41 +0100 Subject: [PATCH 08/41] slight cleanup --- analysis/src/CompletionFrontEnd.ml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/analysis/src/CompletionFrontEnd.ml b/analysis/src/CompletionFrontEnd.ml index 2ff72ed42..6bcf83350 100644 --- a/analysis/src/CompletionFrontEnd.ml +++ b/analysis/src/CompletionFrontEnd.ml @@ -911,8 +911,9 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor ~text = && charBeforeCursor = Some ')') -> ( (* Complete fn argument values and named args when the fn call is piped. E.g. someVar->someFn(). *) let args = extractExpApplyArgs ~args in + let funCtxPath = exprToContextPath funExpr in let argCompletable = - match exprToContextPath funExpr with + match funCtxPath with | Some contextPath -> findArgCompletables ~contextPath ~args ~endPos:(Loc.end_ expr.pexp_loc) ~posBeforeCursor @@ -923,7 +924,7 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor ~text = in match argCompletable with | None -> ( - match exprToContextPath funExpr with + match funCtxPath with | None -> () | Some funCtxPath -> let oldCtxPath = !currentCtxPath in @@ -955,8 +956,9 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor ~text = (Loc.toString exp.pexp_loc)) |> String.concat ", "); + let funCtxPath = exprToContextPath funExpr in let argCompletable = - match exprToContextPath funExpr with + match funCtxPath with | Some contextPath -> findArgCompletables ~contextPath ~args ~endPos:(Loc.end_ expr.pexp_loc) ~posBeforeCursor @@ -967,7 +969,7 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor ~text = in match argCompletable with | None -> ( - match exprToContextPath funExpr with + match funCtxPath with | None -> () | Some funCtxPath -> let oldCtxPath = !currentCtxPath in From 2e4747f584b86da1d5dff2791a85458ded501843 Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Fri, 3 Feb 2023 14:08:56 +0100 Subject: [PATCH 09/41] make Toption work with both extracted and type expr types --- analysis/src/CompletionBackEnd.ml | 43 +++++++++++-------- analysis/src/SharedTypes.ml | 12 ++++-- analysis/src/TypeUtils.ml | 18 +++++--- .../expected/CompletionExpressions.res.txt | 24 +++++------ .../CompletionFunctionArguments.res.txt | 4 +- .../src/expected/CompletionPattern.res.txt | 24 +++++------ .../expected/CompletionTypeAnnotation.res.txt | 8 ++-- 7 files changed, 75 insertions(+), 58 deletions(-) diff --git a/analysis/src/CompletionBackEnd.ml b/analysis/src/CompletionBackEnd.ml index 07298e4a8..e1f28ed41 100644 --- a/analysis/src/CompletionBackEnd.ml +++ b/analysis/src/CompletionBackEnd.ml @@ -731,7 +731,8 @@ and getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env | Some (typ, env) -> [ Completion.create "dummy" ~env - ~kind:(Completion.ExtractedType (Toption (env, typ), `Type)); + ~kind: + (Completion.ExtractedType (Toption (env, ExtractedType typ), `Type)); ]) | CPId (path, completionContext) -> path @@ -1207,27 +1208,31 @@ let rec completeTypedValue ~full ~prefix ~completionContext ~mode ~env ()) |> filterItems ~prefix | Toption (env, t) -> - let innerType = TypeUtils.unwrapCompletionTypeIfOption t in + let innerType = + match t with + | ExtractedType t -> Some t + | TypeExpr t -> t |> TypeUtils.extractType ~env ~package:full.package + in let expandedCompletions = - innerType - |> completeTypedValue ~full ~prefix ~completionContext ~mode - |> List.map (fun (c : Completion.t) -> - { - c with - name = "Some(" ^ c.name ^ ")"; - sortText = None; - insertText = - (match c.insertText with - | None -> None - | Some insertText -> Some ("Some(" ^ insertText ^ ")")); - }) + match innerType with + | None -> [] + | Some innerType -> + innerType + |> completeTypedValue ~full ~prefix ~completionContext ~mode + |> List.map (fun (c : Completion.t) -> + { + c with + name = "Some(" ^ c.name ^ ")"; + sortText = None; + insertText = + (match c.insertText with + | None -> None + | Some insertText -> Some ("Some(" ^ insertText ^ ")")); + }) in [ - Completion.create "None" - ~kind:(Label (t |> TypeUtils.extractedTypeToString)) - ~env; - Completion.createWithSnippet ~name:"Some(_)" - ~kind:(Label (t |> TypeUtils.extractedTypeToString)) + Completion.create "None" ~kind:(kindFromInnerType t) ~env; + Completion.createWithSnippet ~name:"Some(_)" ~kind:(kindFromInnerType t) ~env ~insertText:"Some(${1:_})" (); ] @ expandedCompletions diff --git a/analysis/src/SharedTypes.ml b/analysis/src/SharedTypes.ml index c4a9e385e..aba90b388 100644 --- a/analysis/src/SharedTypes.ml +++ b/analysis/src/SharedTypes.ml @@ -296,11 +296,11 @@ end type polyVariantConstructor = {name: string; args: Types.type_expr list} -(** An type that can be used to drive completion *) -type completionType = +type innerType = TypeExpr of Types.type_expr | ExtractedType of completionType +and completionType = | Tuple of QueryEnv.t * Types.type_expr list * Types.type_expr - | Toption of QueryEnv.t * completionType | Texn of QueryEnv.t + | Toption of QueryEnv.t * innerType | Tbool of QueryEnv.t | Tarray of QueryEnv.t * completionType | Tstring of QueryEnv.t @@ -760,6 +760,12 @@ module Completion = struct | Snippet _ | FollowContextPath _ -> 15 end +let kindFromInnerType (t : innerType) = + match t with + | ExtractedType extractedType -> + Completion.ExtractedType (extractedType, `Value) + | TypeExpr typ -> Value typ + module CursorPosition = struct type t = NoCursor | HasCursor | EmptyLoc diff --git a/analysis/src/TypeUtils.ml b/analysis/src/TypeUtils.ml index 95de5fb55..a4e8c18d7 100644 --- a/analysis/src/TypeUtils.ml +++ b/analysis/src/TypeUtils.ml @@ -112,8 +112,7 @@ let rec extractType ~env ~package (t : Types.type_expr) = match t.desc with | Tlink t1 | Tsubst t1 | Tpoly (t1, []) -> extractType ~env ~package t1 | Tconstr (Path.Pident {name = "option"}, [payloadTypeExpr], _) -> - payloadTypeExpr |> extractType ~env ~package - |> Option.map (fun payloadTyp -> Toption (env, payloadTyp)) + Some (Toption (env, TypeExpr payloadTypeExpr)) | Tconstr (Path.Pident {name = "array"}, [payloadTypeExpr], _) -> payloadTypeExpr |> extractType ~env ~package |> Option.map (fun payloadTyp -> Tarray (env, payloadTyp)) @@ -300,9 +299,14 @@ let rec resolveNested (typ : completionType) ~env ~full ~nested = ( TinlineRecord {fields; env}, env, Some (Completable.RecordField {seenFields}) ) - | NVariantPayload {constructorName = "Some"; itemNum = 0}, Toption (env, typ) - -> + | ( NVariantPayload {constructorName = "Some"; itemNum = 0}, + Toption (env, ExtractedType typ) ) -> typ |> resolveNested ~env ~full ~nested + | ( NVariantPayload {constructorName = "Some"; itemNum = 0}, + Toption (env, TypeExpr typ) ) -> + typ + |> extractType ~env ~package:full.package + |> Utils.Option.flatMap (fun t -> t |> resolveNested ~env ~full ~nested) | NVariantPayload {constructorName; itemNum}, Tvariant {env; constructors} -> ( match @@ -415,7 +419,9 @@ let rec extractedTypeToString ?(inner = false) = function | Tstring _ -> "string" | Tarray (_, innerTyp) -> "array<" ^ extractedTypeToString ~inner:true innerTyp ^ ">" - | Toption (_, innerTyp) -> + | Toption (_, TypeExpr innerTyp) -> + "option<" ^ Shared.typeToString innerTyp ^ ">" + | Toption (_, ExtractedType innerTyp) -> "option<" ^ extractedTypeToString ~inner:true innerTyp ^ ">" | Tvariant {variantDecl; variantName} -> if inner then variantName else Shared.declToString variantName variantDecl @@ -426,5 +432,5 @@ let rec extractedTypeToString ?(inner = false) = function let unwrapCompletionTypeIfOption (t : SharedTypes.completionType) = match t with - | Toption (_, unwrapped) -> unwrapped + | Toption (_, ExtractedType unwrapped) -> unwrapped | _ -> t diff --git a/analysis/tests/src/expected/CompletionExpressions.res.txt b/analysis/tests/src/expected/CompletionExpressions.res.txt index 5f3324514..9b259ecd8 100644 --- a/analysis/tests/src/expected/CompletionExpressions.res.txt +++ b/analysis/tests/src/expected/CompletionExpressions.res.txt @@ -155,13 +155,13 @@ Pexp_apply ...[41:11->41:25] (...[41:26->41:47]) Completable: Cexpression CArgument Value[fnTakingRecord]($0)->recordField(nested) [{ "label": "None", - "kind": 4, + "kind": 12, "tags": [], "detail": "otherRecord", "documentation": null }, { "label": "Some(_)", - "kind": 4, + "kind": 12, "tags": [], "detail": "otherRecord", "documentation": null, @@ -324,13 +324,13 @@ Pexp_apply ...[72:11->72:24] (...[72:25->72:27]) Completable: Cexpression CArgument Value[fnTakingArray]($0)->array [{ "label": "None", - "kind": 4, + "kind": 12, "tags": [], "detail": "bool", "documentation": null }, { "label": "Some(_)", - "kind": 4, + "kind": 12, "tags": [], "detail": "bool", "documentation": null, @@ -386,13 +386,13 @@ Pexp_apply ...[81:11->81:24] (...[81:25->81:33]) Completable: Cexpression CArgument Value[fnTakingArray]($0)->array [{ "label": "None", - "kind": 4, + "kind": 12, "tags": [], "detail": "bool", "documentation": null }, { "label": "Some(_)", - "kind": 4, + "kind": 12, "tags": [], "detail": "bool", "documentation": null, @@ -418,13 +418,13 @@ Pexp_apply ...[84:11->84:24] (...[84:25->84:39]) Completable: Cexpression CArgument Value[fnTakingArray]($0)->array [{ "label": "None", - "kind": 4, + "kind": 12, "tags": [], "detail": "bool", "documentation": null }, { "label": "Some(_)", - "kind": 4, + "kind": 12, "tags": [], "detail": "bool", "documentation": null, @@ -495,15 +495,15 @@ Pexp_apply ...[116:11->116:39] (...[116:40->116:56]) Completable: Cexpression CArgument Value[fnTakingRecordWithOptVariant]($0)->recordField(someVariant) [{ "label": "None", - "kind": 4, + "kind": 12, "tags": [], - "detail": "type someVariant = One | Two | Three(int, string)", + "detail": "someVariant", "documentation": null }, { "label": "Some(_)", - "kind": 4, + "kind": 12, "tags": [], - "detail": "type someVariant = One | Two | Three(int, string)", + "detail": "someVariant", "documentation": null, "insertText": "Some(${1:_})", "insertTextFormat": 2 diff --git a/analysis/tests/src/expected/CompletionFunctionArguments.res.txt b/analysis/tests/src/expected/CompletionFunctionArguments.res.txt index a2b6236f6..ce5de8aac 100644 --- a/analysis/tests/src/expected/CompletionFunctionArguments.res.txt +++ b/analysis/tests/src/expected/CompletionFunctionArguments.res.txt @@ -156,9 +156,9 @@ Pexp_apply ...[57:11->57:30] (...[57:31->57:33]) Completable: Cexpression CArgument Value[someFnTakingVariant]($0)=So [{ "label": "Some(_)", - "kind": 4, + "kind": 12, "tags": [], - "detail": "type someVariant = One | Two | Three(int, string)", + "detail": "someVariant", "documentation": null, "sortText": "A Some(_)", "insertText": "Some(${1:_})", diff --git a/analysis/tests/src/expected/CompletionPattern.res.txt b/analysis/tests/src/expected/CompletionPattern.res.txt index e935e98ca..c41f857f4 100644 --- a/analysis/tests/src/expected/CompletionPattern.res.txt +++ b/analysis/tests/src/expected/CompletionPattern.res.txt @@ -485,13 +485,13 @@ posCursor:[137:29] posNoWhite:[137:28] Found pattern:[137:20->137:32] Completable: Cpattern Value[p]->variantPayload::Test($2) [{ "label": "None", - "kind": 4, + "kind": 12, "tags": [], "detail": "bool", "documentation": null }, { "label": "Some(_)", - "kind": 4, + "kind": 12, "tags": [], "detail": "bool", "documentation": null, @@ -573,13 +573,13 @@ posCursor:[153:30] posNoWhite:[153:29] Found pattern:[153:21->153:32] Completable: Cpattern Value[v]->polyvariantPayload::test($2) [{ "label": "None", - "kind": 4, + "kind": 12, "tags": [], "detail": "bool", "documentation": null }, { "label": "Some(_)", - "kind": 4, + "kind": 12, "tags": [], "detail": "bool", "documentation": null, @@ -659,13 +659,13 @@ posCursor:[167:23] posNoWhite:[167:21] Found pattern:[167:16->167:24] Completable: Cpattern Value[s]->tuple($1) [{ "label": "None", - "kind": 4, + "kind": 12, "tags": [], "detail": "bool", "documentation": null }, { "label": "Some(_)", - "kind": 4, + "kind": 12, "tags": [], "detail": "bool", "documentation": null, @@ -691,13 +691,13 @@ posCursor:[170:22] posNoWhite:[170:21] Found pattern:[170:16->170:28] Completable: Cpattern Value[s]->tuple($1) [{ "label": "None", - "kind": 4, + "kind": 12, "tags": [], "detail": "bool", "documentation": null }, { "label": "Some(_)", - "kind": 4, + "kind": 12, "tags": [], "detail": "bool", "documentation": null, @@ -736,13 +736,13 @@ posCursor:[176:41] posNoWhite:[176:40] Found pattern:[176:35->176:47] Completable: Cpattern Value[s]->tuple($1) [{ "label": "None", - "kind": 4, + "kind": 12, "tags": [], "detail": "bool", "documentation": null }, { "label": "Some(_)", - "kind": 4, + "kind": 12, "tags": [], "detail": "bool", "documentation": null, @@ -878,13 +878,13 @@ posCursor:[194:24] posNoWhite:[194:23] Found pattern:[194:23->194:24] Completable: Cpattern Value[s]->tuple($1) [{ "label": "None", - "kind": 4, + "kind": 12, "tags": [], "detail": "bool", "documentation": null }, { "label": "Some(_)", - "kind": 4, + "kind": 12, "tags": [], "detail": "bool", "documentation": null, diff --git a/analysis/tests/src/expected/CompletionTypeAnnotation.res.txt b/analysis/tests/src/expected/CompletionTypeAnnotation.res.txt index 6d7db71a7..65af0a21f 100644 --- a/analysis/tests/src/expected/CompletionTypeAnnotation.res.txt +++ b/analysis/tests/src/expected/CompletionTypeAnnotation.res.txt @@ -142,13 +142,13 @@ XXX Not found! Completable: Cexpression Type[someTuple]->tuple($1) [{ "label": "None", - "kind": 4, + "kind": 12, "tags": [], "detail": "bool", "documentation": null }, { "label": "Some(_)", - "kind": 4, + "kind": 12, "tags": [], "detail": "bool", "documentation": null, @@ -173,13 +173,13 @@ XXX Not found! Completable: Cexpression option [{ "label": "None", - "kind": 4, + "kind": 12, "tags": [], "detail": "type someVariant = One | Two(bool)", "documentation": null }, { "label": "Some(_)", - "kind": 4, + "kind": 12, "tags": [], "detail": "type someVariant = One | Two(bool)", "documentation": null, From ecbb7b7bf69105cd601bd64e09b38dd75eb3e2b3 Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Fri, 3 Feb 2023 14:12:36 +0100 Subject: [PATCH 10/41] make Tarray work with both extracted and type expr types --- analysis/src/CompletionBackEnd.ml | 16 ++++++++++------ analysis/src/SharedTypes.ml | 2 +- analysis/src/TypeUtils.ml | 15 +++++++++++---- .../src/expected/CompletionJsxProps.res.txt | 2 +- .../tests/src/expected/CompletionPattern.res.txt | 6 +++--- 5 files changed, 26 insertions(+), 15 deletions(-) diff --git a/analysis/src/CompletionBackEnd.ml b/analysis/src/CompletionBackEnd.ml index e1f28ed41..8a05bdda3 100644 --- a/analysis/src/CompletionBackEnd.ml +++ b/analysis/src/CompletionBackEnd.ml @@ -709,7 +709,8 @@ and getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env | Some (typ, env) -> [ Completion.create "dummy" ~env - ~kind:(Completion.ExtractedType (Tarray (env, typ), `Type)); + ~kind: + (Completion.ExtractedType (Tarray (env, ExtractedType typ), `Type)); ]) | Pipe -> (* Pipe completion with array just needs to know that it's an array, not @@ -1314,11 +1315,14 @@ let rec completeTypedValue ~full ~prefix ~completionContext ~mode ~insertText:(if !Cfg.supportsSnippets then "[$0]" else "[]") ~sortText:"A" ~kind: - (ExtractedType - ( typ, - match mode with - | Pattern _ -> `Type - | Expression -> `Value )) + (match typ with + | ExtractedType typ -> + ExtractedType + ( typ, + match mode with + | Pattern _ -> `Type + | Expression -> `Value ) + | TypeExpr typ -> Value typ) ~env (); ] else [] diff --git a/analysis/src/SharedTypes.ml b/analysis/src/SharedTypes.ml index aba90b388..840e64dd5 100644 --- a/analysis/src/SharedTypes.ml +++ b/analysis/src/SharedTypes.ml @@ -302,7 +302,7 @@ and completionType = | Texn of QueryEnv.t | Toption of QueryEnv.t * innerType | Tbool of QueryEnv.t - | Tarray of QueryEnv.t * completionType + | Tarray of QueryEnv.t * innerType | Tstring of QueryEnv.t | Tvariant of { env: QueryEnv.t; diff --git a/analysis/src/TypeUtils.ml b/analysis/src/TypeUtils.ml index a4e8c18d7..d32fcbaf8 100644 --- a/analysis/src/TypeUtils.ml +++ b/analysis/src/TypeUtils.ml @@ -114,8 +114,7 @@ let rec extractType ~env ~package (t : Types.type_expr) = | Tconstr (Path.Pident {name = "option"}, [payloadTypeExpr], _) -> Some (Toption (env, TypeExpr payloadTypeExpr)) | Tconstr (Path.Pident {name = "array"}, [payloadTypeExpr], _) -> - payloadTypeExpr |> extractType ~env ~package - |> Option.map (fun payloadTyp -> Tarray (env, payloadTyp)) + Some (Tarray (env, TypeExpr payloadTypeExpr)) | Tconstr (Path.Pident {name = "bool"}, [], _) -> Some (Tbool env) | Tconstr (Path.Pident {name = "string"}, [], _) -> Some (Tstring env) | Tconstr (Path.Pident {name = "exn"}, [], _) -> Some (Texn env) @@ -341,7 +340,13 @@ let rec resolveNested (typ : completionType) ~env ~full ~nested = |> extractType ~env ~package:full.package |> Utils.Option.flatMap (fun typ -> typ |> resolveNested ~env ~full ~nested))) - | NArray, Tarray (env, typ) -> typ |> resolveNested ~env ~full ~nested + | NArray, Tarray (env, ExtractedType typ) -> + typ |> resolveNested ~env ~full ~nested + | NArray, Tarray (env, TypeExpr typ) -> + typ + |> extractType ~env ~package:full.package + |> Utils.Option.flatMap (fun typ -> + typ |> resolveNested ~env ~full ~nested) | _ -> None) let getArgs ~env (t : Types.type_expr) ~full = @@ -417,7 +422,9 @@ let rec extractedTypeToString ?(inner = false) = function else Shared.typeToString typ | Tbool _ -> "bool" | Tstring _ -> "string" - | Tarray (_, innerTyp) -> + | Tarray (_, TypeExpr innerTyp) -> + "array<" ^ Shared.typeToString innerTyp ^ ">" + | Tarray (_, ExtractedType innerTyp) -> "array<" ^ extractedTypeToString ~inner:true innerTyp ^ ">" | Toption (_, TypeExpr innerTyp) -> "option<" ^ Shared.typeToString innerTyp ^ ">" diff --git a/analysis/tests/src/expected/CompletionJsxProps.res.txt b/analysis/tests/src/expected/CompletionJsxProps.res.txt index 45885f535..398011f2f 100644 --- a/analysis/tests/src/expected/CompletionJsxProps.res.txt +++ b/analysis/tests/src/expected/CompletionJsxProps.res.txt @@ -173,7 +173,7 @@ Completable: Cexpression CJsxPropValue [CompletionSupport, TestComponent] testAr "label": "[]", "kind": 12, "tags": [], - "detail": "type testVariant = One | Two | Three(int)", + "detail": "testVariant", "documentation": null, "sortText": "A", "insertText": "{[$0]}", diff --git a/analysis/tests/src/expected/CompletionPattern.res.txt b/analysis/tests/src/expected/CompletionPattern.res.txt index c41f857f4..f65036bea 100644 --- a/analysis/tests/src/expected/CompletionPattern.res.txt +++ b/analysis/tests/src/expected/CompletionPattern.res.txt @@ -410,7 +410,7 @@ XXX Not found! Completable: Cpattern Value[c] [{ "label": "[]", - "kind": 22, + "kind": 12, "tags": [], "detail": "bool", "documentation": null, @@ -539,7 +539,7 @@ posCursor:[143:35] posNoWhite:[143:34] Found pattern:[143:20->143:38] Completable: Cpattern Value[p]->variantPayload::Test($3) [{ "label": "[]", - "kind": 22, + "kind": 12, "tags": [], "detail": "bool", "documentation": null, @@ -625,7 +625,7 @@ posCursor:[159:36] posNoWhite:[159:35] Found pattern:[159:21->159:38] Completable: Cpattern Value[v]->polyvariantPayload::test($3) [{ "label": "[]", - "kind": 22, + "kind": 12, "tags": [], "detail": "bool", "documentation": null, From 8669c593ef1f573d7bfcd0237d51955403d12da7 Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Fri, 3 Feb 2023 14:38:28 +0100 Subject: [PATCH 11/41] start working on moving through nested pattern paths --- analysis/src/CompletionBackEnd.ml | 23 ++------ analysis/src/TypeUtils.ml | 45 +++++++++++++++ analysis/tests/src/CompletionInferValues.res | 19 +++++-- .../expected/CompletionInferValues.res.txt | 56 ++++++++++++++----- 4 files changed, 104 insertions(+), 39 deletions(-) diff --git a/analysis/src/CompletionBackEnd.ml b/analysis/src/CompletionBackEnd.ml index 8a05bdda3..c5b538a86 100644 --- a/analysis/src/CompletionBackEnd.ml +++ b/analysis/src/CompletionBackEnd.ml @@ -606,10 +606,6 @@ let completionsGetTypeEnv = function type getCompletionsForContextPathMode = Regular | Pipe -type completionsTypeEnvTyp = - | TypeExpr of Types.type_expr - | ExtractedType of completionType - let completionsGetCompletionType ~full = function | {Completion.kind = Value typ; env} :: _ | {Completion.kind = ObjLabel typ; env} :: _ @@ -1098,21 +1094,10 @@ and getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env ~scope with | Some (typ, env) -> ( - let typ = - match typ with - | ExtractedType typ -> Some typ - | TypeExpr typ -> typ |> TypeUtils.extractType ~env ~package - in - match typ with - | None -> [] - | Some typ -> ( - match typ |> TypeUtils.resolveNested ~env ~full ~nested with - | Some (typ, env, _completionContext) -> - [ - Completion.create "dummy" ~env - ~kind:(Completion.ExtractedType (typ, `Value)); - ] - | None -> [])) + match typ |> TypeUtils.resolveNestedPatternPath ~env ~full ~nested with + | Some (typ, env) -> + [Completion.create "dummy" ~env ~kind:(kindFromInnerType typ)] + | None -> []) | None -> []) let getOpens ~debug ~rawOpens ~package ~env = diff --git a/analysis/src/TypeUtils.ml b/analysis/src/TypeUtils.ml index d32fcbaf8..5b67dea0c 100644 --- a/analysis/src/TypeUtils.ml +++ b/analysis/src/TypeUtils.ml @@ -349,6 +349,51 @@ let rec resolveNested (typ : completionType) ~env ~full ~nested = typ |> resolveNested ~env ~full ~nested) | _ -> None) +let rec resolveNestedPatternPath (typ : innerType) ~env ~full ~nested = + let t = + match typ with + | TypeExpr t -> t |> extractType ~env ~package:full.package + | ExtractedType t -> Some t + in + match nested with + | [] -> None + | [finalPatternPath] -> ( + match t with + | None -> None + | Some completionType -> ( + match (finalPatternPath, completionType) with + | ( Completable.NFollowRecordField {fieldName}, + (TinlineRecord {env; fields} | Trecord {env; fields}) ) -> ( + match + fields + |> List.find_opt (fun (field : field) -> field.fname.txt = fieldName) + with + | None -> None + | Some {typ; optional} -> + let typ = if optional then Utils.unwrapIfOption typ else typ in + Some (TypeExpr typ, env)) + | _ -> None)) + | patternPath :: nested -> ( + match t with + | None -> None + | Some completionType -> ( + match (patternPath, completionType) with + | ( Completable.NFollowRecordField {fieldName}, + (TinlineRecord {env; fields} | Trecord {env; fields}) ) -> ( + match + fields + |> List.find_opt (fun (field : field) -> field.fname.txt = fieldName) + with + | None -> None + | Some {typ; optional} -> + let typ = if optional then Utils.unwrapIfOption typ else typ in + typ + |> extractType ~env ~package:full.package + |> Utils.Option.flatMap (fun typ -> + ExtractedType typ + |> resolveNestedPatternPath ~env ~full ~nested)) + | _ -> None)) + let getArgs ~env (t : Types.type_expr) ~full = let rec getArgsLoop ~env (t : Types.type_expr) ~full ~currentArgumentPosition = diff --git a/analysis/tests/src/CompletionInferValues.res b/analysis/tests/src/CompletionInferValues.res index 684723e85..8ff64838a 100644 --- a/analysis/tests/src/CompletionInferValues.res +++ b/analysis/tests/src/CompletionInferValues.res @@ -63,6 +63,7 @@ type someNestedRecord = {someRecord: someRecord} type someRecordWithNestedStuff = { things: string, + someInt: int, srecord: someRecord, nested: someNestedRecord, someStuff: bool, @@ -70,11 +71,17 @@ type someRecordWithNestedStuff = { type otherNestedRecord = {someRecord: someRecord, someTuple: (someVariant, int)} -// let x: someRecordWithNestedStuff = {things: "", someRecord: {name: "Hello", age: 123}, someStuff: true}; let {srecord} = x; srecord. -// ^com +// let x: someRecordWithNestedStuff = Obj.magic(); let {srecord} = x; srecord. +// ^com -// let x: someRecordWithNestedStuff = {things: "", someRecord: {name: "Hello", age: 123}, someStuff: true}; let {nested: aliased} = x; aliased. -// ^com +// let x: someRecordWithNestedStuff = Obj.magic(); let {nested: aliased} = x; aliased. +// ^com -// let x: someRecordWithNestedStuff = {things: "", someRecord: {name: "Hello", age: 123}, someStuff: true}; let {srecord, nested: {someRecord}} = x; someRecord. -// ^com +// let x: someRecordWithNestedStuff = Obj.magic(); let {srecord, nested: {someRecord}} = x; someRecord. +// ^com + +// let x: someRecordWithNestedStuff = Obj.magic(); let {things} = x; things->slic +// ^com + +// let x: someRecordWithNestedStuff = Obj.magic(); let {someInt} = x; someInt->toS +// ^com diff --git a/analysis/tests/src/expected/CompletionInferValues.res.txt b/analysis/tests/src/expected/CompletionInferValues.res.txt index 0ab90afc9..c8ff21ecf 100644 --- a/analysis/tests/src/expected/CompletionInferValues.res.txt +++ b/analysis/tests/src/expected/CompletionInferValues.res.txt @@ -220,51 +220,79 @@ Completable: Cpath Value[x]."" "documentation": null }] -Complete src/CompletionInferValues.res 72:135 -posCursor:[72:135] posNoWhite:[72:134] Found expr:[72:127->72:135] -Pexp_field [72:127->72:134] _:[81:0->72:135] +Complete src/CompletionInferValues.res 73:78 +posCursor:[73:78] posNoWhite:[73:77] Found expr:[73:70->73:78] +Pexp_field [73:70->73:77] _:[88:0->73:78] Completable: Cpath Value[srecord]."" [{ "label": "name", "kind": 5, "tags": [], - "detail": "name: string\n\nsomeRecord", + "detail": "name: string\n\ntype someRecord = {name: string, age: int}", "documentation": null }, { "label": "age", "kind": 5, "tags": [], - "detail": "age: int\n\nsomeRecord", + "detail": "age: int\n\ntype someRecord = {name: string, age: int}", "documentation": null }] -Complete src/CompletionInferValues.res 75:143 -posCursor:[75:143] posNoWhite:[75:142] Found expr:[75:135->75:143] -Pexp_field [75:135->75:142] _:[81:0->75:143] +Complete src/CompletionInferValues.res 76:86 +posCursor:[76:86] posNoWhite:[76:85] Found expr:[76:78->76:86] +Pexp_field [76:78->76:85] _:[88:0->76:86] Completable: Cpath Value[aliased]."" [{ "label": "someRecord", "kind": 5, "tags": [], - "detail": "someRecord: someRecord\n\nsomeNestedRecord", + "detail": "someRecord: someRecord\n\ntype someNestedRecord = {someRecord: someRecord}", "documentation": null }] -Complete src/CompletionInferValues.res 78:160 -posCursor:[78:160] posNoWhite:[78:159] Found expr:[78:149->78:160] -Pexp_field [78:149->78:159] _:[81:0->78:160] +Complete src/CompletionInferValues.res 79:103 +posCursor:[79:103] posNoWhite:[79:102] Found expr:[79:92->79:103] +Pexp_field [79:92->79:102] _:[88:0->79:103] Completable: Cpath Value[someRecord]."" [{ "label": "name", "kind": 5, "tags": [], - "detail": "name: string\n\nsomeRecord", + "detail": "name: string\n\ntype someRecord = {name: string, age: int}", "documentation": null }, { "label": "age", "kind": 5, "tags": [], - "detail": "age: int\n\nsomeRecord", + "detail": "age: int\n\ntype someRecord = {name: string, age: int}", "documentation": null }] +Complete src/CompletionInferValues.res 82:81 +posCursor:[82:81] posNoWhite:[82:80] Found expr:[82:69->82:81] +Completable: Cpath Value[things]->slic +[{ + "label": "Js.String2.sliceToEnd", + "kind": 12, + "tags": [], + "detail": "(t, ~from: int) => t", + "documentation": {"kind": "markdown", "value": "\n`sliceToEnd(str, from:n)` returns the substring of `str` starting at character\n`n` to the end of the string.\n- If `n` is negative, then it is evaluated as `length(str - n)`.\n- If `n` is greater than the length of `str`, then sliceToEnd returns the empty string.\n\nSee [`String.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice) on MDN.\n\n```res example\nJs.String2.sliceToEnd(\"abcdefg\", ~from=4) == \"efg\"\nJs.String2.sliceToEnd(\"abcdefg\", ~from=-2) == \"fg\"\nJs.String2.sliceToEnd(\"abcdefg\", ~from=7) == \"\"\n```\n"} + }, { + "label": "Js.String2.slice", + "kind": 12, + "tags": [], + "detail": "(t, ~from: int, ~to_: int) => t", + "documentation": {"kind": "markdown", "value": "\n`slice(str, from:n1, to_:n2)` returns the substring of `str` starting at\ncharacter `n1` up to but not including `n2`.\n- If either `n1` or `n2` is negative, then it is evaluated as `length(str - n1)` or `length(str - n2)`.\n- If `n2` is greater than the length of `str`, then it is treated as `length(str)`.\n- If `n1` is greater than `n2`, slice returns the empty string.\n\nSee [`String.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice) on MDN.\n\n```res example\nJs.String2.slice(\"abcdefg\", ~from=2, ~to_=5) == \"cde\"\nJs.String2.slice(\"abcdefg\", ~from=2, ~to_=9) == \"cdefg\"\nJs.String2.slice(\"abcdefg\", ~from=-4, ~to_=-2) == \"de\"\nJs.String2.slice(\"abcdefg\", ~from=5, ~to_=1) == \"\"\n```\n"} + }] + +Complete src/CompletionInferValues.res 85:82 +posCursor:[85:82] posNoWhite:[85:81] Found expr:[85:70->85:82] +Completable: Cpath Value[someInt]->toS +[{ + "label": "Belt.Int.toString", + "kind": 12, + "tags": [], + "detail": "int => string", + "documentation": {"kind": "markdown", "value": "\n Converts a given `int` to a `string`. Uses the JavaScript `String` constructor under the hood.\n\n ```res example\n Js.log(Belt.Int.toString(1) === \"1\") /* true */\n ```\n"} + }] + From e1764e62651824af75eabc84da9fc8d5a04ddf8d Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Fri, 3 Feb 2023 18:24:55 +0100 Subject: [PATCH 12/41] follow tuples --- analysis/src/TypeUtils.ml | 39 ++++++++++++------- analysis/tests/src/CompletionInferValues.res | 9 +++++ .../expected/CompletionInferValues.res.txt | 37 +++++++++++------- 3 files changed, 59 insertions(+), 26 deletions(-) diff --git a/analysis/src/TypeUtils.ml b/analysis/src/TypeUtils.ml index 5b67dea0c..24ba129f0 100644 --- a/analysis/src/TypeUtils.ml +++ b/analysis/src/TypeUtils.ml @@ -349,6 +349,15 @@ let rec resolveNested (typ : completionType) ~env ~full ~nested = typ |> resolveNested ~env ~full ~nested) | _ -> None) +let findTypeOfRecordField fields ~fieldName = + match + fields |> List.find_opt (fun (field : field) -> field.fname.txt = fieldName) + with + | None -> None + | Some {typ; optional} -> + let typ = if optional then Utils.unwrapIfOption typ else typ in + Some typ + let rec resolveNestedPatternPath (typ : innerType) ~env ~full ~nested = let t = match typ with @@ -364,14 +373,13 @@ let rec resolveNestedPatternPath (typ : innerType) ~env ~full ~nested = match (finalPatternPath, completionType) with | ( Completable.NFollowRecordField {fieldName}, (TinlineRecord {env; fields} | Trecord {env; fields}) ) -> ( - match - fields - |> List.find_opt (fun (field : field) -> field.fname.txt = fieldName) - with + match fields |> findTypeOfRecordField ~fieldName with + | None -> None + | Some typ -> Some (TypeExpr typ, env)) + | NTupleItem {itemNum}, Tuple (env, tupleItems, _) -> ( + match List.nth_opt tupleItems itemNum with | None -> None - | Some {typ; optional} -> - let typ = if optional then Utils.unwrapIfOption typ else typ in - Some (TypeExpr typ, env)) + | Some typ -> Some (TypeExpr typ, env)) | _ -> None)) | patternPath :: nested -> ( match t with @@ -380,13 +388,18 @@ let rec resolveNestedPatternPath (typ : innerType) ~env ~full ~nested = match (patternPath, completionType) with | ( Completable.NFollowRecordField {fieldName}, (TinlineRecord {env; fields} | Trecord {env; fields}) ) -> ( - match - fields - |> List.find_opt (fun (field : field) -> field.fname.txt = fieldName) - with + match fields |> findTypeOfRecordField ~fieldName with + | None -> None + | Some typ -> + typ + |> extractType ~env ~package:full.package + |> Utils.Option.flatMap (fun typ -> + ExtractedType typ + |> resolveNestedPatternPath ~env ~full ~nested)) + | NTupleItem {itemNum}, Tuple (env, tupleItems, _) -> ( + match List.nth_opt tupleItems itemNum with | None -> None - | Some {typ; optional} -> - let typ = if optional then Utils.unwrapIfOption typ else typ in + | Some typ -> typ |> extractType ~env ~package:full.package |> Utils.Option.flatMap (fun typ -> diff --git a/analysis/tests/src/CompletionInferValues.res b/analysis/tests/src/CompletionInferValues.res index 8ff64838a..1cb5db042 100644 --- a/analysis/tests/src/CompletionInferValues.res +++ b/analysis/tests/src/CompletionInferValues.res @@ -71,17 +71,26 @@ type someRecordWithNestedStuff = { type otherNestedRecord = {someRecord: someRecord, someTuple: (someVariant, int)} +// Destructure record // let x: someRecordWithNestedStuff = Obj.magic(); let {srecord} = x; srecord. // ^com +// Follow aliased // let x: someRecordWithNestedStuff = Obj.magic(); let {nested: aliased} = x; aliased. // ^com +// Follow nested record // let x: someRecordWithNestedStuff = Obj.magic(); let {srecord, nested: {someRecord}} = x; someRecord. // ^com +// Destructure string // let x: someRecordWithNestedStuff = Obj.magic(); let {things} = x; things->slic // ^com +// Destructure int // let x: someRecordWithNestedStuff = Obj.magic(); let {someInt} = x; someInt->toS // ^com + +// Follow tuples +// let x: otherNestedRecord = Obj.magic(); let {someTuple} = x; let (_, someInt) = someTuple; someInt->toS +// ^com diff --git a/analysis/tests/src/expected/CompletionInferValues.res.txt b/analysis/tests/src/expected/CompletionInferValues.res.txt index c8ff21ecf..5b72b592c 100644 --- a/analysis/tests/src/expected/CompletionInferValues.res.txt +++ b/analysis/tests/src/expected/CompletionInferValues.res.txt @@ -220,9 +220,9 @@ Completable: Cpath Value[x]."" "documentation": null }] -Complete src/CompletionInferValues.res 73:78 -posCursor:[73:78] posNoWhite:[73:77] Found expr:[73:70->73:78] -Pexp_field [73:70->73:77] _:[88:0->73:78] +Complete src/CompletionInferValues.res 74:78 +posCursor:[74:78] posNoWhite:[74:77] Found expr:[74:70->74:78] +Pexp_field [74:70->74:77] _:[97:0->74:78] Completable: Cpath Value[srecord]."" [{ "label": "name", @@ -238,9 +238,9 @@ Completable: Cpath Value[srecord]."" "documentation": null }] -Complete src/CompletionInferValues.res 76:86 -posCursor:[76:86] posNoWhite:[76:85] Found expr:[76:78->76:86] -Pexp_field [76:78->76:85] _:[88:0->76:86] +Complete src/CompletionInferValues.res 78:86 +posCursor:[78:86] posNoWhite:[78:85] Found expr:[78:78->78:86] +Pexp_field [78:78->78:85] _:[97:0->78:86] Completable: Cpath Value[aliased]."" [{ "label": "someRecord", @@ -250,9 +250,9 @@ Completable: Cpath Value[aliased]."" "documentation": null }] -Complete src/CompletionInferValues.res 79:103 -posCursor:[79:103] posNoWhite:[79:102] Found expr:[79:92->79:103] -Pexp_field [79:92->79:102] _:[88:0->79:103] +Complete src/CompletionInferValues.res 82:103 +posCursor:[82:103] posNoWhite:[82:102] Found expr:[82:92->82:103] +Pexp_field [82:92->82:102] _:[97:0->82:103] Completable: Cpath Value[someRecord]."" [{ "label": "name", @@ -268,8 +268,8 @@ Completable: Cpath Value[someRecord]."" "documentation": null }] -Complete src/CompletionInferValues.res 82:81 -posCursor:[82:81] posNoWhite:[82:80] Found expr:[82:69->82:81] +Complete src/CompletionInferValues.res 86:81 +posCursor:[86:81] posNoWhite:[86:80] Found expr:[86:69->86:81] Completable: Cpath Value[things]->slic [{ "label": "Js.String2.sliceToEnd", @@ -285,8 +285,19 @@ Completable: Cpath Value[things]->slic "documentation": {"kind": "markdown", "value": "\n`slice(str, from:n1, to_:n2)` returns the substring of `str` starting at\ncharacter `n1` up to but not including `n2`.\n- If either `n1` or `n2` is negative, then it is evaluated as `length(str - n1)` or `length(str - n2)`.\n- If `n2` is greater than the length of `str`, then it is treated as `length(str)`.\n- If `n1` is greater than `n2`, slice returns the empty string.\n\nSee [`String.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice) on MDN.\n\n```res example\nJs.String2.slice(\"abcdefg\", ~from=2, ~to_=5) == \"cde\"\nJs.String2.slice(\"abcdefg\", ~from=2, ~to_=9) == \"cdefg\"\nJs.String2.slice(\"abcdefg\", ~from=-4, ~to_=-2) == \"de\"\nJs.String2.slice(\"abcdefg\", ~from=5, ~to_=1) == \"\"\n```\n"} }] -Complete src/CompletionInferValues.res 85:82 -posCursor:[85:82] posNoWhite:[85:81] Found expr:[85:70->85:82] +Complete src/CompletionInferValues.res 90:82 +posCursor:[90:82] posNoWhite:[90:81] Found expr:[90:70->90:82] +Completable: Cpath Value[someInt]->toS +[{ + "label": "Belt.Int.toString", + "kind": 12, + "tags": [], + "detail": "int => string", + "documentation": {"kind": "markdown", "value": "\n Converts a given `int` to a `string`. Uses the JavaScript `String` constructor under the hood.\n\n ```res example\n Js.log(Belt.Int.toString(1) === \"1\") /* true */\n ```\n"} + }] + +Complete src/CompletionInferValues.res 94:106 +posCursor:[94:106] posNoWhite:[94:105] Found expr:[94:94->94:106] Completable: Cpath Value[someInt]->toS [{ "label": "Belt.Int.toString", From df5db9d0568cdac66d7d7d947ade7fef7ad847c6 Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Fri, 3 Feb 2023 18:55:52 +0100 Subject: [PATCH 13/41] handle switches --- analysis/src/CompletionFrontEnd.ml | 21 ++++++---- analysis/tests/src/CompletionInferValues.res | 4 ++ .../src/expected/BrokenParserCases.res.txt | 2 - .../tests/src/expected/Completion.res.txt | 4 -- .../CompletionFunctionArguments.res.txt | 19 +-------- .../expected/CompletionInferValues.res.txt | 18 ++++++-- .../src/expected/CompletionPattern.res.txt | 41 +------------------ 7 files changed, 34 insertions(+), 75 deletions(-) diff --git a/analysis/src/CompletionFrontEnd.ml b/analysis/src/CompletionFrontEnd.ml index 6bcf83350..33241898f 100644 --- a/analysis/src/CompletionFrontEnd.ml +++ b/analysis/src/CompletionFrontEnd.ml @@ -534,14 +534,6 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor ~text = | false, false -> ())) | _ -> unsetLookingForPat () in - - let case (iterator : Ast_iterator.iterator) (case : Parsetree.case) = - let oldScope = !scope in - scopePattern ?contextPath:!currentCtxPath case.pc_lhs; - completePattern case.pc_lhs; - Ast_iterator.default_iterator.case iterator case; - scope := oldScope - in let structure (iterator : Ast_iterator.iterator) (structure : Parsetree.structure) = let oldScope = !scope in @@ -787,6 +779,18 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor ~text = in typedCompletionExpr expr; match expr.pexp_desc with + | Pexp_match (_expr, []) -> () + | Pexp_match (expr, cases) -> + let ctxPath = exprToContextPath expr in + let oldCtxPath = !currentCtxPath in + cases + |> List.iter (fun (case : Parsetree.case) -> + let oldScope = !scope in + scopePattern ?contextPath:ctxPath case.pc_lhs; + completePattern case.pc_lhs; + Ast_iterator.default_iterator.case iterator case; + scope := oldScope); + resetCurrentCtxPath oldCtxPath | Pexp_apply ( {pexp_desc = Pexp_ident {txt = Lident "|."; loc = opLoc}}, [ @@ -1157,7 +1161,6 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor ~text = { Ast_iterator.default_iterator with attribute; - case; expr; location; module_expr; diff --git a/analysis/tests/src/CompletionInferValues.res b/analysis/tests/src/CompletionInferValues.res index 1cb5db042..32b9f170b 100644 --- a/analysis/tests/src/CompletionInferValues.res +++ b/analysis/tests/src/CompletionInferValues.res @@ -94,3 +94,7 @@ type otherNestedRecord = {someRecord: someRecord, someTuple: (someVariant, int)} // Follow tuples // let x: otherNestedRecord = Obj.magic(); let {someTuple} = x; let (_, someInt) = someTuple; someInt->toS // ^com + +// Same as above, but follow in switch case +// let x: otherNestedRecord; switch x { | {someTuple} => let (_, someInt) = someTuple; someInt->toS } +// ^com diff --git a/analysis/tests/src/expected/BrokenParserCases.res.txt b/analysis/tests/src/expected/BrokenParserCases.res.txt index 1c1134ac2..0d8fe0ebe 100644 --- a/analysis/tests/src/expected/BrokenParserCases.res.txt +++ b/analysis/tests/src/expected/BrokenParserCases.res.txt @@ -5,13 +5,11 @@ Completable: CnamedArg(Value[someFn], isOff, [isOff]) [] Complete src/BrokenParserCases.res 6:17 -posCursor:[6:17] posNoWhite:[6:16] Found expr:[6:3->6:21] posCursor:[6:17] posNoWhite:[6:16] Found pattern:[6:16->6:19] Completable: Cpattern Value[s]=t [] Complete src/BrokenParserCases.res 10:29 -posCursor:[10:29] posNoWhite:[10:27] Found expr:[10:11->10:41] posCursor:[10:29] posNoWhite:[10:27] Found pattern:[10:24->10:39] posCursor:[10:29] posNoWhite:[10:27] Found pattern:[10:24->10:28] Ppat_construct None:[10:24->10:28] diff --git a/analysis/tests/src/expected/Completion.res.txt b/analysis/tests/src/expected/Completion.res.txt index c7a4bce5e..c7f270b8f 100644 --- a/analysis/tests/src/expected/Completion.res.txt +++ b/analysis/tests/src/expected/Completion.res.txt @@ -965,7 +965,6 @@ Resolved opens 2 Completion.res Completion.res [] Complete src/Completion.res 243:8 -posCursor:[243:8] posNoWhite:[243:7] Found expr:[241:8->246:1] posCursor:[243:8] posNoWhite:[243:7] Found expr:[242:14->243:8] Pexp_apply ...[243:3->243:4] (...[242:14->242:15], ...[243:5->243:8]) posCursor:[243:8] posNoWhite:[243:7] Found expr:[243:5->243:8] @@ -1385,7 +1384,6 @@ Resolved opens 2 Completion.res Completion.res }] Complete src/Completion.res 343:57 -posCursor:[343:57] posNoWhite:[343:56] Found expr:[343:10->346:23] posCursor:[343:57] posNoWhite:[343:56] Found expr:[343:53->346:23] posCursor:[343:57] posNoWhite:[343:56] Found expr:[343:53->343:57] Pexp_ident this:[343:53->343:57] @@ -1445,7 +1443,6 @@ posCursor:[355:23] posNoWhite:[355:22] Found expr:[355:12->355:23] Complete src/Completion.res 362:8 posCursor:[362:8] posNoWhite:[362:7] Found expr:[360:8->365:3] -posCursor:[362:8] posNoWhite:[362:7] Found expr:[361:2->365:3] posCursor:[362:8] posNoWhite:[362:7] Found pattern:[362:7->364:5] posCursor:[362:8] posNoWhite:[362:7] Found pattern:[362:7->362:8] Ppat_construct T:[362:7->362:8] @@ -1482,7 +1479,6 @@ Resolved opens 2 Completion.res Completion.res Complete src/Completion.res 373:21 posCursor:[373:21] posNoWhite:[373:20] Found expr:[371:8->376:3] -posCursor:[373:21] posNoWhite:[373:20] Found expr:[372:2->376:3] posCursor:[373:21] posNoWhite:[373:20] Found pattern:[373:7->375:5] posCursor:[373:21] posNoWhite:[373:20] Found pattern:[373:7->373:21] Ppat_construct AndThatOther.T:[373:7->373:21] diff --git a/analysis/tests/src/expected/CompletionFunctionArguments.res.txt b/analysis/tests/src/expected/CompletionFunctionArguments.res.txt index ce5de8aac..4d1f71d05 100644 --- a/analysis/tests/src/expected/CompletionFunctionArguments.res.txt +++ b/analysis/tests/src/expected/CompletionFunctionArguments.res.txt @@ -57,23 +57,8 @@ Complete src/CompletionFunctionArguments.res 21:27 posCursor:[21:27] posNoWhite:[21:26] Found expr:[19:8->25:1] Pexp_apply ...[19:8->19:14] (~isOn20:3->20:7=...[21:7->23:8]) posCursor:[21:27] posNoWhite:[21:26] Found expr:[21:7->23:8] -posCursor:[21:27] posNoWhite:[21:26] Found expr:[21:7->21:28] -posCursor:[21:27] posNoWhite:[21:26] Found expr:[21:14->21:28] -Pexp_apply ...[21:14->21:20] (~isOn21:22->21:26=...__ghost__[0:-1->0:-1]) -Completable: Cexpression CArgument Value[someFn](~isOn) -[{ - "label": "true", - "kind": 4, - "tags": [], - "detail": "bool", - "documentation": null - }, { - "label": "false", - "kind": 4, - "tags": [], - "detail": "bool", - "documentation": null - }] +posCursor:[21:27] posNoWhite:[21:26] Found expr:[21:7->23:8] +[] Complete src/CompletionFunctionArguments.res 34:24 posCursor:[34:24] posNoWhite:[34:23] Found expr:[34:11->34:25] diff --git a/analysis/tests/src/expected/CompletionInferValues.res.txt b/analysis/tests/src/expected/CompletionInferValues.res.txt index 5b72b592c..e1e0020e7 100644 --- a/analysis/tests/src/expected/CompletionInferValues.res.txt +++ b/analysis/tests/src/expected/CompletionInferValues.res.txt @@ -222,7 +222,7 @@ Completable: Cpath Value[x]."" Complete src/CompletionInferValues.res 74:78 posCursor:[74:78] posNoWhite:[74:77] Found expr:[74:70->74:78] -Pexp_field [74:70->74:77] _:[97:0->74:78] +Pexp_field [74:70->74:77] _:[101:0->74:78] Completable: Cpath Value[srecord]."" [{ "label": "name", @@ -240,7 +240,7 @@ Completable: Cpath Value[srecord]."" Complete src/CompletionInferValues.res 78:86 posCursor:[78:86] posNoWhite:[78:85] Found expr:[78:78->78:86] -Pexp_field [78:78->78:85] _:[97:0->78:86] +Pexp_field [78:78->78:85] _:[101:0->78:86] Completable: Cpath Value[aliased]."" [{ "label": "someRecord", @@ -252,7 +252,7 @@ Completable: Cpath Value[aliased]."" Complete src/CompletionInferValues.res 82:103 posCursor:[82:103] posNoWhite:[82:102] Found expr:[82:92->82:103] -Pexp_field [82:92->82:102] _:[97:0->82:103] +Pexp_field [82:92->82:102] _:[101:0->82:103] Completable: Cpath Value[someRecord]."" [{ "label": "name", @@ -307,3 +307,15 @@ Completable: Cpath Value[someInt]->toS "documentation": {"kind": "markdown", "value": "\n Converts a given `int` to a `string`. Uses the JavaScript `String` constructor under the hood.\n\n ```res example\n Js.log(Belt.Int.toString(1) === \"1\") /* true */\n ```\n"} }] +Complete src/CompletionInferValues.res 98:99 +posCursor:[98:99] posNoWhite:[98:98] Found expr:[98:57->98:99] +posCursor:[98:99] posNoWhite:[98:98] Found expr:[98:87->98:99] +Completable: Cpath Value[someInt]->toS +[{ + "label": "Belt.Int.toString", + "kind": 12, + "tags": [], + "detail": "int => string", + "documentation": {"kind": "markdown", "value": "\n Converts a given `int` to a `string`. Uses the JavaScript `String` constructor under the hood.\n\n ```res example\n Js.log(Belt.Int.toString(1) === \"1\") /* true */\n ```\n"} + }] + diff --git a/analysis/tests/src/expected/CompletionPattern.res.txt b/analysis/tests/src/expected/CompletionPattern.res.txt index f65036bea..bac7941e9 100644 --- a/analysis/tests/src/expected/CompletionPattern.res.txt +++ b/analysis/tests/src/expected/CompletionPattern.res.txt @@ -1,5 +1,5 @@ Complete src/CompletionPattern.res 7:13 -posCursor:[7:13] posNoWhite:[7:12] Found expr:[7:3->7:13] +XXX Not found! [] Complete src/CompletionPattern.res 10:15 @@ -16,7 +16,6 @@ Completable: Cpattern Value[v] }] Complete src/CompletionPattern.res 13:18 -posCursor:[13:18] posNoWhite:[13:17] Found expr:[13:3->13:24] posCursor:[13:18] posNoWhite:[13:17] Found pattern:[13:16->13:22] posCursor:[13:18] posNoWhite:[13:17] Found pattern:[13:17->13:18] Completable: Cpattern Value[v]=t->tuple($0) @@ -29,7 +28,6 @@ Completable: Cpattern Value[v]=t->tuple($0) }] Complete src/CompletionPattern.res 16:25 -posCursor:[16:25] posNoWhite:[16:24] Found expr:[16:3->16:32] posCursor:[16:25] posNoWhite:[16:24] Found pattern:[16:16->16:30] posCursor:[16:25] posNoWhite:[16:24] Found pattern:[16:23->16:29] posCursor:[16:25] posNoWhite:[16:24] Found pattern:[16:24->16:25] @@ -60,7 +58,6 @@ Completable: Cpattern Value[x] }] Complete src/CompletionPattern.res 24:17 -posCursor:[24:17] posNoWhite:[24:16] Found expr:[24:3->24:17] posCursor:[24:17] posNoWhite:[24:16] Found pattern:[24:16->24:17] Completable: Cpattern Value[x]=t [{ @@ -86,7 +83,6 @@ Completable: Cpattern Value[f] }] Complete src/CompletionPattern.res 49:17 -posCursor:[49:17] posNoWhite:[49:16] Found expr:[49:3->49:19] posCursor:[49:17] posNoWhite:[49:16] Found pattern:[49:16->49:18] Completable: Cpattern Value[f]->recordBody [{ @@ -116,7 +112,6 @@ Completable: Cpattern Value[f]->recordBody }] Complete src/CompletionPattern.res 52:24 -posCursor:[52:24] posNoWhite:[52:22] Found expr:[52:3->52:36] posCursor:[52:24] posNoWhite:[52:22] Found pattern:[52:16->52:35] Completable: Cpattern Value[f]->recordBody [{ @@ -134,7 +129,6 @@ Completable: Cpattern Value[f]->recordBody }] Complete src/CompletionPattern.res 55:19 -posCursor:[55:19] posNoWhite:[55:18] Found expr:[55:3->55:21] posCursor:[55:19] posNoWhite:[55:18] Found pattern:[55:16->55:20] posCursor:[55:19] posNoWhite:[55:18] Found pattern:[55:17->55:19] Completable: Cpattern Value[f]=fi->recordBody @@ -147,7 +141,6 @@ Completable: Cpattern Value[f]=fi->recordBody }] Complete src/CompletionPattern.res 58:19 -posCursor:[58:19] posNoWhite:[58:18] Found expr:[58:3->58:25] posCursor:[58:19] posNoWhite:[58:18] Found pattern:[58:16->58:24] posCursor:[58:19] posNoWhite:[58:18] Found pattern:[58:17->58:20] posCursor:[58:19] posNoWhite:[58:18] Found pattern:[58:18->58:19] @@ -161,7 +154,6 @@ Completable: Cpattern Value[z]=o->tuple($0), recordBody }] Complete src/CompletionPattern.res 61:22 -posCursor:[61:22] posNoWhite:[61:21] Found expr:[61:3->74:1] posCursor:[61:22] posNoWhite:[61:21] Found pattern:[61:16->61:25] Completable: Cpattern Value[f]->recordField(nest) [{ @@ -176,7 +168,6 @@ Completable: Cpattern Value[f]->recordField(nest) }] Complete src/CompletionPattern.res 64:24 -posCursor:[64:24] posNoWhite:[64:23] Found expr:[64:3->64:27] posCursor:[64:24] posNoWhite:[64:23] Found pattern:[64:16->64:26] posCursor:[64:24] posNoWhite:[64:23] Found pattern:[64:23->64:25] Completable: Cpattern Value[f]->recordField(nest), recordBody @@ -189,10 +180,8 @@ Completable: Cpattern Value[f]->recordField(nest), recordBody }] Complete src/CompletionPattern.res 70:22 -posCursor:[70:22] posNoWhite:[70:21] Found expr:[67:8->74:1] posCursor:[70:22] posNoWhite:[70:21] Found expr:[69:2->72:13] posCursor:[70:22] posNoWhite:[70:21] Found expr:[70:5->72:13] -posCursor:[70:22] posNoWhite:[70:21] Found expr:[70:5->70:24] posCursor:[70:22] posNoWhite:[70:21] Found pattern:[70:21->70:23] Completable: Cpattern Value[nest]->recordBody [{ @@ -246,7 +235,6 @@ Completable: Cpattern Value[f]=n->recordField(nest), recordBody }] Complete src/CompletionPattern.res 87:20 -posCursor:[87:20] posNoWhite:[87:19] Found expr:[87:3->87:22] posCursor:[87:20] posNoWhite:[87:19] Found pattern:[87:16->87:21] Ppat_construct Two:[87:16->87:19] posCursor:[87:20] posNoWhite:[87:19] Found pattern:[87:19->87:21] @@ -267,7 +255,6 @@ Completable: Cpattern Value[z]->variantPayload::Two($0) }] Complete src/CompletionPattern.res 90:21 -posCursor:[90:21] posNoWhite:[90:20] Found expr:[90:3->90:23] posCursor:[90:21] posNoWhite:[90:20] Found pattern:[90:16->90:22] Ppat_construct Two:[90:16->90:19] posCursor:[90:21] posNoWhite:[90:20] Found pattern:[90:20->90:21] @@ -281,7 +268,6 @@ Completable: Cpattern Value[z]=t->variantPayload::Two($0) }] Complete src/CompletionPattern.res 93:23 -posCursor:[93:23] posNoWhite:[93:22] Found expr:[93:3->93:26] posCursor:[93:23] posNoWhite:[93:22] Found pattern:[93:16->93:25] Ppat_construct Three:[93:16->93:21] posCursor:[93:23] posNoWhite:[93:22] Found pattern:[93:22->93:24] @@ -313,7 +299,6 @@ Completable: Cpattern Value[z]->variantPayload::Three($0), recordBody }] Complete src/CompletionPattern.res 96:27 -posCursor:[96:27] posNoWhite:[96:26] Found expr:[96:3->96:29] posCursor:[96:27] posNoWhite:[96:26] Found pattern:[96:16->96:28] Ppat_construct Three:[96:16->96:21] posCursor:[96:27] posNoWhite:[96:26] Found pattern:[96:21->96:29] @@ -328,7 +313,6 @@ Completable: Cpattern Value[z]=t->variantPayload::Three($1) }] Complete src/CompletionPattern.res 103:21 -posCursor:[103:21] posNoWhite:[103:20] Found expr:[103:3->103:23] posCursor:[103:21] posNoWhite:[103:20] Found pattern:[103:16->103:22] posCursor:[103:21] posNoWhite:[103:20] Found pattern:[103:20->103:21] Ppat_construct ():[103:20->103:21] @@ -348,7 +332,6 @@ Completable: Cpattern Value[b]->polyvariantPayload::two($0) }] Complete src/CompletionPattern.res 106:22 -posCursor:[106:22] posNoWhite:[106:21] Found expr:[106:3->106:24] posCursor:[106:22] posNoWhite:[106:21] Found pattern:[106:16->106:23] posCursor:[106:22] posNoWhite:[106:21] Found pattern:[106:21->106:22] Completable: Cpattern Value[b]=t->polyvariantPayload::two($0) @@ -361,7 +344,6 @@ Completable: Cpattern Value[b]=t->polyvariantPayload::two($0) }] Complete src/CompletionPattern.res 109:24 -posCursor:[109:24] posNoWhite:[109:23] Found expr:[109:3->109:27] posCursor:[109:24] posNoWhite:[109:23] Found pattern:[109:16->109:26] posCursor:[109:24] posNoWhite:[109:23] Found pattern:[109:23->109:25] Completable: Cpattern Value[b]->polyvariantPayload::three($0), recordBody @@ -392,7 +374,6 @@ Completable: Cpattern Value[b]->polyvariantPayload::three($0), recordBody }] Complete src/CompletionPattern.res 112:28 -posCursor:[112:28] posNoWhite:[112:27] Found expr:[112:3->112:30] posCursor:[112:28] posNoWhite:[112:27] Found pattern:[112:16->112:29] posCursor:[112:28] posNoWhite:[112:27] Found pattern:[112:22->112:29] posCursor:[112:28] posNoWhite:[112:27] Found pattern:[112:27->112:28] @@ -420,7 +401,6 @@ Completable: Cpattern Value[c] }] Complete src/CompletionPattern.res 121:17 -posCursor:[121:17] posNoWhite:[121:16] Found expr:[121:3->121:20] posCursor:[121:17] posNoWhite:[121:16] Found pattern:[121:16->121:18] Completable: Cpattern Value[c]->array [{ @@ -438,7 +418,6 @@ Completable: Cpattern Value[c]->array }] Complete src/CompletionPattern.res 127:21 -posCursor:[127:21] posNoWhite:[127:20] Found expr:[127:3->127:24] posCursor:[127:21] posNoWhite:[127:20] Found pattern:[127:16->127:22] Ppat_construct Some:[127:16->127:20] posCursor:[127:21] posNoWhite:[127:20] Found pattern:[127:20->127:22] @@ -459,7 +438,6 @@ Completable: Cpattern Value[o]->variantPayload::Some($0) }] Complete src/CompletionPattern.res 134:23 -posCursor:[134:23] posNoWhite:[134:22] Found expr:[134:3->134:26] posCursor:[134:23] posNoWhite:[134:22] Found pattern:[134:16->134:25] Ppat_construct Test:[134:16->134:20] Completable: Cpattern Value[p]->variantPayload::Test($1) @@ -478,7 +456,6 @@ Completable: Cpattern Value[p]->variantPayload::Test($1) }] Complete src/CompletionPattern.res 137:29 -posCursor:[137:29] posNoWhite:[137:28] Found expr:[137:3->137:32] posCursor:[137:29] posNoWhite:[137:28] Found pattern:[137:16->137:31] Ppat_construct Test:[137:16->137:20] posCursor:[137:29] posNoWhite:[137:28] Found pattern:[137:20->137:32] @@ -512,7 +489,6 @@ Completable: Cpattern Value[p]->variantPayload::Test($2) }] Complete src/CompletionPattern.res 140:23 -posCursor:[140:23] posNoWhite:[140:22] Found expr:[140:3->140:32] posCursor:[140:23] posNoWhite:[140:22] Found pattern:[140:16->140:31] Ppat_construct Test:[140:16->140:20] posCursor:[140:23] posNoWhite:[140:22] Found pattern:[140:20->140:32] @@ -532,7 +508,6 @@ Completable: Cpattern Value[p]->variantPayload::Test($1) }] Complete src/CompletionPattern.res 143:35 -posCursor:[143:35] posNoWhite:[143:34] Found expr:[143:3->143:38] posCursor:[143:35] posNoWhite:[143:34] Found pattern:[143:16->143:37] Ppat_construct Test:[143:16->143:20] posCursor:[143:35] posNoWhite:[143:34] Found pattern:[143:20->143:38] @@ -549,7 +524,6 @@ Completable: Cpattern Value[p]->variantPayload::Test($3) }] Complete src/CompletionPattern.res 150:24 -posCursor:[150:24] posNoWhite:[150:23] Found expr:[150:3->150:27] posCursor:[150:24] posNoWhite:[150:23] Found pattern:[150:16->150:26] Completable: Cpattern Value[v]->polyvariantPayload::test($1) [{ @@ -567,7 +541,6 @@ Completable: Cpattern Value[v]->polyvariantPayload::test($1) }] Complete src/CompletionPattern.res 153:30 -posCursor:[153:30] posNoWhite:[153:29] Found expr:[153:3->153:33] posCursor:[153:30] posNoWhite:[153:29] Found pattern:[153:16->153:32] posCursor:[153:30] posNoWhite:[153:29] Found pattern:[153:21->153:32] Completable: Cpattern Value[v]->polyvariantPayload::test($2) @@ -600,7 +573,6 @@ Completable: Cpattern Value[v]->polyvariantPayload::test($2) }] Complete src/CompletionPattern.res 156:24 -posCursor:[156:24] posNoWhite:[156:23] Found expr:[156:3->156:33] posCursor:[156:24] posNoWhite:[156:23] Found pattern:[156:16->156:32] posCursor:[156:24] posNoWhite:[156:23] Found pattern:[156:21->156:32] Completable: Cpattern Value[v]->polyvariantPayload::test($1) @@ -619,7 +591,6 @@ Completable: Cpattern Value[v]->polyvariantPayload::test($1) }] Complete src/CompletionPattern.res 159:36 -posCursor:[159:36] posNoWhite:[159:35] Found expr:[159:3->159:39] posCursor:[159:36] posNoWhite:[159:35] Found pattern:[159:16->159:38] posCursor:[159:36] posNoWhite:[159:35] Found pattern:[159:21->159:38] Completable: Cpattern Value[v]->polyvariantPayload::test($3) @@ -635,7 +606,6 @@ Completable: Cpattern Value[v]->polyvariantPayload::test($3) }] Complete src/CompletionPattern.res 164:17 -posCursor:[164:17] posNoWhite:[164:16] Found expr:[164:3->164:20] posCursor:[164:17] posNoWhite:[164:16] Found pattern:[164:16->164:18] Ppat_construct ():[164:16->164:18] Completable: Cpattern Value[s]->tuple($0) @@ -654,7 +624,6 @@ Completable: Cpattern Value[s]->tuple($0) }] Complete src/CompletionPattern.res 167:23 -posCursor:[167:23] posNoWhite:[167:21] Found expr:[167:3->167:26] posCursor:[167:23] posNoWhite:[167:21] Found pattern:[167:16->167:24] Completable: Cpattern Value[s]->tuple($1) [{ @@ -686,7 +655,6 @@ Completable: Cpattern Value[s]->tuple($1) }] Complete src/CompletionPattern.res 170:22 -posCursor:[170:22] posNoWhite:[170:21] Found expr:[170:3->170:30] posCursor:[170:22] posNoWhite:[170:21] Found pattern:[170:16->170:28] Completable: Cpattern Value[s]->tuple($1) [{ @@ -731,7 +699,6 @@ Completable: Cpattern Value[s] }] Complete src/CompletionPattern.res 176:41 -posCursor:[176:41] posNoWhite:[176:40] Found expr:[176:3->176:50] posCursor:[176:41] posNoWhite:[176:40] Found pattern:[176:35->176:47] Completable: Cpattern Value[s]->tuple($1) [{ @@ -792,7 +759,6 @@ Completable: Cpattern Value[z] }] Complete src/CompletionPattern.res 182:32 -posCursor:[182:32] posNoWhite:[182:31] Found expr:[182:3->182:37] posCursor:[182:32] posNoWhite:[182:31] Found pattern:[182:16->182:34] posCursor:[182:32] posNoWhite:[182:31] Found pattern:[182:22->182:34] Ppat_construct Two:[182:22->182:25] @@ -812,7 +778,6 @@ Completable: Cpattern Value[z]->variantPayload::Two($0) }] Complete src/CompletionPattern.res 185:48 -posCursor:[185:48] posNoWhite:[185:47] Found expr:[185:3->185:53] posCursor:[185:48] posNoWhite:[185:47] Found pattern:[185:16->185:50] posCursor:[185:48] posNoWhite:[185:47] Found pattern:[185:22->185:50] Ppat_construct Three:[185:22->185:27] @@ -833,7 +798,6 @@ Completable: Cpattern Value[z]->variantPayload::Three($1) }] Complete src/CompletionPattern.res 188:34 -posCursor:[188:34] posNoWhite:[188:33] Found expr:[188:3->188:39] posCursor:[188:34] posNoWhite:[188:33] Found pattern:[188:16->188:36] posCursor:[188:34] posNoWhite:[188:33] Found pattern:[188:23->188:36] Completable: Cpattern Value[b]->polyvariantPayload::two($0) @@ -852,7 +816,6 @@ Completable: Cpattern Value[b]->polyvariantPayload::two($0) }] Complete src/CompletionPattern.res 191:50 -posCursor:[191:50] posNoWhite:[191:49] Found expr:[191:3->191:55] posCursor:[191:50] posNoWhite:[191:49] Found pattern:[191:16->191:52] posCursor:[191:50] posNoWhite:[191:49] Found pattern:[191:23->191:52] posCursor:[191:50] posNoWhite:[191:49] Found pattern:[191:29->191:52] @@ -872,7 +835,6 @@ Completable: Cpattern Value[b]->polyvariantPayload::three($1) }] Complete src/CompletionPattern.res 194:24 -posCursor:[194:24] posNoWhite:[194:23] Found expr:[194:3->194:31] posCursor:[194:24] posNoWhite:[194:23] Found pattern:[194:16->194:29] posCursor:[194:24] posNoWhite:[194:23] Found pattern:[194:23->194:24] Completable: Cpattern Value[s]->tuple($1) @@ -905,7 +867,6 @@ Completable: Cpattern Value[s]->tuple($1) }] Complete src/CompletionPattern.res 201:25 -posCursor:[201:25] posNoWhite:[201:24] Found expr:[201:3->204:25] posCursor:[201:25] posNoWhite:[201:24] Found pattern:[201:17->201:28] Completable: Cpattern Value[ff]->recordField(someFn) [] From 1b1e21f56bd3449de851e79b5daa20f42e192403 Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Fri, 3 Feb 2023 20:04:27 +0100 Subject: [PATCH 14/41] poc complete pattern of function parameter --- analysis/src/CompletionFrontEnd.ml | 7 ++++++- analysis/tests/src/CompletionInferValues.res | 8 +++++++ .../expected/CompletionInferValues.res.txt | 21 +++++++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/analysis/src/CompletionFrontEnd.ml b/analysis/src/CompletionFrontEnd.ml index 33241898f..700758df5 100644 --- a/analysis/src/CompletionFrontEnd.ml +++ b/analysis/src/CompletionFrontEnd.ml @@ -456,6 +456,7 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor ~text = scope := !scope |> Scope.addModule ~name:md.pmd_name.txt ~loc:md.pmd_name.loc in + (* TODO: Can get rid of setLookingForPat soon *) let setLookingForPat ctxPath = lookingForPat := Some ctxPath in let inJsxContext = ref false in @@ -1032,8 +1033,12 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor ~text = (match defaultExpOpt with | None -> () | Some defaultExp -> iterator.expr iterator defaultExp); - scopePattern ?contextPath:!currentCtxPath pat; + (match !currentCtxPath with + | None -> () + | Some ctxPath -> setLookingForPat ctxPath); completePattern pat; + unsetLookingForPat (); + scopePattern ?contextPath:!currentCtxPath pat; iterator.pat iterator pat; iterator.expr iterator e; scope := oldScope; diff --git a/analysis/tests/src/CompletionInferValues.res b/analysis/tests/src/CompletionInferValues.res index 32b9f170b..7d4836f3a 100644 --- a/analysis/tests/src/CompletionInferValues.res +++ b/analysis/tests/src/CompletionInferValues.res @@ -98,3 +98,11 @@ type otherNestedRecord = {someRecord: someRecord, someTuple: (someVariant, int)} // Same as above, but follow in switch case // let x: otherNestedRecord; switch x { | {someTuple} => let (_, someInt) = someTuple; someInt->toS } // ^com + +let fnWithRecordCallback = (cb: someRecord => unit) => { + let _ = cb +} + +// Complete pattern of function parameter +// fnWithRecordCallback(({}) => {()}) +// ^com diff --git a/analysis/tests/src/expected/CompletionInferValues.res.txt b/analysis/tests/src/expected/CompletionInferValues.res.txt index e1e0020e7..ba8cd3bb3 100644 --- a/analysis/tests/src/expected/CompletionInferValues.res.txt +++ b/analysis/tests/src/expected/CompletionInferValues.res.txt @@ -319,3 +319,24 @@ Completable: Cpath Value[someInt]->toS "documentation": {"kind": "markdown", "value": "\n Converts a given `int` to a `string`. Uses the JavaScript `String` constructor under the hood.\n\n ```res example\n Js.log(Belt.Int.toString(1) === \"1\") /* true */\n ```\n"} }] +Complete src/CompletionInferValues.res 105:26 +posCursor:[105:26] posNoWhite:[105:25] Found expr:[105:3->105:37] +Pexp_apply ...[105:3->105:23] (...[105:24->105:36]) +posCursor:[105:26] posNoWhite:[105:25] Found expr:[105:24->105:36] +posCursor:[105:26] posNoWhite:[105:25] Found pattern:[105:25->105:27] +posCursor:[105:26] posNoWhite:[105:25] Found pattern:[105:25->105:27] +Completable: Cpattern CArgument CArgument Value[fnWithRecordCallback]($0)($0)->recordBody +[{ + "label": "name", + "kind": 5, + "tags": [], + "detail": "name: string\n\nsomeRecord", + "documentation": null + }, { + "label": "age", + "kind": 5, + "tags": [], + "detail": "age: int\n\nsomeRecord", + "documentation": null + }] + From 071e4b4eecc14d9fa1e4dcb2a7fca64755e8d636 Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Fri, 3 Feb 2023 20:18:58 +0100 Subject: [PATCH 15/41] follow variant payloads --- analysis/src/TypeUtils.ml | 29 +++++++++++++++ analysis/tests/src/CompletionInferValues.res | 3 ++ .../expected/CompletionInferValues.res.txt | 35 ++++++++++++++----- 3 files changed, 58 insertions(+), 9 deletions(-) diff --git a/analysis/src/TypeUtils.ml b/analysis/src/TypeUtils.ml index 24ba129f0..8270c9cbd 100644 --- a/analysis/src/TypeUtils.ml +++ b/analysis/src/TypeUtils.ml @@ -358,6 +358,19 @@ let findTypeOfRecordField fields ~fieldName = let typ = if optional then Utils.unwrapIfOption typ else typ in Some typ +let findTypeOfConstructorArg constructors ~constructorName ~payloadNum ~env = + match + constructors + |> List.find_opt (fun (c : Constructor.t) -> c.cname.txt = constructorName) + with + | Some {args = Args args} -> ( + match List.nth_opt args payloadNum with + | None -> None + | Some (typ, _) -> Some (TypeExpr typ)) + | Some {args = InlineRecord fields} when payloadNum = 0 -> + Some (ExtractedType (TinlineRecord {env; fields})) + | _ -> None + let rec resolveNestedPatternPath (typ : innerType) ~env ~full ~nested = let t = match typ with @@ -380,6 +393,14 @@ let rec resolveNestedPatternPath (typ : innerType) ~env ~full ~nested = match List.nth_opt tupleItems itemNum with | None -> None | Some typ -> Some (TypeExpr typ, env)) + | NVariantPayload {constructorName; itemNum}, Tvariant {env; constructors} + -> ( + match + constructors + |> findTypeOfConstructorArg ~constructorName ~payloadNum:itemNum ~env + with + | Some typ -> Some (typ, env) + | None -> None) | _ -> None)) | patternPath :: nested -> ( match t with @@ -405,6 +426,14 @@ let rec resolveNestedPatternPath (typ : innerType) ~env ~full ~nested = |> Utils.Option.flatMap (fun typ -> ExtractedType typ |> resolveNestedPatternPath ~env ~full ~nested)) + | NVariantPayload {constructorName; itemNum}, Tvariant {env; constructors} + -> ( + match + constructors + |> findTypeOfConstructorArg ~constructorName ~payloadNum:itemNum ~env + with + | Some typ -> typ |> resolveNestedPatternPath ~env ~full ~nested + | None -> None) | _ -> None)) let getArgs ~env (t : Types.type_expr) ~full = diff --git a/analysis/tests/src/CompletionInferValues.res b/analysis/tests/src/CompletionInferValues.res index 7d4836f3a..812a32fbb 100644 --- a/analysis/tests/src/CompletionInferValues.res +++ b/analysis/tests/src/CompletionInferValues.res @@ -99,6 +99,9 @@ type otherNestedRecord = {someRecord: someRecord, someTuple: (someVariant, int)} // let x: otherNestedRecord; switch x { | {someTuple} => let (_, someInt) = someTuple; someInt->toS } // ^com +// Follow variant payloads +// let x: otherNestedRecord; switch x { | {someTuple:(Three(_, str), _)} => str->slic } +// ^com let fnWithRecordCallback = (cb: someRecord => unit) => { let _ = cb } diff --git a/analysis/tests/src/expected/CompletionInferValues.res.txt b/analysis/tests/src/expected/CompletionInferValues.res.txt index ba8cd3bb3..1a8dcec69 100644 --- a/analysis/tests/src/expected/CompletionInferValues.res.txt +++ b/analysis/tests/src/expected/CompletionInferValues.res.txt @@ -222,7 +222,7 @@ Completable: Cpath Value[x]."" Complete src/CompletionInferValues.res 74:78 posCursor:[74:78] posNoWhite:[74:77] Found expr:[74:70->74:78] -Pexp_field [74:70->74:77] _:[101:0->74:78] +Pexp_field [74:70->74:77] _:[104:0->74:78] Completable: Cpath Value[srecord]."" [{ "label": "name", @@ -240,7 +240,7 @@ Completable: Cpath Value[srecord]."" Complete src/CompletionInferValues.res 78:86 posCursor:[78:86] posNoWhite:[78:85] Found expr:[78:78->78:86] -Pexp_field [78:78->78:85] _:[101:0->78:86] +Pexp_field [78:78->78:85] _:[104:0->78:86] Completable: Cpath Value[aliased]."" [{ "label": "someRecord", @@ -252,7 +252,7 @@ Completable: Cpath Value[aliased]."" Complete src/CompletionInferValues.res 82:103 posCursor:[82:103] posNoWhite:[82:102] Found expr:[82:92->82:103] -Pexp_field [82:92->82:102] _:[101:0->82:103] +Pexp_field [82:92->82:102] _:[104:0->82:103] Completable: Cpath Value[someRecord]."" [{ "label": "name", @@ -319,12 +319,29 @@ Completable: Cpath Value[someInt]->toS "documentation": {"kind": "markdown", "value": "\n Converts a given `int` to a `string`. Uses the JavaScript `String` constructor under the hood.\n\n ```res example\n Js.log(Belt.Int.toString(1) === \"1\") /* true */\n ```\n"} }] -Complete src/CompletionInferValues.res 105:26 -posCursor:[105:26] posNoWhite:[105:25] Found expr:[105:3->105:37] -Pexp_apply ...[105:3->105:23] (...[105:24->105:36]) -posCursor:[105:26] posNoWhite:[105:25] Found expr:[105:24->105:36] -posCursor:[105:26] posNoWhite:[105:25] Found pattern:[105:25->105:27] -posCursor:[105:26] posNoWhite:[105:25] Found pattern:[105:25->105:27] +Complete src/CompletionInferValues.res 102:85 +posCursor:[102:85] posNoWhite:[102:84] Found expr:[102:76->102:85] +Completable: Cpath Value[str]->slic +[{ + "label": "Js.String2.sliceToEnd", + "kind": 12, + "tags": [], + "detail": "(t, ~from: int) => t", + "documentation": {"kind": "markdown", "value": "\n`sliceToEnd(str, from:n)` returns the substring of `str` starting at character\n`n` to the end of the string.\n- If `n` is negative, then it is evaluated as `length(str - n)`.\n- If `n` is greater than the length of `str`, then sliceToEnd returns the empty string.\n\nSee [`String.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice) on MDN.\n\n```res example\nJs.String2.sliceToEnd(\"abcdefg\", ~from=4) == \"efg\"\nJs.String2.sliceToEnd(\"abcdefg\", ~from=-2) == \"fg\"\nJs.String2.sliceToEnd(\"abcdefg\", ~from=7) == \"\"\n```\n"} + }, { + "label": "Js.String2.slice", + "kind": 12, + "tags": [], + "detail": "(t, ~from: int, ~to_: int) => t", + "documentation": {"kind": "markdown", "value": "\n`slice(str, from:n1, to_:n2)` returns the substring of `str` starting at\ncharacter `n1` up to but not including `n2`.\n- If either `n1` or `n2` is negative, then it is evaluated as `length(str - n1)` or `length(str - n2)`.\n- If `n2` is greater than the length of `str`, then it is treated as `length(str)`.\n- If `n1` is greater than `n2`, slice returns the empty string.\n\nSee [`String.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice) on MDN.\n\n```res example\nJs.String2.slice(\"abcdefg\", ~from=2, ~to_=5) == \"cde\"\nJs.String2.slice(\"abcdefg\", ~from=2, ~to_=9) == \"cdefg\"\nJs.String2.slice(\"abcdefg\", ~from=-4, ~to_=-2) == \"de\"\nJs.String2.slice(\"abcdefg\", ~from=5, ~to_=1) == \"\"\n```\n"} + }] + +Complete src/CompletionInferValues.res 109:26 +posCursor:[109:26] posNoWhite:[109:25] Found expr:[109:3->109:37] +Pexp_apply ...[109:3->109:23] (...[109:24->109:36]) +posCursor:[109:26] posNoWhite:[109:25] Found expr:[109:24->109:36] +posCursor:[109:26] posNoWhite:[109:25] Found pattern:[109:25->109:27] +posCursor:[109:26] posNoWhite:[109:25] Found pattern:[109:25->109:27] Completable: Cpattern CArgument CArgument Value[fnWithRecordCallback]($0)($0)->recordBody [{ "label": "name", From 407b53e8977ab028162cfd1f0207f0df3051afad Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Fri, 3 Feb 2023 20:24:31 +0100 Subject: [PATCH 16/41] follow polyvariant payloads --- analysis/src/TypeUtils.ml | 29 ++++++++ analysis/tests/src/CompletionInferValues.res | 20 ++++-- .../expected/CompletionInferValues.res.txt | 69 ++++++++++++------- 3 files changed, 85 insertions(+), 33 deletions(-) diff --git a/analysis/src/TypeUtils.ml b/analysis/src/TypeUtils.ml index 8270c9cbd..e145ce4e8 100644 --- a/analysis/src/TypeUtils.ml +++ b/analysis/src/TypeUtils.ml @@ -371,6 +371,18 @@ let findTypeOfConstructorArg constructors ~constructorName ~payloadNum ~env = Some (ExtractedType (TinlineRecord {env; fields})) | _ -> None +let findTypeOfPolyvariantArg constructors ~constructorName ~payloadNum = + match + constructors + |> List.find_opt (fun (c : polyVariantConstructor) -> + c.name = constructorName) + with + | Some {args} -> ( + match List.nth_opt args payloadNum with + | None -> None + | Some typ -> Some typ) + | None -> None + let rec resolveNestedPatternPath (typ : innerType) ~env ~full ~nested = let t = match typ with @@ -401,6 +413,14 @@ let rec resolveNestedPatternPath (typ : innerType) ~env ~full ~nested = with | Some typ -> Some (typ, env) | None -> None) + | ( NPolyvariantPayload {constructorName; itemNum}, + Tpolyvariant {env; constructors} ) -> ( + match + constructors + |> findTypeOfPolyvariantArg ~constructorName ~payloadNum:itemNum + with + | Some typ -> Some (TypeExpr typ, env) + | None -> None) | _ -> None)) | patternPath :: nested -> ( match t with @@ -434,6 +454,15 @@ let rec resolveNestedPatternPath (typ : innerType) ~env ~full ~nested = with | Some typ -> typ |> resolveNestedPatternPath ~env ~full ~nested | None -> None) + | ( NPolyvariantPayload {constructorName; itemNum}, + Tpolyvariant {env; constructors} ) -> ( + match + constructors + |> findTypeOfPolyvariantArg ~constructorName ~payloadNum:itemNum + with + | Some typ -> + TypeExpr typ |> resolveNestedPatternPath ~env ~full ~nested + | None -> None) | _ -> None)) let getArgs ~env (t : Types.type_expr) ~full = diff --git a/analysis/tests/src/CompletionInferValues.res b/analysis/tests/src/CompletionInferValues.res index 812a32fbb..44baa9847 100644 --- a/analysis/tests/src/CompletionInferValues.res +++ b/analysis/tests/src/CompletionInferValues.res @@ -59,6 +59,7 @@ module Div = { // ^com type someVariant = One | Two | Three(int, string) +type somePolyVariant = [#one | #two | #three(int, string)] type someNestedRecord = {someRecord: someRecord} type someRecordWithNestedStuff = { @@ -69,7 +70,7 @@ type someRecordWithNestedStuff = { someStuff: bool, } -type otherNestedRecord = {someRecord: someRecord, someTuple: (someVariant, int)} +type otherNestedRecord = {someRecord: someRecord, someTuple: (someVariant, int, somePolyVariant)} // Destructure record // let x: someRecordWithNestedStuff = Obj.magic(); let {srecord} = x; srecord. @@ -92,16 +93,21 @@ type otherNestedRecord = {someRecord: someRecord, someTuple: (someVariant, int)} // ^com // Follow tuples -// let x: otherNestedRecord = Obj.magic(); let {someTuple} = x; let (_, someInt) = someTuple; someInt->toS -// ^com +// let x: otherNestedRecord = Obj.magic(); let {someTuple} = x; let (_, someInt, _) = someTuple; someInt->toS +// ^com // Same as above, but follow in switch case -// let x: otherNestedRecord; switch x { | {someTuple} => let (_, someInt) = someTuple; someInt->toS } -// ^com +// let x: otherNestedRecord; switch x { | {someTuple} => let (_, someInt, _) = someTuple; someInt->toS } +// ^com // Follow variant payloads -// let x: otherNestedRecord; switch x { | {someTuple:(Three(_, str), _)} => str->slic } -// ^com +// let x: otherNestedRecord; switch x { | {someTuple:(Three(_, str), _, _)} => str->slic } +// ^com + +// Follow polyvariant payloads +// let x: otherNestedRecord; switch x { | {someTuple:(_, _, #three(_, str))} => str->slic } +// ^com + let fnWithRecordCallback = (cb: someRecord => unit) => { let _ = cb } diff --git a/analysis/tests/src/expected/CompletionInferValues.res.txt b/analysis/tests/src/expected/CompletionInferValues.res.txt index 1a8dcec69..8af3ac200 100644 --- a/analysis/tests/src/expected/CompletionInferValues.res.txt +++ b/analysis/tests/src/expected/CompletionInferValues.res.txt @@ -220,9 +220,9 @@ Completable: Cpath Value[x]."" "documentation": null }] -Complete src/CompletionInferValues.res 74:78 -posCursor:[74:78] posNoWhite:[74:77] Found expr:[74:70->74:78] -Pexp_field [74:70->74:77] _:[104:0->74:78] +Complete src/CompletionInferValues.res 75:78 +posCursor:[75:78] posNoWhite:[75:77] Found expr:[75:70->75:78] +Pexp_field [75:70->75:77] _:[110:0->75:78] Completable: Cpath Value[srecord]."" [{ "label": "name", @@ -238,9 +238,9 @@ Completable: Cpath Value[srecord]."" "documentation": null }] -Complete src/CompletionInferValues.res 78:86 -posCursor:[78:86] posNoWhite:[78:85] Found expr:[78:78->78:86] -Pexp_field [78:78->78:85] _:[104:0->78:86] +Complete src/CompletionInferValues.res 79:86 +posCursor:[79:86] posNoWhite:[79:85] Found expr:[79:78->79:86] +Pexp_field [79:78->79:85] _:[110:0->79:86] Completable: Cpath Value[aliased]."" [{ "label": "someRecord", @@ -250,9 +250,9 @@ Completable: Cpath Value[aliased]."" "documentation": null }] -Complete src/CompletionInferValues.res 82:103 -posCursor:[82:103] posNoWhite:[82:102] Found expr:[82:92->82:103] -Pexp_field [82:92->82:102] _:[104:0->82:103] +Complete src/CompletionInferValues.res 83:103 +posCursor:[83:103] posNoWhite:[83:102] Found expr:[83:92->83:103] +Pexp_field [83:92->83:102] _:[110:0->83:103] Completable: Cpath Value[someRecord]."" [{ "label": "name", @@ -268,8 +268,8 @@ Completable: Cpath Value[someRecord]."" "documentation": null }] -Complete src/CompletionInferValues.res 86:81 -posCursor:[86:81] posNoWhite:[86:80] Found expr:[86:69->86:81] +Complete src/CompletionInferValues.res 87:81 +posCursor:[87:81] posNoWhite:[87:80] Found expr:[87:69->87:81] Completable: Cpath Value[things]->slic [{ "label": "Js.String2.sliceToEnd", @@ -285,8 +285,8 @@ Completable: Cpath Value[things]->slic "documentation": {"kind": "markdown", "value": "\n`slice(str, from:n1, to_:n2)` returns the substring of `str` starting at\ncharacter `n1` up to but not including `n2`.\n- If either `n1` or `n2` is negative, then it is evaluated as `length(str - n1)` or `length(str - n2)`.\n- If `n2` is greater than the length of `str`, then it is treated as `length(str)`.\n- If `n1` is greater than `n2`, slice returns the empty string.\n\nSee [`String.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice) on MDN.\n\n```res example\nJs.String2.slice(\"abcdefg\", ~from=2, ~to_=5) == \"cde\"\nJs.String2.slice(\"abcdefg\", ~from=2, ~to_=9) == \"cdefg\"\nJs.String2.slice(\"abcdefg\", ~from=-4, ~to_=-2) == \"de\"\nJs.String2.slice(\"abcdefg\", ~from=5, ~to_=1) == \"\"\n```\n"} }] -Complete src/CompletionInferValues.res 90:82 -posCursor:[90:82] posNoWhite:[90:81] Found expr:[90:70->90:82] +Complete src/CompletionInferValues.res 91:82 +posCursor:[91:82] posNoWhite:[91:81] Found expr:[91:70->91:82] Completable: Cpath Value[someInt]->toS [{ "label": "Belt.Int.toString", @@ -296,8 +296,8 @@ Completable: Cpath Value[someInt]->toS "documentation": {"kind": "markdown", "value": "\n Converts a given `int` to a `string`. Uses the JavaScript `String` constructor under the hood.\n\n ```res example\n Js.log(Belt.Int.toString(1) === \"1\") /* true */\n ```\n"} }] -Complete src/CompletionInferValues.res 94:106 -posCursor:[94:106] posNoWhite:[94:105] Found expr:[94:94->94:106] +Complete src/CompletionInferValues.res 95:109 +posCursor:[95:109] posNoWhite:[95:108] Found expr:[95:97->95:109] Completable: Cpath Value[someInt]->toS [{ "label": "Belt.Int.toString", @@ -307,9 +307,9 @@ Completable: Cpath Value[someInt]->toS "documentation": {"kind": "markdown", "value": "\n Converts a given `int` to a `string`. Uses the JavaScript `String` constructor under the hood.\n\n ```res example\n Js.log(Belt.Int.toString(1) === \"1\") /* true */\n ```\n"} }] -Complete src/CompletionInferValues.res 98:99 -posCursor:[98:99] posNoWhite:[98:98] Found expr:[98:57->98:99] -posCursor:[98:99] posNoWhite:[98:98] Found expr:[98:87->98:99] +Complete src/CompletionInferValues.res 99:102 +posCursor:[99:102] posNoWhite:[99:101] Found expr:[99:57->99:102] +posCursor:[99:102] posNoWhite:[99:101] Found expr:[99:90->99:102] Completable: Cpath Value[someInt]->toS [{ "label": "Belt.Int.toString", @@ -319,8 +319,8 @@ Completable: Cpath Value[someInt]->toS "documentation": {"kind": "markdown", "value": "\n Converts a given `int` to a `string`. Uses the JavaScript `String` constructor under the hood.\n\n ```res example\n Js.log(Belt.Int.toString(1) === \"1\") /* true */\n ```\n"} }] -Complete src/CompletionInferValues.res 102:85 -posCursor:[102:85] posNoWhite:[102:84] Found expr:[102:76->102:85] +Complete src/CompletionInferValues.res 103:88 +posCursor:[103:88] posNoWhite:[103:87] Found expr:[103:79->103:88] Completable: Cpath Value[str]->slic [{ "label": "Js.String2.sliceToEnd", @@ -336,12 +336,29 @@ Completable: Cpath Value[str]->slic "documentation": {"kind": "markdown", "value": "\n`slice(str, from:n1, to_:n2)` returns the substring of `str` starting at\ncharacter `n1` up to but not including `n2`.\n- If either `n1` or `n2` is negative, then it is evaluated as `length(str - n1)` or `length(str - n2)`.\n- If `n2` is greater than the length of `str`, then it is treated as `length(str)`.\n- If `n1` is greater than `n2`, slice returns the empty string.\n\nSee [`String.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice) on MDN.\n\n```res example\nJs.String2.slice(\"abcdefg\", ~from=2, ~to_=5) == \"cde\"\nJs.String2.slice(\"abcdefg\", ~from=2, ~to_=9) == \"cdefg\"\nJs.String2.slice(\"abcdefg\", ~from=-4, ~to_=-2) == \"de\"\nJs.String2.slice(\"abcdefg\", ~from=5, ~to_=1) == \"\"\n```\n"} }] -Complete src/CompletionInferValues.res 109:26 -posCursor:[109:26] posNoWhite:[109:25] Found expr:[109:3->109:37] -Pexp_apply ...[109:3->109:23] (...[109:24->109:36]) -posCursor:[109:26] posNoWhite:[109:25] Found expr:[109:24->109:36] -posCursor:[109:26] posNoWhite:[109:25] Found pattern:[109:25->109:27] -posCursor:[109:26] posNoWhite:[109:25] Found pattern:[109:25->109:27] +Complete src/CompletionInferValues.res 107:89 +posCursor:[107:89] posNoWhite:[107:88] Found expr:[107:80->107:89] +Completable: Cpath Value[str]->slic +[{ + "label": "Js.String2.sliceToEnd", + "kind": 12, + "tags": [], + "detail": "(t, ~from: int) => t", + "documentation": {"kind": "markdown", "value": "\n`sliceToEnd(str, from:n)` returns the substring of `str` starting at character\n`n` to the end of the string.\n- If `n` is negative, then it is evaluated as `length(str - n)`.\n- If `n` is greater than the length of `str`, then sliceToEnd returns the empty string.\n\nSee [`String.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice) on MDN.\n\n```res example\nJs.String2.sliceToEnd(\"abcdefg\", ~from=4) == \"efg\"\nJs.String2.sliceToEnd(\"abcdefg\", ~from=-2) == \"fg\"\nJs.String2.sliceToEnd(\"abcdefg\", ~from=7) == \"\"\n```\n"} + }, { + "label": "Js.String2.slice", + "kind": 12, + "tags": [], + "detail": "(t, ~from: int, ~to_: int) => t", + "documentation": {"kind": "markdown", "value": "\n`slice(str, from:n1, to_:n2)` returns the substring of `str` starting at\ncharacter `n1` up to but not including `n2`.\n- If either `n1` or `n2` is negative, then it is evaluated as `length(str - n1)` or `length(str - n2)`.\n- If `n2` is greater than the length of `str`, then it is treated as `length(str)`.\n- If `n1` is greater than `n2`, slice returns the empty string.\n\nSee [`String.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice) on MDN.\n\n```res example\nJs.String2.slice(\"abcdefg\", ~from=2, ~to_=5) == \"cde\"\nJs.String2.slice(\"abcdefg\", ~from=2, ~to_=9) == \"cdefg\"\nJs.String2.slice(\"abcdefg\", ~from=-4, ~to_=-2) == \"de\"\nJs.String2.slice(\"abcdefg\", ~from=5, ~to_=1) == \"\"\n```\n"} + }] + +Complete src/CompletionInferValues.res 115:26 +posCursor:[115:26] posNoWhite:[115:25] Found expr:[115:3->115:37] +Pexp_apply ...[115:3->115:23] (...[115:24->115:36]) +posCursor:[115:26] posNoWhite:[115:25] Found expr:[115:24->115:36] +posCursor:[115:26] posNoWhite:[115:25] Found pattern:[115:25->115:27] +posCursor:[115:26] posNoWhite:[115:25] Found pattern:[115:25->115:27] Completable: Cpattern CArgument CArgument Value[fnWithRecordCallback]($0)($0)->recordBody [{ "label": "name", From 80909756b1ba024e7b6b6e775bda979c4ee224a2 Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Fri, 3 Feb 2023 20:29:17 +0100 Subject: [PATCH 17/41] follow options --- analysis/src/TypeUtils.ml | 6 ++ analysis/tests/src/CompletionInferValues.res | 10 ++- .../expected/CompletionInferValues.res.txt | 73 ++++++++++++------- 3 files changed, 60 insertions(+), 29 deletions(-) diff --git a/analysis/src/TypeUtils.ml b/analysis/src/TypeUtils.ml index e145ce4e8..b4e44e65e 100644 --- a/analysis/src/TypeUtils.ml +++ b/analysis/src/TypeUtils.ml @@ -421,6 +421,9 @@ let rec resolveNestedPatternPath (typ : innerType) ~env ~full ~nested = with | Some typ -> Some (TypeExpr typ, env) | None -> None) + | ( NVariantPayload {constructorName = "Some"; itemNum = 0}, + Toption (env, typ) ) -> + Some (typ, env) | _ -> None)) | patternPath :: nested -> ( match t with @@ -463,6 +466,9 @@ let rec resolveNestedPatternPath (typ : innerType) ~env ~full ~nested = | Some typ -> TypeExpr typ |> resolveNestedPatternPath ~env ~full ~nested | None -> None) + | ( NVariantPayload {constructorName = "Some"; itemNum = 0}, + Toption (env, typ) ) -> + typ |> resolveNestedPatternPath ~env ~full ~nested | _ -> None)) let getArgs ~env (t : Types.type_expr) ~full = diff --git a/analysis/tests/src/CompletionInferValues.res b/analysis/tests/src/CompletionInferValues.res index 44baa9847..9c6d39b84 100644 --- a/analysis/tests/src/CompletionInferValues.res +++ b/analysis/tests/src/CompletionInferValues.res @@ -70,7 +70,11 @@ type someRecordWithNestedStuff = { someStuff: bool, } -type otherNestedRecord = {someRecord: someRecord, someTuple: (someVariant, int, somePolyVariant)} +type otherNestedRecord = { + someRecord: someRecord, + someTuple: (someVariant, int, somePolyVariant), + optRecord: option, +} // Destructure record // let x: someRecordWithNestedStuff = Obj.magic(); let {srecord} = x; srecord. @@ -108,6 +112,10 @@ type otherNestedRecord = {someRecord: someRecord, someTuple: (someVariant, int, // let x: otherNestedRecord; switch x { | {someTuple:(_, _, #three(_, str))} => str->slic } // ^com +// Follow options +// let x: otherNestedRecord; switch x { | {optRecord:Some({name})} => name->slic } +// ^com + let fnWithRecordCallback = (cb: someRecord => unit) => { let _ = cb } diff --git a/analysis/tests/src/expected/CompletionInferValues.res.txt b/analysis/tests/src/expected/CompletionInferValues.res.txt index 8af3ac200..5e247fc68 100644 --- a/analysis/tests/src/expected/CompletionInferValues.res.txt +++ b/analysis/tests/src/expected/CompletionInferValues.res.txt @@ -220,9 +220,9 @@ Completable: Cpath Value[x]."" "documentation": null }] -Complete src/CompletionInferValues.res 75:78 -posCursor:[75:78] posNoWhite:[75:77] Found expr:[75:70->75:78] -Pexp_field [75:70->75:77] _:[110:0->75:78] +Complete src/CompletionInferValues.res 79:78 +posCursor:[79:78] posNoWhite:[79:77] Found expr:[79:70->79:78] +Pexp_field [79:70->79:77] _:[118:0->79:78] Completable: Cpath Value[srecord]."" [{ "label": "name", @@ -238,9 +238,9 @@ Completable: Cpath Value[srecord]."" "documentation": null }] -Complete src/CompletionInferValues.res 79:86 -posCursor:[79:86] posNoWhite:[79:85] Found expr:[79:78->79:86] -Pexp_field [79:78->79:85] _:[110:0->79:86] +Complete src/CompletionInferValues.res 83:86 +posCursor:[83:86] posNoWhite:[83:85] Found expr:[83:78->83:86] +Pexp_field [83:78->83:85] _:[118:0->83:86] Completable: Cpath Value[aliased]."" [{ "label": "someRecord", @@ -250,9 +250,9 @@ Completable: Cpath Value[aliased]."" "documentation": null }] -Complete src/CompletionInferValues.res 83:103 -posCursor:[83:103] posNoWhite:[83:102] Found expr:[83:92->83:103] -Pexp_field [83:92->83:102] _:[110:0->83:103] +Complete src/CompletionInferValues.res 87:103 +posCursor:[87:103] posNoWhite:[87:102] Found expr:[87:92->87:103] +Pexp_field [87:92->87:102] _:[118:0->87:103] Completable: Cpath Value[someRecord]."" [{ "label": "name", @@ -268,8 +268,8 @@ Completable: Cpath Value[someRecord]."" "documentation": null }] -Complete src/CompletionInferValues.res 87:81 -posCursor:[87:81] posNoWhite:[87:80] Found expr:[87:69->87:81] +Complete src/CompletionInferValues.res 91:81 +posCursor:[91:81] posNoWhite:[91:80] Found expr:[91:69->91:81] Completable: Cpath Value[things]->slic [{ "label": "Js.String2.sliceToEnd", @@ -285,8 +285,8 @@ Completable: Cpath Value[things]->slic "documentation": {"kind": "markdown", "value": "\n`slice(str, from:n1, to_:n2)` returns the substring of `str` starting at\ncharacter `n1` up to but not including `n2`.\n- If either `n1` or `n2` is negative, then it is evaluated as `length(str - n1)` or `length(str - n2)`.\n- If `n2` is greater than the length of `str`, then it is treated as `length(str)`.\n- If `n1` is greater than `n2`, slice returns the empty string.\n\nSee [`String.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice) on MDN.\n\n```res example\nJs.String2.slice(\"abcdefg\", ~from=2, ~to_=5) == \"cde\"\nJs.String2.slice(\"abcdefg\", ~from=2, ~to_=9) == \"cdefg\"\nJs.String2.slice(\"abcdefg\", ~from=-4, ~to_=-2) == \"de\"\nJs.String2.slice(\"abcdefg\", ~from=5, ~to_=1) == \"\"\n```\n"} }] -Complete src/CompletionInferValues.res 91:82 -posCursor:[91:82] posNoWhite:[91:81] Found expr:[91:70->91:82] +Complete src/CompletionInferValues.res 95:82 +posCursor:[95:82] posNoWhite:[95:81] Found expr:[95:70->95:82] Completable: Cpath Value[someInt]->toS [{ "label": "Belt.Int.toString", @@ -296,8 +296,8 @@ Completable: Cpath Value[someInt]->toS "documentation": {"kind": "markdown", "value": "\n Converts a given `int` to a `string`. Uses the JavaScript `String` constructor under the hood.\n\n ```res example\n Js.log(Belt.Int.toString(1) === \"1\") /* true */\n ```\n"} }] -Complete src/CompletionInferValues.res 95:109 -posCursor:[95:109] posNoWhite:[95:108] Found expr:[95:97->95:109] +Complete src/CompletionInferValues.res 99:109 +posCursor:[99:109] posNoWhite:[99:108] Found expr:[99:97->99:109] Completable: Cpath Value[someInt]->toS [{ "label": "Belt.Int.toString", @@ -307,9 +307,9 @@ Completable: Cpath Value[someInt]->toS "documentation": {"kind": "markdown", "value": "\n Converts a given `int` to a `string`. Uses the JavaScript `String` constructor under the hood.\n\n ```res example\n Js.log(Belt.Int.toString(1) === \"1\") /* true */\n ```\n"} }] -Complete src/CompletionInferValues.res 99:102 -posCursor:[99:102] posNoWhite:[99:101] Found expr:[99:57->99:102] -posCursor:[99:102] posNoWhite:[99:101] Found expr:[99:90->99:102] +Complete src/CompletionInferValues.res 103:102 +posCursor:[103:102] posNoWhite:[103:101] Found expr:[103:57->103:102] +posCursor:[103:102] posNoWhite:[103:101] Found expr:[103:90->103:102] Completable: Cpath Value[someInt]->toS [{ "label": "Belt.Int.toString", @@ -319,8 +319,8 @@ Completable: Cpath Value[someInt]->toS "documentation": {"kind": "markdown", "value": "\n Converts a given `int` to a `string`. Uses the JavaScript `String` constructor under the hood.\n\n ```res example\n Js.log(Belt.Int.toString(1) === \"1\") /* true */\n ```\n"} }] -Complete src/CompletionInferValues.res 103:88 -posCursor:[103:88] posNoWhite:[103:87] Found expr:[103:79->103:88] +Complete src/CompletionInferValues.res 107:88 +posCursor:[107:88] posNoWhite:[107:87] Found expr:[107:79->107:88] Completable: Cpath Value[str]->slic [{ "label": "Js.String2.sliceToEnd", @@ -336,8 +336,8 @@ Completable: Cpath Value[str]->slic "documentation": {"kind": "markdown", "value": "\n`slice(str, from:n1, to_:n2)` returns the substring of `str` starting at\ncharacter `n1` up to but not including `n2`.\n- If either `n1` or `n2` is negative, then it is evaluated as `length(str - n1)` or `length(str - n2)`.\n- If `n2` is greater than the length of `str`, then it is treated as `length(str)`.\n- If `n1` is greater than `n2`, slice returns the empty string.\n\nSee [`String.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice) on MDN.\n\n```res example\nJs.String2.slice(\"abcdefg\", ~from=2, ~to_=5) == \"cde\"\nJs.String2.slice(\"abcdefg\", ~from=2, ~to_=9) == \"cdefg\"\nJs.String2.slice(\"abcdefg\", ~from=-4, ~to_=-2) == \"de\"\nJs.String2.slice(\"abcdefg\", ~from=5, ~to_=1) == \"\"\n```\n"} }] -Complete src/CompletionInferValues.res 107:89 -posCursor:[107:89] posNoWhite:[107:88] Found expr:[107:80->107:89] +Complete src/CompletionInferValues.res 111:89 +posCursor:[111:89] posNoWhite:[111:88] Found expr:[111:80->111:89] Completable: Cpath Value[str]->slic [{ "label": "Js.String2.sliceToEnd", @@ -353,12 +353,29 @@ Completable: Cpath Value[str]->slic "documentation": {"kind": "markdown", "value": "\n`slice(str, from:n1, to_:n2)` returns the substring of `str` starting at\ncharacter `n1` up to but not including `n2`.\n- If either `n1` or `n2` is negative, then it is evaluated as `length(str - n1)` or `length(str - n2)`.\n- If `n2` is greater than the length of `str`, then it is treated as `length(str)`.\n- If `n1` is greater than `n2`, slice returns the empty string.\n\nSee [`String.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice) on MDN.\n\n```res example\nJs.String2.slice(\"abcdefg\", ~from=2, ~to_=5) == \"cde\"\nJs.String2.slice(\"abcdefg\", ~from=2, ~to_=9) == \"cdefg\"\nJs.String2.slice(\"abcdefg\", ~from=-4, ~to_=-2) == \"de\"\nJs.String2.slice(\"abcdefg\", ~from=5, ~to_=1) == \"\"\n```\n"} }] -Complete src/CompletionInferValues.res 115:26 -posCursor:[115:26] posNoWhite:[115:25] Found expr:[115:3->115:37] -Pexp_apply ...[115:3->115:23] (...[115:24->115:36]) -posCursor:[115:26] posNoWhite:[115:25] Found expr:[115:24->115:36] -posCursor:[115:26] posNoWhite:[115:25] Found pattern:[115:25->115:27] -posCursor:[115:26] posNoWhite:[115:25] Found pattern:[115:25->115:27] +Complete src/CompletionInferValues.res 115:80 +posCursor:[115:80] posNoWhite:[115:79] Found expr:[115:70->115:80] +Completable: Cpath Value[name]->slic +[{ + "label": "Js.String2.sliceToEnd", + "kind": 12, + "tags": [], + "detail": "(t, ~from: int) => t", + "documentation": {"kind": "markdown", "value": "\n`sliceToEnd(str, from:n)` returns the substring of `str` starting at character\n`n` to the end of the string.\n- If `n` is negative, then it is evaluated as `length(str - n)`.\n- If `n` is greater than the length of `str`, then sliceToEnd returns the empty string.\n\nSee [`String.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice) on MDN.\n\n```res example\nJs.String2.sliceToEnd(\"abcdefg\", ~from=4) == \"efg\"\nJs.String2.sliceToEnd(\"abcdefg\", ~from=-2) == \"fg\"\nJs.String2.sliceToEnd(\"abcdefg\", ~from=7) == \"\"\n```\n"} + }, { + "label": "Js.String2.slice", + "kind": 12, + "tags": [], + "detail": "(t, ~from: int, ~to_: int) => t", + "documentation": {"kind": "markdown", "value": "\n`slice(str, from:n1, to_:n2)` returns the substring of `str` starting at\ncharacter `n1` up to but not including `n2`.\n- If either `n1` or `n2` is negative, then it is evaluated as `length(str - n1)` or `length(str - n2)`.\n- If `n2` is greater than the length of `str`, then it is treated as `length(str)`.\n- If `n1` is greater than `n2`, slice returns the empty string.\n\nSee [`String.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice) on MDN.\n\n```res example\nJs.String2.slice(\"abcdefg\", ~from=2, ~to_=5) == \"cde\"\nJs.String2.slice(\"abcdefg\", ~from=2, ~to_=9) == \"cdefg\"\nJs.String2.slice(\"abcdefg\", ~from=-4, ~to_=-2) == \"de\"\nJs.String2.slice(\"abcdefg\", ~from=5, ~to_=1) == \"\"\n```\n"} + }] + +Complete src/CompletionInferValues.res 123:26 +posCursor:[123:26] posNoWhite:[123:25] Found expr:[123:3->123:37] +Pexp_apply ...[123:3->123:23] (...[123:24->123:36]) +posCursor:[123:26] posNoWhite:[123:25] Found expr:[123:24->123:36] +posCursor:[123:26] posNoWhite:[123:25] Found pattern:[123:25->123:27] +posCursor:[123:26] posNoWhite:[123:25] Found pattern:[123:25->123:27] Completable: Cpattern CArgument CArgument Value[fnWithRecordCallback]($0)($0)->recordBody [{ "label": "name", From ccd19b6ce15a769858b64c65f6a3ee5c05a4e6f6 Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Fri, 3 Feb 2023 20:33:53 +0100 Subject: [PATCH 18/41] follow arrays --- analysis/src/TypeUtils.ml | 3 ++ analysis/tests/src/CompletionInferValues.res | 4 +++ .../expected/CompletionInferValues.res.txt | 36 ++++++++++++++----- 3 files changed, 34 insertions(+), 9 deletions(-) diff --git a/analysis/src/TypeUtils.ml b/analysis/src/TypeUtils.ml index b4e44e65e..bf9c87551 100644 --- a/analysis/src/TypeUtils.ml +++ b/analysis/src/TypeUtils.ml @@ -424,6 +424,7 @@ let rec resolveNestedPatternPath (typ : innerType) ~env ~full ~nested = | ( NVariantPayload {constructorName = "Some"; itemNum = 0}, Toption (env, typ) ) -> Some (typ, env) + | NArray, Tarray (env, typ) -> Some (typ, env) | _ -> None)) | patternPath :: nested -> ( match t with @@ -469,6 +470,8 @@ let rec resolveNestedPatternPath (typ : innerType) ~env ~full ~nested = | ( NVariantPayload {constructorName = "Some"; itemNum = 0}, Toption (env, typ) ) -> typ |> resolveNestedPatternPath ~env ~full ~nested + | NArray, Tarray (env, typ) -> + typ |> resolveNestedPatternPath ~env ~full ~nested | _ -> None)) let getArgs ~env (t : Types.type_expr) ~full = diff --git a/analysis/tests/src/CompletionInferValues.res b/analysis/tests/src/CompletionInferValues.res index 9c6d39b84..2c5cada66 100644 --- a/analysis/tests/src/CompletionInferValues.res +++ b/analysis/tests/src/CompletionInferValues.res @@ -116,6 +116,10 @@ type otherNestedRecord = { // let x: otherNestedRecord; switch x { | {optRecord:Some({name})} => name->slic } // ^com +// Follow arrays +// let x: array; switch x { | [inner] => inner.s } +// ^com + let fnWithRecordCallback = (cb: someRecord => unit) => { let _ = cb } diff --git a/analysis/tests/src/expected/CompletionInferValues.res.txt b/analysis/tests/src/expected/CompletionInferValues.res.txt index 5e247fc68..a8ee94d09 100644 --- a/analysis/tests/src/expected/CompletionInferValues.res.txt +++ b/analysis/tests/src/expected/CompletionInferValues.res.txt @@ -222,7 +222,7 @@ Completable: Cpath Value[x]."" Complete src/CompletionInferValues.res 79:78 posCursor:[79:78] posNoWhite:[79:77] Found expr:[79:70->79:78] -Pexp_field [79:70->79:77] _:[118:0->79:78] +Pexp_field [79:70->79:77] _:[122:0->79:78] Completable: Cpath Value[srecord]."" [{ "label": "name", @@ -240,7 +240,7 @@ Completable: Cpath Value[srecord]."" Complete src/CompletionInferValues.res 83:86 posCursor:[83:86] posNoWhite:[83:85] Found expr:[83:78->83:86] -Pexp_field [83:78->83:85] _:[118:0->83:86] +Pexp_field [83:78->83:85] _:[122:0->83:86] Completable: Cpath Value[aliased]."" [{ "label": "someRecord", @@ -252,7 +252,7 @@ Completable: Cpath Value[aliased]."" Complete src/CompletionInferValues.res 87:103 posCursor:[87:103] posNoWhite:[87:102] Found expr:[87:92->87:103] -Pexp_field [87:92->87:102] _:[118:0->87:103] +Pexp_field [87:92->87:102] _:[122:0->87:103] Completable: Cpath Value[someRecord]."" [{ "label": "name", @@ -370,12 +370,30 @@ Completable: Cpath Value[name]->slic "documentation": {"kind": "markdown", "value": "\n`slice(str, from:n1, to_:n2)` returns the substring of `str` starting at\ncharacter `n1` up to but not including `n2`.\n- If either `n1` or `n2` is negative, then it is evaluated as `length(str - n1)` or `length(str - n2)`.\n- If `n2` is greater than the length of `str`, then it is treated as `length(str)`.\n- If `n1` is greater than `n2`, slice returns the empty string.\n\nSee [`String.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice) on MDN.\n\n```res example\nJs.String2.slice(\"abcdefg\", ~from=2, ~to_=5) == \"cde\"\nJs.String2.slice(\"abcdefg\", ~from=2, ~to_=9) == \"cdefg\"\nJs.String2.slice(\"abcdefg\", ~from=-4, ~to_=-2) == \"de\"\nJs.String2.slice(\"abcdefg\", ~from=5, ~to_=1) == \"\"\n```\n"} }] -Complete src/CompletionInferValues.res 123:26 -posCursor:[123:26] posNoWhite:[123:25] Found expr:[123:3->123:37] -Pexp_apply ...[123:3->123:23] (...[123:24->123:36]) -posCursor:[123:26] posNoWhite:[123:25] Found expr:[123:24->123:36] -posCursor:[123:26] posNoWhite:[123:25] Found pattern:[123:25->123:27] -posCursor:[123:26] posNoWhite:[123:25] Found pattern:[123:25->123:27] +Complete src/CompletionInferValues.res 119:67 +posCursor:[119:67] posNoWhite:[119:66] Found expr:[119:60->119:67] +Pexp_field [119:60->119:65] s:[119:66->119:67] +Completable: Cpath Value[inner].s +[{ + "label": "someRecord", + "kind": 5, + "tags": [], + "detail": "someRecord: someRecord\n\ntype otherNestedRecord = {someRecord: someRecord, someTuple: (someVariant, int, somePolyVariant), optRecord: option}", + "documentation": null + }, { + "label": "someTuple", + "kind": 5, + "tags": [], + "detail": "someTuple: (someVariant, int, somePolyVariant)\n\ntype otherNestedRecord = {someRecord: someRecord, someTuple: (someVariant, int, somePolyVariant), optRecord: option}", + "documentation": null + }] + +Complete src/CompletionInferValues.res 127:26 +posCursor:[127:26] posNoWhite:[127:25] Found expr:[127:3->127:37] +Pexp_apply ...[127:3->127:23] (...[127:24->127:36]) +posCursor:[127:26] posNoWhite:[127:25] Found expr:[127:24->127:36] +posCursor:[127:26] posNoWhite:[127:25] Found pattern:[127:25->127:27] +posCursor:[127:26] posNoWhite:[127:25] Found pattern:[127:25->127:27] Completable: Cpattern CArgument CArgument Value[fnWithRecordCallback]($0)($0)->recordBody [{ "label": "name", From 01873ff92c432c2a72a8d68fc817f371fc8a9b9a Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Fri, 3 Feb 2023 20:40:36 +0100 Subject: [PATCH 19/41] add test --- analysis/tests/src/CompletionInferValues.res | 4 +++ .../expected/CompletionInferValues.res.txt | 29 +++++++++++++------ 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/analysis/tests/src/CompletionInferValues.res b/analysis/tests/src/CompletionInferValues.res index 2c5cada66..8e68d3bda 100644 --- a/analysis/tests/src/CompletionInferValues.res +++ b/analysis/tests/src/CompletionInferValues.res @@ -120,6 +120,10 @@ type otherNestedRecord = { // let x: array; switch x { | [inner] => inner.s } // ^com +// Infer top level return +// let x = 123; switch x { | 123 => () | v => v->toSt } +// ^com + let fnWithRecordCallback = (cb: someRecord => unit) => { let _ = cb } diff --git a/analysis/tests/src/expected/CompletionInferValues.res.txt b/analysis/tests/src/expected/CompletionInferValues.res.txt index a8ee94d09..5a30a32d5 100644 --- a/analysis/tests/src/expected/CompletionInferValues.res.txt +++ b/analysis/tests/src/expected/CompletionInferValues.res.txt @@ -222,7 +222,7 @@ Completable: Cpath Value[x]."" Complete src/CompletionInferValues.res 79:78 posCursor:[79:78] posNoWhite:[79:77] Found expr:[79:70->79:78] -Pexp_field [79:70->79:77] _:[122:0->79:78] +Pexp_field [79:70->79:77] _:[126:0->79:78] Completable: Cpath Value[srecord]."" [{ "label": "name", @@ -240,7 +240,7 @@ Completable: Cpath Value[srecord]."" Complete src/CompletionInferValues.res 83:86 posCursor:[83:86] posNoWhite:[83:85] Found expr:[83:78->83:86] -Pexp_field [83:78->83:85] _:[122:0->83:86] +Pexp_field [83:78->83:85] _:[126:0->83:86] Completable: Cpath Value[aliased]."" [{ "label": "someRecord", @@ -252,7 +252,7 @@ Completable: Cpath Value[aliased]."" Complete src/CompletionInferValues.res 87:103 posCursor:[87:103] posNoWhite:[87:102] Found expr:[87:92->87:103] -Pexp_field [87:92->87:102] _:[122:0->87:103] +Pexp_field [87:92->87:102] _:[126:0->87:103] Completable: Cpath Value[someRecord]."" [{ "label": "name", @@ -388,12 +388,23 @@ Completable: Cpath Value[inner].s "documentation": null }] -Complete src/CompletionInferValues.res 127:26 -posCursor:[127:26] posNoWhite:[127:25] Found expr:[127:3->127:37] -Pexp_apply ...[127:3->127:23] (...[127:24->127:36]) -posCursor:[127:26] posNoWhite:[127:25] Found expr:[127:24->127:36] -posCursor:[127:26] posNoWhite:[127:25] Found pattern:[127:25->127:27] -posCursor:[127:26] posNoWhite:[127:25] Found pattern:[127:25->127:27] +Complete src/CompletionInferValues.res 123:53 +posCursor:[123:53] posNoWhite:[123:52] Found expr:[123:46->123:53] +Completable: Cpath Value[v]->toSt +[{ + "label": "Belt.Int.toString", + "kind": 12, + "tags": [], + "detail": "int => string", + "documentation": {"kind": "markdown", "value": "\n Converts a given `int` to a `string`. Uses the JavaScript `String` constructor under the hood.\n\n ```res example\n Js.log(Belt.Int.toString(1) === \"1\") /* true */\n ```\n"} + }] + +Complete src/CompletionInferValues.res 131:26 +posCursor:[131:26] posNoWhite:[131:25] Found expr:[131:3->131:37] +Pexp_apply ...[131:3->131:23] (...[131:24->131:36]) +posCursor:[131:26] posNoWhite:[131:25] Found expr:[131:24->131:36] +posCursor:[131:26] posNoWhite:[131:25] Found pattern:[131:25->131:27] +posCursor:[131:26] posNoWhite:[131:25] Found pattern:[131:25->131:27] Completable: Cpattern CArgument CArgument Value[fnWithRecordCallback]($0)($0)->recordBody [{ "label": "name", From 647513b3911245ba7b4f0c23272be4d26d52e6b7 Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Fri, 3 Feb 2023 20:54:48 +0100 Subject: [PATCH 20/41] factor away lookingForPat --- analysis/src/CompletionFrontEnd.ml | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/analysis/src/CompletionFrontEnd.ml b/analysis/src/CompletionFrontEnd.ml index 700758df5..38df2e28e 100644 --- a/analysis/src/CompletionFrontEnd.ml +++ b/analysis/src/CompletionFrontEnd.ml @@ -392,18 +392,14 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor ~text = | Ppat_extension _ -> () | Ppat_open (_, p) -> scopePattern ~patternPath ?contextPath p in - - let lookingForPat = ref None in - let locHasCursor = CursorPosition.locHasCursor ~pos:posBeforeCursor in let locIsEmpty = CursorPosition.locIsEmpty ~pos:posBeforeCursor in - - let completePattern (pat : Parsetree.pattern) = + let completePattern ?contextPath (pat : Parsetree.pattern) = match ( pat |> CompletionPatterns.traversePattern ~patternPath:[] ~locHasCursor ~firstCharBeforeCursorNoWhite ~posBeforeCursor, - !lookingForPat ) + contextPath ) with | Some (prefix, nestedPattern), Some ctxPath -> setResult @@ -456,11 +452,7 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor ~text = scope := !scope |> Scope.addModule ~name:md.pmd_name.txt ~loc:md.pmd_name.loc in - (* TODO: Can get rid of setLookingForPat soon *) - let setLookingForPat ctxPath = lookingForPat := Some ctxPath in let inJsxContext = ref false in - - let unsetLookingForPat () = lookingForPat := None in (* Identifies expressions where we can do typed pattern or expr completion. *) let typedCompletionExpr (exp : Parsetree.expression) = if exp.pexp_loc |> CursorPosition.locHasCursor ~pos:posBeforeCursor then @@ -520,7 +512,7 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor ~text = match (hasCaseWithEmptyLoc, hasCaseWithCursor) with | _, true -> (* Always continue if there's a case with the cursor *) - setLookingForPat ctxPath + () | true, false -> (* If there's no case with the cursor, but a broken parser case, complete for the top level. *) setResult @@ -533,7 +525,7 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor ~text = patternMode = Default; }) | false, false -> ())) - | _ -> unsetLookingForPat () + | _ -> () in let structure (iterator : Ast_iterator.iterator) (structure : Parsetree.structure) = @@ -543,7 +535,6 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor ~text = in let structure_item (iterator : Ast_iterator.iterator) (item : Parsetree.structure_item) = - unsetLookingForPat (); let processed = ref false in (match item.pstr_desc with | Pstr_open {popen_lid} -> @@ -788,7 +779,7 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor ~text = |> List.iter (fun (case : Parsetree.case) -> let oldScope = !scope in scopePattern ?contextPath:ctxPath case.pc_lhs; - completePattern case.pc_lhs; + completePattern ?contextPath:ctxPath case.pc_lhs; Ast_iterator.default_iterator.case iterator case; scope := oldScope); resetCurrentCtxPath oldCtxPath @@ -1033,12 +1024,9 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor ~text = (match defaultExpOpt with | None -> () | Some defaultExp -> iterator.expr iterator defaultExp); - (match !currentCtxPath with - | None -> () - | Some ctxPath -> setLookingForPat ctxPath); - completePattern pat; - unsetLookingForPat (); - scopePattern ?contextPath:!currentCtxPath pat; + let currentContextPath = !currentCtxPath in + completePattern ?contextPath:currentContextPath pat; + scopePattern ?contextPath:currentContextPath pat; iterator.pat iterator pat; iterator.expr iterator e; scope := oldScope; From 611a44090e537e981f448469b6cad73fade609fc Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Fri, 3 Feb 2023 21:03:56 +0100 Subject: [PATCH 21/41] correct order --- analysis/src/CompletionFrontEnd.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/analysis/src/CompletionFrontEnd.ml b/analysis/src/CompletionFrontEnd.ml index 38df2e28e..2f8197d3e 100644 --- a/analysis/src/CompletionFrontEnd.ml +++ b/analysis/src/CompletionFrontEnd.ml @@ -778,8 +778,8 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor ~text = cases |> List.iter (fun (case : Parsetree.case) -> let oldScope = !scope in - scopePattern ?contextPath:ctxPath case.pc_lhs; completePattern ?contextPath:ctxPath case.pc_lhs; + scopePattern ?contextPath:ctxPath case.pc_lhs; Ast_iterator.default_iterator.case iterator case; scope := oldScope); resetCurrentCtxPath oldCtxPath From 7e3242012c12083483fad0db48989bef16c041c9 Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Fri, 3 Feb 2023 21:27:38 +0100 Subject: [PATCH 22/41] fix --- analysis/src/CompletionBackEnd.ml | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/analysis/src/CompletionBackEnd.ml b/analysis/src/CompletionBackEnd.ml index c5b538a86..a9b70c56c 100644 --- a/analysis/src/CompletionBackEnd.ml +++ b/analysis/src/CompletionBackEnd.ml @@ -736,14 +736,14 @@ and getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env |> getCompletionsForPath ~package ~opens ~allFiles ~pos ~exact ~completionContext ~env ~scope | CPApply (cp, labels) -> ( - (* TODO: Also needs to support ExtractedType *) match cp |> getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env ~exact:true ~scope - |> completionsGetTypeEnv2 ~full ~opens ~rawOpens ~allFiles ~pos ~scope + |> completionsGetCompletionType2 ~full ~opens ~rawOpens ~allFiles ~pos + ~scope with - | Some (typ, env) -> ( + | Some ((TypeExpr typ | ExtractedType (Tfunction {typ})), env) -> ( let rec reconstructFunctionType args tRet = match args with | [] -> tRet @@ -776,7 +776,7 @@ and getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env let retType = reconstructFunctionType args tRet in [Completion.create "dummy" ~env ~kind:(Completion.Value retType)] | _ -> []) - | None -> []) + | _ -> []) | CPField (CPId (path, Module), fieldName) -> (* M.field *) path @ [fieldName] @@ -1048,16 +1048,17 @@ and getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env ~kind:(Completion.Value (Utils.unwrapIfOption typ)); ]) | CArgument {functionContextPath; argumentLabel} -> ( - (* TODO: Also needs to support ExtractedType *) let labels, env = match functionContextPath |> getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env ~exact:true ~scope - |> completionsGetTypeEnv2 ~full ~opens ~rawOpens ~allFiles ~pos ~scope + |> completionsGetCompletionType2 ~full ~opens ~rawOpens ~allFiles ~pos + ~scope with - | Some (typ, env) -> (typ |> TypeUtils.getArgs ~full ~env, env) - | None -> ([], env) + | Some ((TypeExpr typ | ExtractedType (Tfunction {typ})), env) -> + (typ |> TypeUtils.getArgs ~full ~env, env) + | _ -> ([], env) in let targetLabel = labels From 10530c502a55feb1c7eab885e796746434496d93 Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Fri, 3 Feb 2023 22:04:02 +0100 Subject: [PATCH 23/41] fix cross file --- analysis/src/TypeUtils.ml | 2 +- analysis/tests/src/CompletionInferValues.res | 16 +++++++ analysis/tests/src/CompletionSupport.res | 4 ++ .../expected/CompletionInferValues.res.txt | 48 +++++++++++++++++++ 4 files changed, 69 insertions(+), 1 deletion(-) diff --git a/analysis/src/TypeUtils.ml b/analysis/src/TypeUtils.ml index bf9c87551..4911e4abb 100644 --- a/analysis/src/TypeUtils.ml +++ b/analysis/src/TypeUtils.ml @@ -397,7 +397,7 @@ let rec resolveNestedPatternPath (typ : innerType) ~env ~full ~nested = | Some completionType -> ( match (finalPatternPath, completionType) with | ( Completable.NFollowRecordField {fieldName}, - (TinlineRecord {env; fields} | Trecord {env; fields}) ) -> ( + (TinlineRecord {fields} | Trecord {fields}) ) -> ( match fields |> findTypeOfRecordField ~fieldName with | None -> None | Some typ -> Some (TypeExpr typ, env)) diff --git a/analysis/tests/src/CompletionInferValues.res b/analysis/tests/src/CompletionInferValues.res index 8e68d3bda..9e9ac1b58 100644 --- a/analysis/tests/src/CompletionInferValues.res +++ b/analysis/tests/src/CompletionInferValues.res @@ -131,3 +131,19 @@ let fnWithRecordCallback = (cb: someRecord => unit) => { // Complete pattern of function parameter // fnWithRecordCallback(({}) => {()}) // ^com + +let fn2 = (~cb: CompletionSupport.Nested.config => unit) => { + let _ = cb +} + +// fn2(~cb=({root}) => {root-> }) +// ^com + +type sameFileRecord = {root: CompletionSupport.Test.t, test: int} + +let fn3 = (~cb: sameFileRecord => unit) => { + let _ = cb +} + +// fn3(~cb=({root}) => {root-> }) +// ^com diff --git a/analysis/tests/src/CompletionSupport.res b/analysis/tests/src/CompletionSupport.res index a51b88c87..1d93fe878 100644 --- a/analysis/tests/src/CompletionSupport.res +++ b/analysis/tests/src/CompletionSupport.res @@ -22,3 +22,7 @@ module TestComponent = { React.null } } + +module Nested = { + type config = {root: ReactDOM.Client.Root.t} +} diff --git a/analysis/tests/src/expected/CompletionInferValues.res.txt b/analysis/tests/src/expected/CompletionInferValues.res.txt index 5a30a32d5..c91a199ea 100644 --- a/analysis/tests/src/expected/CompletionInferValues.res.txt +++ b/analysis/tests/src/expected/CompletionInferValues.res.txt @@ -420,3 +420,51 @@ Completable: Cpattern CArgument CArgument Value[fnWithRecordCallback]($0)($0)->r "documentation": null }] +Complete src/CompletionInferValues.res 138:30 +posCursor:[138:30] posNoWhite:[138:29] Found expr:[138:3->138:33] +Pexp_apply ...[138:3->138:6] (~cb138:8->138:10=...[138:11->138:32]) +posCursor:[138:30] posNoWhite:[138:29] Found expr:[138:11->138:32] +posCursor:[138:30] posNoWhite:[138:29] Found expr:[138:24->0:-1] +posCursor:[138:30] posNoWhite:[138:29] Found expr:[138:24->0:-1] +Completable: Cpath Value[root]-> +[{ + "label": "ReactDOM.Client.Root.unmount", + "kind": 12, + "tags": [], + "detail": "(t, unit) => unit", + "documentation": null + }, { + "label": "ReactDOM.Client.Root.render", + "kind": 12, + "tags": [], + "detail": "(t, React.element) => unit", + "documentation": null + }] + +Complete src/CompletionInferValues.res 147:30 +posCursor:[147:30] posNoWhite:[147:29] Found expr:[147:3->147:33] +Pexp_apply ...[147:3->147:6] (~cb147:8->147:10=...[147:11->147:32]) +posCursor:[147:30] posNoWhite:[147:29] Found expr:[147:11->147:32] +posCursor:[147:30] posNoWhite:[147:29] Found expr:[147:24->0:-1] +posCursor:[147:30] posNoWhite:[147:29] Found expr:[147:24->0:-1] +Completable: Cpath Value[root]-> +[{ + "label": "CompletionSupport.Test.add", + "kind": 12, + "tags": [], + "detail": "t => int", + "documentation": null + }, { + "label": "CompletionSupport.Test.addSelf", + "kind": 12, + "tags": [], + "detail": "t => t", + "documentation": null + }, { + "label": "CompletionSupport.Test.make", + "kind": 12, + "tags": [], + "detail": "int => t", + "documentation": null + }] + From 13946e04ad66f5b963465f37b23733c816113a73 Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Sun, 5 Feb 2023 10:33:40 +0100 Subject: [PATCH 24/41] apply pipe transform to ctx path extraction so pipes can be tracked as context paths --- analysis/src/CompletionFrontEnd.ml | 54 +++++++++++-------- analysis/tests/src/CompletionInferValues.res | 8 +++ .../expected/CompletionInferValues.res.txt | 28 ++++++++++ 3 files changed, 67 insertions(+), 23 deletions(-) diff --git a/analysis/src/CompletionFrontEnd.ml b/analysis/src/CompletionFrontEnd.ml index 2f8197d3e..4c8a8f9e7 100644 --- a/analysis/src/CompletionFrontEnd.ml +++ b/analysis/src/CompletionFrontEnd.ml @@ -161,6 +161,33 @@ let rec exprToContextPath (e : Parsetree.expression) = match exprToContextPath e1 with | None -> None | Some contexPath -> Some (CPObj (contexPath, txt))) + | Pexp_apply + ( {pexp_desc = Pexp_ident {txt = Lident "|."}}, + [ + (_, lhs); + (_, {pexp_desc = Pexp_apply (d, args); pexp_loc; pexp_attributes}); + ] ) -> + (* Transform away pipe with apply call *) + exprToContextPath + { + pexp_desc = Pexp_apply (d, (Nolabel, lhs) :: args); + pexp_loc; + pexp_attributes; + } + | Pexp_apply + ( {pexp_desc = Pexp_ident {txt = Lident "|."}}, + [(_, lhs); (_, {pexp_desc = Pexp_ident id; pexp_loc; pexp_attributes})] + ) -> + (* Transform away pipe with identifier *) + exprToContextPath + { + pexp_desc = + Pexp_apply + ( {pexp_desc = Pexp_ident id; pexp_loc; pexp_attributes}, + [(Nolabel, lhs)] ); + pexp_loc; + pexp_attributes; + } | Pexp_apply (e1, args) -> ( match exprToContextPath e1 with | None -> None @@ -185,33 +212,14 @@ let completePipeChain (exp : Parsetree.expression) = Example: someArray->Js.Array2.map(v => v + 2)-> *) | Pexp_apply ( {pexp_desc = Pexp_ident {txt = Lident "|."}}, - [ - (_, lhs); - (_, {pexp_desc = Pexp_apply (d, args); pexp_loc; pexp_attributes}); - ] ) -> - exprToContextPath - { - pexp_desc = Pexp_apply (d, (Nolabel, lhs) :: args); - pexp_loc; - pexp_attributes; - } - |> Option.map (fun ctxPath -> (ctxPath, d.pexp_loc)) + [_; (_, {pexp_desc = Pexp_apply (d, _)})] ) -> + exprToContextPath exp |> Option.map (fun ctxPath -> (ctxPath, d.pexp_loc)) (* When the left side of the pipe we're completing is an identifier application. Example: someArray->filterAllTheGoodStuff-> *) | Pexp_apply ( {pexp_desc = Pexp_ident {txt = Lident "|."}}, - [(_, lhs); (_, {pexp_desc = Pexp_ident id; pexp_loc; pexp_attributes})] - ) -> - exprToContextPath - { - pexp_desc = - Pexp_apply - ( {pexp_desc = Pexp_ident id; pexp_loc; pexp_attributes}, - [(Nolabel, lhs)] ); - pexp_loc; - pexp_attributes; - } - |> Option.map (fun ctxPath -> (ctxPath, pexp_loc)) + [_; (_, {pexp_desc = Pexp_ident _; pexp_loc})] ) -> + exprToContextPath exp |> Option.map (fun ctxPath -> (ctxPath, pexp_loc)) | _ -> None let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor ~text = diff --git a/analysis/tests/src/CompletionInferValues.res b/analysis/tests/src/CompletionInferValues.res index 9e9ac1b58..652e3b3be 100644 --- a/analysis/tests/src/CompletionInferValues.res +++ b/analysis/tests/src/CompletionInferValues.res @@ -147,3 +147,11 @@ let fn3 = (~cb: sameFileRecord => unit) => { // fn3(~cb=({root}) => {root-> }) // ^com + +// Handles pipe chains as input for switch +// let x = 123; switch x->Belt.Int.toString { | } +// ^com + +// Handles pipe chains as input for switch +// let x = 123; switch x->Belt.Int.toString->Js.String2.split("/") { | } +// ^com diff --git a/analysis/tests/src/expected/CompletionInferValues.res.txt b/analysis/tests/src/expected/CompletionInferValues.res.txt index c91a199ea..5963c73b5 100644 --- a/analysis/tests/src/expected/CompletionInferValues.res.txt +++ b/analysis/tests/src/expected/CompletionInferValues.res.txt @@ -468,3 +468,31 @@ Completable: Cpath Value[root]-> "documentation": null }] +Complete src/CompletionInferValues.res 151:47 +XXX Not found! +Completable: Cpattern Value[Belt, Int, toString](Nolabel) +[{ + "label": "\"\"", + "kind": 12, + "tags": [], + "detail": "string", + "documentation": null, + "sortText": "A", + "insertText": "\"$0\"", + "insertTextFormat": 2 + }] + +Complete src/CompletionInferValues.res 155:70 +XXX Not found! +Completable: Cpattern Value[Js, String2, split](Nolabel, Nolabel) +[{ + "label": "[]", + "kind": 12, + "tags": [], + "detail": "t", + "documentation": null, + "sortText": "A", + "insertText": "[$0]", + "insertTextFormat": 2 + }] + From 109fc430c52d71a95999dd27f95ab1d4f45e9dbb Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Sun, 5 Feb 2023 18:53:37 +0100 Subject: [PATCH 25/41] handle processing of functions and fn args --- analysis/src/CompletionFrontEnd.ml | 23 +- analysis/tests/src/CompletionInferValues.res | 1 - .../expected/CompletionInferValues.res.txt | 204 +++++++++--------- 3 files changed, 121 insertions(+), 107 deletions(-) diff --git a/analysis/src/CompletionFrontEnd.ml b/analysis/src/CompletionFrontEnd.ml index 4c8a8f9e7..1a92c4700 100644 --- a/analysis/src/CompletionFrontEnd.ml +++ b/analysis/src/CompletionFrontEnd.ml @@ -268,6 +268,7 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor ~text = in let currentCtxPath = ref None in + let processingFun = ref None in let setCurrentCtxPath ctxPath = if !Cfg.debugFollowCtxPath then Printf.printf "setting current ctxPath: %s\n" @@ -1010,25 +1011,27 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor ~text = | Pexp_fun (lbl, defaultExpOpt, pat, e) -> let oldScope = !scope in let oldCtxPath = !currentCtxPath in - (* TODO: Haven't figured out how to count unlabelled args here yet... *) - (* TODO: This is broken. I'm trying to set the CArgument context path - below here continuously for each argument as I traverse the expr - for the arg, but I end up piling them on each other. So what should - be Carg $0, then Carg $1, then Carg $3... is now (faulty) Carg $0, - then Carg Carg $0 $1, then Carg Carg Carg $0 $1 $2, and so on. *) - (match !currentCtxPath with + (match (!processingFun, !currentCtxPath) with + | None, Some ctxPath -> processingFun := Some (ctxPath, 0) + | _ -> ()); + (match !processingFun with | None -> () - | Some ctxPath -> + | Some (ctxPath, currentUnlabelledCount) -> ( setCurrentCtxPath (CArgument { functionContextPath = ctxPath; argumentLabel = (match lbl with - | Nolabel -> Unlabelled {argumentPosition = 0} + | Nolabel -> + Unlabelled {argumentPosition = currentUnlabelledCount} | Optional name -> Optional name | Labelled name -> Labelled name); - })); + }); + processingFun := + match lbl with + | Nolabel -> Some (ctxPath, currentUnlabelledCount + 1) + | _ -> Some (ctxPath, currentUnlabelledCount))); (match defaultExpOpt with | None -> () | Some defaultExp -> iterator.expr iterator defaultExp); diff --git a/analysis/tests/src/CompletionInferValues.res b/analysis/tests/src/CompletionInferValues.res index 652e3b3be..10d4a2aeb 100644 --- a/analysis/tests/src/CompletionInferValues.res +++ b/analysis/tests/src/CompletionInferValues.res @@ -25,7 +25,6 @@ let reactEventFn = (cb: ReactEvent.Mouse.t => unit) => { // someFnWithCallback((~someRecord, ~num, ~isOn) => someRecord.) // ^com -// Broken because not using the first argument (argument context seems to pile on when they should be plucked off and new one added) // let aliasedFn = someFnWithCallback; aliasedFn((~num, ~someRecord, ~isOn) => someRecord.) // ^com diff --git a/analysis/tests/src/expected/CompletionInferValues.res.txt b/analysis/tests/src/expected/CompletionInferValues.res.txt index 5963c73b5..be147e6b3 100644 --- a/analysis/tests/src/expected/CompletionInferValues.res.txt +++ b/analysis/tests/src/expected/CompletionInferValues.res.txt @@ -17,7 +17,7 @@ Completable: Cpath Value[aliased]->f Complete src/CompletionInferValues.res 18:30 posCursor:[18:30] posNoWhite:[18:29] Found expr:[18:28->18:30] -Pexp_field [18:28->18:29] _:[34:0->18:30] +Pexp_field [18:28->18:29] _:[33:0->18:30] Completable: Cpath Value[x]."" [{ "label": "name", @@ -35,7 +35,7 @@ Completable: Cpath Value[x]."" Complete src/CompletionInferValues.res 21:53 posCursor:[21:53] posNoWhite:[21:52] Found expr:[21:45->21:53] -Pexp_field [21:45->21:52] _:[34:0->21:53] +Pexp_field [21:45->21:52] _:[33:0->21:53] Completable: Cpath Value[aliased]."" [{ "label": "name", @@ -74,22 +74,34 @@ Completable: Cpath Value[someRecord]."" "documentation": null }] -Complete src/CompletionInferValues.res 28:90 -posCursor:[28:90] posNoWhite:[28:89] Found expr:[28:39->28:91] -Pexp_apply ...[28:39->28:48] (...[28:49->28:90]) -posCursor:[28:90] posNoWhite:[28:89] Found expr:[28:49->28:90] -posCursor:[28:90] posNoWhite:[28:89] Found expr:[28:56->28:90] -posCursor:[28:90] posNoWhite:[28:89] Found expr:[28:69->28:90] -posCursor:[28:90] posNoWhite:[28:89] Found expr:[28:79->28:90] -Pexp_field [28:79->28:89] _:[28:90->28:90] +Complete src/CompletionInferValues.res 27:90 +posCursor:[27:90] posNoWhite:[27:89] Found expr:[27:39->27:91] +Pexp_apply ...[27:39->27:48] (...[27:49->27:90]) +posCursor:[27:90] posNoWhite:[27:89] Found expr:[27:49->27:90] +posCursor:[27:90] posNoWhite:[27:89] Found expr:[27:56->27:90] +posCursor:[27:90] posNoWhite:[27:89] Found expr:[27:69->27:90] +posCursor:[27:90] posNoWhite:[27:89] Found expr:[27:79->27:90] +Pexp_field [27:79->27:89] _:[27:90->27:90] Completable: Cpath Value[someRecord]."" -[] +[{ + "label": "name", + "kind": 5, + "tags": [], + "detail": "name: string\n\ntype someRecord = {name: string, age: int}", + "documentation": null + }, { + "label": "age", + "kind": 5, + "tags": [], + "detail": "age: int\n\ntype someRecord = {name: string, age: int}", + "documentation": null + }] -Complete src/CompletionInferValues.res 31:36 -posCursor:[31:36] posNoWhite:[31:35] Found expr:[31:3->31:39] -Pexp_apply ...[31:3->31:15] (...[31:16->31:38]) -posCursor:[31:36] posNoWhite:[31:35] Found expr:[31:16->31:38] -posCursor:[31:36] posNoWhite:[31:35] Found expr:[31:27->31:36] +Complete src/CompletionInferValues.res 30:36 +posCursor:[30:36] posNoWhite:[30:35] Found expr:[30:3->30:39] +Pexp_apply ...[30:3->30:15] (...[30:16->30:38]) +posCursor:[30:36] posNoWhite:[30:35] Found expr:[30:16->30:38] +posCursor:[30:36] posNoWhite:[30:35] Found expr:[30:27->30:36] Completable: Cpath Value[event]->pr [{ "label": "ReactEvent.Mouse.preventDefault", @@ -99,11 +111,11 @@ Completable: Cpath Value[event]->pr "documentation": null }] -Complete src/CompletionInferValues.res 42:50 -posCursor:[42:50] posNoWhite:[42:49] Found expr:[42:12->42:56] -JSX 42:15] onMouseEnter[42:16->42:28]=...[42:36->42:52]> _children:42:54 -posCursor:[42:50] posNoWhite:[42:49] Found expr:[42:36->42:52] -posCursor:[42:50] posNoWhite:[42:49] Found expr:[42:41->42:50] +Complete src/CompletionInferValues.res 41:50 +posCursor:[41:50] posNoWhite:[41:49] Found expr:[41:12->41:56] +JSX 41:15] onMouseEnter[41:16->41:28]=...[41:36->41:52]> _children:41:54 +posCursor:[41:50] posNoWhite:[41:49] Found expr:[41:36->41:52] +posCursor:[41:50] posNoWhite:[41:49] Found expr:[41:41->41:50] Completable: Cpath Value[event]->pr <> [{ "label": "JsxEvent.Mouse.preventDefault", @@ -113,11 +125,11 @@ Completable: Cpath Value[event]->pr <> "documentation": null }] -Complete src/CompletionInferValues.res 45:50 -posCursor:[45:50] posNoWhite:[45:49] Found expr:[45:12->45:56] -JSX 45:15] onMouseEnter[45:16->45:28]=...[45:36->45:52]> _children:45:54 -posCursor:[45:50] posNoWhite:[45:49] Found expr:[45:36->45:52] -posCursor:[45:50] posNoWhite:[45:49] Found expr:[45:41->45:50] +Complete src/CompletionInferValues.res 44:50 +posCursor:[44:50] posNoWhite:[44:49] Found expr:[44:12->44:56] +JSX 44:15] onMouseEnter[44:16->44:28]=...[44:36->44:52]> _children:44:54 +posCursor:[44:50] posNoWhite:[44:49] Found expr:[44:36->44:52] +posCursor:[44:50] posNoWhite:[44:49] Found expr:[44:41->44:50] Completable: Cpath Value[event]->pr <> [{ "label": "JsxEvent.Mouse.preventDefault", @@ -127,12 +139,12 @@ Completable: Cpath Value[event]->pr <> "documentation": null }] -Complete src/CompletionInferValues.res 48:87 -posCursor:[48:87] posNoWhite:[48:86] Found expr:[48:12->48:93] -JSX 48:15] onMouseEnter[48:16->48:28]=...[48:36->48:89]> _children:48:91 -posCursor:[48:87] posNoWhite:[48:86] Found expr:[48:36->48:89] -posCursor:[48:87] posNoWhite:[48:86] Found expr:[48:41->48:87] -posCursor:[48:87] posNoWhite:[48:86] Found expr:[48:81->48:87] +Complete src/CompletionInferValues.res 47:87 +posCursor:[47:87] posNoWhite:[47:86] Found expr:[47:12->47:93] +JSX 47:15] onMouseEnter[47:16->47:28]=...[47:36->47:89]> _children:47:91 +posCursor:[47:87] posNoWhite:[47:86] Found expr:[47:36->47:89] +posCursor:[47:87] posNoWhite:[47:86] Found expr:[47:41->47:87] +posCursor:[47:87] posNoWhite:[47:86] Found expr:[47:81->47:87] Completable: Cpath Value[btn]->t <> [{ "label": "Belt.Int.toString", @@ -148,12 +160,12 @@ Completable: Cpath Value[btn]->t <> "documentation": {"kind": "markdown", "value": "\n Converts a given `int` to a `float`.\n\n ```res example\n Js.log(Belt.Int.toFloat(1) === 1.0) /* true */\n ```\n"} }] -Complete src/CompletionInferValues.res 51:108 -posCursor:[51:108] posNoWhite:[51:107] Found expr:[51:12->51:114] -JSX 51:15] onMouseEnter[51:16->51:28]=...[51:36->51:110]> _children:51:112 -posCursor:[51:108] posNoWhite:[51:107] Found expr:[51:36->51:110] -posCursor:[51:108] posNoWhite:[51:107] Found expr:[51:41->51:108] -posCursor:[51:108] posNoWhite:[51:107] Found expr:[51:100->51:108] +Complete src/CompletionInferValues.res 50:108 +posCursor:[50:108] posNoWhite:[50:107] Found expr:[50:12->50:114] +JSX 50:15] onMouseEnter[50:16->50:28]=...[50:36->50:110]> _children:50:112 +posCursor:[50:108] posNoWhite:[50:107] Found expr:[50:36->50:110] +posCursor:[50:108] posNoWhite:[50:107] Found expr:[50:41->50:108] +posCursor:[50:108] posNoWhite:[50:107] Found expr:[50:100->50:108] Completable: Cpath Value[btn]->spl <> [{ "label": "Js.String2.splitAtMost", @@ -181,12 +193,12 @@ Completable: Cpath Value[btn]->spl <> "documentation": {"kind": "markdown", "value": "\n`splitByReAtMost(str, regex, ~limit:n)` splits the given `str` at every\noccurrence of `regex` and returns an array of the first `n` resulting\nsubstrings. If `n` is negative or greater than the number of substrings, the\narray will contain all the substrings.\n\nSee [`String.split`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split)\non MDN.\n\n```res example\nJs.String2.splitByReAtMost(\"one: two: three: four\", %re(\"/\\s*:\\s*/\"), ~limit=3) == [\n Some(\"one\"),\n Some(\"two\"),\n Some(\"three\"),\n ]\n\nJs.String2.splitByReAtMost(\"one: two: three: four\", %re(\"/\\s*:\\s*/\"), ~limit=0) == []\n\nJs.String2.splitByReAtMost(\"one: two: three: four\", %re(\"/\\s*:\\s*/\"), ~limit=8) == [\n Some(\"one\"),\n Some(\"two\"),\n Some(\"three\"),\n Some(\"four\"),\n ]\n```\n"} }] -Complete src/CompletionInferValues.res 54:130 -posCursor:[54:130] posNoWhite:[54:129] Found expr:[54:12->54:136] -JSX 54:15] onMouseEnter[54:16->54:28]=...[54:36->54:132]> _children:54:134 -posCursor:[54:130] posNoWhite:[54:129] Found expr:[54:36->54:132] -posCursor:[54:130] posNoWhite:[54:129] Found expr:[54:41->54:130] -posCursor:[54:130] posNoWhite:[54:129] Found expr:[54:123->54:130] +Complete src/CompletionInferValues.res 53:130 +posCursor:[53:130] posNoWhite:[53:129] Found expr:[53:12->53:136] +JSX 53:15] onMouseEnter[53:16->53:28]=...[53:36->53:132]> _children:53:134 +posCursor:[53:130] posNoWhite:[53:129] Found expr:[53:36->53:132] +posCursor:[53:130] posNoWhite:[53:129] Found expr:[53:41->53:130] +posCursor:[53:130] posNoWhite:[53:129] Found expr:[53:123->53:130] Completable: Cpath Value[btn]->ma <> [{ "label": "Js.Array2.mapi", @@ -202,9 +214,9 @@ Completable: Cpath Value[btn]->ma <> "documentation": {"kind": "markdown", "value": "\nApplies the function (the second argument) to each item in the array, returning\na new array. The result array does not have to have elements of the same type\nas the input array. See\n[`Array.map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map)\non MDN.\n\n```res example\nJs.Array2.map([12, 4, 8], x => x * x) == [144, 16, 64]\nJs.Array2.map([\"animal\", \"vegetable\", \"mineral\"], Js.String.length) == [6, 9, 7]\n```\n"} }] -Complete src/CompletionInferValues.res 57:52 -posCursor:[57:52] posNoWhite:[57:51] Found expr:[57:50->57:52] -Pexp_field [57:50->57:51] _:[60:0->57:52] +Complete src/CompletionInferValues.res 56:52 +posCursor:[56:52] posNoWhite:[56:51] Found expr:[56:50->56:52] +Pexp_field [56:50->56:51] _:[59:0->56:52] Completable: Cpath Value[x]."" [{ "label": "name", @@ -220,9 +232,9 @@ Completable: Cpath Value[x]."" "documentation": null }] -Complete src/CompletionInferValues.res 79:78 -posCursor:[79:78] posNoWhite:[79:77] Found expr:[79:70->79:78] -Pexp_field [79:70->79:77] _:[126:0->79:78] +Complete src/CompletionInferValues.res 78:78 +posCursor:[78:78] posNoWhite:[78:77] Found expr:[78:70->78:78] +Pexp_field [78:70->78:77] _:[125:0->78:78] Completable: Cpath Value[srecord]."" [{ "label": "name", @@ -238,9 +250,9 @@ Completable: Cpath Value[srecord]."" "documentation": null }] -Complete src/CompletionInferValues.res 83:86 -posCursor:[83:86] posNoWhite:[83:85] Found expr:[83:78->83:86] -Pexp_field [83:78->83:85] _:[126:0->83:86] +Complete src/CompletionInferValues.res 82:86 +posCursor:[82:86] posNoWhite:[82:85] Found expr:[82:78->82:86] +Pexp_field [82:78->82:85] _:[125:0->82:86] Completable: Cpath Value[aliased]."" [{ "label": "someRecord", @@ -250,9 +262,9 @@ Completable: Cpath Value[aliased]."" "documentation": null }] -Complete src/CompletionInferValues.res 87:103 -posCursor:[87:103] posNoWhite:[87:102] Found expr:[87:92->87:103] -Pexp_field [87:92->87:102] _:[126:0->87:103] +Complete src/CompletionInferValues.res 86:103 +posCursor:[86:103] posNoWhite:[86:102] Found expr:[86:92->86:103] +Pexp_field [86:92->86:102] _:[125:0->86:103] Completable: Cpath Value[someRecord]."" [{ "label": "name", @@ -268,8 +280,8 @@ Completable: Cpath Value[someRecord]."" "documentation": null }] -Complete src/CompletionInferValues.res 91:81 -posCursor:[91:81] posNoWhite:[91:80] Found expr:[91:69->91:81] +Complete src/CompletionInferValues.res 90:81 +posCursor:[90:81] posNoWhite:[90:80] Found expr:[90:69->90:81] Completable: Cpath Value[things]->slic [{ "label": "Js.String2.sliceToEnd", @@ -285,8 +297,8 @@ Completable: Cpath Value[things]->slic "documentation": {"kind": "markdown", "value": "\n`slice(str, from:n1, to_:n2)` returns the substring of `str` starting at\ncharacter `n1` up to but not including `n2`.\n- If either `n1` or `n2` is negative, then it is evaluated as `length(str - n1)` or `length(str - n2)`.\n- If `n2` is greater than the length of `str`, then it is treated as `length(str)`.\n- If `n1` is greater than `n2`, slice returns the empty string.\n\nSee [`String.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice) on MDN.\n\n```res example\nJs.String2.slice(\"abcdefg\", ~from=2, ~to_=5) == \"cde\"\nJs.String2.slice(\"abcdefg\", ~from=2, ~to_=9) == \"cdefg\"\nJs.String2.slice(\"abcdefg\", ~from=-4, ~to_=-2) == \"de\"\nJs.String2.slice(\"abcdefg\", ~from=5, ~to_=1) == \"\"\n```\n"} }] -Complete src/CompletionInferValues.res 95:82 -posCursor:[95:82] posNoWhite:[95:81] Found expr:[95:70->95:82] +Complete src/CompletionInferValues.res 94:82 +posCursor:[94:82] posNoWhite:[94:81] Found expr:[94:70->94:82] Completable: Cpath Value[someInt]->toS [{ "label": "Belt.Int.toString", @@ -296,8 +308,8 @@ Completable: Cpath Value[someInt]->toS "documentation": {"kind": "markdown", "value": "\n Converts a given `int` to a `string`. Uses the JavaScript `String` constructor under the hood.\n\n ```res example\n Js.log(Belt.Int.toString(1) === \"1\") /* true */\n ```\n"} }] -Complete src/CompletionInferValues.res 99:109 -posCursor:[99:109] posNoWhite:[99:108] Found expr:[99:97->99:109] +Complete src/CompletionInferValues.res 98:109 +posCursor:[98:109] posNoWhite:[98:108] Found expr:[98:97->98:109] Completable: Cpath Value[someInt]->toS [{ "label": "Belt.Int.toString", @@ -307,9 +319,9 @@ Completable: Cpath Value[someInt]->toS "documentation": {"kind": "markdown", "value": "\n Converts a given `int` to a `string`. Uses the JavaScript `String` constructor under the hood.\n\n ```res example\n Js.log(Belt.Int.toString(1) === \"1\") /* true */\n ```\n"} }] -Complete src/CompletionInferValues.res 103:102 -posCursor:[103:102] posNoWhite:[103:101] Found expr:[103:57->103:102] -posCursor:[103:102] posNoWhite:[103:101] Found expr:[103:90->103:102] +Complete src/CompletionInferValues.res 102:102 +posCursor:[102:102] posNoWhite:[102:101] Found expr:[102:57->102:102] +posCursor:[102:102] posNoWhite:[102:101] Found expr:[102:90->102:102] Completable: Cpath Value[someInt]->toS [{ "label": "Belt.Int.toString", @@ -319,8 +331,8 @@ Completable: Cpath Value[someInt]->toS "documentation": {"kind": "markdown", "value": "\n Converts a given `int` to a `string`. Uses the JavaScript `String` constructor under the hood.\n\n ```res example\n Js.log(Belt.Int.toString(1) === \"1\") /* true */\n ```\n"} }] -Complete src/CompletionInferValues.res 107:88 -posCursor:[107:88] posNoWhite:[107:87] Found expr:[107:79->107:88] +Complete src/CompletionInferValues.res 106:88 +posCursor:[106:88] posNoWhite:[106:87] Found expr:[106:79->106:88] Completable: Cpath Value[str]->slic [{ "label": "Js.String2.sliceToEnd", @@ -336,8 +348,8 @@ Completable: Cpath Value[str]->slic "documentation": {"kind": "markdown", "value": "\n`slice(str, from:n1, to_:n2)` returns the substring of `str` starting at\ncharacter `n1` up to but not including `n2`.\n- If either `n1` or `n2` is negative, then it is evaluated as `length(str - n1)` or `length(str - n2)`.\n- If `n2` is greater than the length of `str`, then it is treated as `length(str)`.\n- If `n1` is greater than `n2`, slice returns the empty string.\n\nSee [`String.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice) on MDN.\n\n```res example\nJs.String2.slice(\"abcdefg\", ~from=2, ~to_=5) == \"cde\"\nJs.String2.slice(\"abcdefg\", ~from=2, ~to_=9) == \"cdefg\"\nJs.String2.slice(\"abcdefg\", ~from=-4, ~to_=-2) == \"de\"\nJs.String2.slice(\"abcdefg\", ~from=5, ~to_=1) == \"\"\n```\n"} }] -Complete src/CompletionInferValues.res 111:89 -posCursor:[111:89] posNoWhite:[111:88] Found expr:[111:80->111:89] +Complete src/CompletionInferValues.res 110:89 +posCursor:[110:89] posNoWhite:[110:88] Found expr:[110:80->110:89] Completable: Cpath Value[str]->slic [{ "label": "Js.String2.sliceToEnd", @@ -353,8 +365,8 @@ Completable: Cpath Value[str]->slic "documentation": {"kind": "markdown", "value": "\n`slice(str, from:n1, to_:n2)` returns the substring of `str` starting at\ncharacter `n1` up to but not including `n2`.\n- If either `n1` or `n2` is negative, then it is evaluated as `length(str - n1)` or `length(str - n2)`.\n- If `n2` is greater than the length of `str`, then it is treated as `length(str)`.\n- If `n1` is greater than `n2`, slice returns the empty string.\n\nSee [`String.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice) on MDN.\n\n```res example\nJs.String2.slice(\"abcdefg\", ~from=2, ~to_=5) == \"cde\"\nJs.String2.slice(\"abcdefg\", ~from=2, ~to_=9) == \"cdefg\"\nJs.String2.slice(\"abcdefg\", ~from=-4, ~to_=-2) == \"de\"\nJs.String2.slice(\"abcdefg\", ~from=5, ~to_=1) == \"\"\n```\n"} }] -Complete src/CompletionInferValues.res 115:80 -posCursor:[115:80] posNoWhite:[115:79] Found expr:[115:70->115:80] +Complete src/CompletionInferValues.res 114:80 +posCursor:[114:80] posNoWhite:[114:79] Found expr:[114:70->114:80] Completable: Cpath Value[name]->slic [{ "label": "Js.String2.sliceToEnd", @@ -370,9 +382,9 @@ Completable: Cpath Value[name]->slic "documentation": {"kind": "markdown", "value": "\n`slice(str, from:n1, to_:n2)` returns the substring of `str` starting at\ncharacter `n1` up to but not including `n2`.\n- If either `n1` or `n2` is negative, then it is evaluated as `length(str - n1)` or `length(str - n2)`.\n- If `n2` is greater than the length of `str`, then it is treated as `length(str)`.\n- If `n1` is greater than `n2`, slice returns the empty string.\n\nSee [`String.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice) on MDN.\n\n```res example\nJs.String2.slice(\"abcdefg\", ~from=2, ~to_=5) == \"cde\"\nJs.String2.slice(\"abcdefg\", ~from=2, ~to_=9) == \"cdefg\"\nJs.String2.slice(\"abcdefg\", ~from=-4, ~to_=-2) == \"de\"\nJs.String2.slice(\"abcdefg\", ~from=5, ~to_=1) == \"\"\n```\n"} }] -Complete src/CompletionInferValues.res 119:67 -posCursor:[119:67] posNoWhite:[119:66] Found expr:[119:60->119:67] -Pexp_field [119:60->119:65] s:[119:66->119:67] +Complete src/CompletionInferValues.res 118:67 +posCursor:[118:67] posNoWhite:[118:66] Found expr:[118:60->118:67] +Pexp_field [118:60->118:65] s:[118:66->118:67] Completable: Cpath Value[inner].s [{ "label": "someRecord", @@ -388,8 +400,8 @@ Completable: Cpath Value[inner].s "documentation": null }] -Complete src/CompletionInferValues.res 123:53 -posCursor:[123:53] posNoWhite:[123:52] Found expr:[123:46->123:53] +Complete src/CompletionInferValues.res 122:53 +posCursor:[122:53] posNoWhite:[122:52] Found expr:[122:46->122:53] Completable: Cpath Value[v]->toSt [{ "label": "Belt.Int.toString", @@ -399,12 +411,12 @@ Completable: Cpath Value[v]->toSt "documentation": {"kind": "markdown", "value": "\n Converts a given `int` to a `string`. Uses the JavaScript `String` constructor under the hood.\n\n ```res example\n Js.log(Belt.Int.toString(1) === \"1\") /* true */\n ```\n"} }] -Complete src/CompletionInferValues.res 131:26 -posCursor:[131:26] posNoWhite:[131:25] Found expr:[131:3->131:37] -Pexp_apply ...[131:3->131:23] (...[131:24->131:36]) -posCursor:[131:26] posNoWhite:[131:25] Found expr:[131:24->131:36] -posCursor:[131:26] posNoWhite:[131:25] Found pattern:[131:25->131:27] -posCursor:[131:26] posNoWhite:[131:25] Found pattern:[131:25->131:27] +Complete src/CompletionInferValues.res 130:26 +posCursor:[130:26] posNoWhite:[130:25] Found expr:[130:3->130:37] +Pexp_apply ...[130:3->130:23] (...[130:24->130:36]) +posCursor:[130:26] posNoWhite:[130:25] Found expr:[130:24->130:36] +posCursor:[130:26] posNoWhite:[130:25] Found pattern:[130:25->130:27] +posCursor:[130:26] posNoWhite:[130:25] Found pattern:[130:25->130:27] Completable: Cpattern CArgument CArgument Value[fnWithRecordCallback]($0)($0)->recordBody [{ "label": "name", @@ -420,12 +432,12 @@ Completable: Cpattern CArgument CArgument Value[fnWithRecordCallback]($0)($0)->r "documentation": null }] -Complete src/CompletionInferValues.res 138:30 -posCursor:[138:30] posNoWhite:[138:29] Found expr:[138:3->138:33] -Pexp_apply ...[138:3->138:6] (~cb138:8->138:10=...[138:11->138:32]) -posCursor:[138:30] posNoWhite:[138:29] Found expr:[138:11->138:32] -posCursor:[138:30] posNoWhite:[138:29] Found expr:[138:24->0:-1] -posCursor:[138:30] posNoWhite:[138:29] Found expr:[138:24->0:-1] +Complete src/CompletionInferValues.res 137:30 +posCursor:[137:30] posNoWhite:[137:29] Found expr:[137:3->137:33] +Pexp_apply ...[137:3->137:6] (~cb137:8->137:10=...[137:11->137:32]) +posCursor:[137:30] posNoWhite:[137:29] Found expr:[137:11->137:32] +posCursor:[137:30] posNoWhite:[137:29] Found expr:[137:24->0:-1] +posCursor:[137:30] posNoWhite:[137:29] Found expr:[137:24->0:-1] Completable: Cpath Value[root]-> [{ "label": "ReactDOM.Client.Root.unmount", @@ -441,12 +453,12 @@ Completable: Cpath Value[root]-> "documentation": null }] -Complete src/CompletionInferValues.res 147:30 -posCursor:[147:30] posNoWhite:[147:29] Found expr:[147:3->147:33] -Pexp_apply ...[147:3->147:6] (~cb147:8->147:10=...[147:11->147:32]) -posCursor:[147:30] posNoWhite:[147:29] Found expr:[147:11->147:32] -posCursor:[147:30] posNoWhite:[147:29] Found expr:[147:24->0:-1] -posCursor:[147:30] posNoWhite:[147:29] Found expr:[147:24->0:-1] +Complete src/CompletionInferValues.res 146:30 +posCursor:[146:30] posNoWhite:[146:29] Found expr:[146:3->146:33] +Pexp_apply ...[146:3->146:6] (~cb146:8->146:10=...[146:11->146:32]) +posCursor:[146:30] posNoWhite:[146:29] Found expr:[146:11->146:32] +posCursor:[146:30] posNoWhite:[146:29] Found expr:[146:24->0:-1] +posCursor:[146:30] posNoWhite:[146:29] Found expr:[146:24->0:-1] Completable: Cpath Value[root]-> [{ "label": "CompletionSupport.Test.add", @@ -468,7 +480,7 @@ Completable: Cpath Value[root]-> "documentation": null }] -Complete src/CompletionInferValues.res 151:47 +Complete src/CompletionInferValues.res 150:47 XXX Not found! Completable: Cpattern Value[Belt, Int, toString](Nolabel) [{ @@ -482,7 +494,7 @@ Completable: Cpattern Value[Belt, Int, toString](Nolabel) "insertTextFormat": 2 }] -Complete src/CompletionInferValues.res 155:70 +Complete src/CompletionInferValues.res 154:70 XXX Not found! Completable: Cpattern Value[Js, String2, split](Nolabel, Nolabel) [{ From f2ad8bab14e190bf8e508b8c8db5e88cbf0dd905 Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Tue, 7 Feb 2023 14:07:50 +0100 Subject: [PATCH 26/41] refactor to make less invasive --- analysis/src/CompletionFrontEnd.ml | 52 ++++++++++++++++-------------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/analysis/src/CompletionFrontEnd.ml b/analysis/src/CompletionFrontEnd.ml index 1a92c4700..e6b0cfa27 100644 --- a/analysis/src/CompletionFrontEnd.ml +++ b/analysis/src/CompletionFrontEnd.ml @@ -802,7 +802,7 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor ~text = (* Case foo-> when the parser adds a ghost expression to the rhs so the apply expression does not include the cursor *) if setPipeResult ~lhs ~id:"" then setFound () - | _ -> + | _ -> ( if expr.pexp_loc |> Loc.hasPos ~pos:posNoWhite && !result = None then ( setFound (); match expr.pexp_desc with @@ -1010,38 +1010,37 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor ~text = | None -> ()) | Pexp_fun (lbl, defaultExpOpt, pat, e) -> let oldScope = !scope in - let oldCtxPath = !currentCtxPath in (match (!processingFun, !currentCtxPath) with | None, Some ctxPath -> processingFun := Some (ctxPath, 0) | _ -> ()); - (match !processingFun with - | None -> () - | Some (ctxPath, currentUnlabelledCount) -> ( - setCurrentCtxPath - (CArgument - { - functionContextPath = ctxPath; - argumentLabel = - (match lbl with - | Nolabel -> - Unlabelled {argumentPosition = currentUnlabelledCount} - | Optional name -> Optional name - | Labelled name -> Labelled name); - }); - processingFun := - match lbl with - | Nolabel -> Some (ctxPath, currentUnlabelledCount + 1) - | _ -> Some (ctxPath, currentUnlabelledCount))); + let argContextPath = + match !processingFun with + | None -> None + | Some (ctxPath, currentUnlabelledCount) -> + (processingFun := + match lbl with + | Nolabel -> Some (ctxPath, currentUnlabelledCount + 1) + | _ -> Some (ctxPath, currentUnlabelledCount)); + Some + (Completable.CArgument + { + functionContextPath = ctxPath; + argumentLabel = + (match lbl with + | Nolabel -> + Unlabelled {argumentPosition = currentUnlabelledCount} + | Optional name -> Optional name + | Labelled name -> Labelled name); + }) + in (match defaultExpOpt with | None -> () | Some defaultExp -> iterator.expr iterator defaultExp); - let currentContextPath = !currentCtxPath in - completePattern ?contextPath:currentContextPath pat; - scopePattern ?contextPath:currentContextPath pat; + completePattern ?contextPath:argContextPath pat; + scopePattern ?contextPath:argContextPath pat; iterator.pat iterator pat; iterator.expr iterator e; scope := oldScope; - resetCurrentCtxPath oldCtxPath; processed := true | Pexp_let (recFlag, bindings, e) -> let oldScope = !scope in @@ -1068,7 +1067,10 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor ~text = processed := true | _ -> ()); if not !processed then Ast_iterator.default_iterator.expr iterator expr; - inJsxContext := oldInJsxContext + inJsxContext := oldInJsxContext; + match expr.pexp_desc with + | Pexp_fun _ -> () + | _ -> processingFun := None) in let typ (iterator : Ast_iterator.iterator) (core_type : Parsetree.core_type) = if core_type.ptyp_loc |> Loc.hasPos ~pos:posNoWhite then ( From 65166fcb52da23637a9d380124e1f767698851ac Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Fri, 10 Feb 2023 20:33:49 +0100 Subject: [PATCH 27/41] fix after rebase --- analysis/src/CompletionBackEnd.ml | 2 +- analysis/src/SharedTypes.ml | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/analysis/src/CompletionBackEnd.ml b/analysis/src/CompletionBackEnd.ml index a9b70c56c..47a592833 100644 --- a/analysis/src/CompletionBackEnd.ml +++ b/analysis/src/CompletionBackEnd.ml @@ -817,7 +817,7 @@ and getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env if Utils.checkName field.fname.txt ~prefix:fieldName ~exact then Some (Completion.create field.fname.txt ~env - ~docstring:field.docstring + ?deprecated:field.deprecated ~docstring:field.docstring ~kind:(Completion.Field (field, recordAsString))) else None)) | CPObj (cp, label) -> ( diff --git a/analysis/src/SharedTypes.ml b/analysis/src/SharedTypes.ml index 840e64dd5..3f4d8c011 100644 --- a/analysis/src/SharedTypes.ml +++ b/analysis/src/SharedTypes.ml @@ -730,12 +730,12 @@ module Completion = struct detail; } - let createWithSnippet ~name ?insertText ~kind ~env ?sortText ?filterText - ?detail ?(docstring = []) () = + let createWithSnippet ~name ?insertText ~kind ~env ?sortText ?deprecated + ?filterText ?detail ?(docstring = []) () = { name; env; - deprecated = None; + deprecated; docstring; kind; sortText; From 9630859f293d055f4a79818c6a1b39d664643d7b Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Sat, 11 Feb 2023 10:47:51 +0100 Subject: [PATCH 28/41] missed traversing switch expr when no cases --- analysis/src/CompletionFrontEnd.ml | 3 +-- .../CompletionFunctionArguments.res.txt | 19 +++++++++++++++++-- .../src/expected/CompletionPattern.res.txt | 2 +- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/analysis/src/CompletionFrontEnd.ml b/analysis/src/CompletionFrontEnd.ml index e6b0cfa27..470becc5e 100644 --- a/analysis/src/CompletionFrontEnd.ml +++ b/analysis/src/CompletionFrontEnd.ml @@ -780,8 +780,7 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor ~text = in typedCompletionExpr expr; match expr.pexp_desc with - | Pexp_match (_expr, []) -> () - | Pexp_match (expr, cases) -> + | Pexp_match (expr, cases) when cases <> [] -> let ctxPath = exprToContextPath expr in let oldCtxPath = !currentCtxPath in cases diff --git a/analysis/tests/src/expected/CompletionFunctionArguments.res.txt b/analysis/tests/src/expected/CompletionFunctionArguments.res.txt index 4d1f71d05..ce5de8aac 100644 --- a/analysis/tests/src/expected/CompletionFunctionArguments.res.txt +++ b/analysis/tests/src/expected/CompletionFunctionArguments.res.txt @@ -57,8 +57,23 @@ Complete src/CompletionFunctionArguments.res 21:27 posCursor:[21:27] posNoWhite:[21:26] Found expr:[19:8->25:1] Pexp_apply ...[19:8->19:14] (~isOn20:3->20:7=...[21:7->23:8]) posCursor:[21:27] posNoWhite:[21:26] Found expr:[21:7->23:8] -posCursor:[21:27] posNoWhite:[21:26] Found expr:[21:7->23:8] -[] +posCursor:[21:27] posNoWhite:[21:26] Found expr:[21:7->21:28] +posCursor:[21:27] posNoWhite:[21:26] Found expr:[21:14->21:28] +Pexp_apply ...[21:14->21:20] (~isOn21:22->21:26=...__ghost__[0:-1->0:-1]) +Completable: Cexpression CArgument Value[someFn](~isOn) +[{ + "label": "true", + "kind": 4, + "tags": [], + "detail": "bool", + "documentation": null + }, { + "label": "false", + "kind": 4, + "tags": [], + "detail": "bool", + "documentation": null + }] Complete src/CompletionFunctionArguments.res 34:24 posCursor:[34:24] posNoWhite:[34:23] Found expr:[34:11->34:25] diff --git a/analysis/tests/src/expected/CompletionPattern.res.txt b/analysis/tests/src/expected/CompletionPattern.res.txt index bac7941e9..e1645c638 100644 --- a/analysis/tests/src/expected/CompletionPattern.res.txt +++ b/analysis/tests/src/expected/CompletionPattern.res.txt @@ -1,5 +1,5 @@ Complete src/CompletionPattern.res 7:13 -XXX Not found! +posCursor:[7:13] posNoWhite:[7:12] Found expr:[7:3->7:13] [] Complete src/CompletionPattern.res 10:15 From 171d49e7ced3e409104b56c804dcdd9db753ca68 Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Sat, 11 Feb 2023 11:10:03 +0100 Subject: [PATCH 29/41] illustrate new issue with pipe completion paths --- analysis/src/CompletionBackEnd.ml | 7 +++++- analysis/tests/src/CompletionInferValues.res | 8 +++++++ analysis/tests/src/CompletionSupport2.res | 17 +++++++++++++ .../expected/CompletionInferValues.res.txt | 24 +++++++++++++++++++ .../src/expected/CompletionSupport2.res.txt | 0 5 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 analysis/tests/src/CompletionSupport2.res create mode 100644 analysis/tests/src/expected/CompletionSupport2.res.txt diff --git a/analysis/src/CompletionBackEnd.ml b/analysis/src/CompletionBackEnd.ml index 47a592833..d90e00a74 100644 --- a/analysis/src/CompletionBackEnd.ml +++ b/analysis/src/CompletionBackEnd.ml @@ -857,9 +857,14 @@ and getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env with | None -> [] | Some (typ, envFromCompletionItem) -> ( + (* Passing `envFromCompletionItem` into `resolveTypeForPipeCompletion` + fixes the issue in `CompletionInferValues.res`, but breaks other pipe + chains. Change it and see what breaks instead. *) let env, typ = typ - |> TypeUtils.resolveTypeForPipeCompletion ~env ~package ~full ~lhsLoc + |> TypeUtils.resolveTypeForPipeCompletion + (* by doing this ~env:envFromCompletionItem*) + ~env ~package ~full ~lhsLoc in let completionPath = match typ with diff --git a/analysis/tests/src/CompletionInferValues.res b/analysis/tests/src/CompletionInferValues.res index 10d4a2aeb..829c26032 100644 --- a/analysis/tests/src/CompletionInferValues.res +++ b/analysis/tests/src/CompletionInferValues.res @@ -154,3 +154,11 @@ let fn3 = (~cb: sameFileRecord => unit) => { // Handles pipe chains as input for switch // let x = 123; switch x->Belt.Int.toString->Js.String2.split("/") { | } // ^com + +// Regular completion works +// let renderer = CompletionSupport2.makeRenderer(~prepare=() => "hello",~render=({support}) => {support.},()) +// ^com + +// But pipe completion gets the wrong completion path. Should be `ReactDOM.Client.Root.t`, but ends up being `CompletionSupport2.ReactDOM.Client.Root.t`. +// let renderer = CompletionSupport2.makeRenderer(~prepare=() => "hello",~render=({support:{root}}) => {root->},()) +// ^com diff --git a/analysis/tests/src/CompletionSupport2.res b/analysis/tests/src/CompletionSupport2.res new file mode 100644 index 000000000..925fc5d57 --- /dev/null +++ b/analysis/tests/src/CompletionSupport2.res @@ -0,0 +1,17 @@ +module Internal = { + type prepareProps<'prepared> = { + someName: string, + support: CompletionSupport.Nested.config, + prepared: 'prepared, + } +} + +let makeRenderer = ( + ~prepare: unit => 'prepared, + ~render: Internal.prepareProps<'prepared> => React.element, + (), +) => { + let _ = prepare + let _ = render + "123" +} diff --git a/analysis/tests/src/expected/CompletionInferValues.res.txt b/analysis/tests/src/expected/CompletionInferValues.res.txt index be147e6b3..957370f75 100644 --- a/analysis/tests/src/expected/CompletionInferValues.res.txt +++ b/analysis/tests/src/expected/CompletionInferValues.res.txt @@ -508,3 +508,27 @@ Completable: Cpattern Value[Js, String2, split](Nolabel, Nolabel) "insertTextFormat": 2 }] +Complete src/CompletionInferValues.res 158:105 +posCursor:[158:105] posNoWhite:[158:104] Found expr:[158:18->158:110] +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]) +posCursor:[158:105] posNoWhite:[158:104] Found expr:[158:81->158:106] +posCursor:[158:105] posNoWhite:[158:104] Found expr:[158:97->158:105] +Pexp_field [158:97->158:104] _:[158:105->158:105] +Completable: Cpath Value[support]."" +[{ + "label": "root", + "kind": 5, + "tags": [], + "detail": "root: ReactDOM.Client.Root.t\n\ntype config = {root: ReactDOM.Client.Root.t}", + "documentation": null + }] + +Complete src/CompletionInferValues.res 162:110 +posCursor:[162:110] posNoWhite:[162:109] Found expr:[162:18->162:115] +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]) +posCursor:[162:110] posNoWhite:[162:109] Found expr:[162:81->162:111] +posCursor:[162:110] posNoWhite:[162:109] Found expr:[162:104->0:-1] +posCursor:[162:110] posNoWhite:[162:109] Found expr:[162:104->0:-1] +Completable: Cpath Value[root]-> +[] + diff --git a/analysis/tests/src/expected/CompletionSupport2.res.txt b/analysis/tests/src/expected/CompletionSupport2.res.txt new file mode 100644 index 000000000..e69de29bb From 4bb9b7703d1fcf2ca562d6bd31df323022b23445 Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Tue, 7 Mar 2023 10:43:45 +0100 Subject: [PATCH 30/41] Completion debug start having a single entry point for completions --- analysis/src/Commands.ml | 28 +++----------- analysis/src/Completions.ml | 25 +++++++++++++ analysis/src/Hover.ml | 73 +++++++++++++------------------------ 3 files changed, 57 insertions(+), 69 deletions(-) create mode 100644 analysis/src/Completions.ml diff --git a/analysis/src/Commands.ml b/analysis/src/Commands.ml index db671ca08..aa4b766ad 100644 --- a/analysis/src/Commands.ml +++ b/analysis/src/Commands.ml @@ -1,29 +1,13 @@ -let getCompletions ~debug ~path ~pos ~currentFile ~forHover = - let textOpt = Files.readFile currentFile in - match textOpt with - | None | Some "" -> [] - | Some text -> ( +let completion ~debug ~path ~pos ~currentFile = + let completions = match - CompletionFrontEnd.completionWithParser ~debug ~path ~posCursor:pos - ~currentFile ~text + Completions.getCompletions ~debug ~path ~pos ~currentFile ~forHover:false with | None -> [] - | Some (completable, scope) -> ( - if debug then - Printf.printf "Completable: %s\n" - (SharedTypes.Completable.toString completable); - (* Only perform expensive ast operations if there are completables *) - match Cmt.loadFullCmtFromPath ~path with - | None -> [] - | Some full -> - let env = SharedTypes.QueryEnv.fromFile full.file in - completable - |> CompletionBackEnd.processCompletable ~debug ~full ~pos ~scope ~env - ~forHover)) - -let completion ~debug ~path ~pos ~currentFile = + | Some (completions, _) -> completions + in print_endline - (getCompletions ~debug ~path ~pos ~currentFile ~forHover:false + (completions |> List.map CompletionBackEnd.completionToItem |> List.map Protocol.stringifyCompletionItem |> Protocol.array) diff --git a/analysis/src/Completions.ml b/analysis/src/Completions.ml new file mode 100644 index 000000000..57376ac22 --- /dev/null +++ b/analysis/src/Completions.ml @@ -0,0 +1,25 @@ +let getCompletions ~debug ~path ~pos ~currentFile ~forHover = + let textOpt = Files.readFile currentFile in + match textOpt with + | None | Some "" -> None + | Some text -> ( + match + CompletionFrontEnd.completionWithParser ~debug ~path ~posCursor:pos + ~currentFile ~text + with + | None -> None + | Some (completable, scope) -> ( + if debug then + Printf.printf "Completable: %s\n" + (SharedTypes.Completable.toString completable); + (* Only perform expensive ast operations if there are completables *) + match Cmt.loadFullCmtFromPath ~path with + | None -> None + | Some full -> + let env = SharedTypes.QueryEnv.fromFile full.file in + let completables = + completable + |> CompletionBackEnd.processCompletable ~debug ~full ~pos ~scope ~env + ~forHover + in + Some (completables, full))) diff --git a/analysis/src/Hover.ml b/analysis/src/Hover.ml index 307f6155a..3ab1a0c74 100644 --- a/analysis/src/Hover.ml +++ b/analysis/src/Hover.ml @@ -123,54 +123,33 @@ let hoverWithExpandedTypes ~file ~package ~supportsMarkdownLinks typ = makes it (most often) work with unsaved content. *) let getHoverViaCompletions ~debug ~path ~pos ~currentFile ~forHover ~supportsMarkdownLinks = - let textOpt = Files.readFile currentFile in - match textOpt with - | None | Some "" -> None - | Some text -> ( - match - CompletionFrontEnd.completionWithParser ~debug ~path ~posCursor:pos - ~currentFile ~text - with - | None -> None - | Some (completable, scope) -> ( - if debug then - Printf.printf "Completable: %s\n" - (SharedTypes.Completable.toString completable); - (* Only perform expensive ast operations if there are completables *) - match Cmt.loadFullCmtFromPath ~path with - | None -> None - | Some full -> ( - let {file; package} = full in - let env = SharedTypes.QueryEnv.fromFile file in - let completions = - completable - |> CompletionBackEnd.processCompletable ~debug ~full ~pos ~scope ~env - ~forHover + match Completions.getCompletions ~debug ~path ~pos ~currentFile ~forHover with + | None -> None + | Some (completions, {file; package}) -> ( + match completions with + | {kind = Label typString; docstring} :: _ -> + let parts = + (if typString = "" then [] else [Markdown.codeBlock typString]) + @ docstring + in + Some (Protocol.stringifyHover (String.concat "\n\n" parts)) + | {kind = Field _; docstring} :: _ -> ( + match CompletionBackEnd.completionsGetTypeEnv completions with + | Some (typ, _env) -> + let typeString = + hoverWithExpandedTypes ~file ~package ~supportsMarkdownLinks typ in - match completions with - | {kind = Label typString; docstring} :: _ -> - let parts = - (if typString = "" then [] else [Markdown.codeBlock typString]) - @ docstring - in - Some (Protocol.stringifyHover (String.concat "\n\n" parts)) - | {kind = Field _; docstring} :: _ -> ( - match CompletionBackEnd.completionsGetTypeEnv completions with - | Some (typ, _env) -> - let typeString = - hoverWithExpandedTypes ~file ~package ~supportsMarkdownLinks typ - in - let parts = typeString :: docstring in - Some (Protocol.stringifyHover (String.concat "\n\n" parts)) - | None -> None) - | _ -> ( - match CompletionBackEnd.completionsGetTypeEnv completions with - | Some (typ, _env) -> - let typeString = - hoverWithExpandedTypes ~file ~package ~supportsMarkdownLinks typ - in - Some (Protocol.stringifyHover typeString) - | None -> None)))) + let parts = typeString :: docstring in + Some (Protocol.stringifyHover (String.concat "\n\n" parts)) + | None -> None) + | _ -> ( + match CompletionBackEnd.completionsGetTypeEnv completions with + | Some (typ, _env) -> + let typeString = + hoverWithExpandedTypes ~file ~package ~supportsMarkdownLinks typ + in + Some (Protocol.stringifyHover typeString) + | None -> None)) let newHover ~full:{file; package} ~supportsMarkdownLinks locItem = match locItem.locType with From 27820c8dede5e8afbd7544e667f2d537d83526f4 Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Tue, 7 Mar 2023 10:52:17 +0100 Subject: [PATCH 31/41] Emit completable where it is processed. --- analysis/src/CompletionBackEnd.ml | 5 +++-- analysis/src/Completions.ml | 3 --- analysis/tests/src/expected/Completion.res.txt | 1 + .../tests/src/expected/SignatureHelp.res.txt | 17 +++++++++++++++++ 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/analysis/src/CompletionBackEnd.ml b/analysis/src/CompletionBackEnd.ml index d90e00a74..3dfb06c96 100644 --- a/analysis/src/CompletionBackEnd.ml +++ b/analysis/src/CompletionBackEnd.ml @@ -1396,8 +1396,9 @@ let rec completeTypedValue ~full ~prefix ~completionContext ~mode ~env; ] -let rec processCompletable ~debug ~full ~scope ~env ~pos ~forHover - (completable : Completable.t) = +let rec processCompletable ~debug ~full ~scope ~env ~pos ~forHover completable = + if debug then + Printf.printf "Completable: %s\n" (Completable.toString completable); let package = full.package in let rawOpens = Scope.getRawOpens scope in let opens = getOpens ~debug ~rawOpens ~package ~env in diff --git a/analysis/src/Completions.ml b/analysis/src/Completions.ml index 57376ac22..3b455817b 100644 --- a/analysis/src/Completions.ml +++ b/analysis/src/Completions.ml @@ -9,9 +9,6 @@ let getCompletions ~debug ~path ~pos ~currentFile ~forHover = with | None -> None | Some (completable, scope) -> ( - if debug then - Printf.printf "Completable: %s\n" - (SharedTypes.Completable.toString completable); (* Only perform expensive ast operations if there are completables *) match Cmt.loadFullCmtFromPath ~path with | None -> None diff --git a/analysis/tests/src/expected/Completion.res.txt b/analysis/tests/src/expected/Completion.res.txt index c7f270b8f..2c8a81575 100644 --- a/analysis/tests/src/expected/Completion.res.txt +++ b/analysis/tests/src/expected/Completion.res.txt @@ -1449,6 +1449,7 @@ Ppat_construct T:[362:7->362:8] Completable: Cpattern Value[x]=T Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder Resolved opens 2 Completion.res Completion.res +Completable: Cpath Value[T] Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder Resolved opens 2 Completion.res Completion.res [{ diff --git a/analysis/tests/src/expected/SignatureHelp.res.txt b/analysis/tests/src/expected/SignatureHelp.res.txt index 802874b2f..68f0517c7 100644 --- a/analysis/tests/src/expected/SignatureHelp.res.txt +++ b/analysis/tests/src/expected/SignatureHelp.res.txt @@ -3,6 +3,7 @@ posCursor:[16:19] posNoWhite:[16:18] Found expr:[16:11->16:20] Pexp_apply ...[16:11->16:19] (...[46:0->16:20]) posCursor:[16:19] posNoWhite:[16:18] Found expr:[16:11->16:19] Pexp_ident someFunc:[16:11->16:19] +Completable: Cpath Value[someFunc] argAtCursor: unlabelled<0> extracted params: [( @@ -22,6 +23,7 @@ posCursor:[19:19] posNoWhite:[19:18] Found expr:[19:11->19:21] Pexp_apply ...[19:11->19:19] (...[19:20->19:21]) posCursor:[19:19] posNoWhite:[19:18] Found expr:[19:11->19:19] Pexp_ident someFunc:[19:11->19:19] +Completable: Cpath Value[someFunc] argAtCursor: unlabelled<0> extracted params: [( @@ -41,6 +43,7 @@ posCursor:[22:19] posNoWhite:[22:18] Found expr:[22:11->22:29] Pexp_apply ...[22:11->22:19] (...[22:20->22:23], ~two22:26->22:29=...[22:26->22:29]) posCursor:[22:19] posNoWhite:[22:18] Found expr:[22:11->22:19] Pexp_ident someFunc:[22:11->22:19] +Completable: Cpath Value[someFunc] argAtCursor: ~two extracted params: [( @@ -60,6 +63,7 @@ posCursor:[25:19] posNoWhite:[25:18] Found expr:[25:11->25:35] Pexp_apply ...[25:11->25:19] (...[25:20->25:23], ~two25:26->25:29=...[25:30->25:35]) posCursor:[25:19] posNoWhite:[25:18] Found expr:[25:11->25:19] Pexp_ident someFunc:[25:11->25:19] +Completable: Cpath Value[someFunc] argAtCursor: ~two extracted params: [( @@ -79,6 +83,7 @@ posCursor:[28:19] posNoWhite:[28:18] Found expr:[28:11->28:42] Pexp_apply ...[28:11->28:19] (...[28:20->28:23], ~two28:26->28:29=...[28:30->28:35], ~four28:38->28:42=...[28:38->28:42]) posCursor:[28:19] posNoWhite:[28:18] Found expr:[28:11->28:19] Pexp_ident someFunc:[28:11->28:19] +Completable: Cpath Value[someFunc] argAtCursor: ~four extracted params: [( @@ -98,6 +103,7 @@ posCursor:[31:19] posNoWhite:[31:18] Found expr:[31:11->31:44] Pexp_apply ...[31:11->31:19] (...[31:20->31:23], ~two31:26->31:29=...[31:30->31:35], ~four31:38->31:42=...[31:43->31:44]) posCursor:[31:19] posNoWhite:[31:18] Found expr:[31:11->31:19] Pexp_ident someFunc:[31:11->31:19] +Completable: Cpath Value[someFunc] argAtCursor: ~four extracted params: [( @@ -117,6 +123,7 @@ posCursor:[34:20] posNoWhite:[34:19] Found expr:[34:11->34:21] Pexp_apply ...[34:11->34:20] (...[46:0->34:21]) posCursor:[34:20] posNoWhite:[34:19] Found expr:[34:11->34:20] Pexp_ident otherFunc:[34:11->34:20] +Completable: Cpath Value[otherFunc] argAtCursor: unlabelled<0> extracted params: [(string, int, float] @@ -134,6 +141,7 @@ posCursor:[37:20] posNoWhite:[37:19] Found expr:[37:11->37:26] Pexp_apply ...[37:11->37:20] (...[37:21->37:26]) posCursor:[37:20] posNoWhite:[37:19] Found expr:[37:11->37:20] Pexp_ident otherFunc:[37:11->37:20] +Completable: Cpath Value[otherFunc] argAtCursor: unlabelled<0> extracted params: [(string, int, float] @@ -151,6 +159,7 @@ posCursor:[40:20] posNoWhite:[40:19] Found expr:[40:11->40:39] Pexp_apply ...[40:11->40:20] (...[40:21->40:26], ...[40:28->40:31], ...[40:33->40:38]) posCursor:[40:20] posNoWhite:[40:19] Found expr:[40:11->40:20] Pexp_ident otherFunc:[40:11->40:20] +Completable: Cpath Value[otherFunc] argAtCursor: unlabelled<2> extracted params: [(string, int, float] @@ -168,6 +177,7 @@ posCursor:[43:29] posNoWhite:[43:28] Found expr:[43:11->43:34] Pexp_apply ...[43:11->43:29] (~age43:31->43:34=...[43:31->43:34]) posCursor:[43:29] posNoWhite:[43:28] Found expr:[43:11->43:29] Pexp_ident Completion.Lib.foo:[43:11->43:29] +Completable: Cpath Value[Completion, Lib, foo] argAtCursor: ~age extracted params: [(~age: int, ~name: string] @@ -185,6 +195,7 @@ posCursor:[50:23] posNoWhite:[50:22] Found expr:[50:11->50:24] Pexp_apply ...[50:11->50:23] (...[56:0->50:24]) posCursor:[50:23] posNoWhite:[50:22] Found expr:[50:11->50:23] Pexp_ident iAmSoSpecial:[50:11->50:23] +Completable: Cpath Value[iAmSoSpecial] argAtCursor: unlabelled<0> extracted params: [string] @@ -203,6 +214,7 @@ posCursor:[53:29] posNoWhite:[53:28] Found expr:[53:20->53:31] Pexp_apply ...[53:20->53:29] (...[53:30->53:31]) posCursor:[53:29] posNoWhite:[53:28] Found expr:[53:20->53:29] Pexp_ident otherFunc:[53:20->53:29] +Completable: Cpath Value[otherFunc] argAtCursor: unlabelled<1> extracted params: [(string, int, float] @@ -220,6 +232,7 @@ posCursor:[62:13] posNoWhite:[62:12] Found expr:[62:11->62:19] Pexp_apply ...[62:11->62:13] (...[62:14->62:16]) posCursor:[62:13] posNoWhite:[62:12] Found expr:[62:11->62:13] Pexp_ident fn:[62:11->62:13] +Completable: Cpath Value[fn] argAtCursor: unlabelled<1> extracted params: [(int, string, int] @@ -237,6 +250,7 @@ posCursor:[65:13] posNoWhite:[65:12] Found expr:[65:11->65:25] Pexp_apply ...[65:11->65:13] (...[65:14->65:16], ...[65:20->65:24]) posCursor:[65:13] posNoWhite:[65:12] Found expr:[65:11->65:13] Pexp_ident fn:[65:11->65:13] +Completable: Cpath Value[fn] argAtCursor: unlabelled<1> extracted params: [(int, string, int] @@ -254,6 +268,7 @@ posCursor:[68:13] posNoWhite:[68:12] Found expr:[68:11->68:28] Pexp_apply ...[68:11->68:13] (...[68:14->68:16], ...[68:18->68:25]) posCursor:[68:13] posNoWhite:[68:12] Found expr:[68:11->68:13] Pexp_ident fn:[68:11->68:13] +Completable: Cpath Value[fn] argAtCursor: unlabelled<2> extracted params: [(int, string, int] @@ -273,6 +288,7 @@ posCursor:[71:28] posNoWhite:[71:27] Found expr:[71:16->71:30] Pexp_apply ...[71:16->71:28] (...[71:29->71:30]) posCursor:[71:28] posNoWhite:[71:27] Found expr:[71:16->71:28] Pexp_ident iAmSoSpecial:[71:16->71:28] +Completable: Cpath Value[iAmSoSpecial] argAtCursor: unlabelled<0> extracted params: [string] @@ -294,6 +310,7 @@ posCursor:[74:39] posNoWhite:[74:38] Found expr:[74:31->74:41] Pexp_apply ...[74:31->74:39] (...[74:40->74:41]) posCursor:[74:39] posNoWhite:[74:38] Found expr:[74:31->74:39] Pexp_ident someFunc:[74:31->74:39] +Completable: Cpath Value[someFunc] argAtCursor: unlabelled<0> extracted params: [( From d6aa0fdb1c94fdb82d3f29d0198535eb18243b14 Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Tue, 7 Mar 2023 11:14:40 +0100 Subject: [PATCH 32/41] Print ContextPath --- analysis/src/CompletionBackEnd.ml | 118 +++++++------- .../src/expected/BrokenParserCases.res.txt | 3 + .../src/expected/CompletePrioritize1.res.txt | 2 + .../src/expected/CompletePrioritize2.res.txt | 3 + .../tests/src/expected/Completion.res.txt | 126 +++++++++++++++ .../expected/CompletionExpressions.res.txt | 75 +++++++++ .../CompletionFunctionArguments.res.txt | 32 ++++ .../expected/CompletionInferValues.res.txt | 147 ++++++++++++++++++ .../tests/src/expected/CompletionJsx.res.txt | 17 ++ .../src/expected/CompletionJsxProps.res.txt | 9 ++ .../src/expected/CompletionPattern.res.txt | 47 ++++++ .../src/expected/CompletionPipeChain.res.txt | 39 +++++ .../expected/CompletionPipeSubmodules.res.txt | 13 ++ .../expected/CompletionTypeAnnotation.res.txt | 23 +++ analysis/tests/src/expected/Cross.res.txt | 1 + analysis/tests/src/expected/Debug.res.txt | 1 + .../tests/src/expected/Destructuring.res.txt | 5 + .../src/expected/ExhaustiveSwitch.res.txt | 4 + analysis/tests/src/expected/Hover.res.txt | 15 ++ analysis/tests/src/expected/Jsx2.res.txt | 13 ++ analysis/tests/src/expected/Jsx2.resi.txt | 2 + .../src/expected/RecordCompletion.res.txt | 9 ++ .../tests/src/expected/RecoveryOnProp.res.txt | 1 + .../tests/src/expected/SignatureHelp.res.txt | 17 ++ 24 files changed, 668 insertions(+), 54 deletions(-) diff --git a/analysis/src/CompletionBackEnd.ml b/analysis/src/CompletionBackEnd.ml index 3dfb06c96..cb87ed694 100644 --- a/analysis/src/CompletionBackEnd.ml +++ b/analysis/src/CompletionBackEnd.ml @@ -620,18 +620,18 @@ let completionsGetCompletionType ~full = function | {Completion.kind = ExtractedType (typ, _); env} :: _ -> Some (typ, env) | _ -> None -let rec completionsGetCompletionType2 ~full ~opens ~rawOpens ~allFiles ~pos - ~scope = function +let rec completionsGetCompletionType2 ~debug ~full ~opens ~rawOpens ~allFiles + ~pos ~scope = function | {Completion.kind = Value typ; env} :: _ | {Completion.kind = ObjLabel typ; env} :: _ | {Completion.kind = Field ({typ}, _); env} :: _ -> Some (TypeExpr typ, env) | {Completion.kind = FollowContextPath ctxPath; env} :: _ -> ctxPath - |> getCompletionsForContextPath ~full ~env ~exact:true ~opens ~rawOpens - ~allFiles ~pos ~scope - |> completionsGetCompletionType2 ~full ~opens ~rawOpens ~allFiles ~pos - ~scope + |> getCompletionsForContextPath ~debug ~full ~env ~exact:true ~opens + ~rawOpens ~allFiles ~pos ~scope + |> completionsGetCompletionType2 ~debug ~full ~opens ~rawOpens ~allFiles + ~pos ~scope | {Completion.kind = Type typ; env} :: _ -> ( match TypeUtils.extractTypeFromResolvedType typ ~env ~full with | None -> None @@ -640,7 +640,7 @@ let rec completionsGetCompletionType2 ~full ~opens ~rawOpens ~allFiles ~pos Some (ExtractedType typ, env) | _ -> None -and completionsGetTypeEnv2 (completions : Completion.t list) ~full ~opens +and completionsGetTypeEnv2 ~debug (completions : Completion.t list) ~full ~opens ~rawOpens ~allFiles ~pos ~scope = match completions with | {Completion.kind = Value typ; env} :: _ -> Some (typ, env) @@ -648,13 +648,17 @@ and completionsGetTypeEnv2 (completions : Completion.t list) ~full ~opens | {Completion.kind = Field ({typ}, _); env} :: _ -> Some (typ, env) | {Completion.kind = FollowContextPath ctxPath; env} :: _ -> ctxPath - |> getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env - ~exact:true ~scope - |> completionsGetTypeEnv2 ~full ~opens ~rawOpens ~allFiles ~pos ~scope + |> getCompletionsForContextPath ~debug ~full ~opens ~rawOpens ~allFiles ~pos + ~env ~exact:true ~scope + |> completionsGetTypeEnv2 ~debug ~full ~opens ~rawOpens ~allFiles ~pos + ~scope | _ -> None -and getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env - ~exact ~scope ?(mode = Regular) (contextPath : Completable.contextPath) = +and getCompletionsForContextPath ~debug ~full ~opens ~rawOpens ~allFiles ~pos + ~env ~exact ~scope ?(mode = Regular) contextPath = + if debug then + Printf.printf "ContextPath %s\n" + (Completable.contextPathToString contextPath); let package = full.package in match contextPath with | CPString -> @@ -697,8 +701,8 @@ and getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env | Regular -> ( match cp - |> getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos - ~env ~exact:true ~scope + |> getCompletionsForContextPath ~debug ~full ~opens ~rawOpens ~allFiles + ~pos ~env ~exact:true ~scope |> completionsGetCompletionType ~full with | None -> [] @@ -720,8 +724,8 @@ and getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env | CPOption cp -> ( match cp - |> getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env - ~exact:true ~scope + |> getCompletionsForContextPath ~debug ~full ~opens ~rawOpens ~allFiles + ~pos ~env ~exact:true ~scope |> completionsGetCompletionType ~full with | None -> [] @@ -738,10 +742,10 @@ and getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env | CPApply (cp, labels) -> ( match cp - |> getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env - ~exact:true ~scope - |> completionsGetCompletionType2 ~full ~opens ~rawOpens ~allFiles ~pos - ~scope + |> getCompletionsForContextPath ~debug ~full ~opens ~rawOpens ~allFiles + ~pos ~env ~exact:true ~scope + |> completionsGetCompletionType2 ~debug ~full ~opens ~rawOpens ~allFiles + ~pos ~scope with | Some ((TypeExpr typ | ExtractedType (Tfunction {typ})), env) -> ( let rec reconstructFunctionType args tRet = @@ -785,14 +789,14 @@ and getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env | CPField (cp, fieldName) -> ( let completionsForCtxPath = cp - |> getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env - ~exact:true ~scope + |> getCompletionsForContextPath ~debug ~full ~opens ~rawOpens ~allFiles + ~pos ~env ~exact:true ~scope in let extracted = match completionsForCtxPath - |> completionsGetCompletionType2 ~full ~opens ~rawOpens ~allFiles ~pos - ~scope + |> completionsGetCompletionType2 ~debug ~full ~opens ~rawOpens ~allFiles + ~pos ~scope with | Some (TypeExpr typ, env) -> ( match typ |> TypeUtils.extractRecordType ~env ~package with @@ -824,9 +828,10 @@ and getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env (* TODO: Also needs to support ExtractedType *) match cp - |> getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env - ~exact:true ~scope - |> completionsGetTypeEnv2 ~full ~opens ~rawOpens ~allFiles ~pos ~scope + |> getCompletionsForContextPath ~debug ~full ~opens ~rawOpens ~allFiles + ~pos ~env ~exact:true ~scope + |> completionsGetTypeEnv2 ~debug ~full ~opens ~rawOpens ~allFiles ~pos + ~scope with | Some (typ, env) -> ( match typ |> TypeUtils.extractObjectType ~env ~package with @@ -851,9 +856,10 @@ and getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env | CPPipe {contextPath = cp; id = funNamePrefix; lhsLoc; inJsx} -> ( match cp - |> getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env - ~exact:true ~scope ~mode:Pipe - |> completionsGetTypeEnv2 ~full ~opens ~rawOpens ~allFiles ~pos ~scope + |> getCompletionsForContextPath ~debug ~full ~opens ~rawOpens ~allFiles + ~pos ~env ~exact:true ~scope ~mode:Pipe + |> completionsGetTypeEnv2 ~debug ~full ~opens ~rawOpens ~allFiles ~pos + ~scope with | None -> [] | Some (typ, envFromCompletionItem) -> ( @@ -994,8 +1000,8 @@ and getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env ctxPaths |> List.map (fun contextPath -> contextPath - |> getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles - ~pos ~env ~exact:true ~scope) + |> getCompletionsForContextPath ~debug ~full ~opens ~rawOpens + ~allFiles ~pos ~env ~exact:true ~scope) |> List.filter_map (fun completionItems -> match completionItems with | {Completion.kind = Value typ} :: _ -> Some typ @@ -1012,7 +1018,8 @@ and getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env path |> getCompletionsForPath ~completionContext:Value ~exact:true ~package ~opens ~allFiles ~pos ~env ~scope - |> completionsGetTypeEnv2 ~full ~opens ~rawOpens ~allFiles ~pos ~scope + |> completionsGetTypeEnv2 ~debug ~full ~opens ~rawOpens ~allFiles ~pos + ~scope in let lowercaseComponent = match pathToComponent with @@ -1056,10 +1063,10 @@ and getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env let labels, env = match functionContextPath - |> getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos - ~env ~exact:true ~scope - |> completionsGetCompletionType2 ~full ~opens ~rawOpens ~allFiles ~pos - ~scope + |> getCompletionsForContextPath ~debug ~full ~opens ~rawOpens ~allFiles + ~pos ~env ~exact:true ~scope + |> completionsGetCompletionType2 ~debug ~full ~opens ~rawOpens ~allFiles + ~pos ~scope with | Some ((TypeExpr typ | ExtractedType (Tfunction {typ})), env) -> (typ |> TypeUtils.getArgs ~full ~env, env) @@ -1094,10 +1101,10 @@ and getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env | CPatternPath {rootCtxPath; nested} -> ( match rootCtxPath - |> getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env - ~exact:true ~scope - |> completionsGetCompletionType2 ~full ~opens ~rawOpens ~allFiles ~pos - ~scope + |> getCompletionsForContextPath ~debug ~full ~opens ~rawOpens ~allFiles + ~pos ~env ~exact:true ~scope + |> completionsGetCompletionType2 ~debug ~full ~opens ~rawOpens ~allFiles + ~pos ~scope with | Some (typ, env) -> ( match typ |> TypeUtils.resolveNestedPatternPath ~env ~full ~nested with @@ -1407,14 +1414,15 @@ let rec processCompletable ~debug ~full ~scope ~env ~pos ~forHover completable = path |> getCompletionsForPath ~completionContext:Value ~exact:true ~package ~opens ~allFiles ~pos ~env ~scope - |> completionsGetTypeEnv2 ~full ~opens ~rawOpens ~allFiles ~pos ~scope + |> completionsGetTypeEnv2 ~debug ~full ~opens ~rawOpens ~allFiles ~pos + ~scope in match completable with | Cnone -> [] | Cpath contextPath -> contextPath - |> getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env - ~exact:forHover ~scope + |> getCompletionsForContextPath ~debug ~full ~opens ~rawOpens ~allFiles ~pos + ~env ~exact:forHover ~scope | Cjsx ([id], prefix, identsSeen) when String.uncapitalize_ascii id = id -> (* Lowercase JSX tag means builtin *) let mkLabel (name, typString) = @@ -1471,9 +1479,10 @@ let rec processCompletable ~debug ~full ~scope ~env ~pos ~forHover completable = let labels = match cp - |> getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos - ~env ~exact:true ~scope - |> completionsGetTypeEnv2 ~full ~opens ~rawOpens ~allFiles ~pos ~scope + |> getCompletionsForContextPath ~debug ~full ~opens ~rawOpens ~allFiles + ~pos ~env ~exact:true ~scope + |> completionsGetTypeEnv2 ~debug ~full ~opens ~rawOpens ~allFiles ~pos + ~scope with | Some (typ, _env) -> if debug then @@ -1507,9 +1516,10 @@ let rec processCompletable ~debug ~full ~scope ~env ~pos ~forHover completable = in match contextPath - |> getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env - ~exact:true ~scope - |> completionsGetTypeEnv2 ~full ~opens ~rawOpens ~allFiles ~pos ~scope + |> getCompletionsForContextPath ~debug ~full ~opens ~rawOpens ~allFiles + ~pos ~env ~exact:true ~scope + |> completionsGetTypeEnv2 ~debug ~full ~opens ~rawOpens ~allFiles ~pos + ~scope with | Some (typ, env) -> ( match @@ -1540,8 +1550,8 @@ let rec processCompletable ~debug ~full ~scope ~env ~pos ~forHover completable = in match contextPath - |> getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env - ~exact:true ~scope + |> getCompletionsForContextPath ~debug ~full ~opens ~rawOpens ~allFiles + ~pos ~env ~exact:true ~scope |> completionsGetCompletionType ~full with | None -> regularCompletions @@ -1620,8 +1630,8 @@ let rec processCompletable ~debug ~full ~scope ~env ~pos ~forHover completable = in let completionsForContextPath = contextPath - |> getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env - ~exact:forHover ~scope + |> getCompletionsForContextPath ~debug ~full ~opens ~rawOpens ~allFiles + ~pos ~env ~exact:forHover ~scope in completionsForContextPath |> List.map (fun (c : Completion.t) -> diff --git a/analysis/tests/src/expected/BrokenParserCases.res.txt b/analysis/tests/src/expected/BrokenParserCases.res.txt index 0d8fe0ebe..95cc1ee06 100644 --- a/analysis/tests/src/expected/BrokenParserCases.res.txt +++ b/analysis/tests/src/expected/BrokenParserCases.res.txt @@ -2,11 +2,13 @@ Complete src/BrokenParserCases.res 2:24 posCursor:[2:24] posNoWhite:[2:23] Found expr:[2:11->2:30] Pexp_apply ...[2:11->2:17] (~isOff2:19->2:24=...[2:27->2:29]) Completable: CnamedArg(Value[someFn], isOff, [isOff]) +ContextPath Value[someFn] [] Complete src/BrokenParserCases.res 6:17 posCursor:[6:17] posNoWhite:[6:16] Found pattern:[6:16->6:19] Completable: Cpattern Value[s]=t +ContextPath Value[s] [] Complete src/BrokenParserCases.res 10:29 @@ -14,5 +16,6 @@ posCursor:[10:29] posNoWhite:[10:27] Found pattern:[10:24->10:39] posCursor:[10:29] posNoWhite:[10:27] Found pattern:[10:24->10:28] Ppat_construct None:[10:24->10:28] Completable: Cpath Value[None] +ContextPath Value[None] [] diff --git a/analysis/tests/src/expected/CompletePrioritize1.res.txt b/analysis/tests/src/expected/CompletePrioritize1.res.txt index 3f5485410..d3c9f64e3 100644 --- a/analysis/tests/src/expected/CompletePrioritize1.res.txt +++ b/analysis/tests/src/expected/CompletePrioritize1.res.txt @@ -1,6 +1,8 @@ Complete src/CompletePrioritize1.res 5:6 posCursor:[5:6] posNoWhite:[5:5] Found expr:[5:3->0:-1] Completable: Cpath Value[a]-> +ContextPath Value[a]-> +ContextPath Value[a] [{ "label": "Test.add", "kind": 12, diff --git a/analysis/tests/src/expected/CompletePrioritize2.res.txt b/analysis/tests/src/expected/CompletePrioritize2.res.txt index b3b9674e1..22b39c086 100644 --- a/analysis/tests/src/expected/CompletePrioritize2.res.txt +++ b/analysis/tests/src/expected/CompletePrioritize2.res.txt @@ -1,6 +1,8 @@ Complete src/CompletePrioritize2.res 9:7 posCursor:[9:7] posNoWhite:[9:6] Found expr:[9:3->0:-1] Completable: Cpath Value[ax]-> +ContextPath Value[ax]-> +ContextPath Value[ax] [{ "label": "Test.add", "kind": 12, @@ -13,6 +15,7 @@ Complete src/CompletePrioritize2.res 12:5 posCursor:[12:5] posNoWhite:[12:4] Found expr:[12:3->12:5] Pexp_ident ax:[12:3->12:5] Completable: Cpath Value[ax] +ContextPath Value[ax] [{ "label": "ax", "kind": 12, diff --git a/analysis/tests/src/expected/Completion.res.txt b/analysis/tests/src/expected/Completion.res.txt index 2c8a81575..744b9ad22 100644 --- a/analysis/tests/src/expected/Completion.res.txt +++ b/analysis/tests/src/expected/Completion.res.txt @@ -2,6 +2,7 @@ Complete src/Completion.res 1:11 posCursor:[1:11] posNoWhite:[1:10] Found expr:[1:3->1:11] Pexp_ident MyList.m:[1:3->1:11] Completable: Cpath Value[MyList, m] +ContextPath Value[MyList, m] [{ "label": "mapReverse", "kind": 12, @@ -74,6 +75,7 @@ Complete src/Completion.res 3:9 posCursor:[3:9] posNoWhite:[3:8] Found expr:[3:3->3:9] Pexp_ident Array.:[3:3->3:9] Completable: Cpath Value[Array, ""] +ContextPath Value[Array, ""] [{ "label": "fold_left", "kind": 12, @@ -296,6 +298,7 @@ Complete src/Completion.res 5:10 posCursor:[5:10] posNoWhite:[5:9] Found expr:[5:3->5:10] Pexp_ident Array.m:[5:3->5:10] Completable: Cpath Value[Array, m] +ContextPath Value[Array, m] [{ "label": "mapi", "kind": 12, @@ -350,6 +353,7 @@ Complete src/Completion.res 15:17 posCursor:[15:17] posNoWhite:[15:16] Found expr:[15:12->15:17] Pexp_ident Dep.c:[15:12->15:17] Completable: Cpath Value[Dep, c] +ContextPath Value[Dep, c] [{ "label": "customDouble", "kind": 12, @@ -362,6 +366,7 @@ Complete src/Completion.res 23:20 posCursor:[23:20] posNoWhite:[23:19] Found expr:[23:11->23:20] Pexp_apply ...[23:11->23:18] () Completable: CnamedArg(Value[Lib, foo], "", []) +ContextPath Value[Lib, foo] Found type for function (~age: int, ~name: string) => string [{ "label": "age", @@ -380,6 +385,8 @@ Found type for function (~age: int, ~name: string) => string Complete src/Completion.res 26:13 posCursor:[26:13] posNoWhite:[26:12] Found expr:[26:3->26:13] Completable: Cpath array->m +ContextPath array->m +ContextPath array [{ "label": "Js.Array2.mapi", "kind": 12, @@ -397,6 +404,8 @@ Completable: Cpath array->m Complete src/Completion.res 29:13 posCursor:[29:13] posNoWhite:[29:12] Found expr:[29:3->29:13] Completable: Cpath string->toU +ContextPath string->toU +ContextPath string [{ "label": "Js.String2.toUpperCase", "kind": 12, @@ -408,6 +417,8 @@ Completable: Cpath string->toU Complete src/Completion.res 34:8 posCursor:[34:8] posNoWhite:[34:7] Found expr:[34:3->34:8] Completable: Cpath Value[op]->e +ContextPath Value[op]->e +ContextPath Value[op] [{ "label": "Belt.Option.eqU", "kind": 12, @@ -427,6 +438,8 @@ posCursor:[44:7] posNoWhite:[44:6] Found expr:[44:3->54:3] Pexp_apply ...[50:9->50:10] (...[44:3->50:8], ...[51:2->54:3]) posCursor:[44:7] posNoWhite:[44:6] Found expr:[44:3->50:8] Completable: Cpath Value[fa]-> +ContextPath Value[fa]-> +ContextPath Value[fa] [{ "label": "ForAuto.abc", "kind": 12, @@ -446,6 +459,7 @@ posCursor:[47:21] posNoWhite:[47:20] Found expr:[47:3->47:21] posCursor:[47:21] posNoWhite:[47:20] Found expr:[47:12->47:21] Pexp_ident Js.Dict.u:[47:12->47:21] Completable: Cpath Value[Js, Dict, u] +ContextPath Value[Js, Dict, u] [{ "label": "unsafeGet", "kind": 12, @@ -464,6 +478,7 @@ Complete src/Completion.res 59:30 posCursor:[59:30] posNoWhite:[59:29] Found expr:[59:15->59:30] JSX 59:21] second[59:22->59:28]=...[59:29->59:30]> _children:None Completable: Cexpression CJsxPropValue [O, Comp] second=z +ContextPath CJsxPropValue [O, Comp] second [{ "label": "zzz", "kind": 12, @@ -512,6 +527,7 @@ Complete src/Completion.res 71:27 posCursor:[71:27] posNoWhite:[71:26] Found expr:[71:11->71:27] Pexp_apply ...[71:11->71:18] (~name71:20->71:24=...[71:20->71:24]) Completable: CnamedArg(Value[Lib, foo], "", [name]) +ContextPath Value[Lib, foo] Found type for function (~age: int, ~name: string) => string [{ "label": "age", @@ -525,6 +541,7 @@ Complete src/Completion.res 74:26 posCursor:[74:26] posNoWhite:[74:25] Found expr:[74:11->74:26] Pexp_apply ...[74:11->74:18] (~age74:20->74:23=...[74:20->74:23]) Completable: CnamedArg(Value[Lib, foo], "", [age]) +ContextPath Value[Lib, foo] Found type for function (~age: int, ~name: string) => string [{ "label": "name", @@ -538,6 +555,7 @@ Complete src/Completion.res 77:32 posCursor:[77:32] posNoWhite:[77:31] Found expr:[77:11->77:32] Pexp_apply ...[77:11->77:18] (~age77:20->77:23=...[77:25->77:28]) Completable: CnamedArg(Value[Lib, foo], "", [age]) +ContextPath Value[Lib, foo] Found type for function (~age: int, ~name: string) => string [{ "label": "name", @@ -551,6 +569,7 @@ Complete src/Completion.res 82:5 posCursor:[82:5] posNoWhite:[82:4] Found expr:[80:8->86:1] Pexp_apply ...[80:8->80:15] (~age84:3->84:6=...[84:7->84:8], ~name85:3->85:7=...[85:8->85:10]) Completable: CnamedArg(Value[Lib, foo], "", [age, name]) +ContextPath Value[Lib, foo] Found type for function (~age: int, ~name: string) => string [] @@ -558,6 +577,8 @@ Complete src/Completion.res 90:13 posCursor:[90:13] posNoWhite:[90:12] Found expr:[90:3->93:18] Pexp_send a[90:12->90:13] e:[90:3->90:10] Completable: Cpath Value[someObj]["a"] +ContextPath Value[someObj]["a"] +ContextPath Value[someObj] [{ "label": "age", "kind": 4, @@ -570,6 +591,10 @@ Complete src/Completion.res 95:24 posCursor:[95:24] posNoWhite:[95:23] Found expr:[95:3->99:6] Pexp_send [95:24->95:24] e:[95:3->95:22] Completable: Cpath Value[nestedObj]["x"]["y"][""] +ContextPath Value[nestedObj]["x"]["y"][""] +ContextPath Value[nestedObj]["x"]["y"] +ContextPath Value[nestedObj]["x"] +ContextPath Value[nestedObj] [{ "label": "age", "kind": 4, @@ -588,6 +613,8 @@ Complete src/Completion.res 99:7 posCursor:[99:7] posNoWhite:[99:6] Found expr:[99:3->102:20] Pexp_send a[99:6->99:7] e:[99:3->99:4] Completable: Cpath Value[o]["a"] +ContextPath Value[o]["a"] +ContextPath Value[o] [{ "label": "age", "kind": 4, @@ -600,6 +627,10 @@ Complete src/Completion.res 104:17 posCursor:[104:17] posNoWhite:[104:16] Found expr:[104:3->125:18] Pexp_send [104:17->104:17] e:[104:3->104:15] Completable: Cpath Value[no]["x"]["y"][""] +ContextPath Value[no]["x"]["y"][""] +ContextPath Value[no]["x"]["y"] +ContextPath Value[no]["x"] +ContextPath Value[no] [{ "label": "name", "kind": 4, @@ -618,6 +649,8 @@ Complete src/Completion.res 110:5 posCursor:[110:5] posNoWhite:[110:4] Found expr:[110:3->110:5] Pexp_field [110:3->110:4] _:[116:0->110:5] Completable: Cpath Value[r]."" +ContextPath Value[r]."" +ContextPath Value[r] [{ "label": "x", "kind": 5, @@ -636,6 +669,8 @@ Complete src/Completion.res 113:24 posCursor:[113:24] posNoWhite:[113:23] Found expr:[113:3->113:24] Pexp_field [113:3->113:23] _:[116:0->113:24] Completable: Cpath Value[Object, Rec, recordVal]."" +ContextPath Value[Object, Rec, recordVal]."" +ContextPath Value[Object, Rec, recordVal] [{ "label": "xx", "kind": 5, @@ -656,6 +691,7 @@ posCursor:[120:7] posNoWhite:[120:6] Found expr:[120:5->122:5] posCursor:[120:7] posNoWhite:[120:6] Found expr:[120:5->120:7] Pexp_ident my:[120:5->120:7] Completable: Cpath Value[my] +ContextPath Value[my] [{ "label": "myAmazingFunction", "kind": 12, @@ -668,6 +704,8 @@ Complete src/Completion.res 125:18 posCursor:[125:18] posNoWhite:[125:17] Found expr:[125:3->145:32] Pexp_send [125:18->125:18] e:[125:3->125:16] Completable: Cpath Value[Object, object][""] +ContextPath Value[Object, object][""] +ContextPath Value[Object, object] [{ "label": "name", "kind": 4, @@ -686,6 +724,7 @@ Complete src/Completion.res 151:6 posCursor:[151:6] posNoWhite:[151:5] Found expr:[151:4->151:6] JSX 151:6] > _children:None Completable: Cpath Module[O, ""] +ContextPath Module[O, ""] [{ "label": "Comp", "kind": 9, @@ -698,6 +737,9 @@ Complete src/Completion.res 157:8 posCursor:[157:8] posNoWhite:[157:7] Found expr:[157:3->157:8] Pexp_field [157:3->157:7] _:[165:0->157:8] Completable: Cpath Value[q].aa."" +ContextPath Value[q].aa."" +ContextPath Value[q].aa +ContextPath Value[q] [{ "label": "x", "kind": 5, @@ -716,6 +758,9 @@ Complete src/Completion.res 159:9 posCursor:[159:9] posNoWhite:[159:8] Found expr:[159:3->159:9] Pexp_field [159:3->159:7] n:[159:8->159:9] Completable: Cpath Value[q].aa.n +ContextPath Value[q].aa.n +ContextPath Value[q].aa +ContextPath Value[q] [{ "label": "name", "kind": 5, @@ -728,6 +773,7 @@ Complete src/Completion.res 162:6 posCursor:[162:6] posNoWhite:[162:5] Found expr:[162:3->162:6] Pexp_construct Lis:[162:3->162:6] None Completable: Cpath Value[Lis] +ContextPath Value[Lis] [{ "label": "List", "kind": 9, @@ -746,6 +792,7 @@ Complete src/Completion.res 169:16 posCursor:[169:16] posNoWhite:[169:15] Found expr:[169:4->169:16] JSX 169:16] > _children:None Completable: Cpath Module[WithChildren] +ContextPath Module[WithChildren] [{ "label": "WithChildren", "kind": 9, @@ -758,6 +805,7 @@ Complete src/Completion.res 172:16 posCursor:[172:16] posNoWhite:[172:15] Found type:[172:12->172:16] Ptyp_constr Js.n:[172:12->172:16] Completable: Cpath Type[Js, n] +ContextPath Type[Js, n] [{ "label": "null_undefined", "kind": 22, @@ -782,6 +830,7 @@ Complete src/Completion.res 174:20 posCursor:[174:20] posNoWhite:[174:19] Found type:[174:12->174:20] Ptyp_constr ForAuto.:[174:12->174:20] Completable: Cpath Type[ForAuto, ""] +ContextPath Type[ForAuto, ""] [{ "label": "t", "kind": 22, @@ -794,6 +843,7 @@ Complete src/Completion.res 179:13 posCursor:[179:13] posNoWhite:[179:12] Found expr:[179:11->179:13] Pexp_construct As:[179:11->179:13] None Completable: Cpath Value[As] +ContextPath Value[As] [{ "label": "Asterix", "kind": 4, @@ -805,6 +855,7 @@ Completable: Cpath Value[As] Complete src/Completion.res 182:17 Pmod_ident For:[182:14->182:17] Completable: Cpath Module[For] +ContextPath Module[For] [{ "label": "ForAuto", "kind": 9, @@ -817,6 +868,7 @@ Complete src/Completion.res 190:11 posCursor:[190:11] posNoWhite:[190:10] Found expr:[190:3->190:11] Pexp_ident Private.:[190:3->190:11] Completable: Cpath Value[Private, ""] +ContextPath Value[Private, ""] [{ "label": "b", "kind": 12, @@ -829,6 +881,7 @@ Complete src/Completion.res 202:6 posCursor:[202:6] posNoWhite:[202:5] Found expr:[202:3->202:6] Pexp_ident sha:[202:3->202:6] Completable: Cpath Value[sha] +ContextPath Value[sha] [] Complete src/Completion.res 205:6 @@ -837,6 +890,7 @@ Pexp_ident sha:[205:3->205:6] Completable: Cpath Value[sha] Raw opens: 1 Shadow.A.place holder Resolved opens 1 Completion.res +ContextPath Value[sha] [{ "label": "shadowed", "kind": 12, @@ -851,6 +905,7 @@ Pexp_ident sha:[208:3->208:6] Completable: Cpath Value[sha] Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder Resolved opens 2 Completion.res Completion.res +ContextPath Value[sha] [{ "label": "shadowed", "kind": 12, @@ -865,6 +920,8 @@ Pexp_send [221:22->221:22] e:[221:3->221:20] Completable: Cpath Value[FAO, forAutoObject][""] Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder Resolved opens 2 Completion.res Completion.res +ContextPath Value[FAO, forAutoObject][""] +ContextPath Value[FAO, forAutoObject] [{ "label": "age", "kind": 4, @@ -885,6 +942,9 @@ Pexp_field [224:3->224:36] _:[233:0->224:37] Completable: Cpath Value[FAO, forAutoObject]["forAutoLabel"]."" Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder Resolved opens 2 Completion.res Completion.res +ContextPath Value[FAO, forAutoObject]["forAutoLabel"]."" +ContextPath Value[FAO, forAutoObject]["forAutoLabel"] +ContextPath Value[FAO, forAutoObject] [{ "label": "forAuto", "kind": 5, @@ -904,6 +964,10 @@ posCursor:[227:46] posNoWhite:[227:45] Found expr:[227:3->0:-1] Completable: Cpath Value[FAO, forAutoObject]["forAutoLabel"].forAuto-> Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder Resolved opens 2 Completion.res Completion.res +ContextPath Value[FAO, forAutoObject]["forAutoLabel"].forAuto-> +ContextPath Value[FAO, forAutoObject]["forAutoLabel"].forAuto +ContextPath Value[FAO, forAutoObject]["forAutoLabel"] +ContextPath Value[FAO, forAutoObject] [{ "label": "ForAuto.abc", "kind": 12, @@ -925,6 +989,7 @@ Pexp_ident ForAuto.a:[230:46->230:55] Completable: Cpath Value[ForAuto, a] Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder Resolved opens 2 Completion.res Completion.res +ContextPath Value[ForAuto, a] [{ "label": "abc", "kind": 12, @@ -949,6 +1014,7 @@ Pexp_ident na:[234:32->234:34] Completable: Cpath Value[na] Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder Resolved opens 2 Completion.res Completion.res +ContextPath Value[na] [{ "label": "name", "kind": 12, @@ -972,6 +1038,8 @@ Pexp_field [243:5->243:7] _:[245:0->243:8] Completable: Cpath Value[_z]."" Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder Resolved opens 2 Completion.res Completion.res +ContextPath Value[_z]."" +ContextPath Value[_z] [{ "label": "x", "kind": 5, @@ -992,6 +1060,7 @@ Pexp_construct SomeLo:[254:11->254:17] None Completable: Cpath Value[SomeLo] Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder Resolved opens 2 Completion.res Completion.res +ContextPath Value[SomeLo] [{ "label": "SomeLocalModule", "kind": 9, @@ -1006,6 +1075,7 @@ Ptyp_constr SomeLocalModule.:[256:13->256:29] Completable: Cpath Type[SomeLocalModule, ""] Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder Resolved opens 2 Completion.res Completion.res +ContextPath Type[SomeLocalModule, ""] [{ "label": "zz", "kind": 22, @@ -1020,6 +1090,7 @@ Ptyp_constr SomeLocalModule.:[261:17->263:11] Completable: Cpath Type[SomeLocalModule, ""] Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder Resolved opens 2 Completion.res Completion.res +ContextPath Type[SomeLocalModule, ""] [{ "label": "zz", "kind": 22, @@ -1033,6 +1104,7 @@ Ptype_variant unary SomeLocal:[268:12->268:21] Completable: Cpath Value[SomeLocal] Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder Resolved opens 2 Completion.res Completion.res +ContextPath Value[SomeLocal] [{ "label": "SomeLocalVariantItem", "kind": 4, @@ -1054,6 +1126,7 @@ Ptyp_constr SomeLocal:[271:11->274:3] Completable: Cpath Type[SomeLocal] Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder Resolved opens 2 Completion.res Completion.res +ContextPath Type[SomeLocal] [{ "label": "SomeLocalModule", "kind": 9, @@ -1070,6 +1143,7 @@ Pexp_ident _w:[275:13->275:15] Completable: Cpath Value[_w] Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder Resolved opens 2 Completion.res Completion.res +ContextPath Value[_w] [{ "label": "_world", "kind": 12, @@ -1084,6 +1158,7 @@ Ptyp_constr s:[281:21->281:22] Completable: Cpath Type[s] Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder Resolved opens 2 Completion.res Completion.res +ContextPath Type[s] [{ "label": "someType", "kind": 22, @@ -1104,6 +1179,8 @@ Pexp_apply ...[291:11->291:28] () Completable: CnamedArg(Value[funRecord].someFun, "", []) Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder Resolved opens 2 Completion.res Completion.res +ContextPath Value[funRecord].someFun +ContextPath Value[funRecord] Found type for function (~name: string) => unit [{ "label": "name", @@ -1119,6 +1196,9 @@ Pexp_field [296:3->296:10] _:[299:0->296:11] Completable: Cpath Value[retAA](Nolabel)."" Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder Resolved opens 2 Completion.res Completion.res +ContextPath Value[retAA](Nolabel)."" +ContextPath Value[retAA](Nolabel) +ContextPath Value[retAA] [{ "label": "x", "kind": 5, @@ -1139,6 +1219,8 @@ Pexp_apply ...[301:3->301:11] () Completable: CnamedArg(Value[ff](~c), "", []) Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder Resolved opens 2 Completion.res Completion.res +ContextPath Value[ff](~c) +ContextPath Value[ff] Found type for function ( ~opt1: int=?, ~a: int, @@ -1179,6 +1261,9 @@ Pexp_apply ...[304:3->304:13] () Completable: CnamedArg(Value[ff](~c)(Nolabel), "", []) Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder Resolved opens 2 Completion.res Completion.res +ContextPath Value[ff](~c)(Nolabel) +ContextPath Value[ff](~c) +ContextPath Value[ff] Found type for function (~a: int, ~b: int, ~opt2: int=?, unit) => int [{ "label": "a", @@ -1206,6 +1291,8 @@ Pexp_apply ...[307:3->307:15] () Completable: CnamedArg(Value[ff](~c, Nolabel), "", []) Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder Resolved opens 2 Completion.res Completion.res +ContextPath Value[ff](~c, Nolabel) +ContextPath Value[ff] Found type for function (~a: int, ~b: int, ~opt2: int=?, unit) => int [{ "label": "a", @@ -1233,6 +1320,8 @@ Pexp_apply ...[310:3->310:19] () Completable: CnamedArg(Value[ff](~c, Nolabel, Nolabel), "", []) Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder Resolved opens 2 Completion.res Completion.res +ContextPath Value[ff](~c, Nolabel, Nolabel) +ContextPath Value[ff] Found type for function (~a: int, ~b: int) => int [{ "label": "a", @@ -1254,6 +1343,8 @@ Pexp_apply ...[313:3->313:21] () Completable: CnamedArg(Value[ff](~c, Nolabel, ~b), "", []) Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder Resolved opens 2 Completion.res Completion.res +ContextPath Value[ff](~c, Nolabel, ~b) +ContextPath Value[ff] Found type for function (~a: int, ~opt2: int=?, unit) => int [{ "label": "a", @@ -1275,6 +1366,8 @@ Pexp_apply ...[316:3->316:14] () Completable: CnamedArg(Value[ff](~opt2), "", []) Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder Resolved opens 2 Completion.res Completion.res +ContextPath Value[ff](~opt2) +ContextPath Value[ff] Found type for function (~opt1: int=?, ~a: int, ~b: int, unit, unit, ~c: int) => int [{ "label": "opt1", @@ -1308,6 +1401,7 @@ Pexp_apply ...[323:3->323:15] () Completable: CnamedArg(Value[withCallback], "", []) Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder Resolved opens 2 Completion.res Completion.res +ContextPath Value[withCallback] Found type for function (~b: int) => callback [{ "label": "b", @@ -1329,6 +1423,8 @@ Pexp_apply ...[326:3->326:19] () Completable: CnamedArg(Value[withCallback](~a), "", []) Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder Resolved opens 2 Completion.res Completion.res +ContextPath Value[withCallback](~a) +ContextPath Value[withCallback] Found type for function (~b: int) => int [{ "label": "b", @@ -1344,6 +1440,8 @@ Pexp_apply ...[329:3->329:19] () Completable: CnamedArg(Value[withCallback](~b), "", []) Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder Resolved opens 2 Completion.res Completion.res +ContextPath Value[withCallback](~b) +ContextPath Value[withCallback] Found type for function (~a: int) => int [{ "label": "a", @@ -1369,6 +1467,7 @@ Ptyp_constr Res:[336:23->338:5] Completable: Cpath Type[Res] Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder Resolved opens 2 Completion.res Completion.res +ContextPath Type[Res] [{ "label": "RescriptReactErrorBoundary", "kind": 9, @@ -1390,6 +1489,7 @@ Pexp_ident this:[343:53->343:57] Completable: Cpath Value[this] Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder Resolved opens 2 Completion.res Completion.res +ContextPath Value[this] [{ "label": "thisIsNotSaved", "kind": 12, @@ -1416,6 +1516,7 @@ Pexp_ident FAO.forAutoObject:[349:11->349:28] Completable: Cpath Value[FAO, forAutoObject] Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder Resolved opens 2 Completion.res Completion.res +ContextPath Value[FAO, forAutoObject] {"contents": {"kind": "markdown", "value": "```rescript\n{\"age\": int, \"forAutoLabel\": FAR.forAutoRecord}\n```"}} Hover src/Completion.res 352:17 @@ -1425,6 +1526,7 @@ Pexp_apply ...[352:11->352:13] (~opt1352:15->352:19=...[352:20->352:21]) Completable: CnamedArg(Value[ff], opt1, [opt1]) Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder Resolved opens 2 Completion.res Completion.res +ContextPath Value[ff] Found type for function ( ~opt1: int=?, ~a: int, @@ -1449,9 +1551,11 @@ Ppat_construct T:[362:7->362:8] Completable: Cpattern Value[x]=T Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder Resolved opens 2 Completion.res Completion.res +ContextPath Value[x] Completable: Cpath Value[T] Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder Resolved opens 2 Completion.res Completion.res +ContextPath Value[T] [{ "label": "That", "kind": 4, @@ -1486,6 +1590,7 @@ Ppat_construct AndThatOther.T:[373:7->373:21] Completable: Cpath Value[AndThatOther, T] Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder Resolved opens 2 Completion.res Completion.res +ContextPath Value[AndThatOther, T] [{ "label": "ThatOther", "kind": 4, @@ -1504,6 +1609,7 @@ Pexp_ident ForAuto.:[378:16->378:24] Completable: Cpath Value[ForAuto, ""] Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder Resolved opens 2 Completion.res Completion.res +ContextPath Value[ForAuto, ""] [{ "label": "abc", "kind": 12, @@ -1528,6 +1634,8 @@ Pexp_send [381:38->381:38] e:[381:19->381:36] Completable: Cpath Value[FAO, forAutoObject][""] Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder Resolved opens 2 Completion.res Completion.res +ContextPath Value[FAO, forAutoObject][""] +ContextPath Value[FAO, forAutoObject] [{ "label": "age", "kind": 4, @@ -1552,6 +1660,8 @@ Pexp_field [384:14->384:23] _:[384:24->384:24] Completable: Cpath Value[funRecord]."" Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder Resolved opens 2 Completion.res Completion.res +ContextPath Value[funRecord]."" +ContextPath Value[funRecord] [{ "label": "someFun", "kind": 5, @@ -1574,6 +1684,8 @@ posCursor:[389:12] posNoWhite:[389:11] Found expr:[389:6->389:12] Completable: Cpath array->ma Raw opens: 3 Js.place holder ... Shadow.B.place holder ... Shadow.A.place holder Resolved opens 3 Completion.res Completion.res js.ml +ContextPath array->ma +ContextPath array [{ "label": "Array2.mapi", "kind": 12, @@ -1598,6 +1710,7 @@ Pexp_ident red:[397:13->397:16] Completable: Cpath Value[red] Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder Resolved opens 2 Completion.res Completion.res +ContextPath Value[red] [{ "label": "red", "kind": 12, @@ -1616,6 +1729,7 @@ Pexp_ident red:[402:24->402:27] Completable: Cpath Value[red] Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder Resolved opens 2 Completion.res Completion.res +ContextPath Value[red] [{ "label": "red", "kind": 12, @@ -1635,6 +1749,7 @@ Pexp_ident r:[405:21->405:22] Completable: Cpath Value[r] Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder Resolved opens 2 Completion.res Completion.res +ContextPath Value[r] [{ "label": "red", "kind": 12, @@ -1664,6 +1779,7 @@ Pexp_ident SomeLocalModule.:[409:5->411:5] Completable: Cpath Value[SomeLocalModule, ""] Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder Resolved opens 2 Completion.res Completion.res +ContextPath Value[SomeLocalModule, ""] [{ "label": "bb", "kind": 12, @@ -1688,6 +1804,7 @@ Pexp_ident SomeLocalModule.:[412:5->414:8] Completable: Cpath Value[SomeLocalModule, ""] Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder Resolved opens 2 Completion.res Completion.res +ContextPath Value[SomeLocalModule, ""] [{ "label": "bb", "kind": 12, @@ -1707,6 +1824,8 @@ posCursor:[417:17] posNoWhite:[417:16] Found expr:[417:11->417:17] Completable: Cpath int->t Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder Resolved opens 2 Completion.res Completion.res +ContextPath int->t +ContextPath int [{ "label": "Belt.Int.toString", "kind": 12, @@ -1726,6 +1845,8 @@ posCursor:[420:19] posNoWhite:[420:18] Found expr:[420:11->420:19] Completable: Cpath float->t Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder Resolved opens 2 Completion.res Completion.res +ContextPath float->t +ContextPath float [{ "label": "Belt.Float.toInt", "kind": 12, @@ -1745,6 +1866,8 @@ posCursor:[425:8] posNoWhite:[425:7] Found expr:[425:3->425:8] Completable: Cpath Value[ok]->g Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder Resolved opens 2 Completion.res Completion.res +ContextPath Value[ok]->g +ContextPath Value[ok] [{ "label": "Belt.Result.getExn", "kind": 12, @@ -1765,6 +1888,8 @@ Pexp_field [443:3->443:12] so:[443:13->443:15] Completable: Cpath Value[rWithDepr].so Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder Resolved opens 2 Completion.res Completion.res +ContextPath Value[rWithDepr].so +ContextPath Value[rWithDepr] [{ "label": "someInt", "kind": 5, @@ -1784,6 +1909,7 @@ XXX Not found! Completable: Cexpression Type[someVariantWithDeprecated] Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder Resolved opens 2 Completion.res Completion.res +ContextPath Type[someVariantWithDeprecated] [{ "label": "DoNotUseMe", "kind": 4, diff --git a/analysis/tests/src/expected/CompletionExpressions.res.txt b/analysis/tests/src/expected/CompletionExpressions.res.txt index 9b259ecd8..fd3c06a8f 100644 --- a/analysis/tests/src/expected/CompletionExpressions.res.txt +++ b/analysis/tests/src/expected/CompletionExpressions.res.txt @@ -1,6 +1,9 @@ Complete src/CompletionExpressions.res 3:20 XXX Not found! Completable: Cpattern CTuple(Value[s], Value[f]) +ContextPath CTuple(Value[s], Value[f]) +ContextPath Value[s] +ContextPath Value[f] [{ "label": "(_, _)", "kind": 12, @@ -15,6 +18,8 @@ Complete src/CompletionExpressions.res 26:27 posCursor:[26:27] posNoWhite:[26:26] Found expr:[26:11->26:29] Pexp_apply ...[26:11->26:25] (...[26:26->26:28]) Completable: Cexpression CArgument Value[fnTakingRecord]($0)->recordBody +ContextPath CArgument Value[fnTakingRecord]($0) +ContextPath Value[fnTakingRecord] [{ "label": "age", "kind": 5, @@ -57,6 +62,8 @@ Complete src/CompletionExpressions.res 29:28 posCursor:[29:28] posNoWhite:[29:27] Found expr:[29:11->29:30] Pexp_apply ...[29:11->29:25] (...[29:27->29:28]) Completable: Cexpression CArgument Value[fnTakingRecord]($0)=n->recordBody +ContextPath CArgument Value[fnTakingRecord]($0) +ContextPath Value[fnTakingRecord] [{ "label": "nested", "kind": 5, @@ -69,6 +76,8 @@ Complete src/CompletionExpressions.res 32:35 posCursor:[32:35] posNoWhite:[32:34] Found expr:[32:11->32:38] Pexp_apply ...[32:11->32:25] (...[32:26->32:38]) Completable: Cexpression CArgument Value[fnTakingRecord]($0)->recordField(offline) +ContextPath CArgument Value[fnTakingRecord]($0) +ContextPath Value[fnTakingRecord] [{ "label": "true", "kind": 4, @@ -87,6 +96,8 @@ Complete src/CompletionExpressions.res 35:36 posCursor:[35:36] posNoWhite:[35:35] Found expr:[35:11->35:39] Pexp_apply ...[35:11->35:25] (...[35:26->35:38]) Completable: Cexpression CArgument Value[fnTakingRecord]($0)->recordBody +ContextPath CArgument Value[fnTakingRecord]($0) +ContextPath Value[fnTakingRecord] [{ "label": "offline", "kind": 5, @@ -123,6 +134,8 @@ Complete src/CompletionExpressions.res 38:37 posCursor:[38:37] posNoWhite:[38:35] Found expr:[38:11->38:53] Pexp_apply ...[38:11->38:25] (...[38:26->38:52]) Completable: Cexpression CArgument Value[fnTakingRecord]($0)->recordBody +ContextPath CArgument Value[fnTakingRecord]($0) +ContextPath Value[fnTakingRecord] [{ "label": "online", "kind": 5, @@ -153,6 +166,8 @@ Complete src/CompletionExpressions.res 41:44 posCursor:[41:44] posNoWhite:[41:43] Found expr:[41:11->41:47] Pexp_apply ...[41:11->41:25] (...[41:26->41:47]) Completable: Cexpression CArgument Value[fnTakingRecord]($0)->recordField(nested) +ContextPath CArgument Value[fnTakingRecord]($0) +ContextPath Value[fnTakingRecord] [{ "label": "None", "kind": 12, @@ -181,12 +196,16 @@ Complete src/CompletionExpressions.res 44:46 posCursor:[44:46] posNoWhite:[44:45] Found expr:[44:11->44:49] Pexp_apply ...[44:11->44:25] (...[44:26->44:48]) Completable: Cexpression CArgument Value[fnTakingRecord]($0)->recordField(nested), recordBody +ContextPath CArgument Value[fnTakingRecord]($0) +ContextPath Value[fnTakingRecord] [] Complete src/CompletionExpressions.res 47:51 posCursor:[47:51] posNoWhite:[47:50] Found expr:[47:11->47:55] Pexp_apply ...[47:11->47:25] (...[47:26->47:54]) Completable: Cexpression CArgument Value[fnTakingRecord]($0)->recordField(nested), variantPayload::Some($0), recordBody +ContextPath CArgument Value[fnTakingRecord]($0) +ContextPath Value[fnTakingRecord] [{ "label": "someField", "kind": 5, @@ -205,6 +224,8 @@ Complete src/CompletionExpressions.res 50:45 posCursor:[50:45] posNoWhite:[50:44] Found expr:[50:11->50:48] Pexp_apply ...[50:11->50:25] (...[50:26->50:48]) Completable: Cexpression CArgument Value[fnTakingRecord]($0)->recordField(variant) +ContextPath CArgument Value[fnTakingRecord]($0) +ContextPath Value[fnTakingRecord] [{ "label": "One", "kind": 4, @@ -235,6 +256,8 @@ Complete src/CompletionExpressions.res 53:47 posCursor:[53:47] posNoWhite:[53:46] Found expr:[53:11->53:50] Pexp_apply ...[53:11->53:25] (...[53:26->53:49]) Completable: Cexpression CArgument Value[fnTakingRecord]($0)=O->recordField(variant) +ContextPath CArgument Value[fnTakingRecord]($0) +ContextPath Value[fnTakingRecord] [{ "label": "One", "kind": 4, @@ -262,6 +285,8 @@ Complete src/CompletionExpressions.res 56:57 posCursor:[56:57] posNoWhite:[56:56] Found expr:[56:11->56:61] Pexp_apply ...[56:11->56:25] (...[56:26->56:60]) Completable: Cexpression CArgument Value[fnTakingRecord]($0)->recordField(polyvariant), polyvariantPayload::three($0) +ContextPath CArgument Value[fnTakingRecord]($0) +ContextPath Value[fnTakingRecord] [{ "label": "{}", "kind": 12, @@ -277,6 +302,8 @@ Complete src/CompletionExpressions.res 59:60 posCursor:[59:60] posNoWhite:[59:59] Found expr:[59:11->59:65] Pexp_apply ...[59:11->59:25] (...[59:26->59:64]) Completable: Cexpression CArgument Value[fnTakingRecord]($0)->recordField(polyvariant), polyvariantPayload::three($1) +ContextPath CArgument Value[fnTakingRecord]($0) +ContextPath Value[fnTakingRecord] [{ "label": "true", "kind": 4, @@ -295,6 +322,8 @@ Complete src/CompletionExpressions.res 62:62 posCursor:[62:62] posNoWhite:[62:61] Found expr:[62:11->62:66] Pexp_apply ...[62:11->62:25] (...[62:26->62:65]) Completable: Cexpression CArgument Value[fnTakingRecord]($0)=t->recordField(polyvariant), polyvariantPayload::three($1) +ContextPath CArgument Value[fnTakingRecord]($0) +ContextPath Value[fnTakingRecord] [{ "label": "true", "kind": 4, @@ -307,6 +336,8 @@ Complete src/CompletionExpressions.res 69:25 posCursor:[69:25] posNoWhite:[69:24] Found expr:[69:11->69:26] Pexp_apply ...[69:11->69:24] (...[69:25->69:26]) Completable: Cexpression CArgument Value[fnTakingArray]($0) +ContextPath CArgument Value[fnTakingArray]($0) +ContextPath Value[fnTakingArray] [{ "label": "[]", "kind": 12, @@ -322,6 +353,8 @@ Complete src/CompletionExpressions.res 72:26 posCursor:[72:26] posNoWhite:[72:25] Found expr:[72:11->72:28] Pexp_apply ...[72:11->72:24] (...[72:25->72:27]) Completable: Cexpression CArgument Value[fnTakingArray]($0)->array +ContextPath CArgument Value[fnTakingArray]($0) +ContextPath Value[fnTakingArray] [{ "label": "None", "kind": 12, @@ -354,6 +387,8 @@ Complete src/CompletionExpressions.res 75:26 posCursor:[75:26] posNoWhite:[75:25] Found expr:[75:11->75:27] Pexp_apply ...[75:11->75:24] (...[75:25->75:26]) Completable: Cexpression CArgument Value[fnTakingArray]($0)=s +ContextPath CArgument Value[fnTakingArray]($0) +ContextPath Value[fnTakingArray] [{ "label": "s", "kind": 12, @@ -366,6 +401,8 @@ Complete src/CompletionExpressions.res 78:31 posCursor:[78:31] posNoWhite:[78:30] Found expr:[78:11->78:34] Pexp_apply ...[78:11->78:24] (...[78:25->78:33]) Completable: Cexpression CArgument Value[fnTakingArray]($0)->array, variantPayload::Some($0) +ContextPath CArgument Value[fnTakingArray]($0) +ContextPath Value[fnTakingArray] [{ "label": "true", "kind": 4, @@ -384,6 +421,8 @@ Complete src/CompletionExpressions.res 81:31 posCursor:[81:31] posNoWhite:[81:30] Found expr:[81:11->81:34] Pexp_apply ...[81:11->81:24] (...[81:25->81:33]) Completable: Cexpression CArgument Value[fnTakingArray]($0)->array +ContextPath CArgument Value[fnTakingArray]($0) +ContextPath Value[fnTakingArray] [{ "label": "None", "kind": 12, @@ -416,6 +455,8 @@ Complete src/CompletionExpressions.res 84:31 posCursor:[84:31] posNoWhite:[84:30] Found expr:[84:11->84:40] Pexp_apply ...[84:11->84:24] (...[84:25->84:39]) Completable: Cexpression CArgument Value[fnTakingArray]($0)->array +ContextPath CArgument Value[fnTakingArray]($0) +ContextPath Value[fnTakingArray] [{ "label": "None", "kind": 12, @@ -448,6 +489,8 @@ Complete src/CompletionExpressions.res 89:38 posCursor:[89:38] posNoWhite:[89:37] Found expr:[89:11->89:41] Pexp_apply ...[89:11->89:25] (...[89:26->89:40]) Completable: Cexpression CArgument Value[fnTakingRecord]($0)=so +ContextPath CArgument Value[fnTakingRecord]($0) +ContextPath Value[fnTakingRecord] [{ "label": "someBoolVar", "kind": 12, @@ -460,6 +503,8 @@ Complete src/CompletionExpressions.res 96:43 posCursor:[96:43] posNoWhite:[96:42] Found expr:[96:11->96:46] Pexp_apply ...[96:11->96:30] (...[96:31->96:46]) Completable: Cexpression CArgument Value[fnTakingOtherRecord]($0)->recordField(otherField) +ContextPath CArgument Value[fnTakingOtherRecord]($0) +ContextPath Value[fnTakingOtherRecord] [{ "label": "\"\"", "kind": 12, @@ -475,6 +520,8 @@ Complete src/CompletionExpressions.res 108:57 posCursor:[108:57] posNoWhite:[108:56] Found expr:[108:11->108:60] Pexp_apply ...[108:11->108:42] (...[108:43->108:60]) Completable: Cexpression CArgument Value[fnTakingRecordWithOptionalField]($0)->recordField(someOptField) +ContextPath CArgument Value[fnTakingRecordWithOptionalField]($0) +ContextPath Value[fnTakingRecordWithOptionalField] [{ "label": "true", "kind": 4, @@ -493,6 +540,8 @@ Complete src/CompletionExpressions.res 116:53 posCursor:[116:53] posNoWhite:[116:52] Found expr:[116:11->116:56] Pexp_apply ...[116:11->116:39] (...[116:40->116:56]) Completable: Cexpression CArgument Value[fnTakingRecordWithOptVariant]($0)->recordField(someVariant) +ContextPath CArgument Value[fnTakingRecordWithOptVariant]($0) +ContextPath Value[fnTakingRecordWithOptVariant] [{ "label": "None", "kind": 12, @@ -537,6 +586,8 @@ Complete src/CompletionExpressions.res 126:49 posCursor:[126:49] posNoWhite:[126:48] Found expr:[126:11->126:51] Pexp_apply ...[126:11->126:31] (...[126:32->126:50]) Completable: Cexpression CArgument Value[fnTakingInlineRecord]($0)->variantPayload::WithInlineRecord($0) +ContextPath CArgument Value[fnTakingInlineRecord]($0) +ContextPath Value[fnTakingInlineRecord] [{ "label": "{}", "kind": 4, @@ -552,6 +603,8 @@ Complete src/CompletionExpressions.res 129:50 posCursor:[129:50] posNoWhite:[129:49] Found expr:[129:11->129:53] Pexp_apply ...[129:11->129:31] (...[129:32->129:52]) Completable: Cexpression CArgument Value[fnTakingInlineRecord]($0)->variantPayload::WithInlineRecord($0), recordBody +ContextPath CArgument Value[fnTakingInlineRecord]($0) +ContextPath Value[fnTakingInlineRecord] [{ "label": "someBoolField", "kind": 4, @@ -576,6 +629,8 @@ Complete src/CompletionExpressions.res 132:51 posCursor:[132:51] posNoWhite:[132:50] Found expr:[132:11->132:54] Pexp_apply ...[132:11->132:31] (...[132:32->132:53]) Completable: Cexpression CArgument Value[fnTakingInlineRecord]($0)=s->variantPayload::WithInlineRecord($0), recordBody +ContextPath CArgument Value[fnTakingInlineRecord]($0) +ContextPath Value[fnTakingInlineRecord] [{ "label": "someBoolField", "kind": 4, @@ -588,6 +643,8 @@ Complete src/CompletionExpressions.res 135:63 posCursor:[135:63] posNoWhite:[135:62] Found expr:[135:11->135:67] Pexp_apply ...[135:11->135:31] (...[135:32->135:66]) Completable: Cexpression CArgument Value[fnTakingInlineRecord]($0)->variantPayload::WithInlineRecord($0), recordField(nestedRecord) +ContextPath CArgument Value[fnTakingInlineRecord]($0) +ContextPath Value[fnTakingInlineRecord] [{ "label": "{}", "kind": 12, @@ -603,6 +660,8 @@ Complete src/CompletionExpressions.res 138:65 posCursor:[138:65] posNoWhite:[138:64] Found expr:[138:11->138:70] Pexp_apply ...[138:11->138:31] (...[138:32->138:69]) Completable: Cexpression CArgument Value[fnTakingInlineRecord]($0)->variantPayload::WithInlineRecord($0), recordField(nestedRecord), recordBody +ContextPath CArgument Value[fnTakingInlineRecord]($0) +ContextPath Value[fnTakingInlineRecord] [{ "label": "someField", "kind": 5, @@ -621,6 +680,8 @@ Complete src/CompletionExpressions.res 159:20 posCursor:[159:20] posNoWhite:[159:19] Found expr:[159:3->159:21] Pexp_apply ...[159:3->159:19] (...[159:20->159:21]) Completable: Cexpression CArgument Value[fnTakingCallback]($0) +ContextPath CArgument Value[fnTakingCallback]($0) +ContextPath Value[fnTakingCallback] [{ "label": "() => {}", "kind": 12, @@ -636,12 +697,16 @@ Complete src/CompletionExpressions.res 162:21 posCursor:[162:21] posNoWhite:[162:20] Found expr:[162:3->162:22] Pexp_apply ...[162:3->162:19] (...[162:20->162:21]) Completable: Cexpression CArgument Value[fnTakingCallback]($0)=a +ContextPath CArgument Value[fnTakingCallback]($0) +ContextPath Value[fnTakingCallback] [] Complete src/CompletionExpressions.res 165:22 posCursor:[165:22] posNoWhite:[165:21] Found expr:[165:3->165:24] Pexp_apply ...[165:3->165:19] (...[165:20->165:21]) Completable: Cexpression CArgument Value[fnTakingCallback]($1) +ContextPath CArgument Value[fnTakingCallback]($1) +ContextPath Value[fnTakingCallback] [{ "label": "v => {}", "kind": 12, @@ -657,6 +722,8 @@ Complete src/CompletionExpressions.res 168:25 posCursor:[168:25] posNoWhite:[168:24] Found expr:[168:3->168:27] Pexp_apply ...[168:3->168:19] (...[168:20->168:21], ...[168:23->168:24]) Completable: Cexpression CArgument Value[fnTakingCallback]($2) +ContextPath CArgument Value[fnTakingCallback]($2) +ContextPath Value[fnTakingCallback] [{ "label": "event => {}", "kind": 12, @@ -672,6 +739,8 @@ Complete src/CompletionExpressions.res 171:29 posCursor:[171:29] posNoWhite:[171:27] Found expr:[171:3->171:30] Pexp_apply ...[171:3->171:19] (...[171:20->171:21], ...[171:23->171:24], ...[171:26->171:27]) Completable: Cexpression CArgument Value[fnTakingCallback]($3) +ContextPath CArgument Value[fnTakingCallback]($3) +ContextPath Value[fnTakingCallback] [{ "label": "(~on, ~off=?, v1) => {}", "kind": 12, @@ -687,6 +756,8 @@ Complete src/CompletionExpressions.res 174:32 posCursor:[174:32] posNoWhite:[174:30] Found expr:[174:3->174:33] Pexp_apply ...[174:3->174:19] (...[174:20->174:21], ...[174:23->174:24], ...[174:26->174:27], ...[174:29->174:30]) Completable: Cexpression CArgument Value[fnTakingCallback]($4) +ContextPath CArgument Value[fnTakingCallback]($4) +ContextPath Value[fnTakingCallback] [{ "label": "(v1, v2, v3) => {}", "kind": 12, @@ -702,6 +773,8 @@ Complete src/CompletionExpressions.res 177:34 posCursor:[177:34] posNoWhite:[177:33] Found expr:[177:3->177:36] Pexp_apply ...[177:3->177:19] (...[177:20->177:21], ...[177:23->177:24], ...[177:26->177:27], ...[177:29->177:30], ...[177:32->177:33]) Completable: Cexpression CArgument Value[fnTakingCallback]($5) +ContextPath CArgument Value[fnTakingCallback]($5) +ContextPath Value[fnTakingCallback] [{ "label": "(~on=?, ~off=?, ()) => {}", "kind": 12, @@ -721,6 +794,8 @@ posCursor:[185:10] posNoWhite:[185:9] Found expr:[184:2->185:11] posCursor:[185:10] posNoWhite:[185:9] Found expr:[185:2->185:11] Pexp_apply ...[185:2->185:8] (...[185:9->185:10]) Completable: Cexpression CArgument Value[Js, log]($0)=s +ContextPath CArgument Value[Js, log]($0) +ContextPath Value[Js, log] [{ "label": "second2", "kind": 12, diff --git a/analysis/tests/src/expected/CompletionFunctionArguments.res.txt b/analysis/tests/src/expected/CompletionFunctionArguments.res.txt index ce5de8aac..0a54e35f7 100644 --- a/analysis/tests/src/expected/CompletionFunctionArguments.res.txt +++ b/analysis/tests/src/expected/CompletionFunctionArguments.res.txt @@ -2,6 +2,8 @@ Complete src/CompletionFunctionArguments.res 10:24 posCursor:[10:24] posNoWhite:[10:23] Found expr:[10:11->10:25] Pexp_apply ...[10:11->10:17] (~isOn10:19->10:23=...__ghost__[0:-1->0:-1]) Completable: Cexpression CArgument Value[someFn](~isOn) +ContextPath CArgument Value[someFn](~isOn) +ContextPath Value[someFn] [{ "label": "true", "kind": 4, @@ -20,6 +22,8 @@ Complete src/CompletionFunctionArguments.res 13:25 posCursor:[13:25] posNoWhite:[13:24] Found expr:[13:11->13:26] Pexp_apply ...[13:11->13:17] (~isOn13:19->13:23=...[13:24->13:25]) Completable: Cexpression CArgument Value[someFn](~isOn)=t +ContextPath CArgument Value[someFn](~isOn) +ContextPath Value[someFn] [{ "label": "true", "kind": 4, @@ -39,6 +43,8 @@ Complete src/CompletionFunctionArguments.res 16:25 posCursor:[16:25] posNoWhite:[16:24] Found expr:[16:11->16:26] Pexp_apply ...[16:11->16:17] (~isOff16:19->16:24=...__ghost__[0:-1->0:-1]) Completable: Cexpression CArgument Value[someFn](~isOff) +ContextPath CArgument Value[someFn](~isOff) +ContextPath Value[someFn] [{ "label": "true", "kind": 4, @@ -61,6 +67,8 @@ posCursor:[21:27] posNoWhite:[21:26] Found expr:[21:7->21:28] posCursor:[21:27] posNoWhite:[21:26] Found expr:[21:14->21:28] Pexp_apply ...[21:14->21:20] (~isOn21:22->21:26=...__ghost__[0:-1->0:-1]) Completable: Cexpression CArgument Value[someFn](~isOn) +ContextPath CArgument Value[someFn](~isOn) +ContextPath Value[someFn] [{ "label": "true", "kind": 4, @@ -79,6 +87,8 @@ Complete src/CompletionFunctionArguments.res 34:24 posCursor:[34:24] posNoWhite:[34:23] Found expr:[34:11->34:25] Pexp_apply ...[34:11->34:22] (...[34:23->34:24]) Completable: Cexpression CArgument Value[someOtherFn]($0)=f +ContextPath CArgument Value[someOtherFn]($0) +ContextPath Value[someOtherFn] [{ "label": "false", "kind": 4, @@ -91,6 +101,8 @@ Complete src/CompletionFunctionArguments.res 51:39 posCursor:[51:39] posNoWhite:[51:38] Found expr:[51:11->51:40] Pexp_apply ...[51:11->51:30] (~config51:32->51:38=...__ghost__[0:-1->0:-1]) Completable: Cexpression CArgument Value[someFnTakingVariant](~config) +ContextPath CArgument Value[someFnTakingVariant](~config) +ContextPath Value[someFnTakingVariant] [{ "label": "One", "kind": 4, @@ -121,6 +133,8 @@ Complete src/CompletionFunctionArguments.res 54:40 posCursor:[54:40] posNoWhite:[54:39] Found expr:[54:11->54:41] Pexp_apply ...[54:11->54:30] (~config54:32->54:38=...[54:39->54:40]) Completable: Cexpression CArgument Value[someFnTakingVariant](~config)=O +ContextPath CArgument Value[someFnTakingVariant](~config) +ContextPath Value[someFnTakingVariant] [{ "label": "One", "kind": 4, @@ -154,6 +168,8 @@ Complete src/CompletionFunctionArguments.res 57:33 posCursor:[57:33] posNoWhite:[57:32] Found expr:[57:11->57:34] Pexp_apply ...[57:11->57:30] (...[57:31->57:33]) Completable: Cexpression CArgument Value[someFnTakingVariant]($0)=So +ContextPath CArgument Value[someFnTakingVariant]($0) +ContextPath Value[someFnTakingVariant] [{ "label": "Some(_)", "kind": 12, @@ -175,6 +191,8 @@ Complete src/CompletionFunctionArguments.res 60:44 posCursor:[60:44] posNoWhite:[60:43] Found expr:[60:11->60:45] Pexp_apply ...[60:11->60:30] (~configOpt260:32->60:42=...[60:43->60:44]) Completable: Cexpression CArgument Value[someFnTakingVariant](~configOpt2)=O +ContextPath CArgument Value[someFnTakingVariant](~configOpt2) +ContextPath Value[someFnTakingVariant] [{ "label": "One", "kind": 4, @@ -208,6 +226,8 @@ Complete src/CompletionFunctionArguments.res 63:23 posCursor:[63:23] posNoWhite:[63:22] Found expr:[63:11->63:24] Pexp_apply ...[63:11->63:22] (...[63:23->63:24]) Completable: Cexpression CArgument Value[someOtherFn]($0) +ContextPath CArgument Value[someOtherFn]($0) +ContextPath Value[someOtherFn] [{ "label": "true", "kind": 4, @@ -226,6 +246,8 @@ Complete src/CompletionFunctionArguments.res 66:28 posCursor:[66:28] posNoWhite:[66:27] Found expr:[66:11->66:30] Pexp_apply ...[66:11->66:22] (...[66:23->66:24], ...[66:26->66:27]) Completable: Cexpression CArgument Value[someOtherFn]($2) +ContextPath CArgument Value[someOtherFn]($2) +ContextPath Value[someOtherFn] [{ "label": "true", "kind": 4, @@ -243,6 +265,8 @@ Completable: Cexpression CArgument Value[someOtherFn]($2) Complete src/CompletionFunctionArguments.res 69:30 posCursor:[69:30] posNoWhite:[69:29] Found expr:[69:11->69:31] Completable: Cexpression CArgument Value[someOtherFn]($2)=t +ContextPath CArgument Value[someOtherFn]($2) +ContextPath Value[someOtherFn] [{ "label": "true", "kind": 4, @@ -262,6 +286,8 @@ Complete src/CompletionFunctionArguments.res 76:25 posCursor:[76:25] posNoWhite:[76:24] Found expr:[76:11->76:26] Pexp_apply ...[76:11->76:24] (...[76:25->76:26]) Completable: Cexpression CArgument Value[fnTakingTuple]($0) +ContextPath CArgument Value[fnTakingTuple]($0) +ContextPath Value[fnTakingTuple] [{ "label": "(_, _, _)", "kind": 12, @@ -276,6 +302,8 @@ Complete src/CompletionFunctionArguments.res 89:27 posCursor:[89:27] posNoWhite:[89:26] Found expr:[89:11->89:29] Pexp_apply ...[89:11->89:25] (...[89:26->89:28]) Completable: Cexpression CArgument Value[fnTakingRecord]($0)->recordBody +ContextPath CArgument Value[fnTakingRecord]($0) +ContextPath Value[fnTakingRecord] [{ "label": "age", "kind": 5, @@ -304,6 +332,8 @@ posCursor:[109:29] posNoWhite:[109:28] Found expr:[107:6->109:29] posCursor:[109:29] posNoWhite:[109:28] Found expr:[108:6->109:29] posCursor:[109:29] posNoWhite:[109:28] Found expr:[109:9->109:29] Completable: Cpath Value[thisGetsBrokenLoc]->a <> +ContextPath Value[thisGetsBrokenLoc]->a <> +ContextPath Value[thisGetsBrokenLoc] [{ "label": "ReactEvent.Mouse.altKey", "kind": 12, @@ -320,6 +350,8 @@ posCursor:[111:27] posNoWhite:[111:26] Found expr:[107:6->111:27] posCursor:[111:27] posNoWhite:[111:26] Found expr:[108:6->111:27] posCursor:[111:27] posNoWhite:[111:26] Found expr:[111:9->111:27] Completable: Cpath Value[reassignedWorks]->a <> +ContextPath Value[reassignedWorks]->a <> +ContextPath Value[reassignedWorks] [{ "label": "ReactEvent.Mouse.altKey", "kind": 12, diff --git a/analysis/tests/src/expected/CompletionInferValues.res.txt b/analysis/tests/src/expected/CompletionInferValues.res.txt index 957370f75..4b6df198c 100644 --- a/analysis/tests/src/expected/CompletionInferValues.res.txt +++ b/analysis/tests/src/expected/CompletionInferValues.res.txt @@ -1,6 +1,10 @@ Complete src/CompletionInferValues.res 15:43 posCursor:[15:43] posNoWhite:[15:42] Found expr:[15:33->15:43] Completable: Cpath Value[aliased]->f +ContextPath Value[aliased]->f +ContextPath Value[aliased] +ContextPath Value[x] +ContextPath int [{ "label": "Belt.Int.fromString", "kind": 12, @@ -19,6 +23,10 @@ Complete src/CompletionInferValues.res 18:30 posCursor:[18:30] posNoWhite:[18:29] Found expr:[18:28->18:30] Pexp_field [18:28->18:29] _:[33:0->18:30] Completable: Cpath Value[x]."" +ContextPath Value[x]."" +ContextPath Value[x] +ContextPath Value[getSomeRecord](Nolabel) +ContextPath Value[getSomeRecord] [{ "label": "name", "kind": 5, @@ -37,6 +45,11 @@ Complete src/CompletionInferValues.res 21:53 posCursor:[21:53] posNoWhite:[21:52] Found expr:[21:45->21:53] Pexp_field [21:45->21:52] _:[33:0->21:53] Completable: Cpath Value[aliased]."" +ContextPath Value[aliased]."" +ContextPath Value[aliased] +ContextPath Value[x] +ContextPath Value[getSomeRecord](Nolabel) +ContextPath Value[getSomeRecord] [{ "label": "name", "kind": 5, @@ -60,6 +73,11 @@ posCursor:[24:63] posNoWhite:[24:62] Found expr:[24:42->24:63] posCursor:[24:63] posNoWhite:[24:62] Found expr:[24:52->24:63] Pexp_field [24:52->24:62] _:[24:63->24:63] Completable: Cpath Value[someRecord]."" +ContextPath Value[someRecord]."" +ContextPath Value[someRecord] +ContextPath CArgument CArgument Value[someFnWithCallback]($0)(~someRecord) +ContextPath CArgument Value[someFnWithCallback]($0) +ContextPath Value[someFnWithCallback] [{ "label": "name", "kind": 5, @@ -83,6 +101,12 @@ posCursor:[27:90] posNoWhite:[27:89] Found expr:[27:69->27:90] posCursor:[27:90] posNoWhite:[27:89] Found expr:[27:79->27:90] Pexp_field [27:79->27:89] _:[27:90->27:90] Completable: Cpath Value[someRecord]."" +ContextPath Value[someRecord]."" +ContextPath Value[someRecord] +ContextPath CArgument CArgument Value[aliasedFn]($0)(~someRecord) +ContextPath CArgument Value[aliasedFn]($0) +ContextPath Value[aliasedFn] +ContextPath Value[someFnWithCallback] [{ "label": "name", "kind": 5, @@ -103,6 +127,11 @@ Pexp_apply ...[30:3->30:15] (...[30:16->30:38]) posCursor:[30:36] posNoWhite:[30:35] Found expr:[30:16->30:38] posCursor:[30:36] posNoWhite:[30:35] Found expr:[30:27->30:36] Completable: Cpath Value[event]->pr +ContextPath Value[event]->pr +ContextPath Value[event] +ContextPath CArgument CArgument Value[reactEventFn]($0)($0) +ContextPath CArgument Value[reactEventFn]($0) +ContextPath Value[reactEventFn] [{ "label": "ReactEvent.Mouse.preventDefault", "kind": 12, @@ -117,6 +146,10 @@ JSX 41:15] onMouseEnter[41:16->41:28]=...[41:36->41:52]> _children: posCursor:[41:50] posNoWhite:[41:49] Found expr:[41:36->41:52] posCursor:[41:50] posNoWhite:[41:49] Found expr:[41:41->41:50] Completable: Cpath Value[event]->pr <> +ContextPath Value[event]->pr <> +ContextPath Value[event] +ContextPath CArgument CJsxPropValue [div] onMouseEnter($0) +ContextPath CJsxPropValue [div] onMouseEnter [{ "label": "JsxEvent.Mouse.preventDefault", "kind": 12, @@ -131,6 +164,10 @@ JSX 44:15] onMouseEnter[44:16->44:28]=...[44:36->44:52]> _children: posCursor:[44:50] posNoWhite:[44:49] Found expr:[44:36->44:52] posCursor:[44:50] posNoWhite:[44:49] Found expr:[44:41->44:50] Completable: Cpath Value[event]->pr <> +ContextPath Value[event]->pr <> +ContextPath Value[event] +ContextPath CArgument CJsxPropValue [Div] onMouseEnter($0) +ContextPath CJsxPropValue [Div] onMouseEnter [{ "label": "JsxEvent.Mouse.preventDefault", "kind": 12, @@ -146,6 +183,10 @@ posCursor:[47:87] posNoWhite:[47:86] Found expr:[47:36->47:89] posCursor:[47:87] posNoWhite:[47:86] Found expr:[47:41->47:87] posCursor:[47:87] posNoWhite:[47:86] Found expr:[47:81->47:87] Completable: Cpath Value[btn]->t <> +ContextPath Value[btn]->t <> +ContextPath Value[btn] +ContextPath Value[JsxEvent, Mouse, button](Nolabel) +ContextPath Value[JsxEvent, Mouse, button] [{ "label": "Belt.Int.toString", "kind": 12, @@ -167,6 +208,10 @@ posCursor:[50:108] posNoWhite:[50:107] Found expr:[50:36->50:110] posCursor:[50:108] posNoWhite:[50:107] Found expr:[50:41->50:108] posCursor:[50:108] posNoWhite:[50:107] Found expr:[50:100->50:108] Completable: Cpath Value[btn]->spl <> +ContextPath Value[btn]->spl <> +ContextPath Value[btn] +ContextPath Value[Belt, Int, toString](Nolabel) +ContextPath Value[Belt, Int, toString] [{ "label": "Js.String2.splitAtMost", "kind": 12, @@ -200,6 +245,10 @@ posCursor:[53:130] posNoWhite:[53:129] Found expr:[53:36->53:132] posCursor:[53:130] posNoWhite:[53:129] Found expr:[53:41->53:130] posCursor:[53:130] posNoWhite:[53:129] Found expr:[53:123->53:130] Completable: Cpath Value[btn]->ma <> +ContextPath Value[btn]->ma <> +ContextPath Value[btn] +ContextPath Value[Js, String2, split](Nolabel, Nolabel) +ContextPath Value[Js, String2, split] [{ "label": "Js.Array2.mapi", "kind": 12, @@ -218,6 +267,9 @@ Complete src/CompletionInferValues.res 56:52 posCursor:[56:52] posNoWhite:[56:51] Found expr:[56:50->56:52] Pexp_field [56:50->56:51] _:[59:0->56:52] Completable: Cpath Value[x]."" +ContextPath Value[x]."" +ContextPath Value[x] +ContextPath Type[someRecord] [{ "label": "name", "kind": 5, @@ -236,6 +288,11 @@ Complete src/CompletionInferValues.res 78:78 posCursor:[78:78] posNoWhite:[78:77] Found expr:[78:70->78:78] Pexp_field [78:70->78:77] _:[125:0->78:78] Completable: Cpath Value[srecord]."" +ContextPath Value[srecord]."" +ContextPath Value[srecord] +ContextPath CPatternPath(Value[x])->recordField(srecord) +ContextPath Value[x] +ContextPath Type[someRecordWithNestedStuff] [{ "label": "name", "kind": 5, @@ -254,6 +311,11 @@ Complete src/CompletionInferValues.res 82:86 posCursor:[82:86] posNoWhite:[82:85] Found expr:[82:78->82:86] Pexp_field [82:78->82:85] _:[125:0->82:86] Completable: Cpath Value[aliased]."" +ContextPath Value[aliased]."" +ContextPath Value[aliased] +ContextPath CPatternPath(Value[x])->recordField(nested) +ContextPath Value[x] +ContextPath Type[someRecordWithNestedStuff] [{ "label": "someRecord", "kind": 5, @@ -266,6 +328,11 @@ Complete src/CompletionInferValues.res 86:103 posCursor:[86:103] posNoWhite:[86:102] Found expr:[86:92->86:103] Pexp_field [86:92->86:102] _:[125:0->86:103] Completable: Cpath Value[someRecord]."" +ContextPath Value[someRecord]."" +ContextPath Value[someRecord] +ContextPath CPatternPath(Value[x])->recordField(nested)->recordField(someRecord) +ContextPath Value[x] +ContextPath Type[someRecordWithNestedStuff] [{ "label": "name", "kind": 5, @@ -283,6 +350,11 @@ Completable: Cpath Value[someRecord]."" Complete src/CompletionInferValues.res 90:81 posCursor:[90:81] posNoWhite:[90:80] Found expr:[90:69->90:81] Completable: Cpath Value[things]->slic +ContextPath Value[things]->slic +ContextPath Value[things] +ContextPath CPatternPath(Value[x])->recordField(things) +ContextPath Value[x] +ContextPath Type[someRecordWithNestedStuff] [{ "label": "Js.String2.sliceToEnd", "kind": 12, @@ -300,6 +372,11 @@ Completable: Cpath Value[things]->slic Complete src/CompletionInferValues.res 94:82 posCursor:[94:82] posNoWhite:[94:81] Found expr:[94:70->94:82] Completable: Cpath Value[someInt]->toS +ContextPath Value[someInt]->toS +ContextPath Value[someInt] +ContextPath CPatternPath(Value[x])->recordField(someInt) +ContextPath Value[x] +ContextPath Type[someRecordWithNestedStuff] [{ "label": "Belt.Int.toString", "kind": 12, @@ -311,6 +388,13 @@ Completable: Cpath Value[someInt]->toS Complete src/CompletionInferValues.res 98:109 posCursor:[98:109] posNoWhite:[98:108] Found expr:[98:97->98:109] Completable: Cpath Value[someInt]->toS +ContextPath Value[someInt]->toS +ContextPath Value[someInt] +ContextPath CPatternPath(Value[someTuple])->tuple($1) +ContextPath Value[someTuple] +ContextPath CPatternPath(Value[x])->recordField(someTuple) +ContextPath Value[x] +ContextPath Type[otherNestedRecord] [{ "label": "Belt.Int.toString", "kind": 12, @@ -323,6 +407,13 @@ Complete src/CompletionInferValues.res 102:102 posCursor:[102:102] posNoWhite:[102:101] Found expr:[102:57->102:102] posCursor:[102:102] posNoWhite:[102:101] Found expr:[102:90->102:102] Completable: Cpath Value[someInt]->toS +ContextPath Value[someInt]->toS +ContextPath Value[someInt] +ContextPath CPatternPath(Value[someTuple])->tuple($1) +ContextPath Value[someTuple] +ContextPath CPatternPath(Value[x])->recordField(someTuple) +ContextPath Value[x] +ContextPath Type[otherNestedRecord] [{ "label": "Belt.Int.toString", "kind": 12, @@ -334,6 +425,11 @@ Completable: Cpath Value[someInt]->toS Complete src/CompletionInferValues.res 106:88 posCursor:[106:88] posNoWhite:[106:87] Found expr:[106:79->106:88] Completable: Cpath Value[str]->slic +ContextPath Value[str]->slic +ContextPath Value[str] +ContextPath CPatternPath(Value[x])->recordField(someTuple)->tuple($0)->variantPayload::Three($1) +ContextPath Value[x] +ContextPath Type[otherNestedRecord] [{ "label": "Js.String2.sliceToEnd", "kind": 12, @@ -351,6 +447,11 @@ Completable: Cpath Value[str]->slic Complete src/CompletionInferValues.res 110:89 posCursor:[110:89] posNoWhite:[110:88] Found expr:[110:80->110:89] Completable: Cpath Value[str]->slic +ContextPath Value[str]->slic +ContextPath Value[str] +ContextPath CPatternPath(Value[x])->recordField(someTuple)->tuple($2)->polyvariantPayload::three($1) +ContextPath Value[x] +ContextPath Type[otherNestedRecord] [{ "label": "Js.String2.sliceToEnd", "kind": 12, @@ -368,6 +469,11 @@ Completable: Cpath Value[str]->slic Complete src/CompletionInferValues.res 114:80 posCursor:[114:80] posNoWhite:[114:79] Found expr:[114:70->114:80] Completable: Cpath Value[name]->slic +ContextPath Value[name]->slic +ContextPath Value[name] +ContextPath CPatternPath(Value[x])->recordField(optRecord)->variantPayload::Some($0)->recordField(name) +ContextPath Value[x] +ContextPath Type[otherNestedRecord] [{ "label": "Js.String2.sliceToEnd", "kind": 12, @@ -386,6 +492,12 @@ Complete src/CompletionInferValues.res 118:67 posCursor:[118:67] posNoWhite:[118:66] Found expr:[118:60->118:67] Pexp_field [118:60->118:65] s:[118:66->118:67] Completable: Cpath Value[inner].s +ContextPath Value[inner].s +ContextPath Value[inner] +ContextPath CPatternPath(Value[x])->array +ContextPath Value[x] +ContextPath array +ContextPath Type[otherNestedRecord] [{ "label": "someRecord", "kind": 5, @@ -403,6 +515,10 @@ Completable: Cpath Value[inner].s Complete src/CompletionInferValues.res 122:53 posCursor:[122:53] posNoWhite:[122:52] Found expr:[122:46->122:53] Completable: Cpath Value[v]->toSt +ContextPath Value[v]->toSt +ContextPath Value[v] +ContextPath Value[x] +ContextPath int [{ "label": "Belt.Int.toString", "kind": 12, @@ -418,6 +534,9 @@ posCursor:[130:26] posNoWhite:[130:25] Found expr:[130:24->130:36] posCursor:[130:26] posNoWhite:[130:25] Found pattern:[130:25->130:27] posCursor:[130:26] posNoWhite:[130:25] Found pattern:[130:25->130:27] Completable: Cpattern CArgument CArgument Value[fnWithRecordCallback]($0)($0)->recordBody +ContextPath CArgument CArgument Value[fnWithRecordCallback]($0)($0) +ContextPath CArgument Value[fnWithRecordCallback]($0) +ContextPath Value[fnWithRecordCallback] [{ "label": "name", "kind": 5, @@ -439,6 +558,12 @@ posCursor:[137:30] posNoWhite:[137:29] Found expr:[137:11->137:32] posCursor:[137:30] posNoWhite:[137:29] Found expr:[137:24->0:-1] posCursor:[137:30] posNoWhite:[137:29] Found expr:[137:24->0:-1] Completable: Cpath Value[root]-> +ContextPath Value[root]-> +ContextPath Value[root] +ContextPath CPatternPath(CArgument CArgument Value[fn2](~cb)($0))->recordField(root) +ContextPath CArgument CArgument Value[fn2](~cb)($0) +ContextPath CArgument Value[fn2](~cb) +ContextPath Value[fn2] [{ "label": "ReactDOM.Client.Root.unmount", "kind": 12, @@ -460,6 +585,12 @@ posCursor:[146:30] posNoWhite:[146:29] Found expr:[146:11->146:32] posCursor:[146:30] posNoWhite:[146:29] Found expr:[146:24->0:-1] posCursor:[146:30] posNoWhite:[146:29] Found expr:[146:24->0:-1] Completable: Cpath Value[root]-> +ContextPath Value[root]-> +ContextPath Value[root] +ContextPath CPatternPath(CArgument CArgument Value[fn3](~cb)($0))->recordField(root) +ContextPath CArgument CArgument Value[fn3](~cb)($0) +ContextPath CArgument Value[fn3](~cb) +ContextPath Value[fn3] [{ "label": "CompletionSupport.Test.add", "kind": 12, @@ -483,6 +614,8 @@ Completable: Cpath Value[root]-> Complete src/CompletionInferValues.res 150:47 XXX Not found! Completable: Cpattern Value[Belt, Int, toString](Nolabel) +ContextPath Value[Belt, Int, toString](Nolabel) +ContextPath Value[Belt, Int, toString] [{ "label": "\"\"", "kind": 12, @@ -497,6 +630,8 @@ Completable: Cpattern Value[Belt, Int, toString](Nolabel) Complete src/CompletionInferValues.res 154:70 XXX Not found! Completable: Cpattern Value[Js, String2, split](Nolabel, Nolabel) +ContextPath Value[Js, String2, split](Nolabel, Nolabel) +ContextPath Value[Js, String2, split] [{ "label": "[]", "kind": 12, @@ -515,6 +650,12 @@ posCursor:[158:105] posNoWhite:[158:104] Found expr:[158:81->158:106] posCursor:[158:105] posNoWhite:[158:104] Found expr:[158:97->158:105] Pexp_field [158:97->158:104] _:[158:105->158:105] Completable: Cpath Value[support]."" +ContextPath Value[support]."" +ContextPath Value[support] +ContextPath CPatternPath(CArgument CArgument Value[CompletionSupport2, makeRenderer](~render)($0))->recordField(support) +ContextPath CArgument CArgument Value[CompletionSupport2, makeRenderer](~render)($0) +ContextPath CArgument Value[CompletionSupport2, makeRenderer](~render) +ContextPath Value[CompletionSupport2, makeRenderer] [{ "label": "root", "kind": 5, @@ -530,5 +671,11 @@ posCursor:[162:110] posNoWhite:[162:109] Found expr:[162:81->162:111] posCursor:[162:110] posNoWhite:[162:109] Found expr:[162:104->0:-1] posCursor:[162:110] posNoWhite:[162:109] Found expr:[162:104->0:-1] Completable: Cpath Value[root]-> +ContextPath Value[root]-> +ContextPath Value[root] +ContextPath CPatternPath(CArgument CArgument Value[CompletionSupport2, makeRenderer](~render)($0))->recordField(support)->recordField(root) +ContextPath CArgument CArgument Value[CompletionSupport2, makeRenderer](~render)($0) +ContextPath CArgument Value[CompletionSupport2, makeRenderer](~render) +ContextPath Value[CompletionSupport2, makeRenderer] [] diff --git a/analysis/tests/src/expected/CompletionJsx.res.txt b/analysis/tests/src/expected/CompletionJsx.res.txt index aae7edac3..dd10a1a2b 100644 --- a/analysis/tests/src/expected/CompletionJsx.res.txt +++ b/analysis/tests/src/expected/CompletionJsx.res.txt @@ -1,6 +1,8 @@ Complete src/CompletionJsx.res 3:17 posCursor:[3:17] posNoWhite:[3:16] Found expr:[3:3->3:17] Completable: Cpath Value[someString]->st +ContextPath Value[someString]->st +ContextPath Value[someString] [{ "label": "Js.String2.startsWith", "kind": 12, @@ -24,6 +26,8 @@ posCursor:[13:21] posNoWhite:[13:20] Found expr:[12:4->32:10] posCursor:[13:21] posNoWhite:[13:20] Found expr:[13:7->32:10] posCursor:[13:21] posNoWhite:[13:20] Found expr:[13:7->13:21] Completable: Cpath Value[someString]->st <> +ContextPath Value[someString]->st <> +ContextPath Value[someString] [{ "label": "React.string", "kind": 12, @@ -65,6 +69,8 @@ Pexp_construct :::[18:10->32:4] [18:10->32:4] posCursor:[18:24] posNoWhite:[18:23] Found expr:[18:10->32:4] posCursor:[18:24] posNoWhite:[18:23] Found expr:[18:10->18:24] Completable: Cpath Value[someString]->st <> +ContextPath Value[someString]->st <> +ContextPath Value[someString] [{ "label": "React.string", "kind": 12, @@ -106,6 +112,8 @@ Pexp_construct :::[20:10->32:4] [20:10->32:4] posCursor:[20:27] posNoWhite:[20:26] Found expr:[20:10->32:4] posCursor:[20:27] posNoWhite:[20:26] Found expr:[20:10->20:27] Completable: Cpath string->st <> +ContextPath string->st <> +ContextPath string [{ "label": "React.string", "kind": 12, @@ -147,6 +155,9 @@ Pexp_construct :::[22:10->32:4] [22:10->32:4] posCursor:[22:44] posNoWhite:[22:43] Found expr:[22:10->32:4] posCursor:[22:44] posNoWhite:[22:43] Found expr:[22:10->22:44] Completable: Cpath Value[Js, String2, trim](Nolabel)->st <> +ContextPath Value[Js, String2, trim](Nolabel)->st <> +ContextPath Value[Js, String2, trim](Nolabel) +ContextPath Value[Js, String2, trim] [{ "label": "React.string", "kind": 12, @@ -188,6 +199,8 @@ Pexp_construct :::[24:10->32:4] [24:10->32:4] posCursor:[24:19] posNoWhite:[24:18] Found expr:[24:10->32:4] posCursor:[24:19] posNoWhite:[24:18] Found expr:[24:10->0:-1] Completable: Cpath Value[someInt]-> <> +ContextPath Value[someInt]-> <> +ContextPath Value[someInt] [{ "label": "React.int", "kind": 12, @@ -265,6 +278,8 @@ Pexp_construct :::[26:10->32:4] [26:10->32:4] posCursor:[26:14] posNoWhite:[26:13] Found expr:[26:10->32:4] posCursor:[26:14] posNoWhite:[26:13] Found expr:[26:10->0:-1] Completable: Cpath int-> <> +ContextPath int-> <> +ContextPath int [{ "label": "React.int", "kind": 12, @@ -342,6 +357,8 @@ Pexp_construct :::[28:10->32:4] [28:10->32:4] posCursor:[28:20] posNoWhite:[28:19] Found expr:[28:10->32:4] posCursor:[28:20] posNoWhite:[28:19] Found expr:[28:10->28:20] Completable: Cpath Value[someArr]->a <> +ContextPath Value[someArr]->a <> +ContextPath Value[someArr] [{ "label": "React.array", "kind": 12, diff --git a/analysis/tests/src/expected/CompletionJsxProps.res.txt b/analysis/tests/src/expected/CompletionJsxProps.res.txt index 398011f2f..e1366954b 100644 --- a/analysis/tests/src/expected/CompletionJsxProps.res.txt +++ b/analysis/tests/src/expected/CompletionJsxProps.res.txt @@ -2,6 +2,7 @@ Complete src/CompletionJsxProps.res 0:47 posCursor:[0:47] posNoWhite:[0:46] Found expr:[0:12->0:47] JSX 0:43] on[0:44->0:46]=...__ghost__[0:-1->0:-1]> _children:None Completable: Cexpression CJsxPropValue [CompletionSupport, TestComponent] on +ContextPath CJsxPropValue [CompletionSupport, TestComponent] on [{ "label": "true", "kind": 4, @@ -20,6 +21,7 @@ Complete src/CompletionJsxProps.res 3:48 posCursor:[3:48] posNoWhite:[3:47] Found expr:[3:12->3:48] JSX 3:43] on[3:44->3:46]=...[3:47->3:48]> _children:None Completable: Cexpression CJsxPropValue [CompletionSupport, TestComponent] on=t +ContextPath CJsxPropValue [CompletionSupport, TestComponent] on [{ "label": "true", "kind": 4, @@ -32,6 +34,7 @@ Complete src/CompletionJsxProps.res 6:50 posCursor:[6:50] posNoWhite:[6:49] Found expr:[6:12->6:50] JSX 6:43] test[6:44->6:48]=...[6:49->6:50]> _children:None Completable: Cexpression CJsxPropValue [CompletionSupport, TestComponent] test=T +ContextPath CJsxPropValue [CompletionSupport, TestComponent] test [{ "label": "Two", "kind": 4, @@ -68,6 +71,7 @@ Complete src/CompletionJsxProps.res 9:52 posCursor:[9:52] posNoWhite:[9:51] Found expr:[9:12->9:52] JSX 9:43] polyArg[9:44->9:51]=...__ghost__[0:-1->0:-1]> _children:None Completable: Cexpression CJsxPropValue [CompletionSupport, TestComponent] polyArg +ContextPath CJsxPropValue [CompletionSupport, TestComponent] polyArg [{ "label": "#one", "kind": 4, @@ -106,6 +110,7 @@ Complete src/CompletionJsxProps.res 12:54 posCursor:[12:54] posNoWhite:[12:53] Found expr:[12:12->12:54] JSX 12:43] polyArg[12:44->12:51]=...[12:52->12:54]> _children:None Completable: Cexpression CJsxPropValue [CompletionSupport, TestComponent] polyArg=#t +ContextPath CJsxPropValue [CompletionSupport, TestComponent] polyArg [{ "label": "#three(_, _)", "kind": 4, @@ -136,6 +141,7 @@ Complete src/CompletionJsxProps.res 15:22 posCursor:[15:22] posNoWhite:[15:21] Found expr:[15:12->15:25] JSX 15:15] muted[15:16->15:21]=...__ghost__[0:-1->0:-1]> _children:15:23 Completable: Cexpression CJsxPropValue [div] muted +ContextPath CJsxPropValue [div] muted [{ "label": "true", "kind": 4, @@ -154,6 +160,7 @@ Complete src/CompletionJsxProps.res 18:29 posCursor:[18:29] posNoWhite:[18:28] Found expr:[18:12->18:32] JSX 18:15] onMouseEnter[18:16->18:28]=...__ghost__[0:-1->0:-1]> _children:18:30 Completable: Cexpression CJsxPropValue [div] onMouseEnter +ContextPath CJsxPropValue [div] onMouseEnter [{ "label": "event => {}", "kind": 12, @@ -169,6 +176,7 @@ Complete src/CompletionJsxProps.res 22:52 posCursor:[22:52] posNoWhite:[22:51] Found expr:[22:12->22:52] JSX 22:43] testArr[22:44->22:51]=...__ghost__[0:-1->0:-1]> _children:None Completable: Cexpression CJsxPropValue [CompletionSupport, TestComponent] testArr +ContextPath CJsxPropValue [CompletionSupport, TestComponent] testArr [{ "label": "[]", "kind": 12, @@ -184,6 +192,7 @@ Complete src/CompletionJsxProps.res 26:54 posCursor:[26:54] posNoWhite:[26:53] Found expr:[26:12->26:56] JSX 26:43] testArr[26:44->26:51]=...[26:53->26:55]> _children:None Completable: Cexpression CJsxPropValue [CompletionSupport, TestComponent] testArr->array +ContextPath CJsxPropValue [CompletionSupport, TestComponent] testArr [{ "label": "One", "kind": 4, diff --git a/analysis/tests/src/expected/CompletionPattern.res.txt b/analysis/tests/src/expected/CompletionPattern.res.txt index e1645c638..4b8261568 100644 --- a/analysis/tests/src/expected/CompletionPattern.res.txt +++ b/analysis/tests/src/expected/CompletionPattern.res.txt @@ -5,6 +5,7 @@ posCursor:[7:13] posNoWhite:[7:12] Found expr:[7:3->7:13] Complete src/CompletionPattern.res 10:15 XXX Not found! Completable: Cpattern Value[v] +ContextPath Value[v] [{ "label": "(_, _, _)", "kind": 12, @@ -19,6 +20,7 @@ Complete src/CompletionPattern.res 13:18 posCursor:[13:18] posNoWhite:[13:17] Found pattern:[13:16->13:22] posCursor:[13:18] posNoWhite:[13:17] Found pattern:[13:17->13:18] Completable: Cpattern Value[v]=t->tuple($0) +ContextPath Value[v] [{ "label": "true", "kind": 4, @@ -32,6 +34,7 @@ posCursor:[16:25] posNoWhite:[16:24] Found pattern:[16:16->16:30] posCursor:[16:25] posNoWhite:[16:24] Found pattern:[16:23->16:29] posCursor:[16:25] posNoWhite:[16:24] Found pattern:[16:24->16:25] Completable: Cpattern Value[v]=f->tuple($2), tuple($0) +ContextPath Value[v] [{ "label": "false", "kind": 4, @@ -43,6 +46,7 @@ Completable: Cpattern Value[v]=f->tuple($2), tuple($0) Complete src/CompletionPattern.res 21:15 XXX Not found! Completable: Cpattern Value[x] +ContextPath Value[x] [{ "label": "true", "kind": 4, @@ -60,6 +64,7 @@ Completable: Cpattern Value[x] Complete src/CompletionPattern.res 24:17 posCursor:[24:17] posNoWhite:[24:16] Found pattern:[24:16->24:17] Completable: Cpattern Value[x]=t +ContextPath Value[x] [{ "label": "true", "kind": 4, @@ -71,6 +76,7 @@ Completable: Cpattern Value[x]=t Complete src/CompletionPattern.res 46:15 XXX Not found! Completable: Cpattern Value[f] +ContextPath Value[f] [{ "label": "{}", "kind": 22, @@ -85,6 +91,7 @@ Completable: Cpattern Value[f] Complete src/CompletionPattern.res 49:17 posCursor:[49:17] posNoWhite:[49:16] Found pattern:[49:16->49:18] Completable: Cpattern Value[f]->recordBody +ContextPath Value[f] [{ "label": "first", "kind": 5, @@ -114,6 +121,7 @@ Completable: Cpattern Value[f]->recordBody Complete src/CompletionPattern.res 52:24 posCursor:[52:24] posNoWhite:[52:22] Found pattern:[52:16->52:35] Completable: Cpattern Value[f]->recordBody +ContextPath Value[f] [{ "label": "optThird", "kind": 5, @@ -132,6 +140,7 @@ Complete src/CompletionPattern.res 55:19 posCursor:[55:19] posNoWhite:[55:18] Found pattern:[55:16->55:20] posCursor:[55:19] posNoWhite:[55:18] Found pattern:[55:17->55:19] Completable: Cpattern Value[f]=fi->recordBody +ContextPath Value[f] [{ "label": "first", "kind": 5, @@ -145,6 +154,7 @@ posCursor:[58:19] posNoWhite:[58:18] Found pattern:[58:16->58:24] posCursor:[58:19] posNoWhite:[58:18] Found pattern:[58:17->58:20] posCursor:[58:19] posNoWhite:[58:18] Found pattern:[58:18->58:19] Completable: Cpattern Value[z]=o->tuple($0), recordBody +ContextPath Value[z] [{ "label": "optThird", "kind": 5, @@ -156,6 +166,7 @@ Completable: Cpattern Value[z]=o->tuple($0), recordBody Complete src/CompletionPattern.res 61:22 posCursor:[61:22] posNoWhite:[61:21] Found pattern:[61:16->61:25] Completable: Cpattern Value[f]->recordField(nest) +ContextPath Value[f] [{ "label": "{}", "kind": 22, @@ -171,6 +182,7 @@ Complete src/CompletionPattern.res 64:24 posCursor:[64:24] posNoWhite:[64:23] Found pattern:[64:16->64:26] posCursor:[64:24] posNoWhite:[64:23] Found pattern:[64:23->64:25] Completable: Cpattern Value[f]->recordField(nest), recordBody +ContextPath Value[f] [{ "label": "nested", "kind": 5, @@ -184,6 +196,7 @@ posCursor:[70:22] posNoWhite:[70:21] Found expr:[69:2->72:13] posCursor:[70:22] posNoWhite:[70:21] Found expr:[70:5->72:13] posCursor:[70:22] posNoWhite:[70:21] Found pattern:[70:21->70:23] Completable: Cpattern Value[nest]->recordBody +ContextPath Value[nest] [{ "label": "nested", "kind": 5, @@ -195,6 +208,7 @@ Completable: Cpattern Value[nest]->recordBody Complete src/CompletionPattern.res 76:8 posCursor:[76:8] posNoWhite:[76:7] Found pattern:[76:7->76:9] Completable: Cpattern Value[f]->recordBody +ContextPath Value[f] [{ "label": "first", "kind": 5, @@ -226,6 +240,7 @@ posCursor:[79:16] posNoWhite:[79:15] Found pattern:[79:7->79:18] posCursor:[79:16] posNoWhite:[79:15] Found pattern:[79:14->79:17] posCursor:[79:16] posNoWhite:[79:15] Found pattern:[79:15->79:16] Completable: Cpattern Value[f]=n->recordField(nest), recordBody +ContextPath Value[f] [{ "label": "nested", "kind": 5, @@ -240,6 +255,7 @@ Ppat_construct Two:[87:16->87:19] posCursor:[87:20] posNoWhite:[87:19] Found pattern:[87:19->87:21] Ppat_construct ():[87:19->87:21] Completable: Cpattern Value[z]->variantPayload::Two($0) +ContextPath Value[z] [{ "label": "true", "kind": 4, @@ -259,6 +275,7 @@ posCursor:[90:21] posNoWhite:[90:20] Found pattern:[90:16->90:22] Ppat_construct Two:[90:16->90:19] posCursor:[90:21] posNoWhite:[90:20] Found pattern:[90:20->90:21] Completable: Cpattern Value[z]=t->variantPayload::Two($0) +ContextPath Value[z] [{ "label": "true", "kind": 4, @@ -272,6 +289,7 @@ posCursor:[93:23] posNoWhite:[93:22] Found pattern:[93:16->93:25] Ppat_construct Three:[93:16->93:21] posCursor:[93:23] posNoWhite:[93:22] Found pattern:[93:22->93:24] Completable: Cpattern Value[z]->variantPayload::Three($0), recordBody +ContextPath Value[z] [{ "label": "first", "kind": 5, @@ -304,6 +322,7 @@ Ppat_construct Three:[96:16->96:21] posCursor:[96:27] posNoWhite:[96:26] Found pattern:[96:21->96:29] posCursor:[96:27] posNoWhite:[96:26] Found pattern:[96:26->96:27] Completable: Cpattern Value[z]=t->variantPayload::Three($1) +ContextPath Value[z] [{ "label": "true", "kind": 4, @@ -317,6 +336,7 @@ posCursor:[103:21] posNoWhite:[103:20] Found pattern:[103:16->103:22] posCursor:[103:21] posNoWhite:[103:20] Found pattern:[103:20->103:21] Ppat_construct ():[103:20->103:21] Completable: Cpattern Value[b]->polyvariantPayload::two($0) +ContextPath Value[b] [{ "label": "true", "kind": 4, @@ -335,6 +355,7 @@ Complete src/CompletionPattern.res 106:22 posCursor:[106:22] posNoWhite:[106:21] Found pattern:[106:16->106:23] posCursor:[106:22] posNoWhite:[106:21] Found pattern:[106:21->106:22] Completable: Cpattern Value[b]=t->polyvariantPayload::two($0) +ContextPath Value[b] [{ "label": "true", "kind": 4, @@ -347,6 +368,7 @@ Complete src/CompletionPattern.res 109:24 posCursor:[109:24] posNoWhite:[109:23] Found pattern:[109:16->109:26] posCursor:[109:24] posNoWhite:[109:23] Found pattern:[109:23->109:25] Completable: Cpattern Value[b]->polyvariantPayload::three($0), recordBody +ContextPath Value[b] [{ "label": "first", "kind": 5, @@ -378,6 +400,7 @@ posCursor:[112:28] posNoWhite:[112:27] Found pattern:[112:16->112:29] posCursor:[112:28] posNoWhite:[112:27] Found pattern:[112:22->112:29] posCursor:[112:28] posNoWhite:[112:27] Found pattern:[112:27->112:28] Completable: Cpattern Value[b]=t->polyvariantPayload::three($1) +ContextPath Value[b] [{ "label": "true", "kind": 4, @@ -389,6 +412,7 @@ Completable: Cpattern Value[b]=t->polyvariantPayload::three($1) Complete src/CompletionPattern.res 118:15 XXX Not found! Completable: Cpattern Value[c] +ContextPath Value[c] [{ "label": "[]", "kind": 12, @@ -403,6 +427,7 @@ Completable: Cpattern Value[c] Complete src/CompletionPattern.res 121:17 posCursor:[121:17] posNoWhite:[121:16] Found pattern:[121:16->121:18] Completable: Cpattern Value[c]->array +ContextPath Value[c] [{ "label": "true", "kind": 4, @@ -423,6 +448,7 @@ Ppat_construct Some:[127:16->127:20] posCursor:[127:21] posNoWhite:[127:20] Found pattern:[127:20->127:22] Ppat_construct ():[127:20->127:22] Completable: Cpattern Value[o]->variantPayload::Some($0) +ContextPath Value[o] [{ "label": "true", "kind": 4, @@ -441,6 +467,7 @@ Complete src/CompletionPattern.res 134:23 posCursor:[134:23] posNoWhite:[134:22] Found pattern:[134:16->134:25] Ppat_construct Test:[134:16->134:20] Completable: Cpattern Value[p]->variantPayload::Test($1) +ContextPath Value[p] [{ "label": "true", "kind": 4, @@ -460,6 +487,7 @@ posCursor:[137:29] posNoWhite:[137:28] Found pattern:[137:16->137:31] Ppat_construct Test:[137:16->137:20] posCursor:[137:29] posNoWhite:[137:28] Found pattern:[137:20->137:32] Completable: Cpattern Value[p]->variantPayload::Test($2) +ContextPath Value[p] [{ "label": "None", "kind": 12, @@ -493,6 +521,7 @@ posCursor:[140:23] posNoWhite:[140:22] Found pattern:[140:16->140:31] Ppat_construct Test:[140:16->140:20] posCursor:[140:23] posNoWhite:[140:22] Found pattern:[140:20->140:32] Completable: Cpattern Value[p]->variantPayload::Test($1) +ContextPath Value[p] [{ "label": "true", "kind": 4, @@ -512,6 +541,7 @@ posCursor:[143:35] posNoWhite:[143:34] Found pattern:[143:16->143:37] Ppat_construct Test:[143:16->143:20] posCursor:[143:35] posNoWhite:[143:34] Found pattern:[143:20->143:38] Completable: Cpattern Value[p]->variantPayload::Test($3) +ContextPath Value[p] [{ "label": "[]", "kind": 12, @@ -526,6 +556,7 @@ Completable: Cpattern Value[p]->variantPayload::Test($3) Complete src/CompletionPattern.res 150:24 posCursor:[150:24] posNoWhite:[150:23] Found pattern:[150:16->150:26] Completable: Cpattern Value[v]->polyvariantPayload::test($1) +ContextPath Value[v] [{ "label": "true", "kind": 4, @@ -544,6 +575,7 @@ Complete src/CompletionPattern.res 153:30 posCursor:[153:30] posNoWhite:[153:29] Found pattern:[153:16->153:32] posCursor:[153:30] posNoWhite:[153:29] Found pattern:[153:21->153:32] Completable: Cpattern Value[v]->polyvariantPayload::test($2) +ContextPath Value[v] [{ "label": "None", "kind": 12, @@ -576,6 +608,7 @@ Complete src/CompletionPattern.res 156:24 posCursor:[156:24] posNoWhite:[156:23] Found pattern:[156:16->156:32] posCursor:[156:24] posNoWhite:[156:23] Found pattern:[156:21->156:32] Completable: Cpattern Value[v]->polyvariantPayload::test($1) +ContextPath Value[v] [{ "label": "true", "kind": 4, @@ -594,6 +627,7 @@ Complete src/CompletionPattern.res 159:36 posCursor:[159:36] posNoWhite:[159:35] Found pattern:[159:16->159:38] posCursor:[159:36] posNoWhite:[159:35] Found pattern:[159:21->159:38] Completable: Cpattern Value[v]->polyvariantPayload::test($3) +ContextPath Value[v] [{ "label": "[]", "kind": 12, @@ -609,6 +643,7 @@ Complete src/CompletionPattern.res 164:17 posCursor:[164:17] posNoWhite:[164:16] Found pattern:[164:16->164:18] Ppat_construct ():[164:16->164:18] Completable: Cpattern Value[s]->tuple($0) +ContextPath Value[s] [{ "label": "true", "kind": 4, @@ -626,6 +661,7 @@ Completable: Cpattern Value[s]->tuple($0) Complete src/CompletionPattern.res 167:23 posCursor:[167:23] posNoWhite:[167:21] Found pattern:[167:16->167:24] Completable: Cpattern Value[s]->tuple($1) +ContextPath Value[s] [{ "label": "None", "kind": 12, @@ -657,6 +693,7 @@ Completable: Cpattern Value[s]->tuple($1) Complete src/CompletionPattern.res 170:22 posCursor:[170:22] posNoWhite:[170:21] Found pattern:[170:16->170:28] Completable: Cpattern Value[s]->tuple($1) +ContextPath Value[s] [{ "label": "None", "kind": 12, @@ -688,6 +725,7 @@ Completable: Cpattern Value[s]->tuple($1) Complete src/CompletionPattern.res 173:35 XXX Not found! Completable: Cpattern Value[s] +ContextPath Value[s] [{ "label": "(_, _, _)", "kind": 12, @@ -701,6 +739,7 @@ Completable: Cpattern Value[s] Complete src/CompletionPattern.res 176:41 posCursor:[176:41] posNoWhite:[176:40] Found pattern:[176:35->176:47] Completable: Cpattern Value[s]->tuple($1) +ContextPath Value[s] [{ "label": "None", "kind": 12, @@ -732,6 +771,7 @@ Completable: Cpattern Value[s]->tuple($1) Complete src/CompletionPattern.res 179:21 XXX Not found! Completable: Cpattern Value[z] +ContextPath Value[z] [{ "label": "One", "kind": 4, @@ -763,6 +803,7 @@ posCursor:[182:32] posNoWhite:[182:31] Found pattern:[182:16->182:34] posCursor:[182:32] posNoWhite:[182:31] Found pattern:[182:22->182:34] Ppat_construct Two:[182:22->182:25] Completable: Cpattern Value[z]->variantPayload::Two($0) +ContextPath Value[z] [{ "label": "true", "kind": 4, @@ -783,6 +824,7 @@ posCursor:[185:48] posNoWhite:[185:47] Found pattern:[185:22->185:50] Ppat_construct Three:[185:22->185:27] posCursor:[185:48] posNoWhite:[185:47] Found pattern:[185:27->185:53] Completable: Cpattern Value[z]->variantPayload::Three($1) +ContextPath Value[z] [{ "label": "true", "kind": 4, @@ -801,6 +843,7 @@ Complete src/CompletionPattern.res 188:34 posCursor:[188:34] posNoWhite:[188:33] Found pattern:[188:16->188:36] posCursor:[188:34] posNoWhite:[188:33] Found pattern:[188:23->188:36] Completable: Cpattern Value[b]->polyvariantPayload::two($0) +ContextPath Value[b] [{ "label": "true", "kind": 4, @@ -820,6 +863,7 @@ posCursor:[191:50] posNoWhite:[191:49] Found pattern:[191:16->191:52] posCursor:[191:50] posNoWhite:[191:49] Found pattern:[191:23->191:52] posCursor:[191:50] posNoWhite:[191:49] Found pattern:[191:29->191:52] Completable: Cpattern Value[b]->polyvariantPayload::three($1) +ContextPath Value[b] [{ "label": "true", "kind": 4, @@ -838,6 +882,7 @@ Complete src/CompletionPattern.res 194:24 posCursor:[194:24] posNoWhite:[194:23] Found pattern:[194:16->194:29] posCursor:[194:24] posNoWhite:[194:23] Found pattern:[194:23->194:24] Completable: Cpattern Value[s]->tuple($1) +ContextPath Value[s] [{ "label": "None", "kind": 12, @@ -869,11 +914,13 @@ Completable: Cpattern Value[s]->tuple($1) Complete src/CompletionPattern.res 201:25 posCursor:[201:25] posNoWhite:[201:24] Found pattern:[201:17->201:28] Completable: Cpattern Value[ff]->recordField(someFn) +ContextPath Value[ff] [] Complete src/CompletionPattern.res 206:16 XXX Not found! Completable: Cpattern Value[xn] +ContextPath Value[xn] [{ "label": "Js.Exn.Error(error)", "kind": 4, diff --git a/analysis/tests/src/expected/CompletionPipeChain.res.txt b/analysis/tests/src/expected/CompletionPipeChain.res.txt index c149770fe..1bdc6d425 100644 --- a/analysis/tests/src/expected/CompletionPipeChain.res.txt +++ b/analysis/tests/src/expected/CompletionPipeChain.res.txt @@ -1,6 +1,8 @@ Complete src/CompletionPipeChain.res 27:16 posCursor:[27:16] posNoWhite:[27:15] Found expr:[27:11->0:-1] Completable: Cpath Value[int]-> +ContextPath Value[int]-> +ContextPath Value[int] [{ "label": "Integer.toInt", "kind": 12, @@ -30,6 +32,9 @@ Completable: Cpath Value[int]-> Complete src/CompletionPipeChain.res 30:23 posCursor:[30:23] posNoWhite:[30:22] Found expr:[30:11->0:-1] Completable: Cpath Value[toFlt](Nolabel)-> +ContextPath Value[toFlt](Nolabel)-> +ContextPath Value[toFlt](Nolabel) +ContextPath Value[toFlt] [{ "label": "SuperFloat.fromInteger", "kind": 12, @@ -47,6 +52,9 @@ Completable: Cpath Value[toFlt](Nolabel)-> Complete src/CompletionPipeChain.res 33:38 posCursor:[33:38] posNoWhite:[33:37] Found expr:[33:11->0:-1] Completable: Cpath Value[Integer, increment](Nolabel, Nolabel)-> +ContextPath Value[Integer, increment](Nolabel, Nolabel)-> +ContextPath Value[Integer, increment](Nolabel, Nolabel) +ContextPath Value[Integer, increment] [{ "label": "Integer.toInt", "kind": 12, @@ -76,6 +84,9 @@ Completable: Cpath Value[Integer, increment](Nolabel, Nolabel)-> Complete src/CompletionPipeChain.res 36:38 posCursor:[36:38] posNoWhite:[36:37] Found expr:[36:11->0:-1] Completable: Cpath Value[Integer, increment](Nolabel, Nolabel)-> +ContextPath Value[Integer, increment](Nolabel, Nolabel)-> +ContextPath Value[Integer, increment](Nolabel, Nolabel) +ContextPath Value[Integer, increment] [{ "label": "Integer.toInt", "kind": 12, @@ -105,6 +116,9 @@ Completable: Cpath Value[Integer, increment](Nolabel, Nolabel)-> Complete src/CompletionPipeChain.res 39:47 posCursor:[39:47] posNoWhite:[39:46] Found expr:[39:11->0:-1] Completable: Cpath Value[Integer, decrement](Nolabel, Nolabel)-> +ContextPath Value[Integer, decrement](Nolabel, Nolabel)-> +ContextPath Value[Integer, decrement](Nolabel, Nolabel) +ContextPath Value[Integer, decrement] [{ "label": "Integer.toInt", "kind": 12, @@ -134,6 +148,9 @@ Completable: Cpath Value[Integer, decrement](Nolabel, Nolabel)-> Complete src/CompletionPipeChain.res 42:69 posCursor:[42:69] posNoWhite:[42:68] Found expr:[42:11->0:-1] Completable: Cpath Value[Integer, decrement](Nolabel, Nolabel)-> +ContextPath Value[Integer, decrement](Nolabel, Nolabel)-> +ContextPath Value[Integer, decrement](Nolabel, Nolabel) +ContextPath Value[Integer, decrement] [{ "label": "Integer.toInt", "kind": 12, @@ -163,6 +180,9 @@ Completable: Cpath Value[Integer, decrement](Nolabel, Nolabel)-> Complete src/CompletionPipeChain.res 45:62 posCursor:[45:62] posNoWhite:[45:61] Found expr:[45:11->0:-1] Completable: Cpath Value[SuperFloat, fromInteger](Nolabel)-> +ContextPath Value[SuperFloat, fromInteger](Nolabel)-> +ContextPath Value[SuperFloat, fromInteger](Nolabel) +ContextPath Value[SuperFloat, fromInteger] [{ "label": "SuperFloat.fromInteger", "kind": 12, @@ -180,6 +200,9 @@ Completable: Cpath Value[SuperFloat, fromInteger](Nolabel)-> Complete src/CompletionPipeChain.res 48:63 posCursor:[48:63] posNoWhite:[48:62] Found expr:[48:11->48:63] Completable: Cpath Value[SuperFloat, fromInteger](Nolabel)->t +ContextPath Value[SuperFloat, fromInteger](Nolabel)->t +ContextPath Value[SuperFloat, fromInteger](Nolabel) +ContextPath Value[SuperFloat, fromInteger] [{ "label": "SuperFloat.toInteger", "kind": 12, @@ -191,6 +214,9 @@ Completable: Cpath Value[SuperFloat, fromInteger](Nolabel)->t Complete src/CompletionPipeChain.res 51:82 posCursor:[51:82] posNoWhite:[51:81] Found expr:[51:11->0:-1] Completable: Cpath Value[CompletionSupport, Test, make](Nolabel)-> +ContextPath Value[CompletionSupport, Test, make](Nolabel)-> +ContextPath Value[CompletionSupport, Test, make](Nolabel) +ContextPath Value[CompletionSupport, Test, make] [{ "label": "CompletionSupport.Test.add", "kind": 12, @@ -214,6 +240,9 @@ Completable: Cpath Value[CompletionSupport, Test, make](Nolabel)-> Complete src/CompletionPipeChain.res 54:78 posCursor:[54:78] posNoWhite:[54:77] Found expr:[54:11->0:-1] Completable: Cpath Value[CompletionSupport, Test, addSelf](Nolabel, Nolabel)-> +ContextPath Value[CompletionSupport, Test, addSelf](Nolabel, Nolabel)-> +ContextPath Value[CompletionSupport, Test, addSelf](Nolabel, Nolabel) +ContextPath Value[CompletionSupport, Test, addSelf] [{ "label": "CompletionSupport.Test.add", "kind": 12, @@ -237,11 +266,17 @@ Completable: Cpath Value[CompletionSupport, Test, addSelf](Nolabel, Nolabel)-> Complete src/CompletionPipeChain.res 58:5 posCursor:[58:5] posNoWhite:[58:4] Found expr:[57:8->0:-1] Completable: Cpath Value[Js, Array2, forEach](Nolabel, Nolabel)-> +ContextPath Value[Js, Array2, forEach](Nolabel, Nolabel)-> +ContextPath Value[Js, Array2, forEach](Nolabel, Nolabel) +ContextPath Value[Js, Array2, forEach] [] Complete src/CompletionPipeChain.res 62:6 posCursor:[62:6] posNoWhite:[62:5] Found expr:[61:8->62:6] Completable: Cpath Value[Belt, Array, reduce](Nolabel, Nolabel, Nolabel)->t +ContextPath Value[Belt, Array, reduce](Nolabel, Nolabel, Nolabel)->t +ContextPath Value[Belt, Array, reduce](Nolabel, Nolabel, Nolabel) +ContextPath Value[Belt, Array, reduce] [{ "label": "Belt.Int.toString", "kind": 12, @@ -259,6 +294,8 @@ Completable: Cpath Value[Belt, Array, reduce](Nolabel, Nolabel, Nolabel)->t Complete src/CompletionPipeChain.res 70:12 posCursor:[70:12] posNoWhite:[70:11] Found expr:[70:3->0:-1] Completable: Cpath Value[aliased]-> +ContextPath Value[aliased]-> +ContextPath Value[aliased] [{ "label": "CompletionSupport.Test.add", "kind": 12, @@ -282,6 +319,8 @@ Completable: Cpath Value[aliased]-> Complete src/CompletionPipeChain.res 73:15 posCursor:[73:15] posNoWhite:[73:14] Found expr:[73:3->0:-1] Completable: Cpath Value[notAliased]-> +ContextPath Value[notAliased]-> +ContextPath Value[notAliased] [{ "label": "CompletionSupport.Test.add", "kind": 12, diff --git a/analysis/tests/src/expected/CompletionPipeSubmodules.res.txt b/analysis/tests/src/expected/CompletionPipeSubmodules.res.txt index a699eb8e6..81eb5e839 100644 --- a/analysis/tests/src/expected/CompletionPipeSubmodules.res.txt +++ b/analysis/tests/src/expected/CompletionPipeSubmodules.res.txt @@ -1,6 +1,8 @@ Complete src/CompletionPipeSubmodules.res 12:20 posCursor:[12:20] posNoWhite:[12:19] Found expr:[12:11->20:8] Completable: Cpath Value[A, B1, xx]-> +ContextPath Value[A, B1, xx]-> +ContextPath Value[A, B1, xx] [{ "label": "A.B1.xx", "kind": 12, @@ -18,6 +20,9 @@ Completable: Cpath Value[A, B1, xx]-> Complete src/CompletionPipeSubmodules.res 16:18 posCursor:[16:18] posNoWhite:[16:17] Found expr:[16:11->20:8] Completable: Cpath Value[A, x].v-> +ContextPath Value[A, x].v-> +ContextPath Value[A, x].v +ContextPath Value[A, x] [{ "label": "A.B1.xx", "kind": 12, @@ -35,6 +40,10 @@ Completable: Cpath Value[A, x].v-> Complete src/CompletionPipeSubmodules.res 38:20 posCursor:[38:20] posNoWhite:[38:19] Found expr:[38:11->0:-1] Completable: Cpath Value[E, e].v.v-> +ContextPath Value[E, e].v.v-> +ContextPath Value[E, e].v.v +ContextPath Value[E, e].v +ContextPath Value[E, e] [{ "label": "C.C", "kind": 4, @@ -46,6 +55,10 @@ Completable: Cpath Value[E, e].v.v-> Complete src/CompletionPipeSubmodules.res 42:21 posCursor:[42:21] posNoWhite:[42:20] Found expr:[42:11->0:-1] Completable: Cpath Value[E, e].v.v2-> +ContextPath Value[E, e].v.v2-> +ContextPath Value[E, e].v.v2 +ContextPath Value[E, e].v +ContextPath Value[E, e] [{ "label": "D.C2.C2", "kind": 4, diff --git a/analysis/tests/src/expected/CompletionTypeAnnotation.res.txt b/analysis/tests/src/expected/CompletionTypeAnnotation.res.txt index 65af0a21f..d79e24bae 100644 --- a/analysis/tests/src/expected/CompletionTypeAnnotation.res.txt +++ b/analysis/tests/src/expected/CompletionTypeAnnotation.res.txt @@ -1,6 +1,7 @@ Complete src/CompletionTypeAnnotation.res 9:22 XXX Not found! Completable: Cexpression Type[someRecord] +ContextPath Type[someRecord] [{ "label": "{}", "kind": 12, @@ -15,6 +16,7 @@ Completable: Cexpression Type[someRecord] Complete src/CompletionTypeAnnotation.res 12:24 XXX Not found! Completable: Cexpression Type[someRecord]->recordBody +ContextPath Type[someRecord] [{ "label": "age", "kind": 5, @@ -32,6 +34,7 @@ Completable: Cexpression Type[someRecord]->recordBody Complete src/CompletionTypeAnnotation.res 15:23 XXX Not found! Completable: Cexpression Type[someVariant] +ContextPath Type[someVariant] [{ "label": "One", "kind": 4, @@ -53,6 +56,7 @@ Completable: Cexpression Type[someVariant] Complete src/CompletionTypeAnnotation.res 18:25 XXX Not found! Completable: Cexpression Type[someVariant]=O +ContextPath Type[someVariant] [{ "label": "One", "kind": 4, @@ -79,6 +83,7 @@ Completable: Cexpression Type[someVariant]=O Complete src/CompletionTypeAnnotation.res 21:27 XXX Not found! Completable: Cexpression Type[somePolyVariant] +ContextPath Type[somePolyVariant] [{ "label": "#one", "kind": 4, @@ -100,6 +105,7 @@ Completable: Cexpression Type[somePolyVariant] Complete src/CompletionTypeAnnotation.res 24:30 XXX Not found! Completable: Cexpression Type[somePolyVariant]=#o +ContextPath Type[somePolyVariant] [{ "label": "#one", "kind": 4, @@ -113,6 +119,7 @@ Completable: Cexpression Type[somePolyVariant]=#o Complete src/CompletionTypeAnnotation.res 29:20 XXX Not found! Completable: Cexpression Type[someFunc] +ContextPath Type[someFunc] [{ "label": "(v1, v2) => {}", "kind": 12, @@ -127,6 +134,7 @@ Completable: Cexpression Type[someFunc] Complete src/CompletionTypeAnnotation.res 34:21 XXX Not found! Completable: Cexpression Type[someTuple] +ContextPath Type[someTuple] [{ "label": "(_, _)", "kind": 12, @@ -140,6 +148,7 @@ Completable: Cexpression Type[someTuple] Complete src/CompletionTypeAnnotation.res 37:28 XXX Not found! Completable: Cexpression Type[someTuple]->tuple($1) +ContextPath Type[someTuple] [{ "label": "None", "kind": 12, @@ -171,6 +180,8 @@ Completable: Cexpression Type[someTuple]->tuple($1) Complete src/CompletionTypeAnnotation.res 40:31 XXX Not found! Completable: Cexpression option +ContextPath option +ContextPath Type[someVariant] [{ "label": "None", "kind": 12, @@ -206,6 +217,8 @@ Completable: Cexpression option Complete src/CompletionTypeAnnotation.res 43:37 XXX Not found! Completable: Cexpression option->variantPayload::Some($0) +ContextPath option +ContextPath Type[someVariant] [{ "label": "One", "kind": 4, @@ -227,6 +240,8 @@ Completable: Cexpression option->variantPayload::Some($0) Complete src/CompletionTypeAnnotation.res 46:30 XXX Not found! Completable: Cexpression array +ContextPath array +ContextPath Type[someVariant] [{ "label": "[]", "kind": 12, @@ -241,6 +256,8 @@ Completable: Cexpression array Complete src/CompletionTypeAnnotation.res 49:32 XXX Not found! Completable: Cexpression array->array +ContextPath array +ContextPath Type[someVariant] [{ "label": "One", "kind": 4, @@ -262,6 +279,9 @@ Completable: Cexpression array->array Complete src/CompletionTypeAnnotation.res 52:38 XXX Not found! Completable: Cexpression array> +ContextPath array> +ContextPath option +ContextPath Type[someVariant] [{ "label": "[]", "kind": 12, @@ -276,6 +296,9 @@ Completable: Cexpression array> Complete src/CompletionTypeAnnotation.res 55:45 XXX Not found! Completable: Cexpression option>->variantPayload::Some($0), array +ContextPath option> +ContextPath array +ContextPath Type[someVariant] [{ "label": "One", "kind": 4, diff --git a/analysis/tests/src/expected/Cross.res.txt b/analysis/tests/src/expected/Cross.res.txt index b51c414b8..fe9a52e69 100644 --- a/analysis/tests/src/expected/Cross.res.txt +++ b/analysis/tests/src/expected/Cross.res.txt @@ -97,6 +97,7 @@ Complete src/Cross.res 36:28 posCursor:[36:28] posNoWhite:[36:27] Found expr:[36:3->36:28] Pexp_ident DefinitionWithInterface.a:[36:3->36:28] Completable: Cpath Value[DefinitionWithInterface, a] +ContextPath Value[DefinitionWithInterface, a] [] Definition src/Cross.res 39:39 diff --git a/analysis/tests/src/expected/Debug.res.txt b/analysis/tests/src/expected/Debug.res.txt index 2ab89d23f..f1554acc9 100644 --- a/analysis/tests/src/expected/Debug.res.txt +++ b/analysis/tests/src/expected/Debug.res.txt @@ -10,6 +10,7 @@ Pexp_ident eqN:[14:5->14:8] Completable: Cpath Value[eqN] Raw opens: 1 Js.place holder Resolved opens 1 js.ml +ContextPath Value[eqN] [{ "label": "eqNullable", "kind": 12, diff --git a/analysis/tests/src/expected/Destructuring.res.txt b/analysis/tests/src/expected/Destructuring.res.txt index 867586806..309ea0972 100644 --- a/analysis/tests/src/expected/Destructuring.res.txt +++ b/analysis/tests/src/expected/Destructuring.res.txt @@ -1,6 +1,7 @@ Complete src/Destructuring.res 4:11 posCursor:[4:11] posNoWhite:[4:9] Found pattern:[4:4->4:12] Completable: Cpattern Value[x]->recordBody +ContextPath Value[x] [{ "label": "age", "kind": 5, @@ -12,6 +13,7 @@ Completable: Cpattern Value[x]->recordBody Complete src/Destructuring.res 7:8 posCursor:[7:8] posNoWhite:[7:7] Found pattern:[7:7->7:9] Completable: Cpattern Value[x]->recordBody +ContextPath Value[x] [{ "label": "name", "kind": 5, @@ -31,6 +33,7 @@ posCursor:[11:13] posNoWhite:[11:11] Found expr:[10:8->14:1] posCursor:[11:13] posNoWhite:[11:11] Found expr:[11:2->13:6] posCursor:[11:13] posNoWhite:[11:11] Found pattern:[11:6->11:14] Completable: Cpattern Value[x]->recordBody +ContextPath Value[x] [{ "label": "age", "kind": 5, @@ -44,6 +47,7 @@ posCursor:[17:10] posNoWhite:[17:9] Found expr:[16:9->20:1] posCursor:[17:10] posNoWhite:[17:9] Found expr:[17:5->19:11] posCursor:[17:10] posNoWhite:[17:9] Found pattern:[17:9->17:11] Completable: Cpattern Value[x]->recordBody +ContextPath Value[x] [{ "label": "name", "kind": 5, @@ -61,6 +65,7 @@ Completable: Cpattern Value[x]->recordBody Complete src/Destructuring.res 31:8 posCursor:[31:8] posNoWhite:[31:7] Found pattern:[31:7->31:9] Completable: Cpattern Value[x]->recordBody +ContextPath Value[x] [{ "label": "someField", "kind": 5, diff --git a/analysis/tests/src/expected/ExhaustiveSwitch.res.txt b/analysis/tests/src/expected/ExhaustiveSwitch.res.txt index c9616503c..6833140a6 100644 --- a/analysis/tests/src/expected/ExhaustiveSwitch.res.txt +++ b/analysis/tests/src/expected/ExhaustiveSwitch.res.txt @@ -1,6 +1,7 @@ Complete src/ExhaustiveSwitch.res 8:24 XXX Not found! Completable: CexhaustiveSwitch Value[withSomeVarian] +ContextPath Value[withSomeVarian] [{ "label": "withSomeVariant", "kind": 12, @@ -21,6 +22,7 @@ Completable: CexhaustiveSwitch Value[withSomeVarian] Complete src/ExhaustiveSwitch.res 11:21 XXX Not found! Completable: CexhaustiveSwitch Value[withSomePol] +ContextPath Value[withSomePol] [{ "label": "withSomePoly", "kind": 12, @@ -41,6 +43,7 @@ Completable: CexhaustiveSwitch Value[withSomePol] Complete src/ExhaustiveSwitch.res 14:17 XXX Not found! Completable: CexhaustiveSwitch Value[someBoo] +ContextPath Value[someBoo] [{ "label": "someBool", "kind": 12, @@ -61,6 +64,7 @@ Completable: CexhaustiveSwitch Value[someBoo] Complete src/ExhaustiveSwitch.res 17:16 XXX Not found! Completable: CexhaustiveSwitch Value[someOp] +ContextPath Value[someOp] [{ "label": "someOpt", "kind": 12, diff --git a/analysis/tests/src/expected/Hover.res.txt b/analysis/tests/src/expected/Hover.res.txt index cdf59d587..af002fc92 100644 --- a/analysis/tests/src/expected/Hover.res.txt +++ b/analysis/tests/src/expected/Hover.res.txt @@ -116,6 +116,9 @@ Complete src/Hover.res 170:16 posCursor:[170:16] posNoWhite:[170:15] Found expr:[170:5->170:16] Pexp_field [170:5->170:15] _:[176:2->170:16] Completable: Cpath Value[x1].content."" +ContextPath Value[x1].content."" +ContextPath Value[x1].content +ContextPath Value[x1] [{ "label": "age", "kind": 5, @@ -128,6 +131,9 @@ Complete src/Hover.res 173:16 posCursor:[173:16] posNoWhite:[173:15] Found expr:[173:5->173:16] Pexp_field [173:5->173:15] _:[176:2->173:16] Completable: Cpath Value[x2].content."" +ContextPath Value[x2].content."" +ContextPath Value[x2].content +ContextPath Value[x2] [{ "label": "age", "kind": 5, @@ -140,6 +146,9 @@ Complete src/Hover.res 182:16 posCursor:[182:16] posNoWhite:[182:15] Found expr:[182:5->182:16] Pexp_field [182:5->182:15] _:[187:0->182:16] Completable: Cpath Value[y1].content."" +ContextPath Value[y1].content."" +ContextPath Value[y1].content +ContextPath Value[y1] [{ "label": "age", "kind": 5, @@ -152,6 +161,9 @@ Complete src/Hover.res 185:16 posCursor:[185:16] posNoWhite:[185:15] Found expr:[185:5->185:16] Pexp_field [185:5->185:15] _:[187:0->185:16] Completable: Cpath Value[y2].content."" +ContextPath Value[y2].content."" +ContextPath Value[y2].content +ContextPath Value[y2] [{ "label": "age", "kind": 5, @@ -171,6 +183,7 @@ Nothing at that position. Now trying to use completion. posCursor:[210:13] posNoWhite:[210:12] Found expr:[210:11->210:14] Pexp_ident usr:[210:11->210:14] Completable: Cpath Value[usr] +ContextPath Value[usr] {"contents": {"kind": "markdown", "value": "```rescript\nuseR\n```\n\n---\n\n```\n \n```\n```rescript\ntype useR = {x: int, y: list>>}\n```\nGo to: [Type definition](command:rescript-vscode.go_to_location?%5B%22Hover.res%22%2C200%2C0%5D)\n\n\n---\n\n```\n \n```\n```rescript\ntype r<'a> = {i: 'a, f: float}\n```\nGo to: [Type definition](command:rescript-vscode.go_to_location?%5B%22Hover.res%22%2C101%2C0%5D)\n"}} Hover src/Hover.res 230:20 @@ -184,6 +197,8 @@ Nothing at that position. Now trying to use completion. posCursor:[245:6] posNoWhite:[245:5] Found expr:[245:3->245:14] Pexp_field [245:3->245:4] someField:[245:5->245:14] Completable: Cpath Value[x].someField +ContextPath Value[x].someField +ContextPath Value[x] {"contents": {"kind": "markdown", "value": "```rescript\nbool\n```\n\n Mighty fine field here. "}} Hover src/Hover.res 248:19 diff --git a/analysis/tests/src/expected/Jsx2.res.txt b/analysis/tests/src/expected/Jsx2.res.txt index 412f41045..297e5736d 100644 --- a/analysis/tests/src/expected/Jsx2.res.txt +++ b/analysis/tests/src/expected/Jsx2.res.txt @@ -7,6 +7,7 @@ Complete src/Jsx2.res 8:15 posCursor:[8:15] posNoWhite:[8:14] Found expr:[8:4->8:15] JSX 8:5] second[8:6->8:12]=...[8:13->8:15]> _children:None Completable: Cexpression CJsxPropValue [M] second=fi +ContextPath CJsxPropValue [M] second [] Complete src/Jsx2.res 11:20 @@ -31,6 +32,7 @@ Complete src/Jsx2.res 14:13 posCursor:[14:13] posNoWhite:[14:12] Found expr:[14:12->14:13] JSX 14:13] > _children:None Completable: Cpath Module[M] +ContextPath Module[M] [{ "label": "M", "kind": 9, @@ -269,6 +271,7 @@ Complete src/Jsx2.res 89:16 posCursor:[89:16] posNoWhite:[89:15] Found expr:[89:4->89:16] JSX 89:16] > _children:None Completable: Cpath Module[WithChildren] +ContextPath Module[WithChildren] [{ "label": "WithChildren", "kind": 9, @@ -294,6 +297,7 @@ posCursor:[94:18] posNoWhite:[94:17] Found pattern:[94:7->94:18] posCursor:[94:18] posNoWhite:[94:17] Found type:[94:11->94:18] Ptyp_constr React.e:[94:11->94:18] Completable: Cpath Type[React, e] +ContextPath Type[React, e] [{ "label": "element", "kind": 22, @@ -307,6 +311,7 @@ posCursor:[96:20] posNoWhite:[96:19] Found pattern:[96:7->99:6] posCursor:[96:20] posNoWhite:[96:19] Found type:[96:11->99:6] Ptyp_constr ReactDOMR:[96:11->99:6] Completable: Cpath Type[ReactDOMR] +ContextPath Type[ReactDOMR] [{ "label": "ReactDOMRe", "kind": 9, @@ -321,12 +326,15 @@ Pexp_apply ...[102:15->102:16] (...[102:13->102:14], ...[102:17->102:21]) posCursor:[102:21] posNoWhite:[102:20] Found expr:[102:17->102:21] Pexp_field [102:17->102:18] th:[102:19->102:21] Completable: Cpath Value[x].th +ContextPath Value[x].th +ContextPath Value[x] [] Complete src/Jsx2.res 106:28 posCursor:[106:28] posNoWhite:[106:27] Found expr:[106:11->106:28] Pexp_ident DefineSomeFields.:[106:11->106:28] Completable: Cpath Value[DefineSomeFields, ""] +ContextPath Value[DefineSomeFields, ""] [{ "label": "thisValue", "kind": 12, @@ -341,6 +349,7 @@ Pexp_apply ...[108:13->108:14] (...[108:11->108:12], ...[108:15->108:36]) posCursor:[108:36] posNoWhite:[108:35] Found expr:[108:15->108:36] Pexp_field [108:15->108:16] DefineSomeFields.th:[108:17->108:36] Completable: Cpath Module[DefineSomeFields].th +ContextPath Module[DefineSomeFields].th [{ "label": "thisField", "kind": 5, @@ -361,6 +370,7 @@ JSX 121:6] x[122:5->122:6]=...[122:7->122:20] name[124:4->124:8]=.. posCursor:[122:20] posNoWhite:[122:19] Found expr:[122:7->122:20] Pexp_ident Outer.Inner.h:[122:7->122:20] Completable: Cpath Value[Outer, Inner, h] +ContextPath Value[Outer, Inner, h] [{ "label": "hello", "kind": 12, @@ -375,6 +385,7 @@ JSX 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.:[129:7->131:8] Completable: Cpath Value[Outer, Inner, ""] +ContextPath Value[Outer, Inner, ""] [{ "label": "hello", "kind": 12, @@ -392,6 +403,7 @@ Complete src/Jsx2.res 150:21 posCursor:[150:21] posNoWhite:[150:20] Found expr:[150:12->150:32] JSX 150:21] name[150:22->150:26]=...[150:27->150:29]> _children:150:30 Completable: Cpath Module[Nested, Co] +ContextPath Module[Nested, Co] [{ "label": "Comp", "kind": 9, @@ -404,6 +416,7 @@ Complete src/Jsx2.res 153:19 posCursor:[153:19] posNoWhite:[153:18] Found expr:[153:12->153:25] JSX 153:24] > _children:None Completable: Cpath Module[Nested, ""] +ContextPath Module[Nested, ""] [{ "label": "Comp", "kind": 9, diff --git a/analysis/tests/src/expected/Jsx2.resi.txt b/analysis/tests/src/expected/Jsx2.resi.txt index aa95d5bc3..5c1f4ae9d 100644 --- a/analysis/tests/src/expected/Jsx2.resi.txt +++ b/analysis/tests/src/expected/Jsx2.resi.txt @@ -10,6 +10,7 @@ Complete src/Jsx2.resi 7:19 posCursor:[7:19] posNoWhite:[7:18] Found type:[7:12->7:19] Ptyp_constr React.e:[7:12->7:19] Completable: Cpath Type[React, e] +ContextPath Type[React, e] [{ "label": "element", "kind": 22, @@ -22,6 +23,7 @@ Complete src/Jsx2.resi 10:18 posCursor:[10:18] posNoWhite:[10:17] Found type:[10:11->10:18] Ptyp_constr React.e:[10:11->10:18] Completable: Cpath Type[React, e] +ContextPath Type[React, e] [{ "label": "element", "kind": 22, diff --git a/analysis/tests/src/expected/RecordCompletion.res.txt b/analysis/tests/src/expected/RecordCompletion.res.txt index d5d0b47dc..e9ad5f29b 100644 --- a/analysis/tests/src/expected/RecordCompletion.res.txt +++ b/analysis/tests/src/expected/RecordCompletion.res.txt @@ -1,6 +1,9 @@ Complete src/RecordCompletion.res 8:9 posCursor:[8:9] posNoWhite:[8:8] Found expr:[8:3->8:9] Completable: Cpath Value[t].n->m +ContextPath Value[t].n->m +ContextPath Value[t].n +ContextPath Value[t] [{ "label": "Js.Array2.mapi", "kind": 12, @@ -18,6 +21,10 @@ Completable: Cpath Value[t].n->m Complete src/RecordCompletion.res 11:13 posCursor:[11:13] posNoWhite:[11:12] Found expr:[11:3->11:13] Completable: Cpath Value[t2].n2.n->m +ContextPath Value[t2].n2.n->m +ContextPath Value[t2].n2.n +ContextPath Value[t2].n2 +ContextPath Value[t2] [{ "label": "Js.Array2.mapi", "kind": 12, @@ -36,6 +43,7 @@ Complete src/RecordCompletion.res 19:7 posCursor:[19:7] posNoWhite:[19:6] Found expr:[19:3->19:7] Pexp_field [19:3->19:4] R.:[19:5->19:7] Completable: Cpath Module[R]."" +ContextPath Module[R]."" [{ "label": "name", "kind": 5, @@ -48,6 +56,7 @@ Complete src/RecordCompletion.res 22:7 posCursor:[22:7] posNoWhite:[22:6] Found expr:[22:3->22:10] Pexp_field [22:3->22:4] R.xx:[22:5->22:10] Completable: Cpath Module[R]."" +ContextPath Module[R]."" [{ "label": "name", "kind": 5, diff --git a/analysis/tests/src/expected/RecoveryOnProp.res.txt b/analysis/tests/src/expected/RecoveryOnProp.res.txt index 950a49bfc..f842bcaf0 100644 --- a/analysis/tests/src/expected/RecoveryOnProp.res.txt +++ b/analysis/tests/src/expected/RecoveryOnProp.res.txt @@ -11,6 +11,7 @@ posCursor:[6:26] posNoWhite:[6:25] Found pattern:[6:20->8:5] posCursor:[6:26] posNoWhite:[6:25] Found type:[6:23->8:5] Ptyp_constr Res:[6:23->8:5] Completable: Cpath Type[Res] +ContextPath Type[Res] [{ "label": "RescriptReactErrorBoundary", "kind": 9, diff --git a/analysis/tests/src/expected/SignatureHelp.res.txt b/analysis/tests/src/expected/SignatureHelp.res.txt index 68f0517c7..4ef3351f0 100644 --- a/analysis/tests/src/expected/SignatureHelp.res.txt +++ b/analysis/tests/src/expected/SignatureHelp.res.txt @@ -4,6 +4,7 @@ Pexp_apply ...[16:11->16:19] (...[46:0->16:20]) posCursor:[16:19] posNoWhite:[16:18] Found expr:[16:11->16:19] Pexp_ident someFunc:[16:11->16:19] Completable: Cpath Value[someFunc] +ContextPath Value[someFunc] argAtCursor: unlabelled<0> extracted params: [( @@ -24,6 +25,7 @@ Pexp_apply ...[19:11->19:19] (...[19:20->19:21]) posCursor:[19:19] posNoWhite:[19:18] Found expr:[19:11->19:19] Pexp_ident someFunc:[19:11->19:19] Completable: Cpath Value[someFunc] +ContextPath Value[someFunc] argAtCursor: unlabelled<0> extracted params: [( @@ -44,6 +46,7 @@ Pexp_apply ...[22:11->22:19] (...[22:20->22:23], ~two22:26->22:29=...[22:26->22: posCursor:[22:19] posNoWhite:[22:18] Found expr:[22:11->22:19] Pexp_ident someFunc:[22:11->22:19] Completable: Cpath Value[someFunc] +ContextPath Value[someFunc] argAtCursor: ~two extracted params: [( @@ -64,6 +67,7 @@ Pexp_apply ...[25:11->25:19] (...[25:20->25:23], ~two25:26->25:29=...[25:30->25: posCursor:[25:19] posNoWhite:[25:18] Found expr:[25:11->25:19] Pexp_ident someFunc:[25:11->25:19] Completable: Cpath Value[someFunc] +ContextPath Value[someFunc] argAtCursor: ~two extracted params: [( @@ -84,6 +88,7 @@ Pexp_apply ...[28:11->28:19] (...[28:20->28:23], ~two28:26->28:29=...[28:30->28: posCursor:[28:19] posNoWhite:[28:18] Found expr:[28:11->28:19] Pexp_ident someFunc:[28:11->28:19] Completable: Cpath Value[someFunc] +ContextPath Value[someFunc] argAtCursor: ~four extracted params: [( @@ -104,6 +109,7 @@ Pexp_apply ...[31:11->31:19] (...[31:20->31:23], ~two31:26->31:29=...[31:30->31: posCursor:[31:19] posNoWhite:[31:18] Found expr:[31:11->31:19] Pexp_ident someFunc:[31:11->31:19] Completable: Cpath Value[someFunc] +ContextPath Value[someFunc] argAtCursor: ~four extracted params: [( @@ -124,6 +130,7 @@ Pexp_apply ...[34:11->34:20] (...[46:0->34:21]) posCursor:[34:20] posNoWhite:[34:19] Found expr:[34:11->34:20] Pexp_ident otherFunc:[34:11->34:20] Completable: Cpath Value[otherFunc] +ContextPath Value[otherFunc] argAtCursor: unlabelled<0> extracted params: [(string, int, float] @@ -142,6 +149,7 @@ Pexp_apply ...[37:11->37:20] (...[37:21->37:26]) posCursor:[37:20] posNoWhite:[37:19] Found expr:[37:11->37:20] Pexp_ident otherFunc:[37:11->37:20] Completable: Cpath Value[otherFunc] +ContextPath Value[otherFunc] argAtCursor: unlabelled<0> extracted params: [(string, int, float] @@ -160,6 +168,7 @@ Pexp_apply ...[40:11->40:20] (...[40:21->40:26], ...[40:28->40:31], ...[40:33->4 posCursor:[40:20] posNoWhite:[40:19] Found expr:[40:11->40:20] Pexp_ident otherFunc:[40:11->40:20] Completable: Cpath Value[otherFunc] +ContextPath Value[otherFunc] argAtCursor: unlabelled<2> extracted params: [(string, int, float] @@ -178,6 +187,7 @@ Pexp_apply ...[43:11->43:29] (~age43:31->43:34=...[43:31->43:34]) posCursor:[43:29] posNoWhite:[43:28] Found expr:[43:11->43:29] Pexp_ident Completion.Lib.foo:[43:11->43:29] Completable: Cpath Value[Completion, Lib, foo] +ContextPath Value[Completion, Lib, foo] argAtCursor: ~age extracted params: [(~age: int, ~name: string] @@ -196,6 +206,7 @@ Pexp_apply ...[50:11->50:23] (...[56:0->50:24]) posCursor:[50:23] posNoWhite:[50:22] Found expr:[50:11->50:23] Pexp_ident iAmSoSpecial:[50:11->50:23] Completable: Cpath Value[iAmSoSpecial] +ContextPath Value[iAmSoSpecial] argAtCursor: unlabelled<0> extracted params: [string] @@ -215,6 +226,7 @@ Pexp_apply ...[53:20->53:29] (...[53:30->53:31]) posCursor:[53:29] posNoWhite:[53:28] Found expr:[53:20->53:29] Pexp_ident otherFunc:[53:20->53:29] Completable: Cpath Value[otherFunc] +ContextPath Value[otherFunc] argAtCursor: unlabelled<1> extracted params: [(string, int, float] @@ -233,6 +245,7 @@ Pexp_apply ...[62:11->62:13] (...[62:14->62:16]) posCursor:[62:13] posNoWhite:[62:12] Found expr:[62:11->62:13] Pexp_ident fn:[62:11->62:13] Completable: Cpath Value[fn] +ContextPath Value[fn] argAtCursor: unlabelled<1> extracted params: [(int, string, int] @@ -251,6 +264,7 @@ Pexp_apply ...[65:11->65:13] (...[65:14->65:16], ...[65:20->65:24]) posCursor:[65:13] posNoWhite:[65:12] Found expr:[65:11->65:13] Pexp_ident fn:[65:11->65:13] Completable: Cpath Value[fn] +ContextPath Value[fn] argAtCursor: unlabelled<1> extracted params: [(int, string, int] @@ -269,6 +283,7 @@ Pexp_apply ...[68:11->68:13] (...[68:14->68:16], ...[68:18->68:25]) posCursor:[68:13] posNoWhite:[68:12] Found expr:[68:11->68:13] Pexp_ident fn:[68:11->68:13] Completable: Cpath Value[fn] +ContextPath Value[fn] argAtCursor: unlabelled<2> extracted params: [(int, string, int] @@ -289,6 +304,7 @@ Pexp_apply ...[71:16->71:28] (...[71:29->71:30]) posCursor:[71:28] posNoWhite:[71:27] Found expr:[71:16->71:28] Pexp_ident iAmSoSpecial:[71:16->71:28] Completable: Cpath Value[iAmSoSpecial] +ContextPath Value[iAmSoSpecial] argAtCursor: unlabelled<0> extracted params: [string] @@ -311,6 +327,7 @@ Pexp_apply ...[74:31->74:39] (...[74:40->74:41]) posCursor:[74:39] posNoWhite:[74:38] Found expr:[74:31->74:39] Pexp_ident someFunc:[74:31->74:39] Completable: Cpath Value[someFunc] +ContextPath Value[someFunc] argAtCursor: unlabelled<0> extracted params: [( From 707ab5ab505f68b40e67d5241105dcd81c11628b Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Tue, 7 Mar 2023 11:19:42 +0100 Subject: [PATCH 33/41] Print Path --- analysis/src/CompletionBackEnd.ml | 19 ++-- .../src/expected/BrokenParserCases.res.txt | 3 + .../src/expected/CompletePrioritize1.res.txt | 2 + .../src/expected/CompletePrioritize2.res.txt | 3 + .../tests/src/expected/Completion.res.txt | 86 +++++++++++++++++ .../expected/CompletionExpressions.res.txt | 38 ++++++++ .../CompletionFunctionArguments.res.txt | 18 ++++ .../expected/CompletionInferValues.res.txt | 93 +++++++++++++++++++ .../tests/src/expected/CompletionJsx.res.txt | 15 +++ .../src/expected/CompletionJsxProps.res.txt | 11 +++ .../src/expected/CompletionPattern.res.txt | 47 ++++++++++ .../src/expected/CompletionPipeChain.res.txt | 27 ++++++ .../expected/CompletionPipeSubmodules.res.txt | 8 ++ .../expected/CompletionTypeAnnotation.res.txt | 15 +++ analysis/tests/src/expected/Cross.res.txt | 1 + analysis/tests/src/expected/Debug.res.txt | 1 + .../tests/src/expected/Destructuring.res.txt | 5 + .../src/expected/ExhaustiveSwitch.res.txt | 4 + analysis/tests/src/expected/Hover.res.txt | 6 ++ analysis/tests/src/expected/Jsx2.res.txt | 32 +++++++ analysis/tests/src/expected/Jsx2.resi.txt | 2 + analysis/tests/src/expected/JsxV4.res.txt | 1 + .../src/expected/RecordCompletion.res.txt | 6 ++ .../tests/src/expected/RecoveryOnProp.res.txt | 1 + .../tests/src/expected/SignatureHelp.res.txt | 17 ++++ 25 files changed, 452 insertions(+), 9 deletions(-) diff --git a/analysis/src/CompletionBackEnd.ml b/analysis/src/CompletionBackEnd.ml index cb87ed694..e9d55cb62 100644 --- a/analysis/src/CompletionBackEnd.ml +++ b/analysis/src/CompletionBackEnd.ml @@ -510,8 +510,9 @@ let getComplementaryCompletionsForTypedValue ~opens ~allFiles ~scope ~env prefix in localCompletionsWithOpens @ fileModules -let getCompletionsForPath ~package ~opens ~allFiles ~pos ~exact ~scope +let getCompletionsForPath ~debug ~package ~opens ~allFiles ~pos ~exact ~scope ~completionContext ~env path = + if debug then Printf.printf "Path %s\n" (path |> String.concat "."); match path with | [] -> [] | [prefix] -> @@ -737,7 +738,7 @@ and getCompletionsForContextPath ~debug ~full ~opens ~rawOpens ~allFiles ~pos ]) | CPId (path, completionContext) -> path - |> getCompletionsForPath ~package ~opens ~allFiles ~pos ~exact + |> getCompletionsForPath ~debug ~package ~opens ~allFiles ~pos ~exact ~completionContext ~env ~scope | CPApply (cp, labels) -> ( match @@ -784,7 +785,7 @@ and getCompletionsForContextPath ~debug ~full ~opens ~rawOpens ~allFiles ~pos | CPField (CPId (path, Module), fieldName) -> (* M.field *) path @ [fieldName] - |> getCompletionsForPath ~package ~opens ~allFiles ~pos ~exact + |> getCompletionsForPath ~debug ~package ~opens ~allFiles ~pos ~exact ~completionContext:Field ~env ~scope | CPField (cp, fieldName) -> ( let completionsForCtxPath = @@ -952,7 +953,7 @@ and getCompletionsForContextPath ~debug ~full ~opens ~rawOpens ~allFiles ~pos in let completions = completionPath @ [funNamePrefix] - |> getCompletionsForPath ~completionContext:Value ~exact:false + |> getCompletionsForPath ~debug ~completionContext:Value ~exact:false ~package ~opens ~allFiles ~pos ~env ~scope in let completions = @@ -1016,8 +1017,8 @@ and getCompletionsForContextPath ~debug ~full ~opens ~rawOpens ~allFiles ~pos | CJsxPropValue {pathToComponent; propName} -> ( let findTypeOfValue path = path - |> getCompletionsForPath ~completionContext:Value ~exact:true ~package - ~opens ~allFiles ~pos ~env ~scope + |> getCompletionsForPath ~debug ~completionContext:Value ~exact:true + ~package ~opens ~allFiles ~pos ~env ~scope |> completionsGetTypeEnv2 ~debug ~full ~opens ~rawOpens ~allFiles ~pos ~scope in @@ -1031,7 +1032,7 @@ and getCompletionsForContextPath ~debug ~full ~opens ~rawOpens ~allFiles ~pos let rec digToTypeForCompletion path = match path - |> getCompletionsForPath ~completionContext:Type ~exact:true + |> getCompletionsForPath ~debug ~completionContext:Type ~exact:true ~package ~opens ~allFiles ~pos ~env ~scope with | {kind = Type {kind = Abstract (Some (p, _))}} :: _ -> @@ -1412,8 +1413,8 @@ let rec processCompletable ~debug ~full ~scope ~env ~pos ~forHover completable = let allFiles = FileSet.union package.projectFiles package.dependenciesFiles in let findTypeOfValue path = path - |> getCompletionsForPath ~completionContext:Value ~exact:true ~package - ~opens ~allFiles ~pos ~env ~scope + |> getCompletionsForPath ~debug ~completionContext:Value ~exact:true + ~package ~opens ~allFiles ~pos ~env ~scope |> completionsGetTypeEnv2 ~debug ~full ~opens ~rawOpens ~allFiles ~pos ~scope in diff --git a/analysis/tests/src/expected/BrokenParserCases.res.txt b/analysis/tests/src/expected/BrokenParserCases.res.txt index 95cc1ee06..0c558e994 100644 --- a/analysis/tests/src/expected/BrokenParserCases.res.txt +++ b/analysis/tests/src/expected/BrokenParserCases.res.txt @@ -3,12 +3,14 @@ posCursor:[2:24] posNoWhite:[2:23] Found expr:[2:11->2:30] Pexp_apply ...[2:11->2:17] (~isOff2:19->2:24=...[2:27->2:29]) Completable: CnamedArg(Value[someFn], isOff, [isOff]) ContextPath Value[someFn] +Path someFn [] Complete src/BrokenParserCases.res 6:17 posCursor:[6:17] posNoWhite:[6:16] Found pattern:[6:16->6:19] Completable: Cpattern Value[s]=t ContextPath Value[s] +Path s [] Complete src/BrokenParserCases.res 10:29 @@ -17,5 +19,6 @@ posCursor:[10:29] posNoWhite:[10:27] Found pattern:[10:24->10:28] Ppat_construct None:[10:24->10:28] Completable: Cpath Value[None] ContextPath Value[None] +Path None [] diff --git a/analysis/tests/src/expected/CompletePrioritize1.res.txt b/analysis/tests/src/expected/CompletePrioritize1.res.txt index d3c9f64e3..db189dc9c 100644 --- a/analysis/tests/src/expected/CompletePrioritize1.res.txt +++ b/analysis/tests/src/expected/CompletePrioritize1.res.txt @@ -3,6 +3,8 @@ posCursor:[5:6] posNoWhite:[5:5] Found expr:[5:3->0:-1] Completable: Cpath Value[a]-> ContextPath Value[a]-> ContextPath Value[a] +Path a +Path Test. [{ "label": "Test.add", "kind": 12, diff --git a/analysis/tests/src/expected/CompletePrioritize2.res.txt b/analysis/tests/src/expected/CompletePrioritize2.res.txt index 22b39c086..b6b949e13 100644 --- a/analysis/tests/src/expected/CompletePrioritize2.res.txt +++ b/analysis/tests/src/expected/CompletePrioritize2.res.txt @@ -3,6 +3,8 @@ posCursor:[9:7] posNoWhite:[9:6] Found expr:[9:3->0:-1] Completable: Cpath Value[ax]-> ContextPath Value[ax]-> ContextPath Value[ax] +Path ax +Path Test. [{ "label": "Test.add", "kind": 12, @@ -16,6 +18,7 @@ posCursor:[12:5] posNoWhite:[12:4] Found expr:[12:3->12:5] Pexp_ident ax:[12:3->12:5] Completable: Cpath Value[ax] ContextPath Value[ax] +Path ax [{ "label": "ax", "kind": 12, diff --git a/analysis/tests/src/expected/Completion.res.txt b/analysis/tests/src/expected/Completion.res.txt index 744b9ad22..19372b06e 100644 --- a/analysis/tests/src/expected/Completion.res.txt +++ b/analysis/tests/src/expected/Completion.res.txt @@ -3,6 +3,7 @@ posCursor:[1:11] posNoWhite:[1:10] Found expr:[1:3->1:11] Pexp_ident MyList.m:[1:3->1:11] Completable: Cpath Value[MyList, m] ContextPath Value[MyList, m] +Path MyList.m [{ "label": "mapReverse", "kind": 12, @@ -76,6 +77,7 @@ posCursor:[3:9] posNoWhite:[3:8] Found expr:[3:3->3:9] Pexp_ident Array.:[3:3->3:9] Completable: Cpath Value[Array, ""] ContextPath Value[Array, ""] +Path Array. [{ "label": "fold_left", "kind": 12, @@ -299,6 +301,7 @@ posCursor:[5:10] posNoWhite:[5:9] Found expr:[5:3->5:10] Pexp_ident Array.m:[5:3->5:10] Completable: Cpath Value[Array, m] ContextPath Value[Array, m] +Path Array.m [{ "label": "mapi", "kind": 12, @@ -354,6 +357,7 @@ posCursor:[15:17] posNoWhite:[15:16] Found expr:[15:12->15:17] Pexp_ident Dep.c:[15:12->15:17] Completable: Cpath Value[Dep, c] ContextPath Value[Dep, c] +Path Dep.c [{ "label": "customDouble", "kind": 12, @@ -367,6 +371,7 @@ posCursor:[23:20] posNoWhite:[23:19] Found expr:[23:11->23:20] Pexp_apply ...[23:11->23:18] () Completable: CnamedArg(Value[Lib, foo], "", []) ContextPath Value[Lib, foo] +Path Lib.foo Found type for function (~age: int, ~name: string) => string [{ "label": "age", @@ -387,6 +392,7 @@ posCursor:[26:13] posNoWhite:[26:12] Found expr:[26:3->26:13] Completable: Cpath array->m ContextPath array->m ContextPath array +Path Js.Array2.m [{ "label": "Js.Array2.mapi", "kind": 12, @@ -406,6 +412,7 @@ posCursor:[29:13] posNoWhite:[29:12] Found expr:[29:3->29:13] Completable: Cpath string->toU ContextPath string->toU ContextPath string +Path Js.String2.toU [{ "label": "Js.String2.toUpperCase", "kind": 12, @@ -419,6 +426,8 @@ posCursor:[34:8] posNoWhite:[34:7] Found expr:[34:3->34:8] Completable: Cpath Value[op]->e ContextPath Value[op]->e ContextPath Value[op] +Path op +Path Belt.Option.e [{ "label": "Belt.Option.eqU", "kind": 12, @@ -440,6 +449,8 @@ posCursor:[44:7] posNoWhite:[44:6] Found expr:[44:3->50:8] Completable: Cpath Value[fa]-> ContextPath Value[fa]-> ContextPath Value[fa] +Path fa +Path ForAuto. [{ "label": "ForAuto.abc", "kind": 12, @@ -460,6 +471,7 @@ posCursor:[47:21] posNoWhite:[47:20] Found expr:[47:12->47:21] Pexp_ident Js.Dict.u:[47:12->47:21] Completable: Cpath Value[Js, Dict, u] ContextPath Value[Js, Dict, u] +Path Js.Dict.u [{ "label": "unsafeGet", "kind": 12, @@ -479,6 +491,7 @@ posCursor:[59:30] posNoWhite:[59:29] Found expr:[59:15->59:30] JSX 59:21] second[59:22->59:28]=...[59:29->59:30]> _children:None Completable: Cexpression CJsxPropValue [O, Comp] second=z ContextPath CJsxPropValue [O, Comp] second +Path O.Comp.make [{ "label": "zzz", "kind": 12, @@ -491,6 +504,7 @@ Complete src/Completion.res 62:23 posCursor:[62:23] posNoWhite:[62:22] Found expr:[62:15->62:23] JSX 62:21] z[62:22->62:23]=...[62:22->62:23]> _children:None Completable: Cjsx([O, Comp], z, [z]) +Path O.Comp.make [{ "label": "zoo", "kind": 4, @@ -528,6 +542,7 @@ posCursor:[71:27] posNoWhite:[71:26] Found expr:[71:11->71:27] Pexp_apply ...[71:11->71:18] (~name71:20->71:24=...[71:20->71:24]) Completable: CnamedArg(Value[Lib, foo], "", [name]) ContextPath Value[Lib, foo] +Path Lib.foo Found type for function (~age: int, ~name: string) => string [{ "label": "age", @@ -542,6 +557,7 @@ posCursor:[74:26] posNoWhite:[74:25] Found expr:[74:11->74:26] Pexp_apply ...[74:11->74:18] (~age74:20->74:23=...[74:20->74:23]) Completable: CnamedArg(Value[Lib, foo], "", [age]) ContextPath Value[Lib, foo] +Path Lib.foo Found type for function (~age: int, ~name: string) => string [{ "label": "name", @@ -556,6 +572,7 @@ posCursor:[77:32] posNoWhite:[77:31] Found expr:[77:11->77:32] Pexp_apply ...[77:11->77:18] (~age77:20->77:23=...[77:25->77:28]) Completable: CnamedArg(Value[Lib, foo], "", [age]) ContextPath Value[Lib, foo] +Path Lib.foo Found type for function (~age: int, ~name: string) => string [{ "label": "name", @@ -570,6 +587,7 @@ posCursor:[82:5] posNoWhite:[82:4] Found expr:[80:8->86:1] Pexp_apply ...[80:8->80:15] (~age84:3->84:6=...[84:7->84:8], ~name85:3->85:7=...[85:8->85:10]) Completable: CnamedArg(Value[Lib, foo], "", [age, name]) ContextPath Value[Lib, foo] +Path Lib.foo Found type for function (~age: int, ~name: string) => string [] @@ -579,6 +597,7 @@ Pexp_send a[90:12->90:13] e:[90:3->90:10] Completable: Cpath Value[someObj]["a"] ContextPath Value[someObj]["a"] ContextPath Value[someObj] +Path someObj [{ "label": "age", "kind": 4, @@ -595,6 +614,7 @@ ContextPath Value[nestedObj]["x"]["y"][""] ContextPath Value[nestedObj]["x"]["y"] ContextPath Value[nestedObj]["x"] ContextPath Value[nestedObj] +Path nestedObj [{ "label": "age", "kind": 4, @@ -615,6 +635,7 @@ Pexp_send a[99:6->99:7] e:[99:3->99:4] Completable: Cpath Value[o]["a"] ContextPath Value[o]["a"] ContextPath Value[o] +Path o [{ "label": "age", "kind": 4, @@ -631,6 +652,7 @@ ContextPath Value[no]["x"]["y"][""] ContextPath Value[no]["x"]["y"] ContextPath Value[no]["x"] ContextPath Value[no] +Path no [{ "label": "name", "kind": 4, @@ -651,6 +673,7 @@ Pexp_field [110:3->110:4] _:[116:0->110:5] Completable: Cpath Value[r]."" ContextPath Value[r]."" ContextPath Value[r] +Path r [{ "label": "x", "kind": 5, @@ -671,6 +694,7 @@ Pexp_field [113:3->113:23] _:[116:0->113:24] Completable: Cpath Value[Object, Rec, recordVal]."" ContextPath Value[Object, Rec, recordVal]."" ContextPath Value[Object, Rec, recordVal] +Path Object.Rec.recordVal [{ "label": "xx", "kind": 5, @@ -692,6 +716,7 @@ posCursor:[120:7] posNoWhite:[120:6] Found expr:[120:5->120:7] Pexp_ident my:[120:5->120:7] Completable: Cpath Value[my] ContextPath Value[my] +Path my [{ "label": "myAmazingFunction", "kind": 12, @@ -706,6 +731,7 @@ Pexp_send [125:18->125:18] e:[125:3->125:16] Completable: Cpath Value[Object, object][""] ContextPath Value[Object, object][""] ContextPath Value[Object, object] +Path Object.object [{ "label": "name", "kind": 4, @@ -725,6 +751,7 @@ posCursor:[151:6] posNoWhite:[151:5] Found expr:[151:4->151:6] JSX 151:6] > _children:None Completable: Cpath Module[O, ""] ContextPath Module[O, ""] +Path O. [{ "label": "Comp", "kind": 9, @@ -740,6 +767,7 @@ Completable: Cpath Value[q].aa."" ContextPath Value[q].aa."" ContextPath Value[q].aa ContextPath Value[q] +Path q [{ "label": "x", "kind": 5, @@ -761,6 +789,7 @@ Completable: Cpath Value[q].aa.n ContextPath Value[q].aa.n ContextPath Value[q].aa ContextPath Value[q] +Path q [{ "label": "name", "kind": 5, @@ -774,6 +803,7 @@ posCursor:[162:6] posNoWhite:[162:5] Found expr:[162:3->162:6] Pexp_construct Lis:[162:3->162:6] None Completable: Cpath Value[Lis] ContextPath Value[Lis] +Path Lis [{ "label": "List", "kind": 9, @@ -793,6 +823,7 @@ posCursor:[169:16] posNoWhite:[169:15] Found expr:[169:4->169:16] JSX 169:16] > _children:None Completable: Cpath Module[WithChildren] ContextPath Module[WithChildren] +Path WithChildren [{ "label": "WithChildren", "kind": 9, @@ -806,6 +837,7 @@ posCursor:[172:16] posNoWhite:[172:15] Found type:[172:12->172:16] Ptyp_constr Js.n:[172:12->172:16] Completable: Cpath Type[Js, n] ContextPath Type[Js, n] +Path Js.n [{ "label": "null_undefined", "kind": 22, @@ -831,6 +863,7 @@ posCursor:[174:20] posNoWhite:[174:19] Found type:[174:12->174:20] Ptyp_constr ForAuto.:[174:12->174:20] Completable: Cpath Type[ForAuto, ""] ContextPath Type[ForAuto, ""] +Path ForAuto. [{ "label": "t", "kind": 22, @@ -844,6 +877,7 @@ posCursor:[179:13] posNoWhite:[179:12] Found expr:[179:11->179:13] Pexp_construct As:[179:11->179:13] None Completable: Cpath Value[As] ContextPath Value[As] +Path As [{ "label": "Asterix", "kind": 4, @@ -856,6 +890,7 @@ Complete src/Completion.res 182:17 Pmod_ident For:[182:14->182:17] Completable: Cpath Module[For] ContextPath Module[For] +Path For [{ "label": "ForAuto", "kind": 9, @@ -869,6 +904,7 @@ posCursor:[190:11] posNoWhite:[190:10] Found expr:[190:3->190:11] Pexp_ident Private.:[190:3->190:11] Completable: Cpath Value[Private, ""] ContextPath Value[Private, ""] +Path Private. [{ "label": "b", "kind": 12, @@ -882,6 +918,7 @@ posCursor:[202:6] posNoWhite:[202:5] Found expr:[202:3->202:6] Pexp_ident sha:[202:3->202:6] Completable: Cpath Value[sha] ContextPath Value[sha] +Path sha [] Complete src/Completion.res 205:6 @@ -891,6 +928,7 @@ Completable: Cpath Value[sha] Raw opens: 1 Shadow.A.place holder Resolved opens 1 Completion.res ContextPath Value[sha] +Path sha [{ "label": "shadowed", "kind": 12, @@ -906,6 +944,7 @@ Completable: Cpath Value[sha] Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder Resolved opens 2 Completion.res Completion.res ContextPath Value[sha] +Path sha [{ "label": "shadowed", "kind": 12, @@ -922,6 +961,7 @@ Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder Resolved opens 2 Completion.res Completion.res ContextPath Value[FAO, forAutoObject][""] ContextPath Value[FAO, forAutoObject] +Path FAO.forAutoObject [{ "label": "age", "kind": 4, @@ -945,6 +985,7 @@ Resolved opens 2 Completion.res Completion.res ContextPath Value[FAO, forAutoObject]["forAutoLabel"]."" ContextPath Value[FAO, forAutoObject]["forAutoLabel"] ContextPath Value[FAO, forAutoObject] +Path FAO.forAutoObject [{ "label": "forAuto", "kind": 5, @@ -968,6 +1009,8 @@ ContextPath Value[FAO, forAutoObject]["forAutoLabel"].forAuto-> ContextPath Value[FAO, forAutoObject]["forAutoLabel"].forAuto ContextPath Value[FAO, forAutoObject]["forAutoLabel"] ContextPath Value[FAO, forAutoObject] +Path FAO.forAutoObject +Path ForAuto. [{ "label": "ForAuto.abc", "kind": 12, @@ -990,6 +1033,7 @@ Completable: Cpath Value[ForAuto, a] Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder Resolved opens 2 Completion.res Completion.res ContextPath Value[ForAuto, a] +Path ForAuto.a [{ "label": "abc", "kind": 12, @@ -1015,6 +1059,7 @@ Completable: Cpath Value[na] Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder Resolved opens 2 Completion.res Completion.res ContextPath Value[na] +Path na [{ "label": "name", "kind": 12, @@ -1040,6 +1085,7 @@ Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder Resolved opens 2 Completion.res Completion.res ContextPath Value[_z]."" ContextPath Value[_z] +Path _z [{ "label": "x", "kind": 5, @@ -1061,6 +1107,7 @@ Completable: Cpath Value[SomeLo] Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder Resolved opens 2 Completion.res Completion.res ContextPath Value[SomeLo] +Path SomeLo [{ "label": "SomeLocalModule", "kind": 9, @@ -1076,6 +1123,7 @@ Completable: Cpath Type[SomeLocalModule, ""] Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder Resolved opens 2 Completion.res Completion.res ContextPath Type[SomeLocalModule, ""] +Path SomeLocalModule. [{ "label": "zz", "kind": 22, @@ -1091,6 +1139,7 @@ Completable: Cpath Type[SomeLocalModule, ""] Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder Resolved opens 2 Completion.res Completion.res ContextPath Type[SomeLocalModule, ""] +Path SomeLocalModule. [{ "label": "zz", "kind": 22, @@ -1105,6 +1154,7 @@ Completable: Cpath Value[SomeLocal] Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder Resolved opens 2 Completion.res Completion.res ContextPath Value[SomeLocal] +Path SomeLocal [{ "label": "SomeLocalVariantItem", "kind": 4, @@ -1127,6 +1177,7 @@ Completable: Cpath Type[SomeLocal] Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder Resolved opens 2 Completion.res Completion.res ContextPath Type[SomeLocal] +Path SomeLocal [{ "label": "SomeLocalModule", "kind": 9, @@ -1144,6 +1195,7 @@ Completable: Cpath Value[_w] Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder Resolved opens 2 Completion.res Completion.res ContextPath Value[_w] +Path _w [{ "label": "_world", "kind": 12, @@ -1159,6 +1211,7 @@ Completable: Cpath Type[s] Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder Resolved opens 2 Completion.res Completion.res ContextPath Type[s] +Path s [{ "label": "someType", "kind": 22, @@ -1181,6 +1234,7 @@ Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder Resolved opens 2 Completion.res Completion.res ContextPath Value[funRecord].someFun ContextPath Value[funRecord] +Path funRecord Found type for function (~name: string) => unit [{ "label": "name", @@ -1199,6 +1253,7 @@ Resolved opens 2 Completion.res Completion.res ContextPath Value[retAA](Nolabel)."" ContextPath Value[retAA](Nolabel) ContextPath Value[retAA] +Path retAA [{ "label": "x", "kind": 5, @@ -1221,6 +1276,7 @@ Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder Resolved opens 2 Completion.res Completion.res ContextPath Value[ff](~c) ContextPath Value[ff] +Path ff Found type for function ( ~opt1: int=?, ~a: int, @@ -1264,6 +1320,7 @@ Resolved opens 2 Completion.res Completion.res ContextPath Value[ff](~c)(Nolabel) ContextPath Value[ff](~c) ContextPath Value[ff] +Path ff Found type for function (~a: int, ~b: int, ~opt2: int=?, unit) => int [{ "label": "a", @@ -1293,6 +1350,7 @@ Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder Resolved opens 2 Completion.res Completion.res ContextPath Value[ff](~c, Nolabel) ContextPath Value[ff] +Path ff Found type for function (~a: int, ~b: int, ~opt2: int=?, unit) => int [{ "label": "a", @@ -1322,6 +1380,7 @@ Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder Resolved opens 2 Completion.res Completion.res ContextPath Value[ff](~c, Nolabel, Nolabel) ContextPath Value[ff] +Path ff Found type for function (~a: int, ~b: int) => int [{ "label": "a", @@ -1345,6 +1404,7 @@ Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder Resolved opens 2 Completion.res Completion.res ContextPath Value[ff](~c, Nolabel, ~b) ContextPath Value[ff] +Path ff Found type for function (~a: int, ~opt2: int=?, unit) => int [{ "label": "a", @@ -1368,6 +1428,7 @@ Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder Resolved opens 2 Completion.res Completion.res ContextPath Value[ff](~opt2) ContextPath Value[ff] +Path ff Found type for function (~opt1: int=?, ~a: int, ~b: int, unit, unit, ~c: int) => int [{ "label": "opt1", @@ -1402,6 +1463,7 @@ Completable: CnamedArg(Value[withCallback], "", []) Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder Resolved opens 2 Completion.res Completion.res ContextPath Value[withCallback] +Path withCallback Found type for function (~b: int) => callback [{ "label": "b", @@ -1425,6 +1487,7 @@ Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder Resolved opens 2 Completion.res Completion.res ContextPath Value[withCallback](~a) ContextPath Value[withCallback] +Path withCallback Found type for function (~b: int) => int [{ "label": "b", @@ -1442,6 +1505,7 @@ Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder Resolved opens 2 Completion.res Completion.res ContextPath Value[withCallback](~b) ContextPath Value[withCallback] +Path withCallback Found type for function (~a: int) => int [{ "label": "a", @@ -1468,6 +1532,7 @@ Completable: Cpath Type[Res] Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder Resolved opens 2 Completion.res Completion.res ContextPath Type[Res] +Path Res [{ "label": "RescriptReactErrorBoundary", "kind": 9, @@ -1490,6 +1555,7 @@ Completable: Cpath Value[this] Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder Resolved opens 2 Completion.res Completion.res ContextPath Value[this] +Path this [{ "label": "thisIsNotSaved", "kind": 12, @@ -1517,6 +1583,7 @@ Completable: Cpath Value[FAO, forAutoObject] Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder Resolved opens 2 Completion.res Completion.res ContextPath Value[FAO, forAutoObject] +Path FAO.forAutoObject {"contents": {"kind": "markdown", "value": "```rescript\n{\"age\": int, \"forAutoLabel\": FAR.forAutoRecord}\n```"}} Hover src/Completion.res 352:17 @@ -1527,6 +1594,7 @@ Completable: CnamedArg(Value[ff], opt1, [opt1]) Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder Resolved opens 2 Completion.res Completion.res ContextPath Value[ff] +Path ff Found type for function ( ~opt1: int=?, ~a: int, @@ -1552,10 +1620,12 @@ Completable: Cpattern Value[x]=T Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder Resolved opens 2 Completion.res Completion.res ContextPath Value[x] +Path x Completable: Cpath Value[T] Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder Resolved opens 2 Completion.res Completion.res ContextPath Value[T] +Path T [{ "label": "That", "kind": 4, @@ -1591,6 +1661,7 @@ Completable: Cpath Value[AndThatOther, T] Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder Resolved opens 2 Completion.res Completion.res ContextPath Value[AndThatOther, T] +Path AndThatOther.T [{ "label": "ThatOther", "kind": 4, @@ -1610,6 +1681,7 @@ Completable: Cpath Value[ForAuto, ""] Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder Resolved opens 2 Completion.res Completion.res ContextPath Value[ForAuto, ""] +Path ForAuto. [{ "label": "abc", "kind": 12, @@ -1636,6 +1708,7 @@ Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder Resolved opens 2 Completion.res Completion.res ContextPath Value[FAO, forAutoObject][""] ContextPath Value[FAO, forAutoObject] +Path FAO.forAutoObject [{ "label": "age", "kind": 4, @@ -1662,6 +1735,7 @@ Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder Resolved opens 2 Completion.res Completion.res ContextPath Value[funRecord]."" ContextPath Value[funRecord] +Path funRecord [{ "label": "someFun", "kind": 5, @@ -1686,6 +1760,7 @@ Raw opens: 3 Js.place holder ... Shadow.B.place holder ... Shadow.A.place holder Resolved opens 3 Completion.res Completion.res js.ml ContextPath array->ma ContextPath array +Path Js.Array2.ma [{ "label": "Array2.mapi", "kind": 12, @@ -1711,6 +1786,7 @@ Completable: Cpath Value[red] Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder Resolved opens 2 Completion.res Completion.res ContextPath Value[red] +Path red [{ "label": "red", "kind": 12, @@ -1730,6 +1806,7 @@ Completable: Cpath Value[red] Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder Resolved opens 2 Completion.res Completion.res ContextPath Value[red] +Path red [{ "label": "red", "kind": 12, @@ -1750,6 +1827,7 @@ Completable: Cpath Value[r] Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder Resolved opens 2 Completion.res Completion.res ContextPath Value[r] +Path r [{ "label": "red", "kind": 12, @@ -1780,6 +1858,7 @@ Completable: Cpath Value[SomeLocalModule, ""] Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder Resolved opens 2 Completion.res Completion.res ContextPath Value[SomeLocalModule, ""] +Path SomeLocalModule. [{ "label": "bb", "kind": 12, @@ -1805,6 +1884,7 @@ Completable: Cpath Value[SomeLocalModule, ""] Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder Resolved opens 2 Completion.res Completion.res ContextPath Value[SomeLocalModule, ""] +Path SomeLocalModule. [{ "label": "bb", "kind": 12, @@ -1826,6 +1906,7 @@ Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder Resolved opens 2 Completion.res Completion.res ContextPath int->t ContextPath int +Path Belt.Int.t [{ "label": "Belt.Int.toString", "kind": 12, @@ -1847,6 +1928,7 @@ Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder Resolved opens 2 Completion.res Completion.res ContextPath float->t ContextPath float +Path Belt.Float.t [{ "label": "Belt.Float.toInt", "kind": 12, @@ -1868,6 +1950,8 @@ Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder Resolved opens 2 Completion.res Completion.res ContextPath Value[ok]->g ContextPath Value[ok] +Path ok +Path Belt.Result.g [{ "label": "Belt.Result.getExn", "kind": 12, @@ -1890,6 +1974,7 @@ Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder Resolved opens 2 Completion.res Completion.res ContextPath Value[rWithDepr].so ContextPath Value[rWithDepr] +Path rWithDepr [{ "label": "someInt", "kind": 5, @@ -1910,6 +1995,7 @@ Completable: Cexpression Type[someVariantWithDeprecated] Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder Resolved opens 2 Completion.res Completion.res ContextPath Type[someVariantWithDeprecated] +Path someVariantWithDeprecated [{ "label": "DoNotUseMe", "kind": 4, diff --git a/analysis/tests/src/expected/CompletionExpressions.res.txt b/analysis/tests/src/expected/CompletionExpressions.res.txt index fd3c06a8f..104a6b663 100644 --- a/analysis/tests/src/expected/CompletionExpressions.res.txt +++ b/analysis/tests/src/expected/CompletionExpressions.res.txt @@ -3,7 +3,9 @@ XXX Not found! Completable: Cpattern CTuple(Value[s], Value[f]) ContextPath CTuple(Value[s], Value[f]) ContextPath Value[s] +Path s ContextPath Value[f] +Path f [{ "label": "(_, _)", "kind": 12, @@ -20,6 +22,7 @@ Pexp_apply ...[26:11->26:25] (...[26:26->26:28]) Completable: Cexpression CArgument Value[fnTakingRecord]($0)->recordBody ContextPath CArgument Value[fnTakingRecord]($0) ContextPath Value[fnTakingRecord] +Path fnTakingRecord [{ "label": "age", "kind": 5, @@ -64,6 +67,7 @@ Pexp_apply ...[29:11->29:25] (...[29:27->29:28]) Completable: Cexpression CArgument Value[fnTakingRecord]($0)=n->recordBody ContextPath CArgument Value[fnTakingRecord]($0) ContextPath Value[fnTakingRecord] +Path fnTakingRecord [{ "label": "nested", "kind": 5, @@ -78,6 +82,7 @@ Pexp_apply ...[32:11->32:25] (...[32:26->32:38]) Completable: Cexpression CArgument Value[fnTakingRecord]($0)->recordField(offline) ContextPath CArgument Value[fnTakingRecord]($0) ContextPath Value[fnTakingRecord] +Path fnTakingRecord [{ "label": "true", "kind": 4, @@ -98,6 +103,7 @@ Pexp_apply ...[35:11->35:25] (...[35:26->35:38]) Completable: Cexpression CArgument Value[fnTakingRecord]($0)->recordBody ContextPath CArgument Value[fnTakingRecord]($0) ContextPath Value[fnTakingRecord] +Path fnTakingRecord [{ "label": "offline", "kind": 5, @@ -136,6 +142,7 @@ Pexp_apply ...[38:11->38:25] (...[38:26->38:52]) Completable: Cexpression CArgument Value[fnTakingRecord]($0)->recordBody ContextPath CArgument Value[fnTakingRecord]($0) ContextPath Value[fnTakingRecord] +Path fnTakingRecord [{ "label": "online", "kind": 5, @@ -168,6 +175,7 @@ Pexp_apply ...[41:11->41:25] (...[41:26->41:47]) Completable: Cexpression CArgument Value[fnTakingRecord]($0)->recordField(nested) ContextPath CArgument Value[fnTakingRecord]($0) ContextPath Value[fnTakingRecord] +Path fnTakingRecord [{ "label": "None", "kind": 12, @@ -198,6 +206,7 @@ Pexp_apply ...[44:11->44:25] (...[44:26->44:48]) Completable: Cexpression CArgument Value[fnTakingRecord]($0)->recordField(nested), recordBody ContextPath CArgument Value[fnTakingRecord]($0) ContextPath Value[fnTakingRecord] +Path fnTakingRecord [] Complete src/CompletionExpressions.res 47:51 @@ -206,6 +215,7 @@ Pexp_apply ...[47:11->47:25] (...[47:26->47:54]) Completable: Cexpression CArgument Value[fnTakingRecord]($0)->recordField(nested), variantPayload::Some($0), recordBody ContextPath CArgument Value[fnTakingRecord]($0) ContextPath Value[fnTakingRecord] +Path fnTakingRecord [{ "label": "someField", "kind": 5, @@ -226,6 +236,7 @@ Pexp_apply ...[50:11->50:25] (...[50:26->50:48]) Completable: Cexpression CArgument Value[fnTakingRecord]($0)->recordField(variant) ContextPath CArgument Value[fnTakingRecord]($0) ContextPath Value[fnTakingRecord] +Path fnTakingRecord [{ "label": "One", "kind": 4, @@ -258,6 +269,7 @@ Pexp_apply ...[53:11->53:25] (...[53:26->53:49]) Completable: Cexpression CArgument Value[fnTakingRecord]($0)=O->recordField(variant) ContextPath CArgument Value[fnTakingRecord]($0) ContextPath Value[fnTakingRecord] +Path fnTakingRecord [{ "label": "One", "kind": 4, @@ -287,6 +299,7 @@ Pexp_apply ...[56:11->56:25] (...[56:26->56:60]) Completable: Cexpression CArgument Value[fnTakingRecord]($0)->recordField(polyvariant), polyvariantPayload::three($0) ContextPath CArgument Value[fnTakingRecord]($0) ContextPath Value[fnTakingRecord] +Path fnTakingRecord [{ "label": "{}", "kind": 12, @@ -304,6 +317,7 @@ Pexp_apply ...[59:11->59:25] (...[59:26->59:64]) Completable: Cexpression CArgument Value[fnTakingRecord]($0)->recordField(polyvariant), polyvariantPayload::three($1) ContextPath CArgument Value[fnTakingRecord]($0) ContextPath Value[fnTakingRecord] +Path fnTakingRecord [{ "label": "true", "kind": 4, @@ -324,6 +338,7 @@ Pexp_apply ...[62:11->62:25] (...[62:26->62:65]) Completable: Cexpression CArgument Value[fnTakingRecord]($0)=t->recordField(polyvariant), polyvariantPayload::three($1) ContextPath CArgument Value[fnTakingRecord]($0) ContextPath Value[fnTakingRecord] +Path fnTakingRecord [{ "label": "true", "kind": 4, @@ -338,6 +353,7 @@ Pexp_apply ...[69:11->69:24] (...[69:25->69:26]) Completable: Cexpression CArgument Value[fnTakingArray]($0) ContextPath CArgument Value[fnTakingArray]($0) ContextPath Value[fnTakingArray] +Path fnTakingArray [{ "label": "[]", "kind": 12, @@ -355,6 +371,7 @@ Pexp_apply ...[72:11->72:24] (...[72:25->72:27]) Completable: Cexpression CArgument Value[fnTakingArray]($0)->array ContextPath CArgument Value[fnTakingArray]($0) ContextPath Value[fnTakingArray] +Path fnTakingArray [{ "label": "None", "kind": 12, @@ -389,6 +406,7 @@ Pexp_apply ...[75:11->75:24] (...[75:25->75:26]) Completable: Cexpression CArgument Value[fnTakingArray]($0)=s ContextPath CArgument Value[fnTakingArray]($0) ContextPath Value[fnTakingArray] +Path fnTakingArray [{ "label": "s", "kind": 12, @@ -403,6 +421,7 @@ Pexp_apply ...[78:11->78:24] (...[78:25->78:33]) Completable: Cexpression CArgument Value[fnTakingArray]($0)->array, variantPayload::Some($0) ContextPath CArgument Value[fnTakingArray]($0) ContextPath Value[fnTakingArray] +Path fnTakingArray [{ "label": "true", "kind": 4, @@ -423,6 +442,7 @@ Pexp_apply ...[81:11->81:24] (...[81:25->81:33]) Completable: Cexpression CArgument Value[fnTakingArray]($0)->array ContextPath CArgument Value[fnTakingArray]($0) ContextPath Value[fnTakingArray] +Path fnTakingArray [{ "label": "None", "kind": 12, @@ -457,6 +477,7 @@ Pexp_apply ...[84:11->84:24] (...[84:25->84:39]) Completable: Cexpression CArgument Value[fnTakingArray]($0)->array ContextPath CArgument Value[fnTakingArray]($0) ContextPath Value[fnTakingArray] +Path fnTakingArray [{ "label": "None", "kind": 12, @@ -491,6 +512,7 @@ Pexp_apply ...[89:11->89:25] (...[89:26->89:40]) Completable: Cexpression CArgument Value[fnTakingRecord]($0)=so ContextPath CArgument Value[fnTakingRecord]($0) ContextPath Value[fnTakingRecord] +Path fnTakingRecord [{ "label": "someBoolVar", "kind": 12, @@ -505,6 +527,7 @@ Pexp_apply ...[96:11->96:30] (...[96:31->96:46]) Completable: Cexpression CArgument Value[fnTakingOtherRecord]($0)->recordField(otherField) ContextPath CArgument Value[fnTakingOtherRecord]($0) ContextPath Value[fnTakingOtherRecord] +Path fnTakingOtherRecord [{ "label": "\"\"", "kind": 12, @@ -522,6 +545,7 @@ Pexp_apply ...[108:11->108:42] (...[108:43->108:60]) Completable: Cexpression CArgument Value[fnTakingRecordWithOptionalField]($0)->recordField(someOptField) ContextPath CArgument Value[fnTakingRecordWithOptionalField]($0) ContextPath Value[fnTakingRecordWithOptionalField] +Path fnTakingRecordWithOptionalField [{ "label": "true", "kind": 4, @@ -542,6 +566,7 @@ Pexp_apply ...[116:11->116:39] (...[116:40->116:56]) Completable: Cexpression CArgument Value[fnTakingRecordWithOptVariant]($0)->recordField(someVariant) ContextPath CArgument Value[fnTakingRecordWithOptVariant]($0) ContextPath Value[fnTakingRecordWithOptVariant] +Path fnTakingRecordWithOptVariant [{ "label": "None", "kind": 12, @@ -588,6 +613,7 @@ Pexp_apply ...[126:11->126:31] (...[126:32->126:50]) Completable: Cexpression CArgument Value[fnTakingInlineRecord]($0)->variantPayload::WithInlineRecord($0) ContextPath CArgument Value[fnTakingInlineRecord]($0) ContextPath Value[fnTakingInlineRecord] +Path fnTakingInlineRecord [{ "label": "{}", "kind": 4, @@ -605,6 +631,7 @@ Pexp_apply ...[129:11->129:31] (...[129:32->129:52]) Completable: Cexpression CArgument Value[fnTakingInlineRecord]($0)->variantPayload::WithInlineRecord($0), recordBody ContextPath CArgument Value[fnTakingInlineRecord]($0) ContextPath Value[fnTakingInlineRecord] +Path fnTakingInlineRecord [{ "label": "someBoolField", "kind": 4, @@ -631,6 +658,7 @@ Pexp_apply ...[132:11->132:31] (...[132:32->132:53]) Completable: Cexpression CArgument Value[fnTakingInlineRecord]($0)=s->variantPayload::WithInlineRecord($0), recordBody ContextPath CArgument Value[fnTakingInlineRecord]($0) ContextPath Value[fnTakingInlineRecord] +Path fnTakingInlineRecord [{ "label": "someBoolField", "kind": 4, @@ -645,6 +673,7 @@ Pexp_apply ...[135:11->135:31] (...[135:32->135:66]) Completable: Cexpression CArgument Value[fnTakingInlineRecord]($0)->variantPayload::WithInlineRecord($0), recordField(nestedRecord) ContextPath CArgument Value[fnTakingInlineRecord]($0) ContextPath Value[fnTakingInlineRecord] +Path fnTakingInlineRecord [{ "label": "{}", "kind": 12, @@ -662,6 +691,7 @@ Pexp_apply ...[138:11->138:31] (...[138:32->138:69]) Completable: Cexpression CArgument Value[fnTakingInlineRecord]($0)->variantPayload::WithInlineRecord($0), recordField(nestedRecord), recordBody ContextPath CArgument Value[fnTakingInlineRecord]($0) ContextPath Value[fnTakingInlineRecord] +Path fnTakingInlineRecord [{ "label": "someField", "kind": 5, @@ -682,6 +712,7 @@ Pexp_apply ...[159:3->159:19] (...[159:20->159:21]) Completable: Cexpression CArgument Value[fnTakingCallback]($0) ContextPath CArgument Value[fnTakingCallback]($0) ContextPath Value[fnTakingCallback] +Path fnTakingCallback [{ "label": "() => {}", "kind": 12, @@ -699,6 +730,7 @@ Pexp_apply ...[162:3->162:19] (...[162:20->162:21]) Completable: Cexpression CArgument Value[fnTakingCallback]($0)=a ContextPath CArgument Value[fnTakingCallback]($0) ContextPath Value[fnTakingCallback] +Path fnTakingCallback [] Complete src/CompletionExpressions.res 165:22 @@ -707,6 +739,7 @@ Pexp_apply ...[165:3->165:19] (...[165:20->165:21]) Completable: Cexpression CArgument Value[fnTakingCallback]($1) ContextPath CArgument Value[fnTakingCallback]($1) ContextPath Value[fnTakingCallback] +Path fnTakingCallback [{ "label": "v => {}", "kind": 12, @@ -724,6 +757,7 @@ Pexp_apply ...[168:3->168:19] (...[168:20->168:21], ...[168:23->168:24]) Completable: Cexpression CArgument Value[fnTakingCallback]($2) ContextPath CArgument Value[fnTakingCallback]($2) ContextPath Value[fnTakingCallback] +Path fnTakingCallback [{ "label": "event => {}", "kind": 12, @@ -741,6 +775,7 @@ Pexp_apply ...[171:3->171:19] (...[171:20->171:21], ...[171:23->171:24], ...[171 Completable: Cexpression CArgument Value[fnTakingCallback]($3) ContextPath CArgument Value[fnTakingCallback]($3) ContextPath Value[fnTakingCallback] +Path fnTakingCallback [{ "label": "(~on, ~off=?, v1) => {}", "kind": 12, @@ -758,6 +793,7 @@ Pexp_apply ...[174:3->174:19] (...[174:20->174:21], ...[174:23->174:24], ...[174 Completable: Cexpression CArgument Value[fnTakingCallback]($4) ContextPath CArgument Value[fnTakingCallback]($4) ContextPath Value[fnTakingCallback] +Path fnTakingCallback [{ "label": "(v1, v2, v3) => {}", "kind": 12, @@ -775,6 +811,7 @@ Pexp_apply ...[177:3->177:19] (...[177:20->177:21], ...[177:23->177:24], ...[177 Completable: Cexpression CArgument Value[fnTakingCallback]($5) ContextPath CArgument Value[fnTakingCallback]($5) ContextPath Value[fnTakingCallback] +Path fnTakingCallback [{ "label": "(~on=?, ~off=?, ()) => {}", "kind": 12, @@ -796,6 +833,7 @@ Pexp_apply ...[185:2->185:8] (...[185:9->185:10]) Completable: Cexpression CArgument Value[Js, log]($0)=s ContextPath CArgument Value[Js, log]($0) ContextPath Value[Js, log] +Path Js.log [{ "label": "second2", "kind": 12, diff --git a/analysis/tests/src/expected/CompletionFunctionArguments.res.txt b/analysis/tests/src/expected/CompletionFunctionArguments.res.txt index 0a54e35f7..1ce949e84 100644 --- a/analysis/tests/src/expected/CompletionFunctionArguments.res.txt +++ b/analysis/tests/src/expected/CompletionFunctionArguments.res.txt @@ -4,6 +4,7 @@ Pexp_apply ...[10:11->10:17] (~isOn10:19->10:23=...__ghost__[0:-1->0:-1]) Completable: Cexpression CArgument Value[someFn](~isOn) ContextPath CArgument Value[someFn](~isOn) ContextPath Value[someFn] +Path someFn [{ "label": "true", "kind": 4, @@ -24,6 +25,7 @@ Pexp_apply ...[13:11->13:17] (~isOn13:19->13:23=...[13:24->13:25]) Completable: Cexpression CArgument Value[someFn](~isOn)=t ContextPath CArgument Value[someFn](~isOn) ContextPath Value[someFn] +Path someFn [{ "label": "true", "kind": 4, @@ -45,6 +47,7 @@ Pexp_apply ...[16:11->16:17] (~isOff16:19->16:24=...__ghost__[0:-1->0:-1]) Completable: Cexpression CArgument Value[someFn](~isOff) ContextPath CArgument Value[someFn](~isOff) ContextPath Value[someFn] +Path someFn [{ "label": "true", "kind": 4, @@ -69,6 +72,7 @@ Pexp_apply ...[21:14->21:20] (~isOn21:22->21:26=...__ghost__[0:-1->0:-1]) Completable: Cexpression CArgument Value[someFn](~isOn) ContextPath CArgument Value[someFn](~isOn) ContextPath Value[someFn] +Path someFn [{ "label": "true", "kind": 4, @@ -89,6 +93,7 @@ Pexp_apply ...[34:11->34:22] (...[34:23->34:24]) Completable: Cexpression CArgument Value[someOtherFn]($0)=f ContextPath CArgument Value[someOtherFn]($0) ContextPath Value[someOtherFn] +Path someOtherFn [{ "label": "false", "kind": 4, @@ -103,6 +108,7 @@ Pexp_apply ...[51:11->51:30] (~config51:32->51:38=...__ghost__[0:-1->0:-1]) Completable: Cexpression CArgument Value[someFnTakingVariant](~config) ContextPath CArgument Value[someFnTakingVariant](~config) ContextPath Value[someFnTakingVariant] +Path someFnTakingVariant [{ "label": "One", "kind": 4, @@ -135,6 +141,7 @@ Pexp_apply ...[54:11->54:30] (~config54:32->54:38=...[54:39->54:40]) Completable: Cexpression CArgument Value[someFnTakingVariant](~config)=O ContextPath CArgument Value[someFnTakingVariant](~config) ContextPath Value[someFnTakingVariant] +Path someFnTakingVariant [{ "label": "One", "kind": 4, @@ -170,6 +177,7 @@ Pexp_apply ...[57:11->57:30] (...[57:31->57:33]) Completable: Cexpression CArgument Value[someFnTakingVariant]($0)=So ContextPath CArgument Value[someFnTakingVariant]($0) ContextPath Value[someFnTakingVariant] +Path someFnTakingVariant [{ "label": "Some(_)", "kind": 12, @@ -193,6 +201,7 @@ Pexp_apply ...[60:11->60:30] (~configOpt260:32->60:42=...[60:43->60:44]) Completable: Cexpression CArgument Value[someFnTakingVariant](~configOpt2)=O ContextPath CArgument Value[someFnTakingVariant](~configOpt2) ContextPath Value[someFnTakingVariant] +Path someFnTakingVariant [{ "label": "One", "kind": 4, @@ -228,6 +237,7 @@ Pexp_apply ...[63:11->63:22] (...[63:23->63:24]) Completable: Cexpression CArgument Value[someOtherFn]($0) ContextPath CArgument Value[someOtherFn]($0) ContextPath Value[someOtherFn] +Path someOtherFn [{ "label": "true", "kind": 4, @@ -248,6 +258,7 @@ Pexp_apply ...[66:11->66:22] (...[66:23->66:24], ...[66:26->66:27]) Completable: Cexpression CArgument Value[someOtherFn]($2) ContextPath CArgument Value[someOtherFn]($2) ContextPath Value[someOtherFn] +Path someOtherFn [{ "label": "true", "kind": 4, @@ -267,6 +278,7 @@ posCursor:[69:30] posNoWhite:[69:29] Found expr:[69:11->69:31] Completable: Cexpression CArgument Value[someOtherFn]($2)=t ContextPath CArgument Value[someOtherFn]($2) ContextPath Value[someOtherFn] +Path someOtherFn [{ "label": "true", "kind": 4, @@ -288,6 +300,7 @@ Pexp_apply ...[76:11->76:24] (...[76:25->76:26]) Completable: Cexpression CArgument Value[fnTakingTuple]($0) ContextPath CArgument Value[fnTakingTuple]($0) ContextPath Value[fnTakingTuple] +Path fnTakingTuple [{ "label": "(_, _, _)", "kind": 12, @@ -304,6 +317,7 @@ Pexp_apply ...[89:11->89:25] (...[89:26->89:28]) Completable: Cexpression CArgument Value[fnTakingRecord]($0)->recordBody ContextPath CArgument Value[fnTakingRecord]($0) ContextPath Value[fnTakingRecord] +Path fnTakingRecord [{ "label": "age", "kind": 5, @@ -334,6 +348,8 @@ posCursor:[109:29] posNoWhite:[109:28] Found expr:[109:9->109:29] Completable: Cpath Value[thisGetsBrokenLoc]->a <> ContextPath Value[thisGetsBrokenLoc]->a <> ContextPath Value[thisGetsBrokenLoc] +Path thisGetsBrokenLoc +Path ReactEvent.Mouse.a [{ "label": "ReactEvent.Mouse.altKey", "kind": 12, @@ -352,6 +368,8 @@ posCursor:[111:27] posNoWhite:[111:26] Found expr:[111:9->111:27] Completable: Cpath Value[reassignedWorks]->a <> ContextPath Value[reassignedWorks]->a <> ContextPath Value[reassignedWorks] +Path reassignedWorks +Path ReactEvent.Mouse.a [{ "label": "ReactEvent.Mouse.altKey", "kind": 12, diff --git a/analysis/tests/src/expected/CompletionInferValues.res.txt b/analysis/tests/src/expected/CompletionInferValues.res.txt index 4b6df198c..638e882a9 100644 --- a/analysis/tests/src/expected/CompletionInferValues.res.txt +++ b/analysis/tests/src/expected/CompletionInferValues.res.txt @@ -3,8 +3,11 @@ posCursor:[15:43] posNoWhite:[15:42] Found expr:[15:33->15:43] Completable: Cpath Value[aliased]->f ContextPath Value[aliased]->f ContextPath Value[aliased] +Path aliased ContextPath Value[x] +Path x ContextPath int +Path Belt.Int.f [{ "label": "Belt.Int.fromString", "kind": 12, @@ -25,8 +28,10 @@ Pexp_field [18:28->18:29] _:[33:0->18:30] Completable: Cpath Value[x]."" ContextPath Value[x]."" ContextPath Value[x] +Path x ContextPath Value[getSomeRecord](Nolabel) ContextPath Value[getSomeRecord] +Path getSomeRecord [{ "label": "name", "kind": 5, @@ -47,9 +52,12 @@ Pexp_field [21:45->21:52] _:[33:0->21:53] Completable: Cpath Value[aliased]."" ContextPath Value[aliased]."" ContextPath Value[aliased] +Path aliased ContextPath Value[x] +Path x ContextPath Value[getSomeRecord](Nolabel) ContextPath Value[getSomeRecord] +Path getSomeRecord [{ "label": "name", "kind": 5, @@ -75,9 +83,11 @@ Pexp_field [24:52->24:62] _:[24:63->24:63] Completable: Cpath Value[someRecord]."" ContextPath Value[someRecord]."" ContextPath Value[someRecord] +Path someRecord ContextPath CArgument CArgument Value[someFnWithCallback]($0)(~someRecord) ContextPath CArgument Value[someFnWithCallback]($0) ContextPath Value[someFnWithCallback] +Path someFnWithCallback [{ "label": "name", "kind": 5, @@ -103,10 +113,13 @@ Pexp_field [27:79->27:89] _:[27:90->27:90] Completable: Cpath Value[someRecord]."" ContextPath Value[someRecord]."" ContextPath Value[someRecord] +Path someRecord ContextPath CArgument CArgument Value[aliasedFn]($0)(~someRecord) ContextPath CArgument Value[aliasedFn]($0) ContextPath Value[aliasedFn] +Path aliasedFn ContextPath Value[someFnWithCallback] +Path someFnWithCallback [{ "label": "name", "kind": 5, @@ -129,9 +142,12 @@ posCursor:[30:36] posNoWhite:[30:35] Found expr:[30:27->30:36] Completable: Cpath Value[event]->pr ContextPath Value[event]->pr ContextPath Value[event] +Path event ContextPath CArgument CArgument Value[reactEventFn]($0)($0) ContextPath CArgument Value[reactEventFn]($0) ContextPath Value[reactEventFn] +Path reactEventFn +Path ReactEvent.Mouse.pr [{ "label": "ReactEvent.Mouse.preventDefault", "kind": 12, @@ -148,8 +164,12 @@ posCursor:[41:50] posNoWhite:[41:49] Found expr:[41:41->41:50] Completable: Cpath Value[event]->pr <> ContextPath Value[event]->pr <> ContextPath Value[event] +Path event ContextPath CArgument CJsxPropValue [div] onMouseEnter($0) ContextPath CJsxPropValue [div] onMouseEnter +Path ReactDOM.domProps +Path JsxDOM.domProps +Path JsxEvent.Mouse.pr [{ "label": "JsxEvent.Mouse.preventDefault", "kind": 12, @@ -166,8 +186,11 @@ posCursor:[44:50] posNoWhite:[44:49] Found expr:[44:41->44:50] Completable: Cpath Value[event]->pr <> ContextPath Value[event]->pr <> ContextPath Value[event] +Path event ContextPath CArgument CJsxPropValue [Div] onMouseEnter($0) ContextPath CJsxPropValue [Div] onMouseEnter +Path Div.make +Path JsxEvent.Mouse.pr [{ "label": "JsxEvent.Mouse.preventDefault", "kind": 12, @@ -185,8 +208,11 @@ posCursor:[47:87] posNoWhite:[47:86] Found expr:[47:81->47:87] Completable: Cpath Value[btn]->t <> ContextPath Value[btn]->t <> ContextPath Value[btn] +Path btn ContextPath Value[JsxEvent, Mouse, button](Nolabel) ContextPath Value[JsxEvent, Mouse, button] +Path JsxEvent.Mouse.button +Path Belt.Int.t [{ "label": "Belt.Int.toString", "kind": 12, @@ -210,8 +236,11 @@ posCursor:[50:108] posNoWhite:[50:107] Found expr:[50:100->50:108] Completable: Cpath Value[btn]->spl <> ContextPath Value[btn]->spl <> ContextPath Value[btn] +Path btn ContextPath Value[Belt, Int, toString](Nolabel) ContextPath Value[Belt, Int, toString] +Path Belt.Int.toString +Path Js.String2.spl [{ "label": "Js.String2.splitAtMost", "kind": 12, @@ -247,8 +276,11 @@ posCursor:[53:130] posNoWhite:[53:129] Found expr:[53:123->53:130] Completable: Cpath Value[btn]->ma <> ContextPath Value[btn]->ma <> ContextPath Value[btn] +Path btn ContextPath Value[Js, String2, split](Nolabel, Nolabel) ContextPath Value[Js, String2, split] +Path Js.String2.split +Path Js.Array2.ma [{ "label": "Js.Array2.mapi", "kind": 12, @@ -269,7 +301,9 @@ Pexp_field [56:50->56:51] _:[59:0->56:52] Completable: Cpath Value[x]."" ContextPath Value[x]."" ContextPath Value[x] +Path x ContextPath Type[someRecord] +Path someRecord [{ "label": "name", "kind": 5, @@ -290,9 +324,12 @@ Pexp_field [78:70->78:77] _:[125:0->78:78] Completable: Cpath Value[srecord]."" ContextPath Value[srecord]."" ContextPath Value[srecord] +Path srecord ContextPath CPatternPath(Value[x])->recordField(srecord) ContextPath Value[x] +Path x ContextPath Type[someRecordWithNestedStuff] +Path someRecordWithNestedStuff [{ "label": "name", "kind": 5, @@ -313,9 +350,12 @@ Pexp_field [82:78->82:85] _:[125:0->82:86] Completable: Cpath Value[aliased]."" ContextPath Value[aliased]."" ContextPath Value[aliased] +Path aliased ContextPath CPatternPath(Value[x])->recordField(nested) ContextPath Value[x] +Path x ContextPath Type[someRecordWithNestedStuff] +Path someRecordWithNestedStuff [{ "label": "someRecord", "kind": 5, @@ -330,9 +370,12 @@ Pexp_field [86:92->86:102] _:[125:0->86:103] Completable: Cpath Value[someRecord]."" ContextPath Value[someRecord]."" ContextPath Value[someRecord] +Path someRecord ContextPath CPatternPath(Value[x])->recordField(nested)->recordField(someRecord) ContextPath Value[x] +Path x ContextPath Type[someRecordWithNestedStuff] +Path someRecordWithNestedStuff [{ "label": "name", "kind": 5, @@ -352,9 +395,13 @@ posCursor:[90:81] posNoWhite:[90:80] Found expr:[90:69->90:81] Completable: Cpath Value[things]->slic ContextPath Value[things]->slic ContextPath Value[things] +Path things ContextPath CPatternPath(Value[x])->recordField(things) ContextPath Value[x] +Path x ContextPath Type[someRecordWithNestedStuff] +Path someRecordWithNestedStuff +Path Js.String2.slic [{ "label": "Js.String2.sliceToEnd", "kind": 12, @@ -374,9 +421,13 @@ posCursor:[94:82] posNoWhite:[94:81] Found expr:[94:70->94:82] Completable: Cpath Value[someInt]->toS ContextPath Value[someInt]->toS ContextPath Value[someInt] +Path someInt ContextPath CPatternPath(Value[x])->recordField(someInt) ContextPath Value[x] +Path x ContextPath Type[someRecordWithNestedStuff] +Path someRecordWithNestedStuff +Path Belt.Int.toS [{ "label": "Belt.Int.toString", "kind": 12, @@ -390,11 +441,16 @@ posCursor:[98:109] posNoWhite:[98:108] Found expr:[98:97->98:109] Completable: Cpath Value[someInt]->toS ContextPath Value[someInt]->toS ContextPath Value[someInt] +Path someInt ContextPath CPatternPath(Value[someTuple])->tuple($1) ContextPath Value[someTuple] +Path someTuple ContextPath CPatternPath(Value[x])->recordField(someTuple) ContextPath Value[x] +Path x ContextPath Type[otherNestedRecord] +Path otherNestedRecord +Path Belt.Int.toS [{ "label": "Belt.Int.toString", "kind": 12, @@ -409,11 +465,16 @@ posCursor:[102:102] posNoWhite:[102:101] Found expr:[102:90->102:102] Completable: Cpath Value[someInt]->toS ContextPath Value[someInt]->toS ContextPath Value[someInt] +Path someInt ContextPath CPatternPath(Value[someTuple])->tuple($1) ContextPath Value[someTuple] +Path someTuple ContextPath CPatternPath(Value[x])->recordField(someTuple) ContextPath Value[x] +Path x ContextPath Type[otherNestedRecord] +Path otherNestedRecord +Path Belt.Int.toS [{ "label": "Belt.Int.toString", "kind": 12, @@ -427,9 +488,13 @@ posCursor:[106:88] posNoWhite:[106:87] Found expr:[106:79->106:88] Completable: Cpath Value[str]->slic ContextPath Value[str]->slic ContextPath Value[str] +Path str ContextPath CPatternPath(Value[x])->recordField(someTuple)->tuple($0)->variantPayload::Three($1) ContextPath Value[x] +Path x ContextPath Type[otherNestedRecord] +Path otherNestedRecord +Path Js.String2.slic [{ "label": "Js.String2.sliceToEnd", "kind": 12, @@ -449,9 +514,13 @@ posCursor:[110:89] posNoWhite:[110:88] Found expr:[110:80->110:89] Completable: Cpath Value[str]->slic ContextPath Value[str]->slic ContextPath Value[str] +Path str ContextPath CPatternPath(Value[x])->recordField(someTuple)->tuple($2)->polyvariantPayload::three($1) ContextPath Value[x] +Path x ContextPath Type[otherNestedRecord] +Path otherNestedRecord +Path Js.String2.slic [{ "label": "Js.String2.sliceToEnd", "kind": 12, @@ -471,9 +540,13 @@ posCursor:[114:80] posNoWhite:[114:79] Found expr:[114:70->114:80] Completable: Cpath Value[name]->slic ContextPath Value[name]->slic ContextPath Value[name] +Path name ContextPath CPatternPath(Value[x])->recordField(optRecord)->variantPayload::Some($0)->recordField(name) ContextPath Value[x] +Path x ContextPath Type[otherNestedRecord] +Path otherNestedRecord +Path Js.String2.slic [{ "label": "Js.String2.sliceToEnd", "kind": 12, @@ -494,10 +567,13 @@ Pexp_field [118:60->118:65] s:[118:66->118:67] Completable: Cpath Value[inner].s ContextPath Value[inner].s ContextPath Value[inner] +Path inner ContextPath CPatternPath(Value[x])->array ContextPath Value[x] +Path x ContextPath array ContextPath Type[otherNestedRecord] +Path otherNestedRecord [{ "label": "someRecord", "kind": 5, @@ -517,8 +593,11 @@ posCursor:[122:53] posNoWhite:[122:52] Found expr:[122:46->122:53] Completable: Cpath Value[v]->toSt ContextPath Value[v]->toSt ContextPath Value[v] +Path v ContextPath Value[x] +Path x ContextPath int +Path Belt.Int.toSt [{ "label": "Belt.Int.toString", "kind": 12, @@ -537,6 +616,7 @@ Completable: Cpattern CArgument CArgument Value[fnWithRecordCallback]($0)($0)->r ContextPath CArgument CArgument Value[fnWithRecordCallback]($0)($0) ContextPath CArgument Value[fnWithRecordCallback]($0) ContextPath Value[fnWithRecordCallback] +Path fnWithRecordCallback [{ "label": "name", "kind": 5, @@ -560,10 +640,13 @@ posCursor:[137:30] posNoWhite:[137:29] Found expr:[137:24->0:-1] Completable: Cpath Value[root]-> ContextPath Value[root]-> ContextPath Value[root] +Path root ContextPath CPatternPath(CArgument CArgument Value[fn2](~cb)($0))->recordField(root) ContextPath CArgument CArgument Value[fn2](~cb)($0) ContextPath CArgument Value[fn2](~cb) ContextPath Value[fn2] +Path fn2 +Path ReactDOM.Client.Root. [{ "label": "ReactDOM.Client.Root.unmount", "kind": 12, @@ -587,10 +670,13 @@ posCursor:[146:30] posNoWhite:[146:29] Found expr:[146:24->0:-1] Completable: Cpath Value[root]-> ContextPath Value[root]-> ContextPath Value[root] +Path root ContextPath CPatternPath(CArgument CArgument Value[fn3](~cb)($0))->recordField(root) ContextPath CArgument CArgument Value[fn3](~cb)($0) ContextPath CArgument Value[fn3](~cb) ContextPath Value[fn3] +Path fn3 +Path CompletionSupport.Test. [{ "label": "CompletionSupport.Test.add", "kind": 12, @@ -616,6 +702,7 @@ XXX Not found! Completable: Cpattern Value[Belt, Int, toString](Nolabel) ContextPath Value[Belt, Int, toString](Nolabel) ContextPath Value[Belt, Int, toString] +Path Belt.Int.toString [{ "label": "\"\"", "kind": 12, @@ -632,6 +719,7 @@ XXX Not found! Completable: Cpattern Value[Js, String2, split](Nolabel, Nolabel) ContextPath Value[Js, String2, split](Nolabel, Nolabel) ContextPath Value[Js, String2, split] +Path Js.String2.split [{ "label": "[]", "kind": 12, @@ -652,10 +740,12 @@ Pexp_field [158:97->158:104] _:[158:105->158:105] Completable: Cpath Value[support]."" ContextPath Value[support]."" ContextPath Value[support] +Path support ContextPath CPatternPath(CArgument CArgument Value[CompletionSupport2, makeRenderer](~render)($0))->recordField(support) ContextPath CArgument CArgument Value[CompletionSupport2, makeRenderer](~render)($0) ContextPath CArgument Value[CompletionSupport2, makeRenderer](~render) ContextPath Value[CompletionSupport2, makeRenderer] +Path CompletionSupport2.makeRenderer [{ "label": "root", "kind": 5, @@ -673,9 +763,12 @@ posCursor:[162:110] posNoWhite:[162:109] Found expr:[162:104->0:-1] Completable: Cpath Value[root]-> ContextPath Value[root]-> ContextPath Value[root] +Path root ContextPath CPatternPath(CArgument CArgument Value[CompletionSupport2, makeRenderer](~render)($0))->recordField(support)->recordField(root) ContextPath CArgument CArgument Value[CompletionSupport2, makeRenderer](~render)($0) ContextPath CArgument Value[CompletionSupport2, makeRenderer](~render) ContextPath Value[CompletionSupport2, makeRenderer] +Path CompletionSupport2.makeRenderer +Path CompletionSupport2.ReactDOM.Client.Root. [] diff --git a/analysis/tests/src/expected/CompletionJsx.res.txt b/analysis/tests/src/expected/CompletionJsx.res.txt index dd10a1a2b..76fe3fa2b 100644 --- a/analysis/tests/src/expected/CompletionJsx.res.txt +++ b/analysis/tests/src/expected/CompletionJsx.res.txt @@ -3,6 +3,8 @@ posCursor:[3:17] posNoWhite:[3:16] Found expr:[3:3->3:17] Completable: Cpath Value[someString]->st ContextPath Value[someString]->st ContextPath Value[someString] +Path someString +Path Js.String2.st [{ "label": "Js.String2.startsWith", "kind": 12, @@ -28,6 +30,8 @@ posCursor:[13:21] posNoWhite:[13:20] Found expr:[13:7->13:21] Completable: Cpath Value[someString]->st <> ContextPath Value[someString]->st <> ContextPath Value[someString] +Path someString +Path Js.String2.st [{ "label": "React.string", "kind": 12, @@ -71,6 +75,8 @@ posCursor:[18:24] posNoWhite:[18:23] Found expr:[18:10->18:24] Completable: Cpath Value[someString]->st <> ContextPath Value[someString]->st <> ContextPath Value[someString] +Path someString +Path Js.String2.st [{ "label": "React.string", "kind": 12, @@ -114,6 +120,7 @@ posCursor:[20:27] posNoWhite:[20:26] Found expr:[20:10->20:27] Completable: Cpath string->st <> ContextPath string->st <> ContextPath string +Path Js.String2.st [{ "label": "React.string", "kind": 12, @@ -158,6 +165,8 @@ Completable: Cpath Value[Js, String2, trim](Nolabel)->st <> ContextPath Value[Js, String2, trim](Nolabel)->st <> ContextPath Value[Js, String2, trim](Nolabel) ContextPath Value[Js, String2, trim] +Path Js.String2.trim +Path Js.String2.st [{ "label": "React.string", "kind": 12, @@ -201,6 +210,8 @@ posCursor:[24:19] posNoWhite:[24:18] Found expr:[24:10->0:-1] Completable: Cpath Value[someInt]-> <> ContextPath Value[someInt]-> <> ContextPath Value[someInt] +Path someInt +Path Belt.Int. [{ "label": "React.int", "kind": 12, @@ -280,6 +291,7 @@ posCursor:[26:14] posNoWhite:[26:13] Found expr:[26:10->0:-1] Completable: Cpath int-> <> ContextPath int-> <> ContextPath int +Path Belt.Int. [{ "label": "React.int", "kind": 12, @@ -359,6 +371,8 @@ posCursor:[28:20] posNoWhite:[28:19] Found expr:[28:10->28:20] Completable: Cpath Value[someArr]->a <> ContextPath Value[someArr]->a <> ContextPath Value[someArr] +Path someArr +Path Js.Array2.a [{ "label": "React.array", "kind": 12, @@ -422,6 +436,7 @@ Complete src/CompletionJsx.res 45:23 posCursor:[45:23] posNoWhite:[45:22] Found expr:[45:4->45:23] JSX 45:21] n[45:22->45:23]=...[45:22->45:23]> _children:None Completable: Cjsx([CompWithoutJsxPpx], n, [n]) +Path CompWithoutJsxPpx.make [{ "label": "name", "kind": 4, diff --git a/analysis/tests/src/expected/CompletionJsxProps.res.txt b/analysis/tests/src/expected/CompletionJsxProps.res.txt index e1366954b..f424a3c10 100644 --- a/analysis/tests/src/expected/CompletionJsxProps.res.txt +++ b/analysis/tests/src/expected/CompletionJsxProps.res.txt @@ -3,6 +3,7 @@ posCursor:[0:47] posNoWhite:[0:46] Found expr:[0:12->0:47] JSX 0:43] on[0:44->0:46]=...__ghost__[0:-1->0:-1]> _children:None Completable: Cexpression CJsxPropValue [CompletionSupport, TestComponent] on ContextPath CJsxPropValue [CompletionSupport, TestComponent] on +Path CompletionSupport.TestComponent.make [{ "label": "true", "kind": 4, @@ -22,6 +23,7 @@ posCursor:[3:48] posNoWhite:[3:47] Found expr:[3:12->3:48] JSX 3:43] on[3:44->3:46]=...[3:47->3:48]> _children:None Completable: Cexpression CJsxPropValue [CompletionSupport, TestComponent] on=t ContextPath CJsxPropValue [CompletionSupport, TestComponent] on +Path CompletionSupport.TestComponent.make [{ "label": "true", "kind": 4, @@ -35,6 +37,7 @@ posCursor:[6:50] posNoWhite:[6:49] Found expr:[6:12->6:50] JSX 6:43] test[6:44->6:48]=...[6:49->6:50]> _children:None Completable: Cexpression CJsxPropValue [CompletionSupport, TestComponent] test=T ContextPath CJsxPropValue [CompletionSupport, TestComponent] test +Path CompletionSupport.TestComponent.make [{ "label": "Two", "kind": 4, @@ -72,6 +75,7 @@ posCursor:[9:52] posNoWhite:[9:51] Found expr:[9:12->9:52] JSX 9:43] polyArg[9:44->9:51]=...__ghost__[0:-1->0:-1]> _children:None Completable: Cexpression CJsxPropValue [CompletionSupport, TestComponent] polyArg ContextPath CJsxPropValue [CompletionSupport, TestComponent] polyArg +Path CompletionSupport.TestComponent.make [{ "label": "#one", "kind": 4, @@ -111,6 +115,7 @@ posCursor:[12:54] posNoWhite:[12:53] Found expr:[12:12->12:54] JSX 12:43] polyArg[12:44->12:51]=...[12:52->12:54]> _children:None Completable: Cexpression CJsxPropValue [CompletionSupport, TestComponent] polyArg=#t ContextPath CJsxPropValue [CompletionSupport, TestComponent] polyArg +Path CompletionSupport.TestComponent.make [{ "label": "#three(_, _)", "kind": 4, @@ -142,6 +147,8 @@ posCursor:[15:22] posNoWhite:[15:21] Found expr:[15:12->15:25] JSX 15:15] muted[15:16->15:21]=...__ghost__[0:-1->0:-1]> _children:15:23 Completable: Cexpression CJsxPropValue [div] muted ContextPath CJsxPropValue [div] muted +Path ReactDOM.domProps +Path JsxDOM.domProps [{ "label": "true", "kind": 4, @@ -161,6 +168,8 @@ posCursor:[18:29] posNoWhite:[18:28] Found expr:[18:12->18:32] JSX 18:15] onMouseEnter[18:16->18:28]=...__ghost__[0:-1->0:-1]> _children:18:30 Completable: Cexpression CJsxPropValue [div] onMouseEnter ContextPath CJsxPropValue [div] onMouseEnter +Path ReactDOM.domProps +Path JsxDOM.domProps [{ "label": "event => {}", "kind": 12, @@ -177,6 +186,7 @@ posCursor:[22:52] posNoWhite:[22:51] Found expr:[22:12->22:52] JSX 22:43] testArr[22:44->22:51]=...__ghost__[0:-1->0:-1]> _children:None Completable: Cexpression CJsxPropValue [CompletionSupport, TestComponent] testArr ContextPath CJsxPropValue [CompletionSupport, TestComponent] testArr +Path CompletionSupport.TestComponent.make [{ "label": "[]", "kind": 12, @@ -193,6 +203,7 @@ posCursor:[26:54] posNoWhite:[26:53] Found expr:[26:12->26:56] JSX 26:43] testArr[26:44->26:51]=...[26:53->26:55]> _children:None Completable: Cexpression CJsxPropValue [CompletionSupport, TestComponent] testArr->array ContextPath CJsxPropValue [CompletionSupport, TestComponent] testArr +Path CompletionSupport.TestComponent.make [{ "label": "One", "kind": 4, diff --git a/analysis/tests/src/expected/CompletionPattern.res.txt b/analysis/tests/src/expected/CompletionPattern.res.txt index 4b8261568..42a22d085 100644 --- a/analysis/tests/src/expected/CompletionPattern.res.txt +++ b/analysis/tests/src/expected/CompletionPattern.res.txt @@ -6,6 +6,7 @@ Complete src/CompletionPattern.res 10:15 XXX Not found! Completable: Cpattern Value[v] ContextPath Value[v] +Path v [{ "label": "(_, _, _)", "kind": 12, @@ -21,6 +22,7 @@ posCursor:[13:18] posNoWhite:[13:17] Found pattern:[13:16->13:22] posCursor:[13:18] posNoWhite:[13:17] Found pattern:[13:17->13:18] Completable: Cpattern Value[v]=t->tuple($0) ContextPath Value[v] +Path v [{ "label": "true", "kind": 4, @@ -35,6 +37,7 @@ posCursor:[16:25] posNoWhite:[16:24] Found pattern:[16:23->16:29] posCursor:[16:25] posNoWhite:[16:24] Found pattern:[16:24->16:25] Completable: Cpattern Value[v]=f->tuple($2), tuple($0) ContextPath Value[v] +Path v [{ "label": "false", "kind": 4, @@ -47,6 +50,7 @@ Complete src/CompletionPattern.res 21:15 XXX Not found! Completable: Cpattern Value[x] ContextPath Value[x] +Path x [{ "label": "true", "kind": 4, @@ -65,6 +69,7 @@ Complete src/CompletionPattern.res 24:17 posCursor:[24:17] posNoWhite:[24:16] Found pattern:[24:16->24:17] Completable: Cpattern Value[x]=t ContextPath Value[x] +Path x [{ "label": "true", "kind": 4, @@ -77,6 +82,7 @@ Complete src/CompletionPattern.res 46:15 XXX Not found! Completable: Cpattern Value[f] ContextPath Value[f] +Path f [{ "label": "{}", "kind": 22, @@ -92,6 +98,7 @@ Complete src/CompletionPattern.res 49:17 posCursor:[49:17] posNoWhite:[49:16] Found pattern:[49:16->49:18] Completable: Cpattern Value[f]->recordBody ContextPath Value[f] +Path f [{ "label": "first", "kind": 5, @@ -122,6 +129,7 @@ Complete src/CompletionPattern.res 52:24 posCursor:[52:24] posNoWhite:[52:22] Found pattern:[52:16->52:35] Completable: Cpattern Value[f]->recordBody ContextPath Value[f] +Path f [{ "label": "optThird", "kind": 5, @@ -141,6 +149,7 @@ posCursor:[55:19] posNoWhite:[55:18] Found pattern:[55:16->55:20] posCursor:[55:19] posNoWhite:[55:18] Found pattern:[55:17->55:19] Completable: Cpattern Value[f]=fi->recordBody ContextPath Value[f] +Path f [{ "label": "first", "kind": 5, @@ -155,6 +164,7 @@ posCursor:[58:19] posNoWhite:[58:18] Found pattern:[58:17->58:20] posCursor:[58:19] posNoWhite:[58:18] Found pattern:[58:18->58:19] Completable: Cpattern Value[z]=o->tuple($0), recordBody ContextPath Value[z] +Path z [{ "label": "optThird", "kind": 5, @@ -167,6 +177,7 @@ Complete src/CompletionPattern.res 61:22 posCursor:[61:22] posNoWhite:[61:21] Found pattern:[61:16->61:25] Completable: Cpattern Value[f]->recordField(nest) ContextPath Value[f] +Path f [{ "label": "{}", "kind": 22, @@ -183,6 +194,7 @@ posCursor:[64:24] posNoWhite:[64:23] Found pattern:[64:16->64:26] posCursor:[64:24] posNoWhite:[64:23] Found pattern:[64:23->64:25] Completable: Cpattern Value[f]->recordField(nest), recordBody ContextPath Value[f] +Path f [{ "label": "nested", "kind": 5, @@ -197,6 +209,7 @@ posCursor:[70:22] posNoWhite:[70:21] Found expr:[70:5->72:13] posCursor:[70:22] posNoWhite:[70:21] Found pattern:[70:21->70:23] Completable: Cpattern Value[nest]->recordBody ContextPath Value[nest] +Path nest [{ "label": "nested", "kind": 5, @@ -209,6 +222,7 @@ Complete src/CompletionPattern.res 76:8 posCursor:[76:8] posNoWhite:[76:7] Found pattern:[76:7->76:9] Completable: Cpattern Value[f]->recordBody ContextPath Value[f] +Path f [{ "label": "first", "kind": 5, @@ -241,6 +255,7 @@ posCursor:[79:16] posNoWhite:[79:15] Found pattern:[79:14->79:17] posCursor:[79:16] posNoWhite:[79:15] Found pattern:[79:15->79:16] Completable: Cpattern Value[f]=n->recordField(nest), recordBody ContextPath Value[f] +Path f [{ "label": "nested", "kind": 5, @@ -256,6 +271,7 @@ posCursor:[87:20] posNoWhite:[87:19] Found pattern:[87:19->87:21] Ppat_construct ():[87:19->87:21] Completable: Cpattern Value[z]->variantPayload::Two($0) ContextPath Value[z] +Path z [{ "label": "true", "kind": 4, @@ -276,6 +292,7 @@ Ppat_construct Two:[90:16->90:19] posCursor:[90:21] posNoWhite:[90:20] Found pattern:[90:20->90:21] Completable: Cpattern Value[z]=t->variantPayload::Two($0) ContextPath Value[z] +Path z [{ "label": "true", "kind": 4, @@ -290,6 +307,7 @@ Ppat_construct Three:[93:16->93:21] posCursor:[93:23] posNoWhite:[93:22] Found pattern:[93:22->93:24] Completable: Cpattern Value[z]->variantPayload::Three($0), recordBody ContextPath Value[z] +Path z [{ "label": "first", "kind": 5, @@ -323,6 +341,7 @@ posCursor:[96:27] posNoWhite:[96:26] Found pattern:[96:21->96:29] posCursor:[96:27] posNoWhite:[96:26] Found pattern:[96:26->96:27] Completable: Cpattern Value[z]=t->variantPayload::Three($1) ContextPath Value[z] +Path z [{ "label": "true", "kind": 4, @@ -337,6 +356,7 @@ posCursor:[103:21] posNoWhite:[103:20] Found pattern:[103:20->103:21] Ppat_construct ():[103:20->103:21] Completable: Cpattern Value[b]->polyvariantPayload::two($0) ContextPath Value[b] +Path b [{ "label": "true", "kind": 4, @@ -356,6 +376,7 @@ posCursor:[106:22] posNoWhite:[106:21] Found pattern:[106:16->106:23] posCursor:[106:22] posNoWhite:[106:21] Found pattern:[106:21->106:22] Completable: Cpattern Value[b]=t->polyvariantPayload::two($0) ContextPath Value[b] +Path b [{ "label": "true", "kind": 4, @@ -369,6 +390,7 @@ posCursor:[109:24] posNoWhite:[109:23] Found pattern:[109:16->109:26] posCursor:[109:24] posNoWhite:[109:23] Found pattern:[109:23->109:25] Completable: Cpattern Value[b]->polyvariantPayload::three($0), recordBody ContextPath Value[b] +Path b [{ "label": "first", "kind": 5, @@ -401,6 +423,7 @@ posCursor:[112:28] posNoWhite:[112:27] Found pattern:[112:22->112:29] posCursor:[112:28] posNoWhite:[112:27] Found pattern:[112:27->112:28] Completable: Cpattern Value[b]=t->polyvariantPayload::three($1) ContextPath Value[b] +Path b [{ "label": "true", "kind": 4, @@ -413,6 +436,7 @@ Complete src/CompletionPattern.res 118:15 XXX Not found! Completable: Cpattern Value[c] ContextPath Value[c] +Path c [{ "label": "[]", "kind": 12, @@ -428,6 +452,7 @@ Complete src/CompletionPattern.res 121:17 posCursor:[121:17] posNoWhite:[121:16] Found pattern:[121:16->121:18] Completable: Cpattern Value[c]->array ContextPath Value[c] +Path c [{ "label": "true", "kind": 4, @@ -449,6 +474,7 @@ posCursor:[127:21] posNoWhite:[127:20] Found pattern:[127:20->127:22] Ppat_construct ():[127:20->127:22] Completable: Cpattern Value[o]->variantPayload::Some($0) ContextPath Value[o] +Path o [{ "label": "true", "kind": 4, @@ -468,6 +494,7 @@ posCursor:[134:23] posNoWhite:[134:22] Found pattern:[134:16->134:25] Ppat_construct Test:[134:16->134:20] Completable: Cpattern Value[p]->variantPayload::Test($1) ContextPath Value[p] +Path p [{ "label": "true", "kind": 4, @@ -488,6 +515,7 @@ Ppat_construct Test:[137:16->137:20] posCursor:[137:29] posNoWhite:[137:28] Found pattern:[137:20->137:32] Completable: Cpattern Value[p]->variantPayload::Test($2) ContextPath Value[p] +Path p [{ "label": "None", "kind": 12, @@ -522,6 +550,7 @@ Ppat_construct Test:[140:16->140:20] posCursor:[140:23] posNoWhite:[140:22] Found pattern:[140:20->140:32] Completable: Cpattern Value[p]->variantPayload::Test($1) ContextPath Value[p] +Path p [{ "label": "true", "kind": 4, @@ -542,6 +571,7 @@ Ppat_construct Test:[143:16->143:20] posCursor:[143:35] posNoWhite:[143:34] Found pattern:[143:20->143:38] Completable: Cpattern Value[p]->variantPayload::Test($3) ContextPath Value[p] +Path p [{ "label": "[]", "kind": 12, @@ -557,6 +587,7 @@ Complete src/CompletionPattern.res 150:24 posCursor:[150:24] posNoWhite:[150:23] Found pattern:[150:16->150:26] Completable: Cpattern Value[v]->polyvariantPayload::test($1) ContextPath Value[v] +Path v [{ "label": "true", "kind": 4, @@ -576,6 +607,7 @@ posCursor:[153:30] posNoWhite:[153:29] Found pattern:[153:16->153:32] posCursor:[153:30] posNoWhite:[153:29] Found pattern:[153:21->153:32] Completable: Cpattern Value[v]->polyvariantPayload::test($2) ContextPath Value[v] +Path v [{ "label": "None", "kind": 12, @@ -609,6 +641,7 @@ posCursor:[156:24] posNoWhite:[156:23] Found pattern:[156:16->156:32] posCursor:[156:24] posNoWhite:[156:23] Found pattern:[156:21->156:32] Completable: Cpattern Value[v]->polyvariantPayload::test($1) ContextPath Value[v] +Path v [{ "label": "true", "kind": 4, @@ -628,6 +661,7 @@ posCursor:[159:36] posNoWhite:[159:35] Found pattern:[159:16->159:38] posCursor:[159:36] posNoWhite:[159:35] Found pattern:[159:21->159:38] Completable: Cpattern Value[v]->polyvariantPayload::test($3) ContextPath Value[v] +Path v [{ "label": "[]", "kind": 12, @@ -644,6 +678,7 @@ posCursor:[164:17] posNoWhite:[164:16] Found pattern:[164:16->164:18] Ppat_construct ():[164:16->164:18] Completable: Cpattern Value[s]->tuple($0) ContextPath Value[s] +Path s [{ "label": "true", "kind": 4, @@ -662,6 +697,7 @@ Complete src/CompletionPattern.res 167:23 posCursor:[167:23] posNoWhite:[167:21] Found pattern:[167:16->167:24] Completable: Cpattern Value[s]->tuple($1) ContextPath Value[s] +Path s [{ "label": "None", "kind": 12, @@ -694,6 +730,7 @@ Complete src/CompletionPattern.res 170:22 posCursor:[170:22] posNoWhite:[170:21] Found pattern:[170:16->170:28] Completable: Cpattern Value[s]->tuple($1) ContextPath Value[s] +Path s [{ "label": "None", "kind": 12, @@ -726,6 +763,7 @@ Complete src/CompletionPattern.res 173:35 XXX Not found! Completable: Cpattern Value[s] ContextPath Value[s] +Path s [{ "label": "(_, _, _)", "kind": 12, @@ -740,6 +778,7 @@ Complete src/CompletionPattern.res 176:41 posCursor:[176:41] posNoWhite:[176:40] Found pattern:[176:35->176:47] Completable: Cpattern Value[s]->tuple($1) ContextPath Value[s] +Path s [{ "label": "None", "kind": 12, @@ -772,6 +811,7 @@ Complete src/CompletionPattern.res 179:21 XXX Not found! Completable: Cpattern Value[z] ContextPath Value[z] +Path z [{ "label": "One", "kind": 4, @@ -804,6 +844,7 @@ posCursor:[182:32] posNoWhite:[182:31] Found pattern:[182:22->182:34] Ppat_construct Two:[182:22->182:25] Completable: Cpattern Value[z]->variantPayload::Two($0) ContextPath Value[z] +Path z [{ "label": "true", "kind": 4, @@ -825,6 +866,7 @@ Ppat_construct Three:[185:22->185:27] posCursor:[185:48] posNoWhite:[185:47] Found pattern:[185:27->185:53] Completable: Cpattern Value[z]->variantPayload::Three($1) ContextPath Value[z] +Path z [{ "label": "true", "kind": 4, @@ -844,6 +886,7 @@ posCursor:[188:34] posNoWhite:[188:33] Found pattern:[188:16->188:36] posCursor:[188:34] posNoWhite:[188:33] Found pattern:[188:23->188:36] Completable: Cpattern Value[b]->polyvariantPayload::two($0) ContextPath Value[b] +Path b [{ "label": "true", "kind": 4, @@ -864,6 +907,7 @@ posCursor:[191:50] posNoWhite:[191:49] Found pattern:[191:23->191:52] posCursor:[191:50] posNoWhite:[191:49] Found pattern:[191:29->191:52] Completable: Cpattern Value[b]->polyvariantPayload::three($1) ContextPath Value[b] +Path b [{ "label": "true", "kind": 4, @@ -883,6 +927,7 @@ posCursor:[194:24] posNoWhite:[194:23] Found pattern:[194:16->194:29] posCursor:[194:24] posNoWhite:[194:23] Found pattern:[194:23->194:24] Completable: Cpattern Value[s]->tuple($1) ContextPath Value[s] +Path s [{ "label": "None", "kind": 12, @@ -915,12 +960,14 @@ Complete src/CompletionPattern.res 201:25 posCursor:[201:25] posNoWhite:[201:24] Found pattern:[201:17->201:28] Completable: Cpattern Value[ff]->recordField(someFn) ContextPath Value[ff] +Path ff [] Complete src/CompletionPattern.res 206:16 XXX Not found! Completable: Cpattern Value[xn] ContextPath Value[xn] +Path xn [{ "label": "Js.Exn.Error(error)", "kind": 4, diff --git a/analysis/tests/src/expected/CompletionPipeChain.res.txt b/analysis/tests/src/expected/CompletionPipeChain.res.txt index 1bdc6d425..0d767a9ed 100644 --- a/analysis/tests/src/expected/CompletionPipeChain.res.txt +++ b/analysis/tests/src/expected/CompletionPipeChain.res.txt @@ -3,6 +3,8 @@ posCursor:[27:16] posNoWhite:[27:15] Found expr:[27:11->0:-1] Completable: Cpath Value[int]-> ContextPath Value[int]-> ContextPath Value[int] +Path int +Path Integer. [{ "label": "Integer.toInt", "kind": 12, @@ -35,6 +37,8 @@ Completable: Cpath Value[toFlt](Nolabel)-> ContextPath Value[toFlt](Nolabel)-> ContextPath Value[toFlt](Nolabel) ContextPath Value[toFlt] +Path toFlt +Path SuperFloat. [{ "label": "SuperFloat.fromInteger", "kind": 12, @@ -55,6 +59,8 @@ Completable: Cpath Value[Integer, increment](Nolabel, Nolabel)-> ContextPath Value[Integer, increment](Nolabel, Nolabel)-> ContextPath Value[Integer, increment](Nolabel, Nolabel) ContextPath Value[Integer, increment] +Path Integer.increment +Path Integer. [{ "label": "Integer.toInt", "kind": 12, @@ -87,6 +93,8 @@ Completable: Cpath Value[Integer, increment](Nolabel, Nolabel)-> ContextPath Value[Integer, increment](Nolabel, Nolabel)-> ContextPath Value[Integer, increment](Nolabel, Nolabel) ContextPath Value[Integer, increment] +Path Integer.increment +Path Integer. [{ "label": "Integer.toInt", "kind": 12, @@ -119,6 +127,8 @@ Completable: Cpath Value[Integer, decrement](Nolabel, Nolabel)-> ContextPath Value[Integer, decrement](Nolabel, Nolabel)-> ContextPath Value[Integer, decrement](Nolabel, Nolabel) ContextPath Value[Integer, decrement] +Path Integer.decrement +Path Integer. [{ "label": "Integer.toInt", "kind": 12, @@ -151,6 +161,8 @@ Completable: Cpath Value[Integer, decrement](Nolabel, Nolabel)-> ContextPath Value[Integer, decrement](Nolabel, Nolabel)-> ContextPath Value[Integer, decrement](Nolabel, Nolabel) ContextPath Value[Integer, decrement] +Path Integer.decrement +Path Integer. [{ "label": "Integer.toInt", "kind": 12, @@ -183,6 +195,8 @@ Completable: Cpath Value[SuperFloat, fromInteger](Nolabel)-> ContextPath Value[SuperFloat, fromInteger](Nolabel)-> ContextPath Value[SuperFloat, fromInteger](Nolabel) ContextPath Value[SuperFloat, fromInteger] +Path SuperFloat.fromInteger +Path SuperFloat. [{ "label": "SuperFloat.fromInteger", "kind": 12, @@ -203,6 +217,8 @@ Completable: Cpath Value[SuperFloat, fromInteger](Nolabel)->t ContextPath Value[SuperFloat, fromInteger](Nolabel)->t ContextPath Value[SuperFloat, fromInteger](Nolabel) ContextPath Value[SuperFloat, fromInteger] +Path SuperFloat.fromInteger +Path SuperFloat.t [{ "label": "SuperFloat.toInteger", "kind": 12, @@ -217,6 +233,8 @@ Completable: Cpath Value[CompletionSupport, Test, make](Nolabel)-> ContextPath Value[CompletionSupport, Test, make](Nolabel)-> ContextPath Value[CompletionSupport, Test, make](Nolabel) ContextPath Value[CompletionSupport, Test, make] +Path CompletionSupport.Test.make +Path CompletionSupport.Test. [{ "label": "CompletionSupport.Test.add", "kind": 12, @@ -243,6 +261,8 @@ Completable: Cpath Value[CompletionSupport, Test, addSelf](Nolabel, Nolabel)-> ContextPath Value[CompletionSupport, Test, addSelf](Nolabel, Nolabel)-> ContextPath Value[CompletionSupport, Test, addSelf](Nolabel, Nolabel) ContextPath Value[CompletionSupport, Test, addSelf] +Path CompletionSupport.Test.addSelf +Path CompletionSupport.Test. [{ "label": "CompletionSupport.Test.add", "kind": 12, @@ -269,6 +289,7 @@ Completable: Cpath Value[Js, Array2, forEach](Nolabel, Nolabel)-> ContextPath Value[Js, Array2, forEach](Nolabel, Nolabel)-> ContextPath Value[Js, Array2, forEach](Nolabel, Nolabel) ContextPath Value[Js, Array2, forEach] +Path Js.Array2.forEach [] Complete src/CompletionPipeChain.res 62:6 @@ -277,6 +298,8 @@ Completable: Cpath Value[Belt, Array, reduce](Nolabel, Nolabel, Nolabel)->t ContextPath Value[Belt, Array, reduce](Nolabel, Nolabel, Nolabel)->t ContextPath Value[Belt, Array, reduce](Nolabel, Nolabel, Nolabel) ContextPath Value[Belt, Array, reduce] +Path Belt.Array.reduce +Path Belt.Int.t [{ "label": "Belt.Int.toString", "kind": 12, @@ -296,6 +319,8 @@ posCursor:[70:12] posNoWhite:[70:11] Found expr:[70:3->0:-1] Completable: Cpath Value[aliased]-> ContextPath Value[aliased]-> ContextPath Value[aliased] +Path aliased +Path CompletionSupport.Test. [{ "label": "CompletionSupport.Test.add", "kind": 12, @@ -321,6 +346,8 @@ posCursor:[73:15] posNoWhite:[73:14] Found expr:[73:3->0:-1] Completable: Cpath Value[notAliased]-> ContextPath Value[notAliased]-> ContextPath Value[notAliased] +Path notAliased +Path CompletionSupport.Test. [{ "label": "CompletionSupport.Test.add", "kind": 12, diff --git a/analysis/tests/src/expected/CompletionPipeSubmodules.res.txt b/analysis/tests/src/expected/CompletionPipeSubmodules.res.txt index 81eb5e839..b6e1b9386 100644 --- a/analysis/tests/src/expected/CompletionPipeSubmodules.res.txt +++ b/analysis/tests/src/expected/CompletionPipeSubmodules.res.txt @@ -3,6 +3,8 @@ posCursor:[12:20] posNoWhite:[12:19] Found expr:[12:11->20:8] Completable: Cpath Value[A, B1, xx]-> ContextPath Value[A, B1, xx]-> ContextPath Value[A, B1, xx] +Path A.B1.xx +Path A.B1. [{ "label": "A.B1.xx", "kind": 12, @@ -23,6 +25,8 @@ Completable: Cpath Value[A, x].v-> ContextPath Value[A, x].v-> ContextPath Value[A, x].v ContextPath Value[A, x] +Path A.x +Path A.B1. [{ "label": "A.B1.xx", "kind": 12, @@ -44,6 +48,8 @@ ContextPath Value[E, e].v.v-> ContextPath Value[E, e].v.v ContextPath Value[E, e].v ContextPath Value[E, e] +Path E.e +Path C. [{ "label": "C.C", "kind": 4, @@ -59,6 +65,8 @@ ContextPath Value[E, e].v.v2-> ContextPath Value[E, e].v.v2 ContextPath Value[E, e].v ContextPath Value[E, e] +Path E.e +Path D.C2. [{ "label": "D.C2.C2", "kind": 4, diff --git a/analysis/tests/src/expected/CompletionTypeAnnotation.res.txt b/analysis/tests/src/expected/CompletionTypeAnnotation.res.txt index d79e24bae..88468602c 100644 --- a/analysis/tests/src/expected/CompletionTypeAnnotation.res.txt +++ b/analysis/tests/src/expected/CompletionTypeAnnotation.res.txt @@ -2,6 +2,7 @@ Complete src/CompletionTypeAnnotation.res 9:22 XXX Not found! Completable: Cexpression Type[someRecord] ContextPath Type[someRecord] +Path someRecord [{ "label": "{}", "kind": 12, @@ -17,6 +18,7 @@ Complete src/CompletionTypeAnnotation.res 12:24 XXX Not found! Completable: Cexpression Type[someRecord]->recordBody ContextPath Type[someRecord] +Path someRecord [{ "label": "age", "kind": 5, @@ -35,6 +37,7 @@ Complete src/CompletionTypeAnnotation.res 15:23 XXX Not found! Completable: Cexpression Type[someVariant] ContextPath Type[someVariant] +Path someVariant [{ "label": "One", "kind": 4, @@ -57,6 +60,7 @@ Complete src/CompletionTypeAnnotation.res 18:25 XXX Not found! Completable: Cexpression Type[someVariant]=O ContextPath Type[someVariant] +Path someVariant [{ "label": "One", "kind": 4, @@ -84,6 +88,7 @@ Complete src/CompletionTypeAnnotation.res 21:27 XXX Not found! Completable: Cexpression Type[somePolyVariant] ContextPath Type[somePolyVariant] +Path somePolyVariant [{ "label": "#one", "kind": 4, @@ -106,6 +111,7 @@ Complete src/CompletionTypeAnnotation.res 24:30 XXX Not found! Completable: Cexpression Type[somePolyVariant]=#o ContextPath Type[somePolyVariant] +Path somePolyVariant [{ "label": "#one", "kind": 4, @@ -120,6 +126,7 @@ Complete src/CompletionTypeAnnotation.res 29:20 XXX Not found! Completable: Cexpression Type[someFunc] ContextPath Type[someFunc] +Path someFunc [{ "label": "(v1, v2) => {}", "kind": 12, @@ -135,6 +142,7 @@ Complete src/CompletionTypeAnnotation.res 34:21 XXX Not found! Completable: Cexpression Type[someTuple] ContextPath Type[someTuple] +Path someTuple [{ "label": "(_, _)", "kind": 12, @@ -149,6 +157,7 @@ Complete src/CompletionTypeAnnotation.res 37:28 XXX Not found! Completable: Cexpression Type[someTuple]->tuple($1) ContextPath Type[someTuple] +Path someTuple [{ "label": "None", "kind": 12, @@ -182,6 +191,7 @@ XXX Not found! Completable: Cexpression option ContextPath option ContextPath Type[someVariant] +Path someVariant [{ "label": "None", "kind": 12, @@ -219,6 +229,7 @@ XXX Not found! Completable: Cexpression option->variantPayload::Some($0) ContextPath option ContextPath Type[someVariant] +Path someVariant [{ "label": "One", "kind": 4, @@ -242,6 +253,7 @@ XXX Not found! Completable: Cexpression array ContextPath array ContextPath Type[someVariant] +Path someVariant [{ "label": "[]", "kind": 12, @@ -258,6 +270,7 @@ XXX Not found! Completable: Cexpression array->array ContextPath array ContextPath Type[someVariant] +Path someVariant [{ "label": "One", "kind": 4, @@ -282,6 +295,7 @@ Completable: Cexpression array> ContextPath array> ContextPath option ContextPath Type[someVariant] +Path someVariant [{ "label": "[]", "kind": 12, @@ -299,6 +313,7 @@ Completable: Cexpression option>->variantPayload::Some( ContextPath option> ContextPath array ContextPath Type[someVariant] +Path someVariant [{ "label": "One", "kind": 4, diff --git a/analysis/tests/src/expected/Cross.res.txt b/analysis/tests/src/expected/Cross.res.txt index fe9a52e69..5407bfa66 100644 --- a/analysis/tests/src/expected/Cross.res.txt +++ b/analysis/tests/src/expected/Cross.res.txt @@ -98,6 +98,7 @@ posCursor:[36:28] posNoWhite:[36:27] Found expr:[36:3->36:28] Pexp_ident DefinitionWithInterface.a:[36:3->36:28] Completable: Cpath Value[DefinitionWithInterface, a] ContextPath Value[DefinitionWithInterface, a] +Path DefinitionWithInterface.a [] Definition src/Cross.res 39:39 diff --git a/analysis/tests/src/expected/Debug.res.txt b/analysis/tests/src/expected/Debug.res.txt index f1554acc9..192122e7b 100644 --- a/analysis/tests/src/expected/Debug.res.txt +++ b/analysis/tests/src/expected/Debug.res.txt @@ -11,6 +11,7 @@ Completable: Cpath Value[eqN] Raw opens: 1 Js.place holder Resolved opens 1 js.ml ContextPath Value[eqN] +Path eqN [{ "label": "eqNullable", "kind": 12, diff --git a/analysis/tests/src/expected/Destructuring.res.txt b/analysis/tests/src/expected/Destructuring.res.txt index 309ea0972..e3669008c 100644 --- a/analysis/tests/src/expected/Destructuring.res.txt +++ b/analysis/tests/src/expected/Destructuring.res.txt @@ -2,6 +2,7 @@ Complete src/Destructuring.res 4:11 posCursor:[4:11] posNoWhite:[4:9] Found pattern:[4:4->4:12] Completable: Cpattern Value[x]->recordBody ContextPath Value[x] +Path x [{ "label": "age", "kind": 5, @@ -14,6 +15,7 @@ Complete src/Destructuring.res 7:8 posCursor:[7:8] posNoWhite:[7:7] Found pattern:[7:7->7:9] Completable: Cpattern Value[x]->recordBody ContextPath Value[x] +Path x [{ "label": "name", "kind": 5, @@ -34,6 +36,7 @@ posCursor:[11:13] posNoWhite:[11:11] Found expr:[11:2->13:6] posCursor:[11:13] posNoWhite:[11:11] Found pattern:[11:6->11:14] Completable: Cpattern Value[x]->recordBody ContextPath Value[x] +Path x [{ "label": "age", "kind": 5, @@ -48,6 +51,7 @@ posCursor:[17:10] posNoWhite:[17:9] Found expr:[17:5->19:11] posCursor:[17:10] posNoWhite:[17:9] Found pattern:[17:9->17:11] Completable: Cpattern Value[x]->recordBody ContextPath Value[x] +Path x [{ "label": "name", "kind": 5, @@ -66,6 +70,7 @@ Complete src/Destructuring.res 31:8 posCursor:[31:8] posNoWhite:[31:7] Found pattern:[31:7->31:9] Completable: Cpattern Value[x]->recordBody ContextPath Value[x] +Path x [{ "label": "someField", "kind": 5, diff --git a/analysis/tests/src/expected/ExhaustiveSwitch.res.txt b/analysis/tests/src/expected/ExhaustiveSwitch.res.txt index 6833140a6..9f53761e5 100644 --- a/analysis/tests/src/expected/ExhaustiveSwitch.res.txt +++ b/analysis/tests/src/expected/ExhaustiveSwitch.res.txt @@ -2,6 +2,7 @@ Complete src/ExhaustiveSwitch.res 8:24 XXX Not found! Completable: CexhaustiveSwitch Value[withSomeVarian] ContextPath Value[withSomeVarian] +Path withSomeVarian [{ "label": "withSomeVariant", "kind": 12, @@ -23,6 +24,7 @@ Complete src/ExhaustiveSwitch.res 11:21 XXX Not found! Completable: CexhaustiveSwitch Value[withSomePol] ContextPath Value[withSomePol] +Path withSomePol [{ "label": "withSomePoly", "kind": 12, @@ -44,6 +46,7 @@ Complete src/ExhaustiveSwitch.res 14:17 XXX Not found! Completable: CexhaustiveSwitch Value[someBoo] ContextPath Value[someBoo] +Path someBoo [{ "label": "someBool", "kind": 12, @@ -65,6 +68,7 @@ Complete src/ExhaustiveSwitch.res 17:16 XXX Not found! Completable: CexhaustiveSwitch Value[someOp] ContextPath Value[someOp] +Path someOp [{ "label": "someOpt", "kind": 12, diff --git a/analysis/tests/src/expected/Hover.res.txt b/analysis/tests/src/expected/Hover.res.txt index af002fc92..423f460f9 100644 --- a/analysis/tests/src/expected/Hover.res.txt +++ b/analysis/tests/src/expected/Hover.res.txt @@ -119,6 +119,7 @@ Completable: Cpath Value[x1].content."" ContextPath Value[x1].content."" ContextPath Value[x1].content ContextPath Value[x1] +Path x1 [{ "label": "age", "kind": 5, @@ -134,6 +135,7 @@ Completable: Cpath Value[x2].content."" ContextPath Value[x2].content."" ContextPath Value[x2].content ContextPath Value[x2] +Path x2 [{ "label": "age", "kind": 5, @@ -149,6 +151,7 @@ Completable: Cpath Value[y1].content."" ContextPath Value[y1].content."" ContextPath Value[y1].content ContextPath Value[y1] +Path y1 [{ "label": "age", "kind": 5, @@ -164,6 +167,7 @@ Completable: Cpath Value[y2].content."" ContextPath Value[y2].content."" ContextPath Value[y2].content ContextPath Value[y2] +Path y2 [{ "label": "age", "kind": 5, @@ -184,6 +188,7 @@ posCursor:[210:13] posNoWhite:[210:12] Found expr:[210:11->210:14] Pexp_ident usr:[210:11->210:14] Completable: Cpath Value[usr] ContextPath Value[usr] +Path usr {"contents": {"kind": "markdown", "value": "```rescript\nuseR\n```\n\n---\n\n```\n \n```\n```rescript\ntype useR = {x: int, y: list>>}\n```\nGo to: [Type definition](command:rescript-vscode.go_to_location?%5B%22Hover.res%22%2C200%2C0%5D)\n\n\n---\n\n```\n \n```\n```rescript\ntype r<'a> = {i: 'a, f: float}\n```\nGo to: [Type definition](command:rescript-vscode.go_to_location?%5B%22Hover.res%22%2C101%2C0%5D)\n"}} Hover src/Hover.res 230:20 @@ -199,6 +204,7 @@ Pexp_field [245:3->245:4] someField:[245:5->245:14] Completable: Cpath Value[x].someField ContextPath Value[x].someField ContextPath Value[x] +Path x {"contents": {"kind": "markdown", "value": "```rescript\nbool\n```\n\n Mighty fine field here. "}} Hover src/Hover.res 248:19 diff --git a/analysis/tests/src/expected/Jsx2.res.txt b/analysis/tests/src/expected/Jsx2.res.txt index 297e5736d..ba54f65f3 100644 --- a/analysis/tests/src/expected/Jsx2.res.txt +++ b/analysis/tests/src/expected/Jsx2.res.txt @@ -8,12 +8,14 @@ posCursor:[8:15] posNoWhite:[8:14] Found expr:[8:4->8:15] JSX 8:5] second[8:6->8:12]=...[8:13->8:15]> _children:None Completable: Cexpression CJsxPropValue [M] second=fi ContextPath CJsxPropValue [M] second +Path M.make [] Complete src/Jsx2.res 11:20 posCursor:[11:20] posNoWhite:[11:19] Found expr:[11:4->11:20] JSX 11:5] second[11:6->11:12]=...[11:13->11:18] f[11:19->11:20]=...[11:19->11:20]> _children:None Completable: Cjsx([M], f, [second, f]) +Path M.make [{ "label": "first", "kind": 4, @@ -33,6 +35,7 @@ posCursor:[14:13] posNoWhite:[14:12] Found expr:[14:12->14:13] JSX 14:13] > _children:None Completable: Cpath Module[M] ContextPath Module[M] +Path M [{ "label": "M", "kind": 9, @@ -63,6 +66,7 @@ Complete src/Jsx2.res 22:19 posCursor:[22:19] posNoWhite:[22:18] Found expr:[22:4->22:19] JSX 22:5] prop[22:6->22:10]=...[22:12->22:16] k[22:18->22:19]=...[22:18->22:19]> _children:None Completable: Cjsx([M], k, [prop, k]) +Path M.make [{ "label": "key", "kind": 4, @@ -75,6 +79,7 @@ Complete src/Jsx2.res 25:17 posCursor:[25:17] posNoWhite:[25:16] Found expr:[25:4->25:17] JSX 25:5] prop[25:6->25:10]=...[25:11->25:15] k[25:16->25:17]=...[25:16->25:17]> _children:None Completable: Cjsx([M], k, [prop, k]) +Path M.make [{ "label": "key", "kind": 4, @@ -87,6 +92,7 @@ Complete src/Jsx2.res 28:21 posCursor:[28:21] posNoWhite:[28:20] Found expr:[28:4->28:21] JSX 28:5] prop[28:6->28:10]=...[28:11->28:19] k[28:20->28:21]=...[28:20->28:21]> _children:None Completable: Cjsx([M], k, [prop, k]) +Path M.make [{ "label": "key", "kind": 4, @@ -99,6 +105,7 @@ Complete src/Jsx2.res 31:24 posCursor:[31:24] posNoWhite:[31:23] Found expr:[31:4->31:24] JSX 31:5] prop[31:6->31:10]=...[31:11->31:22] k[31:23->31:24]=...[31:23->31:24]> _children:None Completable: Cjsx([M], k, [prop, k]) +Path M.make [{ "label": "key", "kind": 4, @@ -111,6 +118,7 @@ Complete src/Jsx2.res 34:18 posCursor:[34:18] posNoWhite:[34:17] Found expr:[34:4->34:18] JSX 34:5] prop[34:6->34:10]=...[34:12->34:16] k[34:17->34:18]=...[34:17->34:18]> _children:None Completable: Cjsx([M], k, [prop, k]) +Path M.make [{ "label": "key", "kind": 4, @@ -123,6 +131,7 @@ Complete src/Jsx2.res 37:16 posCursor:[37:16] posNoWhite:[37:15] Found expr:[37:4->37:16] JSX 37:5] prop[37:6->37:10]=...[37:11->37:14] k[37:15->37:16]=...[37:15->37:16]> _children:None Completable: Cjsx([M], k, [prop, k]) +Path M.make [{ "label": "key", "kind": 4, @@ -135,6 +144,7 @@ Complete src/Jsx2.res 40:17 posCursor:[40:17] posNoWhite:[40:16] Found expr:[40:4->40:17] JSX 40:5] prop[40:6->40:10]=...[40:11->40:15] k[40:16->40:17]=...[40:16->40:17]> _children:None Completable: Cjsx([M], k, [prop, k]) +Path M.make [{ "label": "key", "kind": 4, @@ -147,6 +157,7 @@ Complete src/Jsx2.res 43:18 posCursor:[43:18] posNoWhite:[43:17] Found expr:[43:4->43:18] JSX 43:5] prop[43:6->43:10]=...[43:11->43:16] k[43:17->43:18]=...[43:17->43:18]> _children:None Completable: Cjsx([M], k, [prop, k]) +Path M.make [{ "label": "key", "kind": 4, @@ -159,6 +170,7 @@ Complete src/Jsx2.res 46:16 posCursor:[46:16] posNoWhite:[46:15] Found expr:[46:4->46:16] JSX 46:5] prop[46:6->46:10]=...[46:11->46:14] k[46:15->46:16]=...[46:15->46:16]> _children:None Completable: Cjsx([M], k, [prop, k]) +Path M.make [{ "label": "key", "kind": 4, @@ -171,6 +183,7 @@ Complete src/Jsx2.res 49:27 posCursor:[49:27] posNoWhite:[49:26] Found expr:[49:4->49:27] JSX 49:5] prop[49:6->49:10]=...[49:11->49:25] k[49:26->49:27]=...[49:26->49:27]> _children:None Completable: Cjsx([M], k, [prop, k]) +Path M.make [{ "label": "key", "kind": 4, @@ -183,6 +196,7 @@ Complete src/Jsx2.res 52:38 posCursor:[52:38] posNoWhite:[52:37] Found expr:[52:4->52:38] JSX 52:5] prop[52:6->52:10]=...[52:11->52:36] k[52:37->52:38]=...[52:37->52:38]> _children:None Completable: Cjsx([M], k, [prop, k]) +Path M.make [{ "label": "key", "kind": 4, @@ -195,6 +209,7 @@ Complete src/Jsx2.res 55:25 posCursor:[55:25] posNoWhite:[55:24] Found expr:[55:4->55:25] JSX 55:5] prop[55:6->55:10]=...[55:11->55:23] k[55:24->55:25]=...[55:24->55:25]> _children:None Completable: Cjsx([M], k, [prop, k]) +Path M.make [{ "label": "key", "kind": 4, @@ -212,6 +227,7 @@ Complete src/Jsx2.res 68:10 posCursor:[68:10] posNoWhite:[68:9] Found expr:[68:4->68:10] JSX 68:7] al[68:8->68:10]=...[68:8->68:10]> _children:None Completable: Cjsx([Ext], al, [al]) +Path Ext.make [{ "label": "align", "kind": 4, @@ -224,12 +240,14 @@ Complete src/Jsx2.res 71:11 posCursor:[71:11] posNoWhite:[71:10] Found expr:[71:4->71:11] JSX 71:5] first[71:6->71:11]=...[71:6->71:11]> _children:None Completable: Cjsx([M], first, [first]) +Path M.make [] Complete src/Jsx2.res 74:16 posCursor:[74:16] posNoWhite:[74:15] Found expr:[74:4->74:16] JSX 74:5] first[74:6->74:11]=...[74:12->74:14] k[74:15->74:16]=...[74:15->74:16]> _children:None Completable: Cjsx([M], k, [first, k]) +Path M.make [{ "label": "key", "kind": 4, @@ -242,6 +260,7 @@ Complete src/Jsx2.res 77:23 posCursor:[77:23] posNoWhite:[77:22] Found expr:[77:4->77:23] JSX 77:5] first[77:6->77:11]=...[77:19->77:21] k[77:22->77:23]=...[77:22->77:23]> _children:None Completable: Cjsx([M], k, [first, k]) +Path M.make [{ "label": "key", "kind": 4, @@ -272,6 +291,7 @@ posCursor:[89:16] posNoWhite:[89:15] Found expr:[89:4->89:16] JSX 89:16] > _children:None Completable: Cpath Module[WithChildren] ContextPath Module[WithChildren] +Path WithChildren [{ "label": "WithChildren", "kind": 9, @@ -284,6 +304,7 @@ Complete src/Jsx2.res 91:18 posCursor:[91:18] posNoWhite:[91:17] Found expr:[91:4->91:18] JSX 91:16] n[91:17->91:18]=...[91:17->91:18]> _children:None Completable: Cjsx([WithChildren], n, [n]) +Path WithChildren.make [{ "label": "name", "kind": 4, @@ -298,6 +319,7 @@ posCursor:[94:18] posNoWhite:[94:17] Found type:[94:11->94:18] Ptyp_constr React.e:[94:11->94:18] Completable: Cpath Type[React, e] ContextPath Type[React, e] +Path React.e [{ "label": "element", "kind": 22, @@ -312,6 +334,7 @@ posCursor:[96:20] posNoWhite:[96:19] Found type:[96:11->99:6] Ptyp_constr ReactDOMR:[96:11->99:6] Completable: Cpath Type[ReactDOMR] ContextPath Type[ReactDOMR] +Path ReactDOMR [{ "label": "ReactDOMRe", "kind": 9, @@ -328,6 +351,7 @@ Pexp_field [102:17->102:18] th:[102:19->102:21] Completable: Cpath Value[x].th ContextPath Value[x].th ContextPath Value[x] +Path x [] Complete src/Jsx2.res 106:28 @@ -335,6 +359,7 @@ posCursor:[106:28] posNoWhite:[106:27] Found expr:[106:11->106:28] Pexp_ident DefineSomeFields.:[106:11->106:28] Completable: Cpath Value[DefineSomeFields, ""] ContextPath Value[DefineSomeFields, ""] +Path DefineSomeFields. [{ "label": "thisValue", "kind": 12, @@ -350,6 +375,7 @@ posCursor:[108:36] posNoWhite:[108:35] Found expr:[108:15->108:36] Pexp_field [108:15->108:16] DefineSomeFields.th:[108:17->108:36] Completable: Cpath Module[DefineSomeFields].th ContextPath Module[DefineSomeFields].th +Path DefineSomeFields.th [{ "label": "thisField", "kind": 5, @@ -371,6 +397,7 @@ posCursor:[122:20] posNoWhite:[122:19] Found expr:[122:7->122:20] Pexp_ident Outer.Inner.h:[122:7->122:20] Completable: Cpath Value[Outer, Inner, h] ContextPath Value[Outer, Inner, h] +Path Outer.Inner.h [{ "label": "hello", "kind": 12, @@ -386,6 +413,7 @@ posCursor:[129:19] posNoWhite:[129:18] Found expr:[129:7->131:8] Pexp_ident Outer.Inner.:[129:7->131:8] Completable: Cpath Value[Outer, Inner, ""] ContextPath Value[Outer, Inner, ""] +Path Outer.Inner. [{ "label": "hello", "kind": 12, @@ -404,6 +432,7 @@ posCursor:[150:21] posNoWhite:[150:20] Found expr:[150:12->150:32] JSX 150:21] name[150:22->150:26]=...[150:27->150:29]> _children:150:30 Completable: Cpath Module[Nested, Co] ContextPath Module[Nested, Co] +Path Nested.Co [{ "label": "Comp", "kind": 9, @@ -417,6 +446,7 @@ posCursor:[153:19] posNoWhite:[153:18] Found expr:[153:12->153:25] JSX 153:24] > _children:None Completable: Cpath Module[Nested, ""] ContextPath Module[Nested, ""] +Path Nested. [{ "label": "Comp", "kind": 9, @@ -433,6 +463,7 @@ posCursor:[162:12] posNoWhite:[162:11] Found expr:[162:6->162:21] posCursor:[162:12] posNoWhite:[162:11] Found expr:[162:6->162:20] JSX 162:10] age[162:11->162:14]=...[162:15->162:17]> _children:162:18 Completable: Cjsx([Comp], age, [age]) +Path Comp.make {"contents": {"kind": "markdown", "value": "```rescript\nint\n```"}} Hover src/Jsx2.res 167:16 @@ -446,5 +477,6 @@ posCursor:[167:16] posNoWhite:[167:15] Found expr:[167:10->167:25] posCursor:[167:16] posNoWhite:[167:15] Found expr:[167:10->167:24] JSX 167:14] age[167:15->167:18]=...[167:19->167:21]> _children:167:22 Completable: Cjsx([Comp], age, [age]) +Path Comp.make {"contents": {"kind": "markdown", "value": "```rescript\nint\n```"}} diff --git a/analysis/tests/src/expected/Jsx2.resi.txt b/analysis/tests/src/expected/Jsx2.resi.txt index 5c1f4ae9d..fa86df12c 100644 --- a/analysis/tests/src/expected/Jsx2.resi.txt +++ b/analysis/tests/src/expected/Jsx2.resi.txt @@ -11,6 +11,7 @@ posCursor:[7:19] posNoWhite:[7:18] Found type:[7:12->7:19] Ptyp_constr React.e:[7:12->7:19] Completable: Cpath Type[React, e] ContextPath Type[React, e] +Path React.e [{ "label": "element", "kind": 22, @@ -24,6 +25,7 @@ posCursor:[10:18] posNoWhite:[10:17] Found type:[10:11->10:18] Ptyp_constr React.e:[10:11->10:18] Completable: Cpath Type[React, e] ContextPath Type[React, e] +Path React.e [{ "label": "element", "kind": 22, diff --git a/analysis/tests/src/expected/JsxV4.res.txt b/analysis/tests/src/expected/JsxV4.res.txt index 3ae47a79e..fc6552084 100644 --- a/analysis/tests/src/expected/JsxV4.res.txt +++ b/analysis/tests/src/expected/JsxV4.res.txt @@ -5,6 +5,7 @@ Complete src/JsxV4.res 11:20 posCursor:[11:20] posNoWhite:[11:19] Found expr:[11:4->11:20] JSX 11:6] first[11:7->11:12]=...[11:13->11:18] f[11:19->11:20]=...[11:19->11:20]> _children:None Completable: Cjsx([M4], f, [first, f]) +Path M4.make [{ "label": "fun", "kind": 4, diff --git a/analysis/tests/src/expected/RecordCompletion.res.txt b/analysis/tests/src/expected/RecordCompletion.res.txt index e9ad5f29b..f74350306 100644 --- a/analysis/tests/src/expected/RecordCompletion.res.txt +++ b/analysis/tests/src/expected/RecordCompletion.res.txt @@ -4,6 +4,8 @@ Completable: Cpath Value[t].n->m ContextPath Value[t].n->m ContextPath Value[t].n ContextPath Value[t] +Path t +Path Js.Array2.m [{ "label": "Js.Array2.mapi", "kind": 12, @@ -25,6 +27,8 @@ ContextPath Value[t2].n2.n->m ContextPath Value[t2].n2.n ContextPath Value[t2].n2 ContextPath Value[t2] +Path t2 +Path Js.Array2.m [{ "label": "Js.Array2.mapi", "kind": 12, @@ -44,6 +48,7 @@ posCursor:[19:7] posNoWhite:[19:6] Found expr:[19:3->19:7] Pexp_field [19:3->19:4] R.:[19:5->19:7] Completable: Cpath Module[R]."" ContextPath Module[R]."" +Path R. [{ "label": "name", "kind": 5, @@ -57,6 +62,7 @@ posCursor:[22:7] posNoWhite:[22:6] Found expr:[22:3->22:10] Pexp_field [22:3->22:4] R.xx:[22:5->22:10] Completable: Cpath Module[R]."" ContextPath Module[R]."" +Path R. [{ "label": "name", "kind": 5, diff --git a/analysis/tests/src/expected/RecoveryOnProp.res.txt b/analysis/tests/src/expected/RecoveryOnProp.res.txt index f842bcaf0..b7e3bc268 100644 --- a/analysis/tests/src/expected/RecoveryOnProp.res.txt +++ b/analysis/tests/src/expected/RecoveryOnProp.res.txt @@ -12,6 +12,7 @@ posCursor:[6:26] posNoWhite:[6:25] Found type:[6:23->8:5] Ptyp_constr Res:[6:23->8:5] Completable: Cpath Type[Res] ContextPath Type[Res] +Path Res [{ "label": "RescriptReactErrorBoundary", "kind": 9, diff --git a/analysis/tests/src/expected/SignatureHelp.res.txt b/analysis/tests/src/expected/SignatureHelp.res.txt index 4ef3351f0..5ed218e47 100644 --- a/analysis/tests/src/expected/SignatureHelp.res.txt +++ b/analysis/tests/src/expected/SignatureHelp.res.txt @@ -5,6 +5,7 @@ posCursor:[16:19] posNoWhite:[16:18] Found expr:[16:11->16:19] Pexp_ident someFunc:[16:11->16:19] Completable: Cpath Value[someFunc] ContextPath Value[someFunc] +Path someFunc argAtCursor: unlabelled<0> extracted params: [( @@ -26,6 +27,7 @@ posCursor:[19:19] posNoWhite:[19:18] Found expr:[19:11->19:19] Pexp_ident someFunc:[19:11->19:19] Completable: Cpath Value[someFunc] ContextPath Value[someFunc] +Path someFunc argAtCursor: unlabelled<0> extracted params: [( @@ -47,6 +49,7 @@ posCursor:[22:19] posNoWhite:[22:18] Found expr:[22:11->22:19] Pexp_ident someFunc:[22:11->22:19] Completable: Cpath Value[someFunc] ContextPath Value[someFunc] +Path someFunc argAtCursor: ~two extracted params: [( @@ -68,6 +71,7 @@ posCursor:[25:19] posNoWhite:[25:18] Found expr:[25:11->25:19] Pexp_ident someFunc:[25:11->25:19] Completable: Cpath Value[someFunc] ContextPath Value[someFunc] +Path someFunc argAtCursor: ~two extracted params: [( @@ -89,6 +93,7 @@ posCursor:[28:19] posNoWhite:[28:18] Found expr:[28:11->28:19] Pexp_ident someFunc:[28:11->28:19] Completable: Cpath Value[someFunc] ContextPath Value[someFunc] +Path someFunc argAtCursor: ~four extracted params: [( @@ -110,6 +115,7 @@ posCursor:[31:19] posNoWhite:[31:18] Found expr:[31:11->31:19] Pexp_ident someFunc:[31:11->31:19] Completable: Cpath Value[someFunc] ContextPath Value[someFunc] +Path someFunc argAtCursor: ~four extracted params: [( @@ -131,6 +137,7 @@ posCursor:[34:20] posNoWhite:[34:19] Found expr:[34:11->34:20] Pexp_ident otherFunc:[34:11->34:20] Completable: Cpath Value[otherFunc] ContextPath Value[otherFunc] +Path otherFunc argAtCursor: unlabelled<0> extracted params: [(string, int, float] @@ -150,6 +157,7 @@ posCursor:[37:20] posNoWhite:[37:19] Found expr:[37:11->37:20] Pexp_ident otherFunc:[37:11->37:20] Completable: Cpath Value[otherFunc] ContextPath Value[otherFunc] +Path otherFunc argAtCursor: unlabelled<0> extracted params: [(string, int, float] @@ -169,6 +177,7 @@ posCursor:[40:20] posNoWhite:[40:19] Found expr:[40:11->40:20] Pexp_ident otherFunc:[40:11->40:20] Completable: Cpath Value[otherFunc] ContextPath Value[otherFunc] +Path otherFunc argAtCursor: unlabelled<2> extracted params: [(string, int, float] @@ -188,6 +197,7 @@ posCursor:[43:29] posNoWhite:[43:28] Found expr:[43:11->43:29] Pexp_ident Completion.Lib.foo:[43:11->43:29] Completable: Cpath Value[Completion, Lib, foo] ContextPath Value[Completion, Lib, foo] +Path Completion.Lib.foo argAtCursor: ~age extracted params: [(~age: int, ~name: string] @@ -207,6 +217,7 @@ posCursor:[50:23] posNoWhite:[50:22] Found expr:[50:11->50:23] Pexp_ident iAmSoSpecial:[50:11->50:23] Completable: Cpath Value[iAmSoSpecial] ContextPath Value[iAmSoSpecial] +Path iAmSoSpecial argAtCursor: unlabelled<0> extracted params: [string] @@ -227,6 +238,7 @@ posCursor:[53:29] posNoWhite:[53:28] Found expr:[53:20->53:29] Pexp_ident otherFunc:[53:20->53:29] Completable: Cpath Value[otherFunc] ContextPath Value[otherFunc] +Path otherFunc argAtCursor: unlabelled<1> extracted params: [(string, int, float] @@ -246,6 +258,7 @@ posCursor:[62:13] posNoWhite:[62:12] Found expr:[62:11->62:13] Pexp_ident fn:[62:11->62:13] Completable: Cpath Value[fn] ContextPath Value[fn] +Path fn argAtCursor: unlabelled<1> extracted params: [(int, string, int] @@ -265,6 +278,7 @@ posCursor:[65:13] posNoWhite:[65:12] Found expr:[65:11->65:13] Pexp_ident fn:[65:11->65:13] Completable: Cpath Value[fn] ContextPath Value[fn] +Path fn argAtCursor: unlabelled<1> extracted params: [(int, string, int] @@ -284,6 +298,7 @@ posCursor:[68:13] posNoWhite:[68:12] Found expr:[68:11->68:13] Pexp_ident fn:[68:11->68:13] Completable: Cpath Value[fn] ContextPath Value[fn] +Path fn argAtCursor: unlabelled<2> extracted params: [(int, string, int] @@ -305,6 +320,7 @@ posCursor:[71:28] posNoWhite:[71:27] Found expr:[71:16->71:28] Pexp_ident iAmSoSpecial:[71:16->71:28] Completable: Cpath Value[iAmSoSpecial] ContextPath Value[iAmSoSpecial] +Path iAmSoSpecial argAtCursor: unlabelled<0> extracted params: [string] @@ -328,6 +344,7 @@ posCursor:[74:39] posNoWhite:[74:38] Found expr:[74:31->74:39] Pexp_ident someFunc:[74:31->74:39] Completable: Cpath Value[someFunc] ContextPath Value[someFunc] +Path someFunc argAtCursor: unlabelled<0> extracted params: [( From cd2ad406fd46b0f685b94ac11af6fbf83a7b1bc3 Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Sat, 11 Feb 2023 14:56:06 +0100 Subject: [PATCH 34/41] example of when pipe completion across files doesnt work --- analysis/tests/src/CompletionPipeChain.res | 19 ++++++++++ .../src/expected/CompletionPipeChain.res.txt | 38 +++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/analysis/tests/src/CompletionPipeChain.res b/analysis/tests/src/CompletionPipeChain.res index 813bc1a85..b6b177173 100644 --- a/analysis/tests/src/CompletionPipeChain.res +++ b/analysis/tests/src/CompletionPipeChain.res @@ -73,3 +73,22 @@ let notAliased: CompletionSupport.Test.t = {name: 123} // notAliased-> // ^com + +let renderer = CompletionSupport2.makeRenderer( + ~prepare=() => "hello", + ~render=props => { + ignore(props) + + // Doesn't work when tried through this chain. Presumably because it now goes through multiple different files. + // props.support.root->ren + // ^com + let root = props.support.root + ignore(root) + + // Works here though when it's lifted out. Probably because it only goes through one file...? + // root->ren + // ^com + React.null + }, + (), +) diff --git a/analysis/tests/src/expected/CompletionPipeChain.res.txt b/analysis/tests/src/expected/CompletionPipeChain.res.txt index 0d767a9ed..e183827f8 100644 --- a/analysis/tests/src/expected/CompletionPipeChain.res.txt +++ b/analysis/tests/src/expected/CompletionPipeChain.res.txt @@ -368,3 +368,41 @@ Path CompletionSupport.Test. "documentation": null }] +Complete src/CompletionPipeChain.res 82:30 +posCursor:[82:30] posNoWhite:[82:29] Found expr:[76:15->93:1] +Pexp_apply ...[76:15->76:46] (~prepare77:3->77:10=...[77:11->77:24], ~render78:3->78:9=...[78:10->91:3], ...[92:2->92:4]) +posCursor:[82:30] posNoWhite:[82:29] Found expr:[78:10->91:3] +posCursor:[82:30] posNoWhite:[82:29] Found expr:[79:4->90:14] +posCursor:[82:30] posNoWhite:[82:29] Found expr:[82:7->90:14] +posCursor:[82:30] posNoWhite:[82:29] Found expr:[82:7->82:30] +Completable: Cpath Value[props].support.root->ren +ContextPath Value[props].support.root->ren +ContextPath Value[props].support.root +ContextPath Value[props].support +ContextPath Value[props] +Path props +Path CompletionSupport.ReactDOM.Client.Root.ren +[] + +Complete src/CompletionPipeChain.res 88:16 +posCursor:[88:16] posNoWhite:[88:15] Found expr:[76:15->93:1] +Pexp_apply ...[76:15->76:46] (~prepare77:3->77:10=...[77:11->77:24], ~render78:3->78:9=...[78:10->91:3], ...[92:2->92:4]) +posCursor:[88:16] posNoWhite:[88:15] Found expr:[78:10->91:3] +posCursor:[88:16] posNoWhite:[88:15] Found expr:[79:4->90:14] +posCursor:[88:16] posNoWhite:[88:15] Found expr:[84:4->90:14] +posCursor:[88:16] posNoWhite:[88:15] Found expr:[85:4->90:14] +posCursor:[88:16] posNoWhite:[88:15] Found expr:[88:7->90:14] +posCursor:[88:16] posNoWhite:[88:15] Found expr:[88:7->88:16] +Completable: Cpath Value[root]->ren +ContextPath Value[root]->ren +ContextPath Value[root] +Path root +Path ReactDOM.Client.Root.ren +[{ + "label": "ReactDOM.Client.Root.render", + "kind": 12, + "tags": [], + "detail": "(t, React.element) => unit", + "documentation": null + }] + From 08f002bddb4bdc0c59870d56fea8466d2a771d90 Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Wed, 8 Mar 2023 09:25:31 +0100 Subject: [PATCH 35/41] Add debug for pipe internals. --- analysis/src/CompletionBackEnd.ml | 7 +++++ analysis/src/SharedTypes.ml | 5 +++ .../src/expected/CompletePrioritize1.res.txt | 2 ++ .../src/expected/CompletePrioritize2.res.txt | 2 ++ .../tests/src/expected/Completion.res.txt | 11 +++++++ .../CompletionFunctionArguments.res.txt | 4 +++ .../expected/CompletionInferValues.res.txt | 24 ++++++++++++++ .../tests/src/expected/CompletionJsx.res.txt | 8 +++++ .../src/expected/CompletionPipeChain.res.txt | 31 +++++++++++++++++++ .../expected/CompletionPipeSubmodules.res.txt | 8 +++++ .../src/expected/RecordCompletion.res.txt | 2 ++ 11 files changed, 104 insertions(+) diff --git a/analysis/src/CompletionBackEnd.ml b/analysis/src/CompletionBackEnd.ml index e9d55cb62..69b886e8b 100644 --- a/analysis/src/CompletionBackEnd.ml +++ b/analysis/src/CompletionBackEnd.ml @@ -873,6 +873,12 @@ and getCompletionsForContextPath ~debug ~full ~opens ~rawOpens ~allFiles ~pos (* by doing this ~env:envFromCompletionItem*) ~env ~package ~full ~lhsLoc in + if debug then + if env <> envFromCompletionItem then + Printf.printf "CPPipe env:%s envFromCompletionItem:%s\n" + (QueryEnv.toString env) + (QueryEnv.toString envFromCompletionItem) + else Printf.printf "CPPipe env:%s\n" (QueryEnv.toString env); let completionPath = match typ with | Builtin (builtin, _) -> @@ -906,6 +912,7 @@ and getCompletionsForContextPath ~debug ~full ~opens ~rawOpens ~allFiles ~pos | Tlink {desc = Tconstr (path, _typeArgs, _)} | Tsubst {desc = Tconstr (path, _typeArgs, _)} | Tpoly ({desc = Tconstr (path, _typeArgs, _)}, []) -> ( + if debug then Printf.printf "CPPipe type path:%s\n" (Path.name path); match Utils.expandPath path with | _ :: pathRev -> (* type path is relative to the completion environment diff --git a/analysis/src/SharedTypes.ml b/analysis/src/SharedTypes.ml index 3f4d8c011..437c246a2 100644 --- a/analysis/src/SharedTypes.ml +++ b/analysis/src/SharedTypes.ml @@ -267,9 +267,14 @@ module QueryEnv : sig The result is A.B.C.D if D is inside C. Or A.B.D or A.D or D if it's in one of its parents. *) val pathFromEnv : t -> path -> path + + val toString : t -> string end = struct type t = {file: File.t; exported: Exported.t; pathRev: path; parent: t option} + let toString {file; pathRev} = + file.moduleName :: List.rev pathRev |> String.concat "." + let fromFile (file : File.t) = {file; exported = file.structure.exported; pathRev = []; parent = None} diff --git a/analysis/tests/src/expected/CompletePrioritize1.res.txt b/analysis/tests/src/expected/CompletePrioritize1.res.txt index db189dc9c..8437146c4 100644 --- a/analysis/tests/src/expected/CompletePrioritize1.res.txt +++ b/analysis/tests/src/expected/CompletePrioritize1.res.txt @@ -4,6 +4,8 @@ Completable: Cpath Value[a]-> ContextPath Value[a]-> ContextPath Value[a] Path a +CPPipe env:CompletePrioritize1 +CPPipe type path:Test.t Path Test. [{ "label": "Test.add", diff --git a/analysis/tests/src/expected/CompletePrioritize2.res.txt b/analysis/tests/src/expected/CompletePrioritize2.res.txt index b6b949e13..ed7feac33 100644 --- a/analysis/tests/src/expected/CompletePrioritize2.res.txt +++ b/analysis/tests/src/expected/CompletePrioritize2.res.txt @@ -4,6 +4,8 @@ Completable: Cpath Value[ax]-> ContextPath Value[ax]-> ContextPath Value[ax] Path ax +CPPipe env:CompletePrioritize2 +CPPipe type path:Test.t Path Test. [{ "label": "Test.add", diff --git a/analysis/tests/src/expected/Completion.res.txt b/analysis/tests/src/expected/Completion.res.txt index 19372b06e..71937eb46 100644 --- a/analysis/tests/src/expected/Completion.res.txt +++ b/analysis/tests/src/expected/Completion.res.txt @@ -392,6 +392,7 @@ posCursor:[26:13] posNoWhite:[26:12] Found expr:[26:3->26:13] Completable: Cpath array->m ContextPath array->m ContextPath array +CPPipe env:Completion Path Js.Array2.m [{ "label": "Js.Array2.mapi", @@ -412,6 +413,7 @@ posCursor:[29:13] posNoWhite:[29:12] Found expr:[29:3->29:13] Completable: Cpath string->toU ContextPath string->toU ContextPath string +CPPipe env:Completion Path Js.String2.toU [{ "label": "Js.String2.toUpperCase", @@ -427,6 +429,7 @@ Completable: Cpath Value[op]->e ContextPath Value[op]->e ContextPath Value[op] Path op +CPPipe env:Completion Path Belt.Option.e [{ "label": "Belt.Option.eqU", @@ -450,6 +453,8 @@ Completable: Cpath Value[fa]-> ContextPath Value[fa]-> ContextPath Value[fa] Path fa +CPPipe env:Completion +CPPipe type path:ForAuto.t Path ForAuto. [{ "label": "ForAuto.abc", @@ -1010,6 +1015,8 @@ ContextPath Value[FAO, forAutoObject]["forAutoLabel"].forAuto ContextPath Value[FAO, forAutoObject]["forAutoLabel"] ContextPath Value[FAO, forAutoObject] Path FAO.forAutoObject +CPPipe env:Completion envFromCompletionItem:Completion.FAR +CPPipe type path:ForAuto.t Path ForAuto. [{ "label": "ForAuto.abc", @@ -1760,6 +1767,7 @@ Raw opens: 3 Js.place holder ... Shadow.B.place holder ... Shadow.A.place holder Resolved opens 3 Completion.res Completion.res js.ml ContextPath array->ma ContextPath array +CPPipe env:Completion Path Js.Array2.ma [{ "label": "Array2.mapi", @@ -1906,6 +1914,7 @@ Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder Resolved opens 2 Completion.res Completion.res ContextPath int->t ContextPath int +CPPipe env:Completion Path Belt.Int.t [{ "label": "Belt.Int.toString", @@ -1928,6 +1937,7 @@ Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder Resolved opens 2 Completion.res Completion.res ContextPath float->t ContextPath float +CPPipe env:Completion Path Belt.Float.t [{ "label": "Belt.Float.toInt", @@ -1951,6 +1961,7 @@ Resolved opens 2 Completion.res Completion.res ContextPath Value[ok]->g ContextPath Value[ok] Path ok +CPPipe env:Completion Path Belt.Result.g [{ "label": "Belt.Result.getExn", diff --git a/analysis/tests/src/expected/CompletionFunctionArguments.res.txt b/analysis/tests/src/expected/CompletionFunctionArguments.res.txt index 1ce949e84..1c4b6fc7e 100644 --- a/analysis/tests/src/expected/CompletionFunctionArguments.res.txt +++ b/analysis/tests/src/expected/CompletionFunctionArguments.res.txt @@ -349,6 +349,8 @@ Completable: Cpath Value[thisGetsBrokenLoc]->a <> ContextPath Value[thisGetsBrokenLoc]->a <> ContextPath Value[thisGetsBrokenLoc] Path thisGetsBrokenLoc +CPPipe env:CompletionFunctionArguments +CPPipe type path:ReactEvent.Mouse.t Path ReactEvent.Mouse.a [{ "label": "ReactEvent.Mouse.altKey", @@ -369,6 +371,8 @@ Completable: Cpath Value[reassignedWorks]->a <> ContextPath Value[reassignedWorks]->a <> ContextPath Value[reassignedWorks] Path reassignedWorks +CPPipe env:CompletionFunctionArguments +CPPipe type path:ReactEvent.Mouse.t Path ReactEvent.Mouse.a [{ "label": "ReactEvent.Mouse.altKey", diff --git a/analysis/tests/src/expected/CompletionInferValues.res.txt b/analysis/tests/src/expected/CompletionInferValues.res.txt index 638e882a9..c9920ea66 100644 --- a/analysis/tests/src/expected/CompletionInferValues.res.txt +++ b/analysis/tests/src/expected/CompletionInferValues.res.txt @@ -7,6 +7,7 @@ Path aliased ContextPath Value[x] Path x ContextPath int +CPPipe env:CompletionInferValues Path Belt.Int.f [{ "label": "Belt.Int.fromString", @@ -147,6 +148,8 @@ ContextPath CArgument CArgument Value[reactEventFn]($0)($0) ContextPath CArgument Value[reactEventFn]($0) ContextPath Value[reactEventFn] Path reactEventFn +CPPipe env:CompletionInferValues +CPPipe type path:ReactEvent.Mouse.t Path ReactEvent.Mouse.pr [{ "label": "ReactEvent.Mouse.preventDefault", @@ -169,6 +172,8 @@ ContextPath CArgument CJsxPropValue [div] onMouseEnter($0) ContextPath CJsxPropValue [div] onMouseEnter Path ReactDOM.domProps Path JsxDOM.domProps +CPPipe env:CompletionInferValues +CPPipe type path:JsxEvent.Mouse.t Path JsxEvent.Mouse.pr [{ "label": "JsxEvent.Mouse.preventDefault", @@ -190,6 +195,8 @@ Path event ContextPath CArgument CJsxPropValue [Div] onMouseEnter($0) ContextPath CJsxPropValue [Div] onMouseEnter Path Div.make +CPPipe env:CompletionInferValues envFromCompletionItem:CompletionInferValues.Div +CPPipe type path:JsxEvent.Mouse.t Path JsxEvent.Mouse.pr [{ "label": "JsxEvent.Mouse.preventDefault", @@ -212,6 +219,7 @@ Path btn ContextPath Value[JsxEvent, Mouse, button](Nolabel) ContextPath Value[JsxEvent, Mouse, button] Path JsxEvent.Mouse.button +CPPipe env:CompletionInferValues envFromCompletionItem:JsxEvent.Mouse Path Belt.Int.t [{ "label": "Belt.Int.toString", @@ -240,6 +248,7 @@ Path btn ContextPath Value[Belt, Int, toString](Nolabel) ContextPath Value[Belt, Int, toString] Path Belt.Int.toString +CPPipe env:CompletionInferValues envFromCompletionItem:Belt_Int Path Js.String2.spl [{ "label": "Js.String2.splitAtMost", @@ -280,6 +289,7 @@ Path btn ContextPath Value[Js, String2, split](Nolabel, Nolabel) ContextPath Value[Js, String2, split] Path Js.String2.split +CPPipe env:CompletionInferValues envFromCompletionItem:Js_string2 Path Js.Array2.ma [{ "label": "Js.Array2.mapi", @@ -401,6 +411,7 @@ ContextPath Value[x] Path x ContextPath Type[someRecordWithNestedStuff] Path someRecordWithNestedStuff +CPPipe env:CompletionInferValues Path Js.String2.slic [{ "label": "Js.String2.sliceToEnd", @@ -427,6 +438,7 @@ ContextPath Value[x] Path x ContextPath Type[someRecordWithNestedStuff] Path someRecordWithNestedStuff +CPPipe env:CompletionInferValues Path Belt.Int.toS [{ "label": "Belt.Int.toString", @@ -450,6 +462,7 @@ ContextPath Value[x] Path x ContextPath Type[otherNestedRecord] Path otherNestedRecord +CPPipe env:CompletionInferValues Path Belt.Int.toS [{ "label": "Belt.Int.toString", @@ -474,6 +487,7 @@ ContextPath Value[x] Path x ContextPath Type[otherNestedRecord] Path otherNestedRecord +CPPipe env:CompletionInferValues Path Belt.Int.toS [{ "label": "Belt.Int.toString", @@ -494,6 +508,7 @@ ContextPath Value[x] Path x ContextPath Type[otherNestedRecord] Path otherNestedRecord +CPPipe env:CompletionInferValues Path Js.String2.slic [{ "label": "Js.String2.sliceToEnd", @@ -520,6 +535,7 @@ ContextPath Value[x] Path x ContextPath Type[otherNestedRecord] Path otherNestedRecord +CPPipe env:CompletionInferValues Path Js.String2.slic [{ "label": "Js.String2.sliceToEnd", @@ -546,6 +562,7 @@ ContextPath Value[x] Path x ContextPath Type[otherNestedRecord] Path otherNestedRecord +CPPipe env:CompletionInferValues Path Js.String2.slic [{ "label": "Js.String2.sliceToEnd", @@ -597,6 +614,7 @@ Path v ContextPath Value[x] Path x ContextPath int +CPPipe env:CompletionInferValues Path Belt.Int.toSt [{ "label": "Belt.Int.toString", @@ -646,6 +664,8 @@ ContextPath CArgument CArgument Value[fn2](~cb)($0) ContextPath CArgument Value[fn2](~cb) ContextPath Value[fn2] Path fn2 +CPPipe env:CompletionInferValues +CPPipe type path:ReactDOM.Client.Root.t Path ReactDOM.Client.Root. [{ "label": "ReactDOM.Client.Root.unmount", @@ -676,6 +696,8 @@ ContextPath CArgument CArgument Value[fn3](~cb)($0) ContextPath CArgument Value[fn3](~cb) ContextPath Value[fn3] Path fn3 +CPPipe env:CompletionInferValues +CPPipe type path:CompletionSupport.Test.t Path CompletionSupport.Test. [{ "label": "CompletionSupport.Test.add", @@ -769,6 +791,8 @@ ContextPath CArgument CArgument Value[CompletionSupport2, makeRenderer](~render) ContextPath CArgument Value[CompletionSupport2, makeRenderer](~render) ContextPath Value[CompletionSupport2, makeRenderer] Path CompletionSupport2.makeRenderer +CPPipe env:CompletionInferValues envFromCompletionItem:CompletionSupport2.Internal +CPPipe type path:ReactDOM.Client.Root.t Path CompletionSupport2.ReactDOM.Client.Root. [] diff --git a/analysis/tests/src/expected/CompletionJsx.res.txt b/analysis/tests/src/expected/CompletionJsx.res.txt index 76fe3fa2b..3559b81ef 100644 --- a/analysis/tests/src/expected/CompletionJsx.res.txt +++ b/analysis/tests/src/expected/CompletionJsx.res.txt @@ -4,6 +4,7 @@ Completable: Cpath Value[someString]->st ContextPath Value[someString]->st ContextPath Value[someString] Path someString +CPPipe env:CompletionJsx Path Js.String2.st [{ "label": "Js.String2.startsWith", @@ -31,6 +32,7 @@ Completable: Cpath Value[someString]->st <> ContextPath Value[someString]->st <> ContextPath Value[someString] Path someString +CPPipe env:CompletionJsx Path Js.String2.st [{ "label": "React.string", @@ -76,6 +78,7 @@ Completable: Cpath Value[someString]->st <> ContextPath Value[someString]->st <> ContextPath Value[someString] Path someString +CPPipe env:CompletionJsx Path Js.String2.st [{ "label": "React.string", @@ -120,6 +123,7 @@ posCursor:[20:27] posNoWhite:[20:26] Found expr:[20:10->20:27] Completable: Cpath string->st <> ContextPath string->st <> ContextPath string +CPPipe env:CompletionJsx Path Js.String2.st [{ "label": "React.string", @@ -166,6 +170,7 @@ ContextPath Value[Js, String2, trim](Nolabel)->st <> ContextPath Value[Js, String2, trim](Nolabel) ContextPath Value[Js, String2, trim] Path Js.String2.trim +CPPipe env:CompletionJsx envFromCompletionItem:Js_string2 Path Js.String2.st [{ "label": "React.string", @@ -211,6 +216,7 @@ Completable: Cpath Value[someInt]-> <> ContextPath Value[someInt]-> <> ContextPath Value[someInt] Path someInt +CPPipe env:CompletionJsx Path Belt.Int. [{ "label": "React.int", @@ -291,6 +297,7 @@ posCursor:[26:14] posNoWhite:[26:13] Found expr:[26:10->0:-1] Completable: Cpath int-> <> ContextPath int-> <> ContextPath int +CPPipe env:CompletionJsx Path Belt.Int. [{ "label": "React.int", @@ -372,6 +379,7 @@ Completable: Cpath Value[someArr]->a <> ContextPath Value[someArr]->a <> ContextPath Value[someArr] Path someArr +CPPipe env:CompletionJsx Path Js.Array2.a [{ "label": "React.array", diff --git a/analysis/tests/src/expected/CompletionPipeChain.res.txt b/analysis/tests/src/expected/CompletionPipeChain.res.txt index e183827f8..8a1a9255a 100644 --- a/analysis/tests/src/expected/CompletionPipeChain.res.txt +++ b/analysis/tests/src/expected/CompletionPipeChain.res.txt @@ -4,6 +4,8 @@ Completable: Cpath Value[int]-> ContextPath Value[int]-> ContextPath Value[int] Path int +CPPipe env:CompletionPipeChain +CPPipe type path:Integer.t Path Integer. [{ "label": "Integer.toInt", @@ -38,6 +40,8 @@ ContextPath Value[toFlt](Nolabel)-> ContextPath Value[toFlt](Nolabel) ContextPath Value[toFlt] Path toFlt +CPPipe env:CompletionPipeChain +CPPipe type path:SuperFloat.t Path SuperFloat. [{ "label": "SuperFloat.fromInteger", @@ -60,6 +64,8 @@ ContextPath Value[Integer, increment](Nolabel, Nolabel)-> ContextPath Value[Integer, increment](Nolabel, Nolabel) ContextPath Value[Integer, increment] Path Integer.increment +CPPipe env:CompletionPipeChain envFromCompletionItem:CompletionPipeChain.Integer +CPPipe type path:t Path Integer. [{ "label": "Integer.toInt", @@ -94,6 +100,8 @@ ContextPath Value[Integer, increment](Nolabel, Nolabel)-> ContextPath Value[Integer, increment](Nolabel, Nolabel) ContextPath Value[Integer, increment] Path Integer.increment +CPPipe env:CompletionPipeChain envFromCompletionItem:CompletionPipeChain.Integer +CPPipe type path:t Path Integer. [{ "label": "Integer.toInt", @@ -128,6 +136,8 @@ ContextPath Value[Integer, decrement](Nolabel, Nolabel)-> ContextPath Value[Integer, decrement](Nolabel, Nolabel) ContextPath Value[Integer, decrement] Path Integer.decrement +CPPipe env:CompletionPipeChain envFromCompletionItem:CompletionPipeChain.Integer +CPPipe type path:t Path Integer. [{ "label": "Integer.toInt", @@ -162,6 +172,8 @@ ContextPath Value[Integer, decrement](Nolabel, Nolabel)-> ContextPath Value[Integer, decrement](Nolabel, Nolabel) ContextPath Value[Integer, decrement] Path Integer.decrement +CPPipe env:CompletionPipeChain envFromCompletionItem:CompletionPipeChain.Integer +CPPipe type path:t Path Integer. [{ "label": "Integer.toInt", @@ -196,6 +208,8 @@ ContextPath Value[SuperFloat, fromInteger](Nolabel)-> ContextPath Value[SuperFloat, fromInteger](Nolabel) ContextPath Value[SuperFloat, fromInteger] Path SuperFloat.fromInteger +CPPipe env:CompletionPipeChain envFromCompletionItem:CompletionPipeChain.SuperFloat +CPPipe type path:t Path SuperFloat. [{ "label": "SuperFloat.fromInteger", @@ -218,6 +232,8 @@ ContextPath Value[SuperFloat, fromInteger](Nolabel)->t ContextPath Value[SuperFloat, fromInteger](Nolabel) ContextPath Value[SuperFloat, fromInteger] Path SuperFloat.fromInteger +CPPipe env:CompletionPipeChain envFromCompletionItem:CompletionPipeChain.SuperFloat +CPPipe type path:t Path SuperFloat.t [{ "label": "SuperFloat.toInteger", @@ -234,6 +250,8 @@ ContextPath Value[CompletionSupport, Test, make](Nolabel)-> ContextPath Value[CompletionSupport, Test, make](Nolabel) ContextPath Value[CompletionSupport, Test, make] Path CompletionSupport.Test.make +CPPipe env:CompletionPipeChain envFromCompletionItem:CompletionSupport.Test +CPPipe type path:t Path CompletionSupport.Test. [{ "label": "CompletionSupport.Test.add", @@ -262,6 +280,8 @@ ContextPath Value[CompletionSupport, Test, addSelf](Nolabel, Nolabel)-> ContextPath Value[CompletionSupport, Test, addSelf](Nolabel, Nolabel) ContextPath Value[CompletionSupport, Test, addSelf] Path CompletionSupport.Test.addSelf +CPPipe env:CompletionPipeChain envFromCompletionItem:CompletionSupport.Test +CPPipe type path:t Path CompletionSupport.Test. [{ "label": "CompletionSupport.Test.add", @@ -290,6 +310,8 @@ ContextPath Value[Js, Array2, forEach](Nolabel, Nolabel)-> ContextPath Value[Js, Array2, forEach](Nolabel, Nolabel) ContextPath Value[Js, Array2, forEach] Path Js.Array2.forEach +CPPipe env:CompletionPipeChain envFromCompletionItem:Js_array2 +CPPipe type path:unit [] Complete src/CompletionPipeChain.res 62:6 @@ -299,6 +321,7 @@ ContextPath Value[Belt, Array, reduce](Nolabel, Nolabel, Nolabel)->t ContextPath Value[Belt, Array, reduce](Nolabel, Nolabel, Nolabel) ContextPath Value[Belt, Array, reduce] Path Belt.Array.reduce +CPPipe env:CompletionPipeChain envFromCompletionItem:Belt_Array Path Belt.Int.t [{ "label": "Belt.Int.toString", @@ -320,6 +343,8 @@ Completable: Cpath Value[aliased]-> ContextPath Value[aliased]-> ContextPath Value[aliased] Path aliased +CPPipe env:CompletionPipeChain +CPPipe type path:CompletionSupport.Test.t Path CompletionSupport.Test. [{ "label": "CompletionSupport.Test.add", @@ -347,6 +372,8 @@ Completable: Cpath Value[notAliased]-> ContextPath Value[notAliased]-> ContextPath Value[notAliased] Path notAliased +CPPipe env:CompletionPipeChain +CPPipe type path:CompletionSupport.Test.t Path CompletionSupport.Test. [{ "label": "CompletionSupport.Test.add", @@ -381,6 +408,8 @@ ContextPath Value[props].support.root ContextPath Value[props].support ContextPath Value[props] Path props +CPPipe env:CompletionPipeChain envFromCompletionItem:CompletionSupport.Nested +CPPipe type path:ReactDOM.Client.Root.t Path CompletionSupport.ReactDOM.Client.Root.ren [] @@ -397,6 +426,8 @@ Completable: Cpath Value[root]->ren ContextPath Value[root]->ren ContextPath Value[root] Path root +CPPipe env:CompletionPipeChain +CPPipe type path:ReactDOM.Client.Root.t Path ReactDOM.Client.Root.ren [{ "label": "ReactDOM.Client.Root.render", diff --git a/analysis/tests/src/expected/CompletionPipeSubmodules.res.txt b/analysis/tests/src/expected/CompletionPipeSubmodules.res.txt index b6e1b9386..536a5228f 100644 --- a/analysis/tests/src/expected/CompletionPipeSubmodules.res.txt +++ b/analysis/tests/src/expected/CompletionPipeSubmodules.res.txt @@ -4,6 +4,8 @@ Completable: Cpath Value[A, B1, xx]-> ContextPath Value[A, B1, xx]-> ContextPath Value[A, B1, xx] Path A.B1.xx +CPPipe env:CompletionPipeSubmodules envFromCompletionItem:CompletionPipeSubmodules.A.B1 +CPPipe type path:b1 Path A.B1. [{ "label": "A.B1.xx", @@ -26,6 +28,8 @@ ContextPath Value[A, x].v-> ContextPath Value[A, x].v ContextPath Value[A, x] Path A.x +CPPipe env:CompletionPipeSubmodules envFromCompletionItem:CompletionPipeSubmodules.A +CPPipe type path:B1.b1 Path A.B1. [{ "label": "A.B1.xx", @@ -49,6 +53,8 @@ ContextPath Value[E, e].v.v ContextPath Value[E, e].v ContextPath Value[E, e] Path E.e +CPPipe env:CompletionPipeSubmodules envFromCompletionItem:CompletionPipeSubmodules.D +CPPipe type path:C.t Path C. [{ "label": "C.C", @@ -66,6 +72,8 @@ ContextPath Value[E, e].v.v2 ContextPath Value[E, e].v ContextPath Value[E, e] Path E.e +CPPipe env:CompletionPipeSubmodules envFromCompletionItem:CompletionPipeSubmodules.D +CPPipe type path:C2.t2 Path D.C2. [{ "label": "D.C2.C2", diff --git a/analysis/tests/src/expected/RecordCompletion.res.txt b/analysis/tests/src/expected/RecordCompletion.res.txt index f74350306..a898b97d4 100644 --- a/analysis/tests/src/expected/RecordCompletion.res.txt +++ b/analysis/tests/src/expected/RecordCompletion.res.txt @@ -5,6 +5,7 @@ ContextPath Value[t].n->m ContextPath Value[t].n ContextPath Value[t] Path t +CPPipe env:RecordCompletion Path Js.Array2.m [{ "label": "Js.Array2.mapi", @@ -28,6 +29,7 @@ ContextPath Value[t2].n2.n ContextPath Value[t2].n2 ContextPath Value[t2] Path t2 +CPPipe env:RecordCompletion Path Js.Array2.m [{ "label": "Js.Array2.mapi", From d972afe36f49ea722958abb6432a4526f9486857 Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Wed, 8 Mar 2023 10:36:06 +0100 Subject: [PATCH 36/41] Print pathFromEnv and whether the path was found. --- analysis/src/CompletionBackEnd.ml | 19 ++++++++++--------- analysis/src/SharedTypes.ml | 14 +++++++------- .../src/expected/CompletePrioritize1.res.txt | 1 + .../src/expected/CompletePrioritize2.res.txt | 1 + .../tests/src/expected/Completion.res.txt | 2 ++ .../CompletionFunctionArguments.res.txt | 2 ++ .../expected/CompletionInferValues.res.txt | 6 ++++++ .../src/expected/CompletionPipeChain.res.txt | 15 +++++++++++++++ .../expected/CompletionPipeSubmodules.res.txt | 4 ++++ 9 files changed, 48 insertions(+), 16 deletions(-) diff --git a/analysis/src/CompletionBackEnd.ml b/analysis/src/CompletionBackEnd.ml index 69b886e8b..2af726200 100644 --- a/analysis/src/CompletionBackEnd.ml +++ b/analysis/src/CompletionBackEnd.ml @@ -917,17 +917,18 @@ and getCompletionsForContextPath ~debug ~full ~opens ~rawOpens ~allFiles ~pos | _ :: pathRev -> (* type path is relative to the completion environment express it from the root of the file *) - let pathFromEnv_ = + let found, pathFromEnv = QueryEnv.pathFromEnv envFromCompletionItem (List.rev pathRev) in - if pathFromEnv_ = [] then None - else - let pathFromEnv = - if env.file.moduleName = envFromCompletionItem.file.moduleName - then pathFromEnv_ - else envFromCompletionItem.file.moduleName :: pathFromEnv_ - in - Some pathFromEnv + if debug then + Printf.printf "CPPipe pathFromEnv:%s found:%b\n" + (pathFromEnv |> String.concat ".") + found; + if pathFromEnv = [] then None + else if + env.file.moduleName = envFromCompletionItem.file.moduleName + then Some pathFromEnv + else Some (envFromCompletionItem.file.moduleName :: pathFromEnv) | _ -> None) | _ -> None) in diff --git a/analysis/src/SharedTypes.ml b/analysis/src/SharedTypes.ml index 437c246a2..27448c0b8 100644 --- a/analysis/src/SharedTypes.ml +++ b/analysis/src/SharedTypes.ml @@ -266,7 +266,7 @@ module QueryEnv : sig E.g. the env is at A.B.C and the path is D. The result is A.B.C.D if D is inside C. Or A.B.D or A.D or D if it's in one of its parents. *) - val pathFromEnv : t -> path -> path + val pathFromEnv : t -> path -> bool * path val toString : t -> string end = struct @@ -280,22 +280,22 @@ end = struct (* Prune a path and find a parent environment that contains the module name *) let rec prunePath pathRev env name = - if Exported.find env.exported Module name <> None then pathRev + if Exported.find env.exported Module name <> None then (true, pathRev) else match (pathRev, env.parent) with | _ :: rest, Some env -> prunePath rest env name - | _ -> [] + | _ -> (false, []) let pathFromEnv env path = match path with - | [] -> env.pathRev |> List.rev + | [] -> (true, env.pathRev |> List.rev) | name :: _ -> - let prunedPathRev = prunePath env.pathRev env name in - List.rev_append prunedPathRev path + let found, prunedPathRev = prunePath env.pathRev env name in + (found, List.rev_append prunedPathRev path) let enterStructure env (structure : Module.structure) = let name = structure.name in - let pathRev = name :: prunePath env.pathRev env name in + let pathRev = name :: snd (prunePath env.pathRev env name) in {env with exported = structure.exported; pathRev; parent = Some env} end diff --git a/analysis/tests/src/expected/CompletePrioritize1.res.txt b/analysis/tests/src/expected/CompletePrioritize1.res.txt index 8437146c4..f011ba5c9 100644 --- a/analysis/tests/src/expected/CompletePrioritize1.res.txt +++ b/analysis/tests/src/expected/CompletePrioritize1.res.txt @@ -6,6 +6,7 @@ ContextPath Value[a] Path a CPPipe env:CompletePrioritize1 CPPipe type path:Test.t +CPPipe pathFromEnv:Test found:true Path Test. [{ "label": "Test.add", diff --git a/analysis/tests/src/expected/CompletePrioritize2.res.txt b/analysis/tests/src/expected/CompletePrioritize2.res.txt index ed7feac33..6831be426 100644 --- a/analysis/tests/src/expected/CompletePrioritize2.res.txt +++ b/analysis/tests/src/expected/CompletePrioritize2.res.txt @@ -6,6 +6,7 @@ ContextPath Value[ax] Path ax CPPipe env:CompletePrioritize2 CPPipe type path:Test.t +CPPipe pathFromEnv:Test found:true Path Test. [{ "label": "Test.add", diff --git a/analysis/tests/src/expected/Completion.res.txt b/analysis/tests/src/expected/Completion.res.txt index 71937eb46..409d7b7b8 100644 --- a/analysis/tests/src/expected/Completion.res.txt +++ b/analysis/tests/src/expected/Completion.res.txt @@ -455,6 +455,7 @@ ContextPath Value[fa] Path fa CPPipe env:Completion CPPipe type path:ForAuto.t +CPPipe pathFromEnv:ForAuto found:true Path ForAuto. [{ "label": "ForAuto.abc", @@ -1017,6 +1018,7 @@ ContextPath Value[FAO, forAutoObject] Path FAO.forAutoObject CPPipe env:Completion envFromCompletionItem:Completion.FAR CPPipe type path:ForAuto.t +CPPipe pathFromEnv:ForAuto found:false Path ForAuto. [{ "label": "ForAuto.abc", diff --git a/analysis/tests/src/expected/CompletionFunctionArguments.res.txt b/analysis/tests/src/expected/CompletionFunctionArguments.res.txt index 1c4b6fc7e..e15baa7a3 100644 --- a/analysis/tests/src/expected/CompletionFunctionArguments.res.txt +++ b/analysis/tests/src/expected/CompletionFunctionArguments.res.txt @@ -351,6 +351,7 @@ ContextPath Value[thisGetsBrokenLoc] Path thisGetsBrokenLoc CPPipe env:CompletionFunctionArguments CPPipe type path:ReactEvent.Mouse.t +CPPipe pathFromEnv:ReactEvent.Mouse found:false Path ReactEvent.Mouse.a [{ "label": "ReactEvent.Mouse.altKey", @@ -373,6 +374,7 @@ ContextPath Value[reassignedWorks] Path reassignedWorks CPPipe env:CompletionFunctionArguments CPPipe type path:ReactEvent.Mouse.t +CPPipe pathFromEnv:ReactEvent.Mouse found:false Path ReactEvent.Mouse.a [{ "label": "ReactEvent.Mouse.altKey", diff --git a/analysis/tests/src/expected/CompletionInferValues.res.txt b/analysis/tests/src/expected/CompletionInferValues.res.txt index c9920ea66..96662e898 100644 --- a/analysis/tests/src/expected/CompletionInferValues.res.txt +++ b/analysis/tests/src/expected/CompletionInferValues.res.txt @@ -150,6 +150,7 @@ ContextPath Value[reactEventFn] Path reactEventFn CPPipe env:CompletionInferValues CPPipe type path:ReactEvent.Mouse.t +CPPipe pathFromEnv:ReactEvent.Mouse found:false Path ReactEvent.Mouse.pr [{ "label": "ReactEvent.Mouse.preventDefault", @@ -174,6 +175,7 @@ Path ReactDOM.domProps Path JsxDOM.domProps CPPipe env:CompletionInferValues CPPipe type path:JsxEvent.Mouse.t +CPPipe pathFromEnv:JsxEvent.Mouse found:false Path JsxEvent.Mouse.pr [{ "label": "JsxEvent.Mouse.preventDefault", @@ -197,6 +199,7 @@ ContextPath CJsxPropValue [Div] onMouseEnter Path Div.make CPPipe env:CompletionInferValues envFromCompletionItem:CompletionInferValues.Div CPPipe type path:JsxEvent.Mouse.t +CPPipe pathFromEnv:JsxEvent.Mouse found:false Path JsxEvent.Mouse.pr [{ "label": "JsxEvent.Mouse.preventDefault", @@ -666,6 +669,7 @@ ContextPath Value[fn2] Path fn2 CPPipe env:CompletionInferValues CPPipe type path:ReactDOM.Client.Root.t +CPPipe pathFromEnv:ReactDOM.Client.Root found:false Path ReactDOM.Client.Root. [{ "label": "ReactDOM.Client.Root.unmount", @@ -698,6 +702,7 @@ ContextPath Value[fn3] Path fn3 CPPipe env:CompletionInferValues CPPipe type path:CompletionSupport.Test.t +CPPipe pathFromEnv:CompletionSupport.Test found:false Path CompletionSupport.Test. [{ "label": "CompletionSupport.Test.add", @@ -793,6 +798,7 @@ ContextPath Value[CompletionSupport2, makeRenderer] Path CompletionSupport2.makeRenderer CPPipe env:CompletionInferValues envFromCompletionItem:CompletionSupport2.Internal CPPipe type path:ReactDOM.Client.Root.t +CPPipe pathFromEnv:ReactDOM.Client.Root found:false Path CompletionSupport2.ReactDOM.Client.Root. [] diff --git a/analysis/tests/src/expected/CompletionPipeChain.res.txt b/analysis/tests/src/expected/CompletionPipeChain.res.txt index 8a1a9255a..2dd269db5 100644 --- a/analysis/tests/src/expected/CompletionPipeChain.res.txt +++ b/analysis/tests/src/expected/CompletionPipeChain.res.txt @@ -6,6 +6,7 @@ ContextPath Value[int] Path int CPPipe env:CompletionPipeChain CPPipe type path:Integer.t +CPPipe pathFromEnv:Integer found:true Path Integer. [{ "label": "Integer.toInt", @@ -42,6 +43,7 @@ ContextPath Value[toFlt] Path toFlt CPPipe env:CompletionPipeChain CPPipe type path:SuperFloat.t +CPPipe pathFromEnv:SuperFloat found:true Path SuperFloat. [{ "label": "SuperFloat.fromInteger", @@ -66,6 +68,7 @@ ContextPath Value[Integer, increment] Path Integer.increment CPPipe env:CompletionPipeChain envFromCompletionItem:CompletionPipeChain.Integer CPPipe type path:t +CPPipe pathFromEnv:Integer found:true Path Integer. [{ "label": "Integer.toInt", @@ -102,6 +105,7 @@ ContextPath Value[Integer, increment] Path Integer.increment CPPipe env:CompletionPipeChain envFromCompletionItem:CompletionPipeChain.Integer CPPipe type path:t +CPPipe pathFromEnv:Integer found:true Path Integer. [{ "label": "Integer.toInt", @@ -138,6 +142,7 @@ ContextPath Value[Integer, decrement] Path Integer.decrement CPPipe env:CompletionPipeChain envFromCompletionItem:CompletionPipeChain.Integer CPPipe type path:t +CPPipe pathFromEnv:Integer found:true Path Integer. [{ "label": "Integer.toInt", @@ -174,6 +179,7 @@ ContextPath Value[Integer, decrement] Path Integer.decrement CPPipe env:CompletionPipeChain envFromCompletionItem:CompletionPipeChain.Integer CPPipe type path:t +CPPipe pathFromEnv:Integer found:true Path Integer. [{ "label": "Integer.toInt", @@ -210,6 +216,7 @@ ContextPath Value[SuperFloat, fromInteger] Path SuperFloat.fromInteger CPPipe env:CompletionPipeChain envFromCompletionItem:CompletionPipeChain.SuperFloat CPPipe type path:t +CPPipe pathFromEnv:SuperFloat found:true Path SuperFloat. [{ "label": "SuperFloat.fromInteger", @@ -234,6 +241,7 @@ ContextPath Value[SuperFloat, fromInteger] Path SuperFloat.fromInteger CPPipe env:CompletionPipeChain envFromCompletionItem:CompletionPipeChain.SuperFloat CPPipe type path:t +CPPipe pathFromEnv:SuperFloat found:true Path SuperFloat.t [{ "label": "SuperFloat.toInteger", @@ -252,6 +260,7 @@ ContextPath Value[CompletionSupport, Test, make] Path CompletionSupport.Test.make CPPipe env:CompletionPipeChain envFromCompletionItem:CompletionSupport.Test CPPipe type path:t +CPPipe pathFromEnv:Test found:true Path CompletionSupport.Test. [{ "label": "CompletionSupport.Test.add", @@ -282,6 +291,7 @@ ContextPath Value[CompletionSupport, Test, addSelf] Path CompletionSupport.Test.addSelf CPPipe env:CompletionPipeChain envFromCompletionItem:CompletionSupport.Test CPPipe type path:t +CPPipe pathFromEnv:Test found:true Path CompletionSupport.Test. [{ "label": "CompletionSupport.Test.add", @@ -312,6 +322,7 @@ ContextPath Value[Js, Array2, forEach] Path Js.Array2.forEach CPPipe env:CompletionPipeChain envFromCompletionItem:Js_array2 CPPipe type path:unit +CPPipe pathFromEnv: found:true [] Complete src/CompletionPipeChain.res 62:6 @@ -345,6 +356,7 @@ ContextPath Value[aliased] Path aliased CPPipe env:CompletionPipeChain CPPipe type path:CompletionSupport.Test.t +CPPipe pathFromEnv:CompletionSupport.Test found:false Path CompletionSupport.Test. [{ "label": "CompletionSupport.Test.add", @@ -374,6 +386,7 @@ ContextPath Value[notAliased] Path notAliased CPPipe env:CompletionPipeChain CPPipe type path:CompletionSupport.Test.t +CPPipe pathFromEnv:CompletionSupport.Test found:false Path CompletionSupport.Test. [{ "label": "CompletionSupport.Test.add", @@ -410,6 +423,7 @@ ContextPath Value[props] Path props CPPipe env:CompletionPipeChain envFromCompletionItem:CompletionSupport.Nested CPPipe type path:ReactDOM.Client.Root.t +CPPipe pathFromEnv:ReactDOM.Client.Root found:false Path CompletionSupport.ReactDOM.Client.Root.ren [] @@ -428,6 +442,7 @@ ContextPath Value[root] Path root CPPipe env:CompletionPipeChain CPPipe type path:ReactDOM.Client.Root.t +CPPipe pathFromEnv:ReactDOM.Client.Root found:false Path ReactDOM.Client.Root.ren [{ "label": "ReactDOM.Client.Root.render", diff --git a/analysis/tests/src/expected/CompletionPipeSubmodules.res.txt b/analysis/tests/src/expected/CompletionPipeSubmodules.res.txt index 536a5228f..666931ee5 100644 --- a/analysis/tests/src/expected/CompletionPipeSubmodules.res.txt +++ b/analysis/tests/src/expected/CompletionPipeSubmodules.res.txt @@ -6,6 +6,7 @@ ContextPath Value[A, B1, xx] Path A.B1.xx CPPipe env:CompletionPipeSubmodules envFromCompletionItem:CompletionPipeSubmodules.A.B1 CPPipe type path:b1 +CPPipe pathFromEnv:A.B1 found:true Path A.B1. [{ "label": "A.B1.xx", @@ -30,6 +31,7 @@ ContextPath Value[A, x] Path A.x CPPipe env:CompletionPipeSubmodules envFromCompletionItem:CompletionPipeSubmodules.A CPPipe type path:B1.b1 +CPPipe pathFromEnv:A.B1 found:true Path A.B1. [{ "label": "A.B1.xx", @@ -55,6 +57,7 @@ ContextPath Value[E, e] Path E.e CPPipe env:CompletionPipeSubmodules envFromCompletionItem:CompletionPipeSubmodules.D CPPipe type path:C.t +CPPipe pathFromEnv:C found:false Path C. [{ "label": "C.C", @@ -74,6 +77,7 @@ ContextPath Value[E, e] Path E.e CPPipe env:CompletionPipeSubmodules envFromCompletionItem:CompletionPipeSubmodules.D CPPipe type path:C2.t2 +CPPipe pathFromEnv:D.C2 found:true Path D.C2. [{ "label": "D.C2.C2", From 2bf84ea8082787b6d31bc35879fd9cc7778bbfb2 Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Wed, 8 Mar 2023 10:38:04 +0100 Subject: [PATCH 37/41] refactor --- analysis/src/CompletionBackEnd.ml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/analysis/src/CompletionBackEnd.ml b/analysis/src/CompletionBackEnd.ml index 2af726200..5f4ab6130 100644 --- a/analysis/src/CompletionBackEnd.ml +++ b/analysis/src/CompletionBackEnd.ml @@ -926,9 +926,9 @@ and getCompletionsForContextPath ~debug ~full ~opens ~rawOpens ~allFiles ~pos found; if pathFromEnv = [] then None else if - env.file.moduleName = envFromCompletionItem.file.moduleName - then Some pathFromEnv - else Some (envFromCompletionItem.file.moduleName :: pathFromEnv) + env.file.moduleName <> envFromCompletionItem.file.moduleName + then Some (envFromCompletionItem.file.moduleName :: pathFromEnv) + else Some pathFromEnv | _ -> None) | _ -> None) in From ba861ce83cf35facd2dd2876daba2b0c3338aea3 Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Wed, 8 Mar 2023 10:40:35 +0100 Subject: [PATCH 38/41] Fix pipe completion across files. --- analysis/src/CompletionBackEnd.ml | 3 +++ .../src/expected/CompletionInferValues.res.txt | 16 ++++++++++++++-- .../src/expected/CompletionPipeChain.res.txt | 10 ++++++++-- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/analysis/src/CompletionBackEnd.ml b/analysis/src/CompletionBackEnd.ml index 5f4ab6130..eb0b2cad5 100644 --- a/analysis/src/CompletionBackEnd.ml +++ b/analysis/src/CompletionBackEnd.ml @@ -927,6 +927,9 @@ and getCompletionsForContextPath ~debug ~full ~opens ~rawOpens ~allFiles ~pos if pathFromEnv = [] then None else if env.file.moduleName <> envFromCompletionItem.file.moduleName + && found + (* If the module names are different, then one needs to qualify the path. + But only if the path belongs to the env from completion *) then Some (envFromCompletionItem.file.moduleName :: pathFromEnv) else Some pathFromEnv | _ -> None) diff --git a/analysis/tests/src/expected/CompletionInferValues.res.txt b/analysis/tests/src/expected/CompletionInferValues.res.txt index 96662e898..4d6034ad7 100644 --- a/analysis/tests/src/expected/CompletionInferValues.res.txt +++ b/analysis/tests/src/expected/CompletionInferValues.res.txt @@ -799,6 +799,18 @@ Path CompletionSupport2.makeRenderer CPPipe env:CompletionInferValues envFromCompletionItem:CompletionSupport2.Internal CPPipe type path:ReactDOM.Client.Root.t CPPipe pathFromEnv:ReactDOM.Client.Root found:false -Path CompletionSupport2.ReactDOM.Client.Root. -[] +Path ReactDOM.Client.Root. +[{ + "label": "ReactDOM.Client.Root.unmount", + "kind": 12, + "tags": [], + "detail": "(t, unit) => unit", + "documentation": null + }, { + "label": "ReactDOM.Client.Root.render", + "kind": 12, + "tags": [], + "detail": "(t, React.element) => unit", + "documentation": null + }] diff --git a/analysis/tests/src/expected/CompletionPipeChain.res.txt b/analysis/tests/src/expected/CompletionPipeChain.res.txt index 2dd269db5..8afb814c0 100644 --- a/analysis/tests/src/expected/CompletionPipeChain.res.txt +++ b/analysis/tests/src/expected/CompletionPipeChain.res.txt @@ -424,8 +424,14 @@ Path props CPPipe env:CompletionPipeChain envFromCompletionItem:CompletionSupport.Nested CPPipe type path:ReactDOM.Client.Root.t CPPipe pathFromEnv:ReactDOM.Client.Root found:false -Path CompletionSupport.ReactDOM.Client.Root.ren -[] +Path ReactDOM.Client.Root.ren +[{ + "label": "ReactDOM.Client.Root.render", + "kind": 12, + "tags": [], + "detail": "(t, React.element) => unit", + "documentation": null + }] Complete src/CompletionPipeChain.res 88:16 posCursor:[88:16] posNoWhite:[88:15] Found expr:[76:15->93:1] From dafa03e00e65e7096f52db357510016c63bcf38b Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Wed, 8 Mar 2023 15:07:29 +0100 Subject: [PATCH 39/41] debug output --- analysis/tests/src/expected/CompletionExpressions.res.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/analysis/tests/src/expected/CompletionExpressions.res.txt b/analysis/tests/src/expected/CompletionExpressions.res.txt index 104a6b663..64dddf545 100644 --- a/analysis/tests/src/expected/CompletionExpressions.res.txt +++ b/analysis/tests/src/expected/CompletionExpressions.res.txt @@ -864,6 +864,9 @@ Complete src/CompletionExpressions.res 196:14 posCursor:[196:14] posNoWhite:[196:13] Found expr:[196:3->196:14] Pexp_field [196:3->196:6] someOpt:[196:7->196:14] Completable: Cpath Value[fff].someOpt +ContextPath Value[fff].someOpt +ContextPath Value[fff] +Path fff [{ "label": "someOptField", "kind": 5, From 3c9193fc35ab14364abad318f29045c55377ab35 Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Wed, 8 Mar 2023 15:19:22 +0100 Subject: [PATCH 40/41] remove now irrelevant comments about issues --- analysis/src/CompletionBackEnd.ml | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/analysis/src/CompletionBackEnd.ml b/analysis/src/CompletionBackEnd.ml index eb0b2cad5..89a1e3bd6 100644 --- a/analysis/src/CompletionBackEnd.ml +++ b/analysis/src/CompletionBackEnd.ml @@ -864,14 +864,9 @@ and getCompletionsForContextPath ~debug ~full ~opens ~rawOpens ~allFiles ~pos with | None -> [] | Some (typ, envFromCompletionItem) -> ( - (* Passing `envFromCompletionItem` into `resolveTypeForPipeCompletion` - fixes the issue in `CompletionInferValues.res`, but breaks other pipe - chains. Change it and see what breaks instead. *) let env, typ = typ - |> TypeUtils.resolveTypeForPipeCompletion - (* by doing this ~env:envFromCompletionItem*) - ~env ~package ~full ~lhsLoc + |> TypeUtils.resolveTypeForPipeCompletion ~env ~package ~full ~lhsLoc in if debug then if env <> envFromCompletionItem then From ed0cdee05e1e19d66241a72ad51e7a77b529ff28 Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Thu, 9 Mar 2023 18:43:03 +0100 Subject: [PATCH 41/41] changleog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d6d6cb43e..50c1dd84d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,10 @@ ## master +#### :rocket: New Feature + +- Greatly extend completion abilities for unsaved code. WARNING: Might be a bit unstable initially. Report any issues you see. https://github.com/rescript-lang/rescript-vscode/pull/712 + ## 1.14.0 #### :rocket: New Feature