Skip to content
Merged
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
29 changes: 28 additions & 1 deletion crates/amalthea/src/comm/ui_comm.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @generated

/*---------------------------------------------------------------------------------------------
* Copyright (C) 2024-2025 Posit Software, PBC. All rights reserved.
* Copyright (C) 2024-2026 Posit Software, PBC. All rights reserved.
*--------------------------------------------------------------------------------------------*/

//
Expand Down Expand Up @@ -166,6 +166,17 @@ pub struct CallMethodParams {
pub params: Vec<Param>,
}

/// Parameters for the EditorContextChanged method.
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
pub struct EditorContextChangedParams {
/// The URI of the active document, or empty string if no editor is active
pub document_uri: String,

/// Whether this editor is the source of code being executed. When true,
/// the backend may temporarily add the file's directory to sys.path.
pub is_execution_source: bool,
}

/// Parameters for the Busy method.
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
pub struct BusyParams {
Expand All @@ -188,6 +199,10 @@ pub struct OpenEditorParams {
/// How to interpret the 'file' argument: as a file path or as a URI. If
/// omitted, defaults to 'path'.
pub kind: OpenEditorKind,

/// Whether to open the editor pinned (non-preview mode). If omitted,
/// defaults to true.
pub pinned: Option<bool>,
}

/// Parameters for the NewDocument method.
Expand Down Expand Up @@ -399,6 +414,15 @@ pub enum UiBackendRequest {
#[serde(rename = "call_method")]
CallMethod(CallMethodParams),

/// Active editor context changed
///
/// This notification is sent from the frontend to the backend when the
/// active text editor changes or when code is about to be executed from a
/// file. It provides the document URI and indicates whether this is the
/// source file for code execution.
#[serde(rename = "editor_context_changed")]
EditorContextChanged(EditorContextChangedParams),

}

/**
Expand All @@ -413,6 +437,9 @@ pub enum UiBackendReply {
/// The method result
CallMethodReply(CallMethodResult),

/// Unused response to notification
EditorContextChangedReply(),

}

/**
Expand Down
1 change: 1 addition & 0 deletions crates/ark/src/ui/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ pub unsafe extern "C-unwind" fn ps_ui_navigate_to_file(
line: RObject::view(line).try_into()?,
column: RObject::view(column).try_into()?,
kind,
pinned: None,
};

let event = UiFrontendEvent::OpenEditor(params);
Expand Down
16 changes: 16 additions & 0 deletions crates/ark/src/ui/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use amalthea::comm::comm_channel::CommMsg;
use amalthea::comm::ui_comm::CallMethodParams;
use amalthea::comm::ui_comm::DidChangePlotsRenderSettingsParams;
use amalthea::comm::ui_comm::EditorContextChangedParams;
use amalthea::comm::ui_comm::UiBackendReply;
use amalthea::comm::ui_comm::UiBackendRequest;
use amalthea::comm::ui_comm::UiFrontendEvent;
Expand Down Expand Up @@ -150,6 +151,9 @@ impl UiComm {
UiBackendRequest::DidChangePlotsRenderSettings(params) => {
self.handle_did_change_plot_render_settings(params)
},
UiBackendRequest::EditorContextChanged(params) => {
self.handle_editor_context_changed(params)
},
}
}

Expand Down Expand Up @@ -217,6 +221,18 @@ impl UiComm {
Ok(UiBackendReply::DidChangePlotsRenderSettingsReply())
}

fn handle_editor_context_changed(
&self,
params: EditorContextChangedParams,
) -> anyhow::Result<UiBackendReply, anyhow::Error> {
log::trace!(
"Editor context changed: document_uri={}, is_execution_source={}",
params.document_uri,
params.is_execution_source
);
Ok(UiBackendReply::EditorContextChangedReply())
}

/**
* Send an RPC request to the frontend.
*/
Expand Down