Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ocaml-decoders conversion experiment #1280

Merged
merged 9 commits into from
Feb 3, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/Core/Json.re
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ type t = Yojson.Safe.json;
module Decode = {
include Decoders_yojson.Safe.Decode;

let default = default =>
map(Utility.Option.value(~default));
let default = default => map(Utility.Option.value(~default));
};

module Encode = {
Expand Down
26 changes: 13 additions & 13 deletions src/Extensions/ExtHostInitData.re
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,16 @@ module ExtensionInfo = {
("version", data.version |> string),
("engines", data.engines |> string),
("activationEvents", data.activationEvents |> list(string)),
("extensionDependencies", data.extensionDependencies |> list(string)),
("extensionKind", data.extensionKind |> ExtensionManifest.Encode.kind),
(
"extensionDependencies",
data.extensionDependencies |> list(string),
),
(
"extensionKind",
data.extensionKind |> ExtensionManifest.Encode.kind,
),
("contributes", data.contributes |> ExtensionContributions.encode),
])
])
);
};

Expand All @@ -80,11 +86,7 @@ module Workspace = {
type t = {__test: string};

let encode = workspace =>
Json.Encode.(
obj([
("__test", workspace.__test |> string)
])
);
Json.Encode.(obj([("__test", workspace.__test |> string)]));
};

module Environment = {
Expand All @@ -98,9 +100,7 @@ module Environment = {

let encode = env =>
Json.Encode.(
obj([
("globalStorageHomePath", env.globalStorageHomePath |> string)
])
obj([("globalStorageHomePath", env.globalStorageHomePath |> string)])
);
};

Expand Down Expand Up @@ -142,5 +142,5 @@ let encode = data =>
("logsLocationPath", data.logsLocationPath |> string),
("autoStart", data.autoStart |> bool),
("workspace", data.workspace |> Workspace.encode),
])
);
])
);
137 changes: 105 additions & 32 deletions src/Extensions/ExtensionContributions.re
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,16 @@ module Command = {

let decode =
Json.Decode.(
field("command", string) >>= command =>
field("title", LocalizedToken.decode) >>= title =>
field_opt("category", string) >>= category =>
succeed({command, title, category})
field("command", string)
>>= (
command =>
field("title", LocalizedToken.decode)
>>= (
title =>
field_opt("category", string)
>>= (category => succeed({command, title, category}))
)
)
);

let encode = command =>
Expand Down Expand Up @@ -56,8 +62,7 @@ module Configuration = {
|> default(Json.Encode.null)
|> map(default => {name, default});

let properties =
key_value_pairs_seq(property);
let properties = key_value_pairs_seq(property);

let configuration = {
let simple = field("properties", properties);
Expand All @@ -83,11 +88,25 @@ module Language = {

let decode =
Json.Decode.(
field("id", string) >>= id =>
field_opt("extensions", list(string)) |> default([]) >>= extensions =>
field_opt("aliases", list(string)) |> default([]) >>= aliases =>
field_opt("configuration", string) >>= configuration =>
succeed({id, extensions, aliases, configuration})
field("id", string)
>>= (
id =>
field_opt("extensions", list(string))
|> default([])
>>= (
extensions =>
field_opt("aliases", list(string))
|> default([])
>>= (
aliases =>
field_opt("configuration", string)
>>= (
configuration =>
succeed({id, extensions, aliases, configuration})
)
)
)
)
);

let encode = language =>
Expand All @@ -112,11 +131,23 @@ module Grammar = {

let decode =
Json.Decode.(
field_opt("language", string) >>= language =>
field("scopeName", string) >>= scopeName =>
field("path", string) >>= path =>
field_opt("treeSitterPath", string) >>= treeSitterPath =>
succeed({language, scopeName, path, treeSitterPath})
field_opt("language", string)
>>= (
language =>
field("scopeName", string)
>>= (
scopeName =>
field("path", string)
>>= (
path =>
field_opt("treeSitterPath", string)
>>= (
treeSitterPath =>
succeed({language, scopeName, path, treeSitterPath})
)
)
)
)
);

let encode = grammar =>
Expand Down Expand Up @@ -149,10 +180,16 @@ module Theme = {

let decode =
Json.Decode.(
field("label", string) >>= label =>
field("uiTheme", string) >>= uiTheme =>
field("path", string) >>= path =>
succeed({label, uiTheme, path})
field("label", string)
>>= (
label =>
field("uiTheme", string)
>>= (
uiTheme =>
field("path", string)
>>= (path => succeed({label, uiTheme, path}))
)
)
);

let encode = theme =>
Expand All @@ -175,10 +212,15 @@ module IconTheme = {

let decode =
Json.Decode.(
field("id", string) >>= id =>
field("label", string) >>= label =>
field("path", string) >>= path =>
succeed({id, label, path})
field("id", string)
>>= (
id =>
field("label", string)
>>= (
label =>
field("path", string) >>= (path => succeed({id, label, path}))
)
)
);

let encode = theme =>
Expand All @@ -203,13 +245,44 @@ type t = {

let decode =
Json.Decode.(
field_opt("commands", list(Command.decode)) |> default([]) >>= commands =>
field_opt("languages", list(Language.decode)) |> default([]) >>= languages =>
field_opt("grammars", list(Grammar.decode)) |> default([]) >>= grammars =>
field_opt("themes", list(Theme.decode)) |> default([]) >>= themes =>
field_opt("iconThemes", list(IconTheme.decode)) |> default([]) >>= iconThemes =>
field_opt("configuration", Configuration.decode) |> default([]) >>= configuration =>
succeed({commands, languages, grammars, themes, iconThemes, configuration})
field_opt("commands", list(Command.decode))
|> default([])
>>= (
commands =>
field_opt("languages", list(Language.decode))
|> default([])
>>= (
languages =>
field_opt("grammars", list(Grammar.decode))
|> default([])
>>= (
grammars =>
field_opt("themes", list(Theme.decode))
|> default([])
>>= (
themes =>
field_opt("iconThemes", list(IconTheme.decode))
|> default([])
>>= (
iconThemes =>
field_opt("configuration", Configuration.decode)
|> default([])
>>= (
configuration =>
succeed({
commands,
languages,
grammars,
themes,
iconThemes,
configuration,
})
)
)
)
)
)
)
);

let encode = data =>
Expand All @@ -222,7 +295,7 @@ let encode = data =>
("iconThemes", data.iconThemes |> list(IconTheme.encode)),
("configuration", null),
])
)
);

let _remapGrammars = (path: string, grammars: list(Grammar.t)) => {
List.map(g => Grammar.toAbsolutePath(path, g), grammars);
Expand Down