Skip to content

Commit b32ba6a

Browse files
committed
support compiler api v5
1 parent c239a11 commit b32ba6a

File tree

5 files changed

+22
-7
lines changed

5 files changed

+22
-7
lines changed

src/Playground.res

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -896,7 +896,7 @@ module Settings = {
896896

897897
let open_modules = switch readyState.selected.apiVersion {
898898
| V1 | V2 | V3 | UnknownVersion(_) => None
899-
| V4 =>
899+
| V4 | V5 =>
900900
readyState.selected.libraries->Array.some(el => el === "@rescript/core")
901901
? Some(["RescriptCore"])
902902
: None

src/bindings/RescriptCompilerApi.res

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ module Version = {
3737
| V2
3838
| V3
3939
| V4
40+
| V5
4041
| UnknownVersion(string)
4142

4243
// Helps finding the right API version
@@ -59,6 +60,7 @@ module Version = {
5960
| list{"2"} => V2
6061
| list{"3"} => V3
6162
| list{"4"} => V4
63+
| list{"5"} => V5
6264
| _ => UnknownVersion(apiVersion)
6365
}
6466

@@ -68,6 +70,7 @@ module Version = {
6870
| V2 => "2.0"
6971
| V3 => "3.0"
7072
| V4 => "4.0"
73+
| V5 => "5.0"
7174
| UnknownVersion(version) => version
7275
}
7376

@@ -76,7 +79,7 @@ module Version = {
7679
let availableLanguages = t =>
7780
switch t {
7881
| V1 => [Lang.Reason, Res]
79-
| V2 | V3 | V4 => [Lang.Res]
82+
| V2 | V3 | V4 | V5 => [Lang.Res]
8083
| UnknownVersion(_) => [Res]
8184
}
8285
}
@@ -405,7 +408,13 @@ module Compiler = {
405408
ConversionResult.decode(~fromLang=Reason, ~toLang=Reason, json)
406409
}
407410

408-
@get @scope("ocaml") external ocamlVersion: t => string = "version"
411+
@get external ocaml: t => option<{..}> = "ocaml"
412+
let ocamlVersion = (t: t): option<string> => {
413+
switch ocaml(t) {
414+
| Some(ocaml) => ocaml->Obj.magic->Dict.get("version")
415+
| None => None
416+
}
417+
}
409418

410419
@send @scope("ocaml")
411420
external ocamlCompile: (t, string) => JSON.t = "compile"

src/bindings/RescriptCompilerApi.resi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ module Version: {
2525
| V2
2626
| V3
2727
| V4
28+
| V5
2829
| UnknownVersion(string)
2930

3031
// Helps finding the right API version
@@ -188,7 +189,7 @@ module Compiler: {
188189
/*
189190
* OCaml compiler actions (Note: no pretty print available for OCaml)
190191
*/
191-
let ocamlVersion: t => string
192+
let ocamlVersion: t => option<string>
192193
let ocamlCompile: (t, string) => CompilationResult.t
193194

194195
/*

src/common/CompilerManagerHook.res

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ let getLibrariesForVersion = (~version: Semver.t): array<string> => {
147147
let getOpenModules = (~apiVersion: Version.t, ~libraries: array<string>): option<array<string>> =>
148148
switch apiVersion {
149149
| V1 | V2 | V3 | UnknownVersion(_) => None
150-
| V4 => libraries->Array.some(el => el === "@rescript/core") ? Some(["RescriptCore"]) : None
150+
| V4 | V5 => libraries->Array.some(el => el === "@rescript/core") ? Some(["RescriptCore"]) : None
151151
}
152152

153153
/*
@@ -207,7 +207,7 @@ type selected = {
207207
id: Semver.t, // The id used for loading the compiler bundle (ideally should be the same as compilerVersion)
208208
apiVersion: Version.t, // The playground API version in use
209209
compilerVersion: string,
210-
ocamlVersion: string,
210+
ocamlVersion: option<string>,
211211
libraries: array<string>,
212212
config: Config.t,
213213
instance: Compiler.t,
@@ -510,6 +510,11 @@ let useCompilerManager = (
510510
)
511511
| Lang.Res => instance->Compiler.resCompile(code)
512512
}
513+
| V5 =>
514+
switch lang {
515+
| Lang.Res => instance->Compiler.resCompile(code)
516+
| _ => CompilationResult.UnexpectedError(`Can't handle with lang: ${lang->Lang.toString}`)
517+
}
513518
| UnknownVersion(version) =>
514519
CompilationResult.UnexpectedError(
515520
`Can't handle result of compiler API version "${version}"`,

src/common/CompilerManagerHook.resi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ type selected = {
2828
id: Semver.t, // The id used for loading the compiler bundle (ideally should be the same as compilerVersion)
2929
apiVersion: Version.t, // The playground API version in use
3030
compilerVersion: string,
31-
ocamlVersion: string,
31+
ocamlVersion: option<string>,
3232
libraries: array<string>,
3333
config: Config.t,
3434
instance: Compiler.t,

0 commit comments

Comments
 (0)