Skip to content

Commit d3231cd

Browse files
committed
fall back to regular local completions when typed expression completion misses
1 parent 6477993 commit d3231cd

File tree

3 files changed

+1276
-10
lines changed

3 files changed

+1276
-10
lines changed

analysis/src/CompletionBackEnd.ml

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1410,17 +1410,22 @@ let rec processCompletable ~debug ~full ~scope ~env ~pos ~forHover
14101410
fallbackOrEmpty ~items ())
14111411
| None -> fallbackOrEmpty ())
14121412
| Cexpression {contextPath; prefix; nested} -> (
1413+
(* Completions for local things like variables in scope, modules in the project, etc. *)
1414+
let regularCompletions =
1415+
prefix
1416+
|> getComplementaryCompletionsForTypedValue ~opens ~allFiles ~env ~scope
1417+
in
14131418
match
14141419
contextPath
14151420
|> getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env
14161421
~exact:true ~scope
14171422
|> completionsGetCompletionType ~full
14181423
with
1419-
| None -> []
1424+
| None -> regularCompletions
14201425
| Some (typ, env) -> (
14211426
match typ |> TypeUtils.resolveNested ~env ~full ~nested with
1422-
| None -> []
1423-
| Some (typ, env, completionContext) -> (
1427+
| None -> regularCompletions
1428+
| Some (typ, _env, completionContext) -> (
14241429
(* Wrap the insert text in braces when we're completing the root of a
14251430
JSX prop value. *)
14261431
let wrapInsertTextInBraces =
@@ -1448,12 +1453,6 @@ let rec processCompletable ~debug ~full ~scope ~env ~pos ~forHover
14481453
match (prefix, completionContext) with
14491454
| "", _ -> items
14501455
| _, None ->
1451-
(* Completions for local things like variables in scope, modules in the project, etc. *)
1452-
let regularCompletions =
1453-
prefix
1454-
|> getComplementaryCompletionsForTypedValue ~opens ~allFiles ~env
1455-
~scope
1456-
in
14571456
let items =
14581457
if List.length regularCompletions > 0 then
14591458
(* The client will occasionally sort the list of completions alphabetically, disregarding the order

analysis/tests/src/CompletionExpressions.res

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,3 +177,12 @@ let fnTakingCallback = (
177177

178178
// fnTakingCallback(a, b, c, d, e, )
179179
// ^com
180+
181+
let something = {
182+
let second = true
183+
let second2 = 1
184+
ignore(second)
185+
ignore(second2)
186+
Js.log(s)
187+
// ^com
188+
}

0 commit comments

Comments
 (0)