summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKunal Mohan <kunalmohan99@gmail.com>2021-03-20 01:18:09 +0530
committerKunal Mohan <kunalmohan99@gmail.com>2021-04-14 01:41:31 +0530
commit9d433532564bb2819f3d757758ecc51556cd3d8a (patch)
treec2c5a7c1ab2da73a7209f24d5260d0d137de5b21
parente5acce39a9d241be3b11135a703a9202edab103f (diff)
Introduce ServerContext
-rw-r--r--src/common/errors.rs42
-rw-r--r--src/server/mod.rs6
2 files changed, 42 insertions, 6 deletions
diff --git a/src/common/errors.rs b/src/common/errors.rs
index 013012665..b0ca7e7ef 100644
--- a/src/common/errors.rs
+++ b/src/common/errors.rs
@@ -1,7 +1,9 @@
//! Error context system based on a thread-local representation of the call stack, itself based on
//! the instructions that are sent between threads.
-use super::{os_input_output::ServerOsApiInstruction, AppInstruction, OPENCALLS};
+use super::{
+ os_input_output::ServerOsApiInstruction, AppInstruction, ServerInstruction, OPENCALLS,
+};
use crate::pty_bus::PtyInstruction;
use crate::screen::ScreenInstruction;
use serde::{Deserialize, Serialize};
@@ -144,7 +146,7 @@ pub enum ContextType {
Plugin(PluginContext),
/// An app-related call.
App(AppContext),
- IPCServer, // Fix: Create a separate ServerContext when sessions are introduced
+ IPCServer(ServerContext),
StdinHandler,
AsyncTask,
/// An empty, placeholder call. This should be thought of as representing no call at all.
@@ -163,7 +165,7 @@ impl Display for ContextType {
ContextType::Os(c) => write!(f, "{}os_thread: {}{:?}", purple, green, c),
ContextType::Plugin(c) => write!(f, "{}plugin_thread: {}{:?}", purple, green, c),
ContextType::App(c) => write!(f, "{}main_thread: {}{:?}", purple, green, c),
- ContextType::IpcServer => write!(f, "{}ipc_server: {}AcceptInput", purple, green),
+ ContextType::IPCServer(c) => write!(f, "{}ipc_server: {}{:?}", purple, green, c),
ContextType::StdinHandler => {
write!(f, "{}stdin_handler_thread: {}AcceptInput", purple, green)
}
@@ -361,3 +363,37 @@ impl From<&AppInstruction> for AppContext {
}
}
}
+
+/// Stack call representations corresponding to the different types of [`AppInstruction`]s.
+#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
+pub enum ServerContext {
+ OpenFile,
+ SplitHorizontally,
+ SplitVertically,
+ MoveFocus,
+ NewClient,
+ ToPty,
+ ToScreen,
+ OsApi,
+ DoneClosingPane,
+ ClosePluginPane,
+ Exit,
+}
+
+impl From<&ServerInstruction> for ServerContext {
+ fn from(server_instruction: &ServerInstruction) -> Self {
+ match *server_instruction {
+ ServerInstruction::OpenFile(_) => ServerContext::OpenFile,
+ ServerInstruction::SplitHorizontally => ServerContext::SplitHorizontally,
+ ServerInstruction::SplitVertically => ServerContext::SplitVertically,
+ ServerInstruction::MoveFocus => ServerContext::MoveFocus,
+ ServerInstruction::NewClient(_) => ServerContext::NewClient,
+ ServerInstruction::ToPty(_) => ServerContext::ToPty,
+ ServerInstruction::ToScreen(_) => ServerContext::ToScreen,
+ ServerInstruction::OsApi(_) => ServerContext::OsApi,
+ ServerInstruction::DoneClosingPane => ServerContext::DoneClosingPane,
+ ServerInstruction::ClosePluginPane(_) => ServerContext::ClosePluginPane,
+ ServerInstruction::Exit => ServerContext::Exit,
+ }
+ }
+}
diff --git a/src/server/mod.rs b/src/server/mod.rs
index 9ad2cbcec..b13180619 100644
--- a/src/server/mod.rs
+++ b/src/server/mod.rs
@@ -3,8 +3,8 @@ use crate::common::{
ChannelWithContext, ClientInstruction, IpcSenderWithContext, SenderType, SenderWithContext,
ServerInstruction,
};
-use crate::errors::{ContextType, ErrorContext, OsContext, PtyContext};
-use crate::os_input_output::{get_server_os_input, ServerOsApi, ServerOsApiInstruction};
+use crate::errors::{ContextType, ErrorContext, OsContext, PtyContext, ServerContext};
+use crate::os_input_output::{ServerOsApi, ServerOsApiInstruction};
use crate::panes::PaneId;
use crate::pty_bus::{PtyBus, PtyInstruction};
use crate::screen::ScreenInstruction;
@@ -161,7 +161,7 @@ pub fn start_server(
move || loop {
let (mut err_ctx, instruction): (ErrorContext, ServerInstruction) =
recv_server_instructions.recv().unwrap();
- err_ctx.add_call(ContextType::IPCServer);
+ err_ctx.add_call(ContextType::IPCServer(ServerContext::from(&instruction)));
send_pty_instructions.update(err_ctx);
send_os_instructions.update(err_ctx);
if send_client_instructions.len() == 1 {