Skip to content

Commit d954df8

Browse files
authored
fix issue where pattern completion would not be triggered (#999)
1 parent e76c405 commit d954df8

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

analysis/src/CompletionFrontEnd.ml

+4-2
Original file line numberDiff line numberDiff line change
@@ -1026,8 +1026,10 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
10261026
cases
10271027
|> List.iter (fun (case : Parsetree.case) ->
10281028
let oldScope = !scope in
1029-
if locHasCursor case.pc_rhs.pexp_loc = false then
1030-
completePattern ?contextPath:ctxPath case.pc_lhs;
1029+
if
1030+
locHasCursor case.pc_rhs.pexp_loc = false
1031+
&& locHasCursor case.pc_lhs.ppat_loc
1032+
then completePattern ?contextPath:ctxPath case.pc_lhs;
10311033
scopePattern ?contextPath:ctxPath case.pc_lhs;
10321034
Ast_iterator.default_iterator.case iterator case;
10331035
scope := oldScope);

analysis/tests/src/CompletionPattern.res

+12
Original file line numberDiff line numberDiff line change
@@ -230,3 +230,15 @@ let make = (~thing: result<someVariant, unit>) => {
230230
| _ => ()
231231
}
232232
}
233+
234+
type results = {
235+
query: string,
236+
nbHits: int,
237+
}
238+
239+
type hitsUse = {results: results, hits: array<string>}
240+
241+
let hitsUse = (): hitsUse => Obj.magic()
242+
243+
// let {results: {query, nbHits}, } = hitsUse()
244+
// ^com

analysis/tests/src/expected/CompletionPattern.res.txt

+16
Original file line numberDiff line numberDiff line change
@@ -1207,3 +1207,19 @@ Path r
12071207
"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```"}
12081208
}]
12091209

1210+
Complete src/CompletionPattern.res 242:33
1211+
posCursor:[242:33] posNoWhite:[242:32] Found pattern:[242:7->242:35]
1212+
Completable: Cpattern Value[hitsUse](Nolabel)->recordBody
1213+
Package opens Pervasives.JsxModules.place holder
1214+
Resolved opens 1 pervasives
1215+
ContextPath Value[hitsUse](Nolabel)
1216+
ContextPath Value[hitsUse]
1217+
Path hitsUse
1218+
[{
1219+
"label": "hits",
1220+
"kind": 5,
1221+
"tags": [],
1222+
"detail": "array<string>",
1223+
"documentation": {"kind": "markdown", "value": "```rescript\nhits: array<string>\n```\n\n```rescript\ntype hitsUse = {results: results, hits: array<string>}\n```"}
1224+
}]
1225+

0 commit comments

Comments
 (0)