Skip to content

Commit

Permalink
fix issue where pattern completion would not be triggered (#999)
Browse files Browse the repository at this point in the history
  • Loading branch information
zth authored May 31, 2024
1 parent e76c405 commit d954df8
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
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```"}
}]

0 comments on commit d954df8

Please sign in to comment.