Skip to content

Commit

Permalink
feat(exthost): Types / handlers for MainThreadOutputService
Browse files Browse the repository at this point in the history
  • Loading branch information
bryphe authored Jul 18, 2020
1 parent 1b9250b commit f83f335
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 1 deletion.
26 changes: 26 additions & 0 deletions src/Exthost/Exthost.rei
Original file line number Diff line number Diff line change
Expand Up @@ -1055,6 +1055,31 @@ module Msg: {
});
};

module OutputService: {
[@deriving show]
type msg =
| Register({
label: string,
log: bool,
file: option(Oni_Core.Uri.t),
})
| Append({
channelId: string,
value: string,
})
| Update({channelId: string})
| Clear({
channelId: string,
till: int,
})
| Reveal({
channelId: string,
preserveFocus: bool,
})
| Close({channelId: string})
| Dispose({channelId: string});
};

module StatusBar: {
[@deriving show]
type alignment =
Expand Down Expand Up @@ -1091,6 +1116,7 @@ module Msg: {
| FileSystem(FileSystem.msg)
| LanguageFeatures(LanguageFeatures.msg)
| MessageService(MessageService.msg)
| OutputService(OutputService.msg)
| SCM(SCM.msg)
| StatusBar(StatusBar.msg)
| Telemetry(Telemetry.msg)
Expand Down
6 changes: 5 additions & 1 deletion src/Exthost/Handlers.re
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,11 @@ let handlers =
~mapper=msg => Msg.MessageService(msg),
"MainThreadMessageService",
),
mainNotImplemented("MainThreadOutputService"),
main(
~handler=Msg.OutputService.handle,
~mapper=msg => Msg.OutputService(msg),
"MainThreadOutputService",
),
mainNotImplemented("MainThreadProgress"),
mainNotImplemented("MainThreadQuickOpen"),
main(
Expand Down
54 changes: 54 additions & 0 deletions src/Exthost/Msg.re
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,59 @@ module MessageService = {
};
};
};
module OutputService = {
[@deriving show]
type msg =
| Register({
label: string,
log: bool,
file: option(Oni_Core.Uri.t),
})
| Append({
channelId: string,
value: string,
})
| Update({channelId: string})
| Clear({
channelId: string,
till: int,
})
| Reveal({
channelId: string,
preserveFocus: bool,
})
| Close({channelId: string})
| Dispose({channelId: string});
let handle = (method, args: Yojson.Safe.t) => {
Base.Result.Let_syntax.(
Json.Decode.(
switch (method, args) {
| ("$register", `List([`String(label), `Bool(log), maybeUriJson])) =>
let%bind maybeUri =
maybeUriJson
|> Internal.decode_value(nullable(Oni_Core.Uri.decode));
Ok(Register({label, log, file: maybeUri}));
| ("$append", `List([`String(channelId), `String(value)])) =>
Ok(Append({channelId, value}))
| ("$update", `List([`String(channelId)])) =>
Ok(Update({channelId: channelId}))
| ("$clear", `List([`String(channelId), `Int(till)])) =>
Ok(Clear({channelId, till}))
| ("$reveal", `List([`String(channelId), `Bool(preserveFocus)])) =>
Ok(Reveal({channelId, preserveFocus}))
| ("$close", `List([`String(channelId)])) =>
Ok(Close({channelId: channelId}))
| ("$dispose", `List([`String(channelId)])) =>
Ok(Dispose({channelId: channelId}))
| _ => Error("Unable to parse OutputService method: " ++ method)
}
)
);
};
};
module StatusBar = {
[@deriving show]
type alignment =
Expand Down Expand Up @@ -1163,6 +1216,7 @@ type t =
| FileSystem(FileSystem.msg)
| LanguageFeatures(LanguageFeatures.msg)
| MessageService(MessageService.msg)
| OutputService(OutputService.msg)
| SCM(SCM.msg)
| StatusBar(StatusBar.msg)
| Telemetry(Telemetry.msg)
Expand Down

0 comments on commit f83f335

Please sign in to comment.