Skip to content

Commit 78f5779

Browse files
committed
complete modules in payload of mainTypeForModule
1 parent 2263d4c commit 78f5779

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

analysis/src/CompletionFrontEnd.ml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -946,6 +946,32 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
946946
setResult
947947
(Completable.CdecoratorPayload
948948
(JsxConfig {nested = List.rev nested; prefix})))
949+
| _ -> ()
950+
else if id.txt = "mainTypeForModule" then
951+
match payload with
952+
| PStr
953+
[
954+
{
955+
pstr_desc =
956+
Pstr_eval
957+
( {
958+
pexp_loc;
959+
pexp_desc = Pexp_construct ({txt = path; loc}, None);
960+
},
961+
_ );
962+
};
963+
]
964+
when locHasCursor pexp_loc ->
965+
if Debug.verbose () then
966+
print_endline "[decoratorCompletion] Found @mainTypeForModule";
967+
setResult
968+
(Completable.Cpath
969+
(CPId
970+
{
971+
path = Utils.flattenLongIdent path;
972+
completionContext = Module;
973+
loc;
974+
}))
949975
| _ -> ());
950976
Ast_iterator.default_iterator.attribute iterator (id, payload)
951977
in

analysis/tests/src/CompletionFromModule.res

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,6 @@ let nn: SomeOtherModule.t = {nname: "hello"}
3434
// nn.
3535
// ^com
3636
// ^dv-
37+
38+
// @mainTypeForModule(SomeOthe) type typeOutsideModule = {nname: string}
39+
// ^com

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Path SomeModule.
3535

3636
Complete src/CompletionFromModule.res 33:6
3737
posCursor:[33:6] posNoWhite:[33:5] Found expr:[33:3->33:6]
38-
Pexp_field [33:3->33:5] _:[37:0->33:6]
38+
Pexp_field [33:3->33:5] _:[40:0->33:6]
3939
[set_result] set new result to Cpath Value[nn].""
4040
Completable: Cpath Value[nn].""
4141
Package opens Pervasives.JsxModules.place holder
@@ -77,3 +77,18 @@ Path SomeOtherModule.
7777
}]
7878

7979

80+
Complete src/CompletionFromModule.res 37:30
81+
XXX Not found!
82+
Completable: Cpath Module[SomeOthe]
83+
Package opens Pervasives.JsxModules.place holder
84+
Resolved opens 1 pervasives
85+
ContextPath Module[SomeOthe]
86+
Path SomeOthe
87+
[{
88+
"label": "SomeOtherModule",
89+
"kind": 9,
90+
"tags": [],
91+
"detail": "module SomeOtherModule",
92+
"documentation": null
93+
}]
94+

0 commit comments

Comments
 (0)