Skip to content

Commit 97726aa

Browse files
committed
refactor nested pattern completion handling in backend
1 parent 01e3a90 commit 97726aa

File tree

1 file changed

+11
-27
lines changed

1 file changed

+11
-27
lines changed

analysis/src/CompletionBackEnd.ml

+11-27
Original file line numberDiff line numberDiff line change
@@ -2173,27 +2173,14 @@ Note: The `@react.component` decorator requires the react-jsx config to be set i
21732173
Utils.startsWith name prefix
21742174
&& (forHover || not (List.mem name identsSeen)))
21752175
|> List.map mkLabel
2176-
| Cpattern {typ; prefix; nested = []; fallback} -> (
2177-
let envWhereCompletionStarted = env in
2178-
match
2179-
typ
2180-
|> getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env
2181-
~exact:true ~scope
2182-
|> completionsGetTypeEnv
2183-
with
2184-
| Some (typ, env) -> (
2185-
let items =
2186-
typ
2187-
|> completeTypedValue ~env ~envWhereCompletionStarted ~full ~prefix
2188-
~expandOption:false ~includeLocalValues:false
2189-
~completionContext:None
2190-
in
2191-
match (items, fallback) with
2192-
| [], Some fallback ->
2193-
fallback |> processCompletable ~debug ~full ~scope ~env ~pos ~forHover
2194-
| items, _ -> items)
2195-
| None -> [])
21962176
| Cpattern {typ; prefix; nested; fallback} -> (
2177+
let fallbackOrEmpty ?items () =
2178+
match (fallback, items) with
2179+
| Some fallback, (None | Some []) ->
2180+
fallback |> processCompletable ~debug ~full ~scope ~env ~pos ~forHover
2181+
| _, Some items -> items
2182+
| None, None -> []
2183+
in
21972184
let envWhereCompletionStarted = env in
21982185
match
21992186
typ
@@ -2203,15 +2190,12 @@ Note: The `@react.component` decorator requires the react-jsx config to be set i
22032190
with
22042191
| Some (typ, env) -> (
22052192
match typ |> resolveNestedPattern ~env ~package:full.package ~nested with
2206-
| None -> []
2207-
| Some (typ, env, completionContext) -> (
2193+
| None -> fallbackOrEmpty ()
2194+
| Some (typ, env, completionContext) ->
22082195
let items =
22092196
typ
22102197
|> completeTypedValue ~env ~envWhereCompletionStarted ~full ~prefix
22112198
~expandOption:false ~includeLocalValues:false ~completionContext
22122199
in
2213-
match (items, fallback) with
2214-
| [], Some fallback ->
2215-
fallback |> processCompletable ~debug ~full ~scope ~env ~pos ~forHover
2216-
| items, _ -> items))
2217-
| None -> [])
2200+
fallbackOrEmpty ~items ())
2201+
| None -> fallbackOrEmpty ())

0 commit comments

Comments
 (0)