From d7375a2e19364d588150460cfe4c84827ea2adac Mon Sep 17 00:00:00 2001 From: Bryan Phelps Date: Sat, 25 Jul 2020 11:47:17 -0700 Subject: [PATCH 1/3] Stub out types for additional terminal APIs --- src/Exthost/Exthost.rei | 31 +++++++++++++++++++++++++++++++ src/Exthost/Msg.re | 17 +++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/src/Exthost/Exthost.rei b/src/Exthost/Exthost.rei index f20001522b..dff4bdfdd6 100644 --- a/src/Exthost/Exthost.rei +++ b/src/Exthost/Exthost.rei @@ -593,6 +593,26 @@ module SymbolKind: { let decode: Json.decoder(t); }; +module Terminal: { + module LaunchConfig: { + [@deriving show] + type t = { + name: option(string), + shellPath: option(string), + shellArgs: list(string), + cwd: option(Oni_Core.Uri.t), + // TODO: Env + //env: + waitOnExit: bool, + strictEnv: bool, + hideFromUser: bool, + isExtensionTerminal: bool, + }; + + let decode: Json.decoder(t); + }; +}; + module DocumentSymbol: { [@deriving show] type t = { @@ -1367,6 +1387,17 @@ module Msg: { module TerminalService: { [@deriving show] type msg = + | CreateTerminal({ + config: Terminal.LaunchConfig.t, + }) + | Dispose({ terminalId: int }) + | Hide({ terminalId: int }) + | SendText({ terminalId: int, text: string, addNewLine: bool}) + | Show({terminalId: int, preserveFocus: bool}) + | StartSendingDataEvents + | StopSendingDataEvents + | StartHandlingLinks + | StopHandlingLinks | SendProcessTitle({ terminalId: int, title: string, diff --git a/src/Exthost/Msg.re b/src/Exthost/Msg.re index fd74e0c968..ec54928bcd 100644 --- a/src/Exthost/Msg.re +++ b/src/Exthost/Msg.re @@ -1467,6 +1467,23 @@ module SCM = { module TerminalService = { [@deriving show] type msg = + | CreateTerminal({ + config: Terminal.LaunchConfig.t, + }) + | Dispose({ terminalId: int }) + | Hide({ terminalId: int }) + | SendText({ terminalId: int, text: string, addNewLine: bool}) + | Show({terminalId: int, preserveFocus: bool}) + | StartSendingDataEvents + | StopSendingDataEvents + | StartHandlingLinks + | StopHandlingLinks +// TODO: +// | SetEnvironmentVariableCollection({ +// extensionId: string, +// persistent: bool, +// }) + | SendProcessTitle({ terminalId: int, title: string, From 9993d7d445819525daac78bb4336e96fd776dff0 Mon Sep 17 00:00:00 2001 From: Bryan Phelps Date: Sat, 25 Jul 2020 12:12:49 -0700 Subject: [PATCH 2/3] Stub out create terminal API --- src/Exthost/Exthost.re | 1 + src/Exthost/Exthost.rei | 39 ++++++++++++++++++-------------- src/Exthost/Handlers.re | 2 ++ src/Exthost/Msg.re | 30 ++++++++++++++----------- src/Exthost/Terminal.re | 49 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 91 insertions(+), 30 deletions(-) create mode 100644 src/Exthost/Terminal.re diff --git a/src/Exthost/Exthost.re b/src/Exthost/Exthost.re index 97fb5ffdc8..916cdf396c 100644 --- a/src/Exthost/Exthost.re +++ b/src/Exthost/Exthost.re @@ -44,6 +44,7 @@ module SignatureHelp = SignatureHelp; module SuggestItem = SuggestItem; module SuggestResult = SuggestResult; module SymbolKind = SymbolKind; +module Terminal = Terminal; module TextEditor = TextEditor; module ThemeColor = ThemeColor; module WorkspaceData = WorkspaceData; diff --git a/src/Exthost/Exthost.rei b/src/Exthost/Exthost.rei index dff4bdfdd6..9ec2dfb15c 100644 --- a/src/Exthost/Exthost.rei +++ b/src/Exthost/Exthost.rei @@ -597,16 +597,16 @@ module Terminal: { module LaunchConfig: { [@deriving show] type t = { - name: option(string), - shellPath: option(string), - shellArgs: list(string), - cwd: option(Oni_Core.Uri.t), - // TODO: Env - //env: - waitOnExit: bool, - strictEnv: bool, - hideFromUser: bool, - isExtensionTerminal: bool, + name: option(string), + shellPath: option(string), + shellArgs: list(string), + cwd: option(Oni_Core.Uri.t), + // TODO: Env + //env: + waitOnExit: bool, + strictEnv: bool, + hideFromUser: bool, + isExtensionTerminal: bool, }; let decode: Json.decoder(t); @@ -1387,13 +1387,18 @@ module Msg: { module TerminalService: { [@deriving show] type msg = - | CreateTerminal({ - config: Terminal.LaunchConfig.t, - }) - | Dispose({ terminalId: int }) - | Hide({ terminalId: int }) - | SendText({ terminalId: int, text: string, addNewLine: bool}) - | Show({terminalId: int, preserveFocus: bool}) + | CreateTerminal({config: Terminal.LaunchConfig.t}) + | Dispose({terminalId: int}) + | Hide({terminalId: int}) + | SendText({ + terminalId: int, + text: string, + addNewLine: bool, + }) + | Show({ + terminalId: int, + preserveFocus: bool, + }) | StartSendingDataEvents | StopSendingDataEvents | StartHandlingLinks diff --git a/src/Exthost/Handlers.re b/src/Exthost/Handlers.re index c8b54646da..12f18d98e5 100644 --- a/src/Exthost/Handlers.re +++ b/src/Exthost/Handlers.re @@ -250,6 +250,8 @@ module Internal = { let stringToId = Hashtbl.find_opt(Internal.stringToId); let handle = (rpcId, method, args) => { + prerr_endline("method: " ++ method); + prerr_endline("args: " ++ Yojson.Safe.to_string(args)); rpcId |> Hashtbl.find_opt(Internal.idToHandler) |> Option.to_result( diff --git a/src/Exthost/Msg.re b/src/Exthost/Msg.re index ec54928bcd..5b4dfc521e 100644 --- a/src/Exthost/Msg.re +++ b/src/Exthost/Msg.re @@ -1467,23 +1467,27 @@ module SCM = { module TerminalService = { [@deriving show] type msg = - | CreateTerminal({ - config: Terminal.LaunchConfig.t, - }) - | Dispose({ terminalId: int }) - | Hide({ terminalId: int }) - | SendText({ terminalId: int, text: string, addNewLine: bool}) - | Show({terminalId: int, preserveFocus: bool}) + | CreateTerminal({config: Terminal.LaunchConfig.t}) + | Dispose({terminalId: int}) + | Hide({terminalId: int}) + | SendText({ + terminalId: int, + text: string, + addNewLine: bool, + }) + | Show({ + terminalId: int, + preserveFocus: bool, + }) | StartSendingDataEvents | StopSendingDataEvents | StartHandlingLinks | StopHandlingLinks -// TODO: -// | SetEnvironmentVariableCollection({ -// extensionId: string, -// persistent: bool, -// }) - + // TODO: + // | SetEnvironmentVariableCollection({ + // extensionId: string, + // persistent: bool, + // }) | SendProcessTitle({ terminalId: int, title: string, diff --git a/src/Exthost/Terminal.re b/src/Exthost/Terminal.re new file mode 100644 index 0000000000..1bf8adc9a3 --- /dev/null +++ b/src/Exthost/Terminal.re @@ -0,0 +1,49 @@ +open Oni_Core; +module LaunchConfig = { + [@deriving show] + type t = { + name: option(string), + shellPath: option(string), + shellArgs: list(string), + cwd: option(Oni_Core.Uri.t), + // TODO: Env + //env: + waitOnExit: bool, + strictEnv: bool, + hideFromUser: bool, + isExtensionTerminal: bool, + }; + + module Decode = { + open Json.Decode; + + let shellArgs = + one_of([ + ("single string", string |> map(str => [str])), + ("string list", list(string)), + ]); + + let uri = + one_of([ + ("string", string |> map(Uri.fromPath)), + ("uri", Uri.decode), + ]); + }; + + let decode = + Json.Decode.( + obj(({field, _}) => + { + name: field.optional("name", string), + shellPath: field.optional("shellPath", string), + shellArgs: field.withDefault("shellArgs", [], Decode.shellArgs), + cwd: field.optional("cwd", Decode.uri), + waitOnExit: field.withDefault("waitOnExit", false, bool), + strictEnv: field.withDefault("strictEnv", false, bool), + hideFromUser: field.withDefault("hideFromUser", false, bool), + isExtensionTerminal: + field.withDefault("isExtensionTerminal", false, bool), + } + ) + ); +}; From 66630d2d8b8742d71f1b6429ecd33783614fef27 Mon Sep 17 00:00:00 2001 From: Bryan Phelps Date: Sat, 25 Jul 2020 14:39:59 -0700 Subject: [PATCH 3/3] Formatting --- src/Exthost/Msg.re | 114 +++++++++++++++++++++++++++++++-------------- 1 file changed, 80 insertions(+), 34 deletions(-) diff --git a/src/Exthost/Msg.re b/src/Exthost/Msg.re index adfc683f14..c984929a77 100644 --- a/src/Exthost/Msg.re +++ b/src/Exthost/Msg.re @@ -1492,46 +1492,92 @@ module TerminalService = { }); let handle = (method, args: Yojson.Safe.t) => { - switch (method) { - | "$sendProcessTitle" => - switch (args) { - | `List([`Int(terminalId), `String(title)]) => - Ok(SendProcessTitle({terminalId, title})) - | _ => Error("Unexpected arguments for $sendProcessTitle") - } + Base.Result.Let_syntax.( + switch (method) { + | "$createTerminal" => + switch (args) { + | `List([configJson]) => + let%bind config = + configJson |> Internal.decode_value(Terminal.LaunchConfig.decode); + Ok(CreateTerminal({config: config})); + | _ => Error("Unexpected arguments for $createTerminal") + } - | "$sendProcessData" => - switch (args) { - | `List([`Int(terminalId), `String(data)]) => - Ok(SendProcessData({terminalId, data})) - | _ => Error("Unexpected arguments for $sendProcessData") - } + | "$dispose" => + switch (args) { + | `List([terminalIdJson]) => + let%bind terminalId = + terminalIdJson |> Internal.decode_value(Decode.int); + Ok(Dispose({terminalId: terminalId})); + | _ => Error("Unexpected arguments for $dispose") + } - | "$sendProcessReady" => - switch (args) { - | `List([`Int(terminalId), `Int(pid), `String(workingDirectory)]) => - Ok(SendProcessReady({terminalId, pid, workingDirectory})) + | "$hide" => + switch (args) { + | `List([terminalIdJson]) => + let%bind terminalId = + terminalIdJson |> Internal.decode_value(Decode.int); + Ok(Hide({terminalId: terminalId})); + | _ => Error("Unexpected arguments for $dispose") + } - | _ => Error("Unexpected arguments for $sendProcessReady") - } + | "$show" => + switch (args) { + | `List([terminalIdJson, `Bool(preserveFocus)]) => + let%bind terminalId = + terminalIdJson |> Internal.decode_value(Decode.int); + Ok(Show({terminalId, preserveFocus})); + | _ => Error("Unexpected arguments for $dispose") + } - | "$sendProcessExit" => - switch (args) { - | `List([`Int(terminalId), `Int(exitCode)]) => - Ok(SendProcessExit({terminalId, exitCode})) + | "$startSendingDataEvents" => Ok(StartSendingDataEvents) - | _ => Error("Unexpected arguments for $sendProcessExit") - } + | "$stopSendingDataEvents" => Ok(StopSendingDataEvents) - | _ => - Error( - Printf.sprintf( - "Unhandled Terminal message - %s: %s", - method, - Yojson.Safe.to_string(args), - ), - ) - }; + | "$startHandlingLinks" => Ok(StartHandlingLinks) + + | "$stopHandlingLinks" => Ok(StopHandlingLinks) + + | "$sendProcessTitle" => + switch (args) { + | `List([`Int(terminalId), `String(title)]) => + Ok(SendProcessTitle({terminalId, title})) + | _ => Error("Unexpected arguments for $sendProcessTitle") + } + + | "$sendProcessData" => + switch (args) { + | `List([`Int(terminalId), `String(data)]) => + Ok(SendProcessData({terminalId, data})) + | _ => Error("Unexpected arguments for $sendProcessData") + } + + | "$sendProcessReady" => + switch (args) { + | `List([`Int(terminalId), `Int(pid), `String(workingDirectory)]) => + Ok(SendProcessReady({terminalId, pid, workingDirectory})) + + | _ => Error("Unexpected arguments for $sendProcessReady") + } + + | "$sendProcessExit" => + switch (args) { + | `List([`Int(terminalId), `Int(exitCode)]) => + Ok(SendProcessExit({terminalId, exitCode})) + + | _ => Error("Unexpected arguments for $sendProcessExit") + } + + | _ => + Error( + Printf.sprintf( + "Unhandled Terminal message - %s: %s", + method, + Yojson.Safe.to_string(args), + ), + ) + } + ); }; };