diff --git a/analysis/src/CompletionFrontEnd.ml b/analysis/src/CompletionFrontEnd.ml index a38015a86..88bbdd2ce 100644 --- a/analysis/src/CompletionFrontEnd.ml +++ b/analysis/src/CompletionFrontEnd.ml @@ -1026,8 +1026,10 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor cases |> List.iter (fun (case : Parsetree.case) -> let oldScope = !scope in - if locHasCursor case.pc_rhs.pexp_loc = false then - completePattern ?contextPath:ctxPath case.pc_lhs; + if + locHasCursor case.pc_rhs.pexp_loc = false + && locHasCursor case.pc_lhs.ppat_loc + then completePattern ?contextPath:ctxPath case.pc_lhs; scopePattern ?contextPath:ctxPath case.pc_lhs; Ast_iterator.default_iterator.case iterator case; scope := oldScope); diff --git a/analysis/tests/src/CompletionPattern.res b/analysis/tests/src/CompletionPattern.res index 763903a03..e3fe6d342 100644 --- a/analysis/tests/src/CompletionPattern.res +++ b/analysis/tests/src/CompletionPattern.res @@ -230,3 +230,15 @@ let make = (~thing: result<someVariant, unit>) => { | _ => () } } + +type results = { + query: string, + nbHits: int, +} + +type hitsUse = {results: results, hits: array<string>} + +let hitsUse = (): hitsUse => Obj.magic() + +// let {results: {query, nbHits}, } = hitsUse() +// ^com diff --git a/analysis/tests/src/expected/CompletionPattern.res.txt b/analysis/tests/src/expected/CompletionPattern.res.txt index 99b8b188d..9a442c241 100644 --- a/analysis/tests/src/expected/CompletionPattern.res.txt +++ b/analysis/tests/src/expected/CompletionPattern.res.txt @@ -1207,3 +1207,19 @@ Path r "documentation": {"kind": "markdown", "value": "```rescript\nnest: nestedRecord\n```\n\n```rescript\ntype someRecord = {first: int, second: (bool, option<someRecord>), optThird: option<[#first | #second(someRecord)]>, nest: nestedRecord}\n```"} }] +Complete src/CompletionPattern.res 242:33 +posCursor:[242:33] posNoWhite:[242:32] Found pattern:[242:7->242:35] +Completable: Cpattern Value[hitsUse](Nolabel)->recordBody +Package opens Pervasives.JsxModules.place holder +Resolved opens 1 pervasives +ContextPath Value[hitsUse](Nolabel) +ContextPath Value[hitsUse] +Path hitsUse +[{ + "label": "hits", + "kind": 5, + "tags": [], + "detail": "array<string>", + "documentation": {"kind": "markdown", "value": "```rescript\nhits: array<string>\n```\n\n```rescript\ntype hitsUse = {results: results, hits: array<string>}\n```"} + }] +