Skip to content

Commit 103c8ec

Browse files
authored
update ui comm (for sys path on python side) (#1022)
* add ui comm changes for sys path on python side * handle calls
1 parent 8c819ef commit 103c8ec

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

crates/amalthea/src/comm/ui_comm.rs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// @generated
22

33
/*---------------------------------------------------------------------------------------------
4-
* Copyright (C) 2024-2025 Posit Software, PBC. All rights reserved.
4+
* Copyright (C) 2024-2026 Posit Software, PBC. All rights reserved.
55
*--------------------------------------------------------------------------------------------*/
66

77
//
@@ -166,6 +166,17 @@ pub struct CallMethodParams {
166166
pub params: Vec<Param>,
167167
}
168168

169+
/// Parameters for the EditorContextChanged method.
170+
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
171+
pub struct EditorContextChangedParams {
172+
/// The URI of the active document, or empty string if no editor is active
173+
pub document_uri: String,
174+
175+
/// Whether this editor is the source of code being executed. When true,
176+
/// the backend may temporarily add the file's directory to sys.path.
177+
pub is_execution_source: bool,
178+
}
179+
169180
/// Parameters for the Busy method.
170181
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
171182
pub struct BusyParams {
@@ -188,6 +199,10 @@ pub struct OpenEditorParams {
188199
/// How to interpret the 'file' argument: as a file path or as a URI. If
189200
/// omitted, defaults to 'path'.
190201
pub kind: OpenEditorKind,
202+
203+
/// Whether to open the editor pinned (non-preview mode). If omitted,
204+
/// defaults to true.
205+
pub pinned: Option<bool>,
191206
}
192207

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

417+
/// Active editor context changed
418+
///
419+
/// This notification is sent from the frontend to the backend when the
420+
/// active text editor changes or when code is about to be executed from a
421+
/// file. It provides the document URI and indicates whether this is the
422+
/// source file for code execution.
423+
#[serde(rename = "editor_context_changed")]
424+
EditorContextChanged(EditorContextChangedParams),
425+
402426
}
403427

404428
/**
@@ -413,6 +437,9 @@ pub enum UiBackendReply {
413437
/// The method result
414438
CallMethodReply(CallMethodResult),
415439

440+
/// Unused response to notification
441+
EditorContextChangedReply(),
442+
416443
}
417444

418445
/**

crates/ark/src/ui/events.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ pub unsafe extern "C-unwind" fn ps_ui_navigate_to_file(
7676
line: RObject::view(line).try_into()?,
7777
column: RObject::view(column).try_into()?,
7878
kind,
79+
pinned: None,
7980
};
8081

8182
let event = UiFrontendEvent::OpenEditor(params);

crates/ark/src/ui/ui.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use amalthea::comm::comm_channel::CommMsg;
99
use amalthea::comm::ui_comm::CallMethodParams;
1010
use amalthea::comm::ui_comm::DidChangePlotsRenderSettingsParams;
11+
use amalthea::comm::ui_comm::EditorContextChangedParams;
1112
use amalthea::comm::ui_comm::UiBackendReply;
1213
use amalthea::comm::ui_comm::UiBackendRequest;
1314
use amalthea::comm::ui_comm::UiFrontendEvent;
@@ -150,6 +151,9 @@ impl UiComm {
150151
UiBackendRequest::DidChangePlotsRenderSettings(params) => {
151152
self.handle_did_change_plot_render_settings(params)
152153
},
154+
UiBackendRequest::EditorContextChanged(params) => {
155+
self.handle_editor_context_changed(params)
156+
},
153157
}
154158
}
155159

@@ -217,6 +221,18 @@ impl UiComm {
217221
Ok(UiBackendReply::DidChangePlotsRenderSettingsReply())
218222
}
219223

224+
fn handle_editor_context_changed(
225+
&self,
226+
params: EditorContextChangedParams,
227+
) -> anyhow::Result<UiBackendReply, anyhow::Error> {
228+
log::trace!(
229+
"Editor context changed: document_uri={}, is_execution_source={}",
230+
params.document_uri,
231+
params.is_execution_source
232+
);
233+
Ok(UiBackendReply::EditorContextChangedReply())
234+
}
235+
220236
/**
221237
* Send an RPC request to the frontend.
222238
*/

0 commit comments

Comments
 (0)