Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions src/Exthost/Exthost.re
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
36 changes: 36 additions & 0 deletions src/Exthost/Exthost.rei
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,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 = {
Expand Down Expand Up @@ -1371,6 +1391,22 @@ 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,
Expand Down
2 changes: 2 additions & 0 deletions src/Exthost/Handlers.re
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
135 changes: 101 additions & 34 deletions src/Exthost/Msg.re
Original file line number Diff line number Diff line change
Expand Up @@ -1452,6 +1452,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,
})
| StartSendingDataEvents
| StopSendingDataEvents
| StartHandlingLinks
| StopHandlingLinks
// TODO:
// | SetEnvironmentVariableCollection({
// extensionId: string,
// persistent: bool,
// })
| SendProcessTitle({
terminalId: int,
title: string,
Expand All @@ -1471,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),
),
)
}
);
};
};

Expand Down
49 changes: 49 additions & 0 deletions src/Exthost/Terminal.re
Original file line number Diff line number Diff line change
@@ -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),
}
)
);
};