Skip to content

Commit

Permalink
complete modules in payload of mainTypeForModule
Browse files Browse the repository at this point in the history
  • Loading branch information
zth committed Nov 7, 2024
1 parent 2263d4c commit 78f5779
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
26 changes: 26 additions & 0 deletions analysis/src/CompletionFrontEnd.ml
Original file line number Diff line number Diff line change
Expand Up @@ -946,6 +946,32 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
setResult
(Completable.CdecoratorPayload
(JsxConfig {nested = List.rev nested; prefix})))
| _ -> ()
else if id.txt = "mainTypeForModule" then
match payload with
| PStr
[
{
pstr_desc =
Pstr_eval
( {
pexp_loc;
pexp_desc = Pexp_construct ({txt = path; loc}, None);
},
_ );
};
]
when locHasCursor pexp_loc ->
if Debug.verbose () then
print_endline "[decoratorCompletion] Found @mainTypeForModule";
setResult
(Completable.Cpath
(CPId
{
path = Utils.flattenLongIdent path;
completionContext = Module;
loc;
}))
| _ -> ());
Ast_iterator.default_iterator.attribute iterator (id, payload)
in
Expand Down
3 changes: 3 additions & 0 deletions analysis/tests/src/CompletionFromModule.res
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,6 @@ let nn: SomeOtherModule.t = {nname: "hello"}
// nn.
// ^com
// ^dv-

// @mainTypeForModule(SomeOthe) type typeOutsideModule = {nname: string}
// ^com
17 changes: 16 additions & 1 deletion analysis/tests/src/expected/CompletionFromModule.res.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Path SomeModule.

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


Complete src/CompletionFromModule.res 37:30
XXX Not found!
Completable: Cpath Module[SomeOthe]
Package opens Pervasives.JsxModules.place holder
Resolved opens 1 pervasives
ContextPath Module[SomeOthe]
Path SomeOthe
[{
"label": "SomeOtherModule",
"kind": 9,
"tags": [],
"detail": "module SomeOtherModule",
"documentation": null
}]

0 comments on commit 78f5779

Please sign in to comment.