@@ -972,8 +972,10 @@ let printConstructorArgs argsLen ~asSnippet =
972
972
if List. length ! args > 0 then " (" ^ (! args |> String. concat " , " ) ^ " )"
973
973
else " "
974
974
975
+ type completionMode = Pattern | Expression
976
+
975
977
let rec completeTypedValue (t : SharedTypes.completionType ) ~env ~full ~prefix
976
- ~completionContext =
978
+ ~completionContext ~ mode =
977
979
let extractedType =
978
980
match t with
979
981
| TypeExpr t -> t |> TypeUtils. extractType ~env ~package: full.package
@@ -1030,7 +1032,7 @@ let rec completeTypedValue (t : SharedTypes.completionType) ~env ~full ~prefix
1030
1032
let innerType = Utils. unwrapIfOption t in
1031
1033
let expandedCompletions =
1032
1034
TypeExpr innerType
1033
- |> completeTypedValue ~env ~full ~prefix ~completion Context
1035
+ |> completeTypedValue ~env ~full ~prefix ~completion Context ~mode
1034
1036
|> List. map (fun (c : Completion.t ) ->
1035
1037
{
1036
1038
c with
@@ -1118,41 +1120,44 @@ let rec completeTypedValue (t : SharedTypes.completionType) ~env ~full ~prefix
1118
1120
]
1119
1121
else []
1120
1122
| Some (Tfunction {env; typ; args} ) ->
1121
- let mkFnBody ~asSnippet =
1122
- match args with
1123
- | [(Nolabel , argTyp)] when TypeUtils. typeIsUnit argTyp -> " ()"
1124
- | [(Nolabel , _)] -> if asSnippet then " ${1:v1}" else " v1"
1125
- | _ ->
1126
- let currentUnlabelledIndex = ref 0 in
1127
- let argsText =
1128
- args
1129
- |> List. map (fun ((label , typ ) : typedFnArg ) ->
1130
- match label with
1131
- | Optional name -> " ~" ^ name ^ " =?"
1132
- | Labelled name -> " ~" ^ name
1133
- | Nolabel ->
1134
- if TypeUtils. typeIsUnit typ then " ()"
1135
- else (
1136
- currentUnlabelledIndex := ! currentUnlabelledIndex + 1 ;
1137
- let num = ! currentUnlabelledIndex in
1138
- if asSnippet then
1139
- " ${" ^ string_of_int num ^ " :v" ^ string_of_int num ^ " }"
1140
- else " v" ^ string_of_int num))
1141
- |> String. concat " , "
1142
- in
1143
- " (" ^ argsText ^ " )"
1144
- in
1145
- if prefix = " " then
1146
- [
1147
- Completion. createWithSnippet
1148
- ~name: (mkFnBody ~as Snippet:false ^ " => {}" )
1149
- ~insert Text:
1150
- (mkFnBody ~as Snippet:! Cfg. supportsSnippets
1151
- ^ " => "
1152
- ^ if ! Cfg. supportsSnippets then " ${0:{\\ }}" else " {}" )
1153
- ~sort Text:" A" ~kind: (Value typ) ~env () ;
1154
- ]
1155
- else []
1123
+ if mode = Pattern then []
1124
+ else
1125
+ let mkFnBody ~asSnippet =
1126
+ match args with
1127
+ | [(Nolabel , argTyp)] when TypeUtils. typeIsUnit argTyp -> " ()"
1128
+ | [(Nolabel , _)] -> if asSnippet then " ${1:v1}" else " v1"
1129
+ | _ ->
1130
+ let currentUnlabelledIndex = ref 0 in
1131
+ let argsText =
1132
+ args
1133
+ |> List. map (fun ((label , typ ) : typedFnArg ) ->
1134
+ match label with
1135
+ | Optional name -> " ~" ^ name ^ " =?"
1136
+ | Labelled name -> " ~" ^ name
1137
+ | Nolabel ->
1138
+ if TypeUtils. typeIsUnit typ then " ()"
1139
+ else (
1140
+ currentUnlabelledIndex := ! currentUnlabelledIndex + 1 ;
1141
+ let num = ! currentUnlabelledIndex in
1142
+ if asSnippet then
1143
+ " ${" ^ string_of_int num ^ " :v" ^ string_of_int num
1144
+ ^ " }"
1145
+ else " v" ^ string_of_int num))
1146
+ |> String. concat " , "
1147
+ in
1148
+ " (" ^ argsText ^ " )"
1149
+ in
1150
+ if prefix = " " then
1151
+ [
1152
+ Completion. createWithSnippet
1153
+ ~name: (mkFnBody ~as Snippet:false ^ " => {}" )
1154
+ ~insert Text:
1155
+ (mkFnBody ~as Snippet:! Cfg. supportsSnippets
1156
+ ^ " => "
1157
+ ^ if ! Cfg. supportsSnippets then " ${0:{\\ }}" else " {}" )
1158
+ ~sort Text:" A" ~kind: (Value typ) ~env () ;
1159
+ ]
1160
+ else []
1156
1161
| _ -> []
1157
1162
1158
1163
let rec processCompletable ~debug ~full ~scope ~env ~pos ~forHover
@@ -1277,7 +1282,9 @@ let rec processCompletable ~debug ~full ~scope ~env ~pos ~forHover
1277
1282
| None -> fallbackOrEmpty ()
1278
1283
| Some (typ , env , completionContext ) ->
1279
1284
let items =
1280
- typ |> completeTypedValue ~env ~full ~prefix ~completion Context
1285
+ typ
1286
+ |> completeTypedValue ~mode: Pattern ~env ~full ~prefix
1287
+ ~completion Context
1281
1288
in
1282
1289
fallbackOrEmpty ~items () )
1283
1290
| None -> fallbackOrEmpty () )
@@ -1297,7 +1304,9 @@ let rec processCompletable ~debug ~full ~scope ~env ~pos ~forHover
1297
1304
| None -> []
1298
1305
| Some (typ , env , completionContext ) -> (
1299
1306
let items =
1300
- typ |> completeTypedValue ~env ~full ~prefix ~completion Context
1307
+ typ
1308
+ |> completeTypedValue ~mode: Expression ~env ~full ~prefix
1309
+ ~completion Context
1301
1310
in
1302
1311
match (prefix, completionContext) with
1303
1312
| "" , _ -> items
0 commit comments