Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix issue where pattern completion would not be triggered
  • Loading branch information
zth committed May 31, 2024
commit 8d61958f919610a671b1aac32131520f930a718d
6 changes: 4 additions & 2 deletions analysis/src/CompletionFrontEnd.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 12 additions & 0 deletions analysis/tests/src/CompletionPattern.res
Original file line number Diff line number Diff line change
Expand Up @@ -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
16 changes: 16 additions & 0 deletions analysis/tests/src/expected/CompletionPattern.res.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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```"}
}]