Skip to content

Playground: support compiler API v5 #900

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

Merged
merged 2 commits into from
Jul 29, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Playground.res
Original file line number Diff line number Diff line change
Expand Up @@ -896,7 +896,7 @@ module Settings = {

let open_modules = switch readyState.selected.apiVersion {
| V1 | V2 | V3 | UnknownVersion(_) => None
| V4 =>
| V4 | V5 =>
readyState.selected.libraries->Array.some(el => el === "@rescript/core")
? Some(["RescriptCore"])
: None
Expand Down
13 changes: 11 additions & 2 deletions src/bindings/RescriptCompilerApi.res
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ module Version = {
| V2
| V3
| V4
| V5
| UnknownVersion(string)

// Helps finding the right API version
Expand All @@ -59,6 +60,7 @@ module Version = {
| list{"2"} => V2
| list{"3"} => V3
| list{"4"} => V4
| list{"5"} => V5
| _ => UnknownVersion(apiVersion)
}

Expand All @@ -68,6 +70,7 @@ module Version = {
| V2 => "2.0"
| V3 => "3.0"
| V4 => "4.0"
| V5 => "5.0"
| UnknownVersion(version) => version
}

Expand All @@ -76,7 +79,7 @@ module Version = {
let availableLanguages = t =>
switch t {
| V1 => [Lang.Reason, Res]
| V2 | V3 | V4 => [Lang.Res]
| V2 | V3 | V4 | V5 => [Lang.Res]
| UnknownVersion(_) => [Res]
}
}
Expand Down Expand Up @@ -405,7 +408,13 @@ module Compiler = {
ConversionResult.decode(~fromLang=Reason, ~toLang=Reason, json)
}

@get @scope("ocaml") external ocamlVersion: t => string = "version"
@get external ocaml: t => option<{..}> = "ocaml"
let ocamlVersion = (t: t): option<string> => {
switch ocaml(t) {
| Some(ocaml) => ocaml->Obj.magic->Dict.get("version")
| None => None
}
}

@send @scope("ocaml")
external ocamlCompile: (t, string) => JSON.t = "compile"
Expand Down
3 changes: 2 additions & 1 deletion src/bindings/RescriptCompilerApi.resi
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ module Version: {
| V2
| V3
| V4
| V5
| UnknownVersion(string)

// Helps finding the right API version
Expand Down Expand Up @@ -188,7 +189,7 @@ module Compiler: {
/*
* OCaml compiler actions (Note: no pretty print available for OCaml)
*/
let ocamlVersion: t => string
let ocamlVersion: t => option<string>
let ocamlCompile: (t, string) => CompilationResult.t

/*
Expand Down
9 changes: 7 additions & 2 deletions src/common/CompilerManagerHook.res
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ let getLibrariesForVersion = (~version: Semver.t): array<string> => {
let getOpenModules = (~apiVersion: Version.t, ~libraries: array<string>): option<array<string>> =>
switch apiVersion {
| V1 | V2 | V3 | UnknownVersion(_) => None
| V4 => libraries->Array.some(el => el === "@rescript/core") ? Some(["RescriptCore"]) : None
| V4 | V5 => libraries->Array.some(el => el === "@rescript/core") ? Some(["RescriptCore"]) : None
}

/*
Expand Down Expand Up @@ -207,7 +207,7 @@ type selected = {
id: Semver.t, // The id used for loading the compiler bundle (ideally should be the same as compilerVersion)
apiVersion: Version.t, // The playground API version in use
compilerVersion: string,
ocamlVersion: string,
ocamlVersion: option<string>,
libraries: array<string>,
config: Config.t,
instance: Compiler.t,
Expand Down Expand Up @@ -510,6 +510,11 @@ let useCompilerManager = (
)
| Lang.Res => instance->Compiler.resCompile(code)
}
| V5 =>
switch lang {
| Lang.Res => instance->Compiler.resCompile(code)
| _ => CompilationResult.UnexpectedError(`Can't handle with lang: ${lang->Lang.toString}`)
}
| UnknownVersion(version) =>
CompilationResult.UnexpectedError(
`Can't handle result of compiler API version "${version}"`,
Expand Down
2 changes: 1 addition & 1 deletion src/common/CompilerManagerHook.resi
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type selected = {
id: Semver.t, // The id used for loading the compiler bundle (ideally should be the same as compilerVersion)
apiVersion: Version.t, // The playground API version in use
compilerVersion: string,
ocamlVersion: string,
ocamlVersion: option<string>,
libraries: array<string>,
config: Config.t,
instance: Compiler.t,
Expand Down