@@ -770,46 +770,58 @@ let completionsGetTypeEnv = function
770
770
771
771
type getCompletionsForContextPathMode = Regular | Pipe
772
772
773
- let completionsGetCompletionType ~full = function
774
- | {Completion. kind = Value typ; env} :: _
775
- | {Completion. kind = ObjLabel typ; env} :: _
776
- | {Completion. kind = Field ({typ} , _ ); env} :: _ ->
773
+ let completionsGetCompletionType ~full completions =
774
+ let firstNonSyntheticCompletion =
775
+ List. find_opt (fun c -> not c.Completion. synthetic) completions
776
+ in
777
+ match firstNonSyntheticCompletion with
778
+ | Some {Completion. kind = Value typ; env}
779
+ | Some {Completion. kind = ObjLabel typ; env}
780
+ | Some {Completion. kind = Field ({typ} , _ ); env} ->
777
781
typ
778
782
|> TypeUtils. extractType ~env ~package: full.package
779
783
|> Option. map (fun (typ , _ ) -> (typ, env))
780
- | {Completion. kind = Type typ ; env} :: _ -> (
784
+ | Some {Completion. kind = Type typ ; env} -> (
781
785
match TypeUtils. extractTypeFromResolvedType typ ~env ~full with
782
786
| None -> None
783
787
| Some extractedType -> Some (extractedType, env))
784
- | {Completion. kind = ExtractedType (typ , _ ); env} :: _ -> Some (typ, env)
788
+ | Some {Completion. kind = ExtractedType (typ , _ ); env} -> Some (typ, env)
785
789
| _ -> None
786
790
787
- let rec completionsGetCompletionType2 ~debug ~full ~opens ~rawOpens ~pos =
788
- function
789
- | {Completion. kind = Value typ; env} :: _
790
- | {Completion. kind = ObjLabel typ; env} :: _
791
- | {Completion. kind = Field ({typ} , _ ); env} :: _ ->
791
+ let rec completionsGetCompletionType2 ~debug ~full ~opens ~rawOpens ~pos
792
+ completions =
793
+ let firstNonSyntheticCompletion =
794
+ List. find_opt (fun c -> not c.Completion. synthetic) completions
795
+ in
796
+ match firstNonSyntheticCompletion with
797
+ | Some
798
+ ( {Completion. kind = Value typ; env}
799
+ | {Completion. kind = ObjLabel typ; env}
800
+ | {Completion. kind = Field ({typ} , _ ); env} ) ->
792
801
Some (TypeExpr typ, env)
793
- | {Completion. kind = FollowContextPath (ctxPath , scope ); env} :: _ ->
802
+ | Some {Completion. kind = FollowContextPath (ctxPath , scope ); env} ->
794
803
ctxPath
795
804
|> getCompletionsForContextPath ~debug ~full ~env ~exact: true ~opens
796
805
~raw Opens ~pos ~scope
797
806
|> completionsGetCompletionType2 ~debug ~full ~opens ~raw Opens ~pos
798
- | {Completion. kind = Type typ ; env} :: _ -> (
807
+ | Some {Completion. kind = Type typ ; env} -> (
799
808
match TypeUtils. extractTypeFromResolvedType typ ~env ~full with
800
809
| None -> None
801
810
| Some extractedType -> Some (ExtractedType extractedType, env))
802
- | {Completion. kind = ExtractedType (typ , _ ); env} :: _ ->
811
+ | Some {Completion. kind = ExtractedType (typ , _ ); env} ->
803
812
Some (ExtractedType typ, env)
804
813
| _ -> None
805
814
806
815
and completionsGetTypeEnv2 ~debug (completions : Completion.t list ) ~full ~opens
807
816
~rawOpens ~pos =
808
- match completions with
809
- | {Completion. kind = Value typ ; env} :: _ -> Some (typ, env)
810
- | {Completion. kind = ObjLabel typ ; env} :: _ -> Some (typ, env)
811
- | {Completion. kind = Field ({typ} , _ ); env} :: _ -> Some (typ, env)
812
- | {Completion. kind = FollowContextPath (ctxPath , scope ); env} :: _ ->
817
+ let firstNonSyntheticCompletion =
818
+ List. find_opt (fun c -> not c.Completion. synthetic) completions
819
+ in
820
+ match firstNonSyntheticCompletion with
821
+ | Some {Completion. kind = Value typ ; env} -> Some (typ, env)
822
+ | Some {Completion. kind = ObjLabel typ ; env} -> Some (typ, env)
823
+ | Some {Completion. kind = Field ({typ} , _ ); env} -> Some (typ, env)
824
+ | Some {Completion. kind = FollowContextPath (ctxPath , scope ); env} ->
813
825
ctxPath
814
826
|> getCompletionsForContextPath ~debug ~full ~opens ~raw Opens ~pos ~env
815
827
~exact: true ~scope
@@ -993,19 +1005,21 @@ and getCompletionsForContextPath ~debug ~full ~opens ~rawOpens ~pos ~env ~exact
993
1005
path @ [fieldName]
994
1006
|> getCompletionsForPath ~debug ~opens ~full ~pos ~exact
995
1007
~completion Context:Field ~env ~scope
996
- | CPField {contextPath = cp ; fieldName; fieldNameLoc} when Debug. verbose () ->
997
- (* TODO: this should only happen when the dot completion is at the end of the path *)
1008
+ | CPField {contextPath = cp ; fieldName; fieldNameLoc} ->
998
1009
if Debug. verbose () then print_endline " [ctx_path]--> dot completion!" ;
999
- let completionsForCtxPath =
1010
+ let completions =
1000
1011
cp
1001
1012
|> getCompletionsForContextPath ~debug ~full ~opens ~raw Opens ~pos ~env
1002
1013
~exact: true ~scope
1003
- |> completionsGetTypeEnv2 ~debug ~full ~opens ~raw Opens ~pos
1014
+ in
1015
+ let completionsForCtxPath =
1016
+ completions
1017
+ |> completionsGetCompletionType2 ~debug ~full ~opens ~raw Opens ~pos
1004
1018
in
1005
1019
(* These are the main completions for the dot. *)
1006
1020
let mainCompletions =
1007
1021
match completionsForCtxPath with
1008
- | Some (typ, env)
1022
+ | Some (TypeExpr typ, env)
1009
1023
when typ |> TypeUtils. extractObjectType ~env ~package |> Option. is_some
1010
1024
->
1011
1025
(* Handle obj completion via dot *)
@@ -1019,46 +1033,70 @@ and getCompletionsForContextPath ~debug ~full ~opens ~rawOpens ~pos ~env ~exact
1019
1033
if Utils. checkName field ~prefix: fieldName ~exact then
1020
1034
let fullObjFieldName = Printf. sprintf " [\" %s\" ]" field in
1021
1035
Some
1022
- (Completion. create fullObjFieldName ~range: fieldNameLoc
1023
- ~insert Text:fullObjFieldName ~env: objEnv
1024
- ~kind: (Completion. ObjLabel typ))
1036
+ (Completion. create fullObjFieldName ~synthetic: true
1037
+ ~range: fieldNameLoc ~insert Text:fullObjFieldName
1038
+ ~env: objEnv ~ kind: (Completion. ObjLabel typ))
1025
1039
else None )
1026
- | Some (typ, env)
1027
- when typ |> TypeUtils. extractRecordType ~env ~package |> Option. is_some
1028
- ->
1029
- let env, fields, decl, _path, _attributes =
1030
- typ |> TypeUtils. extractRecordType ~env ~package |> Option. get
1031
- in
1032
- if Debug. verbose () then
1033
- Printf. printf " [dot_completion]--> Record type found\n " ;
1034
- let recordAsString =
1035
- decl.item.decl |> Shared. declToString decl.name.txt
1040
+ | Some (t , env ) -> (
1041
+ let extracted =
1042
+ match t with
1043
+ | TypeExpr typ -> (
1044
+ if Debug. verbose () then
1045
+ Printf. printf
1046
+ " [dot_completion]--> Found type expr for main completions\n " ;
1047
+ match typ |> TypeUtils. extractRecordType ~env ~package with
1048
+ | Some (env , fields , typDecl , _path , _attributes ) ->
1049
+ Some
1050
+ ( env,
1051
+ fields,
1052
+ typDecl.item.decl |> Shared. declToString typDecl.name.txt )
1053
+ | None -> None )
1054
+ | ExtractedType typ -> (
1055
+ if Debug. verbose () then
1056
+ Printf. printf
1057
+ " [dot_completion]--> Found extracted type for main completions\n " ;
1058
+ match typ with
1059
+ | Trecord {fields} ->
1060
+ Some (env, fields, typ |> TypeUtils. extractedTypeToString)
1061
+ | _ -> None )
1036
1062
in
1037
- fields
1038
- |> Utils. filterMap (fun field ->
1039
- if Utils. checkName field.fname.txt ~prefix: fieldName ~exact then
1040
- Some
1041
- (Completion. create field.fname.txt ~env
1042
- ?deprecated:field.deprecated ~docstring: field.docstring
1043
- ~kind: (Completion. Field (field, recordAsString)))
1044
- else None )
1045
- | Some (_typ , _env ) ->
1046
- (* No more primary completions, for now. *)
1047
- []
1063
+ match extracted with
1064
+ | None -> []
1065
+ | Some (envFromExtracted , fields , recordAsString ) ->
1066
+ fields
1067
+ |> Utils. filterMap (fun field ->
1068
+ if Utils. checkName field.fname.txt ~prefix: fieldName ~exact
1069
+ then
1070
+ Some
1071
+ (Completion. create field.fname.txt ~env: envFromExtracted
1072
+ ?deprecated:field.deprecated ~docstring: field.docstring
1073
+ ~kind: (Completion. Field (field, recordAsString)))
1074
+ else None ))
1048
1075
| None -> []
1049
1076
in
1050
1077
let pipeCompletions =
1051
1078
match completionsForCtxPath with
1052
- | None -> []
1053
- | Some (typ , envFromCompletionItem ) -> (
1054
- let tPath = TypeUtils. pathFromTypeExpr typ in
1079
+ | Some (TypeExpr typ , envFromCompletionItem ) -> (
1080
+ if Debug. verbose () then
1081
+ Printf. printf
1082
+ " [dot_completion]--> Found Type expr when doing pipe completions\n " ;
1083
+ let tPath =
1084
+ match TypeUtils. pathFromTypeExpr typ with
1085
+ | None -> None
1086
+ | Some tPath -> (
1087
+ match
1088
+ TypeUtils. getPathRelativeToEnv ~debug ~env: envCompletionIsMadeFrom
1089
+ ~env FromItem:envFromCompletionItem (Utils. expandPath tPath)
1090
+ with
1091
+ | None -> None
1092
+ | Some completionPath -> Some (completionPath, tPath))
1093
+ in
1055
1094
match tPath with
1056
1095
| None -> []
1057
- | Some tPath ->
1058
- let completionPath =
1059
- (tPath |> Utils. expandPath |> List. tl |> List. rev)
1060
- @ (envFromCompletionItem.pathRev |> List. rev)
1061
- in
1096
+ | Some (completionPath , tPath ) ->
1097
+ if Debug. verbose () then
1098
+ Printf. printf " [dot_completion]--> Got completion path %s\n "
1099
+ (completionPath |> String. concat " ." );
1062
1100
if List. length completionPath = 0 then []
1063
1101
else
1064
1102
let completions =
@@ -1067,14 +1105,20 @@ and getCompletionsForContextPath ~debug ~full ~opens ~rawOpens ~pos ~env ~exact
1067
1105
completionPath
1068
1106
in
1069
1107
completions
1070
- |> TypeUtils. filterPipeableFunctions ~env ~full
1108
+ |> TypeUtils. filterPipeableFunctions ~synthetic: true ~ env ~full
1071
1109
~last Path:(Path. last tPath) ~replace Range:fieldNameLoc)
1110
+ | Some (ExtractedType _ , _ ) ->
1111
+ if Debug. verbose () then
1112
+ Printf. printf
1113
+ " [dot_completion]--> PROBLEM: Found extracted type when trying to \
1114
+ do pipe completions\n " ;
1115
+ []
1116
+ | _ -> []
1072
1117
in
1073
1118
(* Extra completions from configure extra module(s) *)
1074
1119
let extraCompletions =
1075
1120
match completionsForCtxPath with
1076
- | None -> []
1077
- | Some (typ , envFromCompletionItem ) -> (
1121
+ | Some (TypeExpr typ , envFromCompletionItem ) -> (
1078
1122
match
1079
1123
TypeUtils. getExtraModuleToCompleteFromForType typ
1080
1124
~env: envFromCompletionItem ~full
@@ -1084,90 +1128,21 @@ and getCompletionsForContextPath ~debug ~full ~opens ~rawOpens ~pos ~env ~exact
1084
1128
completionsForPipeFromCompletionPath ~env CompletionIsMadeFrom ~opens
1085
1129
~pos ~scope ~debug ~prefix: fieldName ~env ~raw Opens ~full
1086
1130
completionPath
1087
- |> TypeUtils. filterPipeableFunctions ~env ~full
1131
+ |> TypeUtils. filterPipeableFunctions ~synthetic: true ~ env ~full
1088
1132
~replace Range:fieldNameLoc
1089
1133
?lastPath:
1090
1134
(match TypeUtils. pathFromTypeExpr typ with
1091
1135
| None -> None
1092
1136
| Some tPath -> Some (Path. last tPath)))
1137
+ | Some (ExtractedType _ , _ ) ->
1138
+ if Debug. verbose () then
1139
+ Printf. printf
1140
+ " [dot_completion]--> PROBLEM: Found extracted type when trying to \
1141
+ do extra completions\n " ;
1142
+ []
1143
+ | _ -> []
1093
1144
in
1094
- mainCompletions @ pipeCompletions @ extraCompletions
1095
- | CPField {contextPath = cp ; fieldName; fieldNameLoc} -> (
1096
- if Debug. verbose () then print_endline " [ctx_path]--> CPField" ;
1097
- let completionsForCtxPath =
1098
- cp
1099
- |> getCompletionsForContextPath ~debug ~full ~opens ~raw Opens ~pos ~env
1100
- ~exact: true ~scope
1101
- in
1102
- let extracted =
1103
- match
1104
- completionsForCtxPath
1105
- |> completionsGetCompletionType2 ~debug ~full ~opens ~raw Opens ~pos
1106
- with
1107
- | Some (TypeExpr typ , env ) -> (
1108
- match typ |> TypeUtils. extractRecordType ~env ~package with
1109
- | Some (env , fields , typDecl , path , attributes ) ->
1110
- Some
1111
- ( env,
1112
- fields,
1113
- typDecl.item.decl |> Shared. declToString typDecl.name.txt,
1114
- Some path,
1115
- attributes )
1116
- | None -> None )
1117
- | Some (ExtractedType typ , env ) -> (
1118
- match typ with
1119
- | Trecord {fields; path; attributes} ->
1120
- Some
1121
- ( env,
1122
- fields,
1123
- typ |> TypeUtils. extractedTypeToString,
1124
- path,
1125
- attributes )
1126
- | _ -> None )
1127
- | None -> None
1128
- in
1129
- match extracted with
1130
- | None -> []
1131
- | Some (envFromExtracted , fields , recordAsString , path , attributes ) ->
1132
- let pipeCompletion =
1133
- match
1134
- (path, ProcessAttributes. findEditorCompleteFromAttribute attributes)
1135
- with
1136
- | Some path , _ when Path. last path = " t" ->
1137
- if Debug. verbose () then Printf. printf " CPField--> type is type t\n " ;
1138
- Some
1139
- ( path,
1140
- path |> SharedTypes. pathIdentToString |> String. split_on_char '.'
1141
- |> List. rev |> List. tl )
1142
- | Some path , Some modulePath ->
1143
- if Debug. verbose () then
1144
- Printf. printf
1145
- " CPField--> type has completeFrom config for module %s, hd: %s, \
1146
- env moduleName: %s\n "
1147
- (modulePath |> SharedTypes. pathToString)
1148
- (List. hd modulePath) env.file.moduleName;
1149
- Some (path, modulePath)
1150
- | _ -> None
1151
- in
1152
- let pipeCompletionsForModule =
1153
- match pipeCompletion with
1154
- | Some (path , completionPath ) ->
1155
- completionsForPipeFromCompletionPath ~opens ~pos ~scope ~debug
1156
- ~prefix: fieldName ~env CompletionIsMadeFrom:env ~env: envFromExtracted
1157
- ~raw Opens ~full completionPath
1158
- |> TypeUtils. filterPipeableFunctions ~env: envFromExtracted ~full
1159
- ~last Path:(Path. last path) ~replace Range:fieldNameLoc
1160
- | None -> []
1161
- in
1162
- pipeCompletionsForModule
1163
- @ (fields
1164
- |> Utils. filterMap (fun field ->
1165
- if Utils. checkName field.fname.txt ~prefix: fieldName ~exact then
1166
- Some
1167
- (Completion. create field.fname.txt ~env: envFromExtracted
1168
- ?deprecated:field.deprecated ~docstring: field.docstring
1169
- ~kind: (Completion. Field (field, recordAsString)))
1170
- else None )))
1145
+ pipeCompletions @ extraCompletions @ mainCompletions
1171
1146
| CPObj (cp , label ) -> (
1172
1147
(* TODO: Also needs to support ExtractedType *)
1173
1148
if Debug. verbose () then print_endline " [ctx_path]--> CPObj" ;
@@ -1310,8 +1285,8 @@ and getCompletionsForContextPath ~debug ~full ~opens ~rawOpens ~pos ~env ~exact
1310
1285
|> String. concat " ."
1311
1286
in
1312
1287
[
1313
- Completion. create name ~includes Snippets :true ~kind: ( Value typ) ~env
1314
- ~sort Text:" A"
1288
+ Completion. create name ~synthetic : true ~includes Snippets: true
1289
+ ~kind: ( Value typ) ~env ~ sort Text:" A"
1315
1290
~docstring:
1316
1291
[
1317
1292
" Turns `" ^ builtinNameToComplete
0 commit comments