Skip to content

Commit

Permalink
feat(exthost): MainThreadProgress shape (onivim#2129)
Browse files Browse the repository at this point in the history
* Typing for Progress module

* Add types for MainThreadProgress
  • Loading branch information
bryphe authored Jul 20, 2020
1 parent 60920cf commit fb41bf0
Show file tree
Hide file tree
Showing 5 changed files with 184 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/Exthost/Exthost.re
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ module ModelChangedEvent = ModelChangedEvent;
module ModelContentChange = ModelContentChange;
module OneBasedPosition = OneBasedPosition;
module OneBasedRange = OneBasedRange;
module Progress = Progress;
module ReferenceContext = ReferenceContext;
module Reply = Reply;
module SCM = SCM;
Expand Down
56 changes: 56 additions & 0 deletions src/Exthost/Exthost.rei
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,47 @@ module Label: {
let decode: Json.decoder(t);
};

module Progress: {
module Location: {
[@deriving show]
type t =
| Explorer
| SCM
| Extensions
| Window
| Notification
| Dialog
| Other(string);

let decode: Json.decoder(t);
};

module Options: {
[@deriving show]
type t = {
location: Location.t,
title: option(string),
source: option(string),
total: option(int),
cancellable: bool,
buttons: list(string),
};

let decode: Json.decoder(t);
};

module Step: {
[@deriving show]
type t = {
message: option(string),
increment: option(int),
total: option(int),
};

let decode: Json.decoder(t);
};
};

module SCM: {
[@deriving show({with_path: false})]
type command = {
Expand Down Expand Up @@ -1003,6 +1044,20 @@ module Msg: {
});
};

module Progress: {
[@deriving show]
type msg =
| StartProgress({
handle: int,
options: Progress.Options.t,
})
| ProgressReport({
handle: int,
message: Progress.Step.t,
})
| ProgressEnd({handle: int});
};

module SCM: {
[@deriving show]
type msg =
Expand Down Expand Up @@ -1136,6 +1191,7 @@ module Msg: {
| LanguageFeatures(LanguageFeatures.msg)
| MessageService(MessageService.msg)
| OutputService(OutputService.msg)
| Progress(Progress.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 @@ -134,7 +134,11 @@ let handlers =
~mapper=msg => Msg.OutputService(msg),
"MainThreadOutputService",
),
mainNotImplemented("MainThreadProgress"),
main(
~handler=Msg.Progress.handle,
~mapper=msg => Msg.Progress(msg),
"MainThreadProgress",
),
mainNotImplemented("MainThreadQuickOpen"),
main(
~handler=Msg.StatusBar.handle,
Expand Down
36 changes: 36 additions & 0 deletions src/Exthost/Msg.re
Original file line number Diff line number Diff line change
Expand Up @@ -1048,6 +1048,41 @@ module Telemetry = {
};
};
module Progress = {
[@deriving show]
type msg =
| StartProgress({
handle: int,
options: Progress.Options.t,
})
| ProgressReport({
handle: int,
message: Progress.Step.t,
})
| ProgressEnd({handle: int});
let handle = (method, args: Yojson.Safe.t) => {
Base.Result.Let_syntax.(
switch (method, args) {
| ("$startProgress", `List([`Int(handle), optionsJson, ..._])) =>
let%bind options =
optionsJson |> Internal.decode_value(Progress.Options.decode);
Ok(StartProgress({handle, options}));
| ("$progressReport", `List([`Int(handle), messageJson])) =>
let%bind message =
messageJson |> Internal.decode_value(Progress.Step.decode);
Ok(ProgressReport({handle, message}));
| ("$progressEnd", `List([`Int(handle)])) =>
Ok(ProgressEnd({handle: handle}))
| _ => Error("Progress - unhandled method: " ++ method)
}
);
};
};
module SCM = {
[@deriving show]
type msg =
Expand Down Expand Up @@ -1256,6 +1291,7 @@ type t =
| LanguageFeatures(LanguageFeatures.msg)
| MessageService(MessageService.msg)
| OutputService(OutputService.msg)
| Progress(Progress.msg)
| SCM(SCM.msg)
| StatusBar(StatusBar.msg)
| Telemetry(Telemetry.msg)
Expand Down
86 changes: 86 additions & 0 deletions src/Exthost/Progress.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
open Oni_Core;

module Location = {
[@deriving show]
type t =
| Explorer
| SCM
| Extensions
| Window
| Notification
| Dialog
| Other(string);

let ofInt =
fun
| 1 => Some(Explorer)
| 3 => Some(SCM)
| 5 => Some(Extensions)
| 10 => Some(Window)
| 15 => Some(Notification)
| 20 => Some(Dialog)
| _ => None;

module Decode = {
open Json.Decode;
let int =
int
|> map(ofInt)
|> and_then(
fun
| None => fail("Unrecognized location")
| Some(location) => succeed(location),
);

let string = string |> map(str => Other(str));
};

let decode =
Json.Decode.one_of([("int", Decode.int), ("string", Decode.string)]);
};

module Options = {
[@deriving show]
type t = {
location: Location.t,
title: option(string),
source: option(string),
total: option(int),
cancellable: bool,
buttons: list(string),
};

let decode =
Json.Decode.(
obj(({field, _}) =>
{
location: field.required("location", Location.decode),
title: field.optional("title", string),
source: field.optional("source", string),
total: field.optional("total", int),
cancellable: field.withDefault("cancellable", false, bool),
buttons: field.withDefault("buttons", [], list(string)),
}
)
);
};

module Step = {
[@deriving show]
type t = {
message: option(string),
increment: option(int),
total: option(int),
};

let decode =
Json.Decode.(
obj(({field, _}) =>
{
message: field.optional("title", string),
increment: field.optional("increment", int),
total: field.optional("total", int),
}
)
);
};

0 comments on commit fb41bf0

Please sign in to comment.