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
282 changes: 145 additions & 137 deletions package-lock.json

Large diffs are not rendered by default.

39 changes: 37 additions & 2 deletions src-tauri/src/bin/codex_monitor_daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,9 @@ use shared::{
use storage::{read_settings, read_workspaces};
use types::{
AppSettings, GitCommitDiff, GitFileDiff, GitHubIssuesResponse, GitHubPullRequestComment,
GitHubPullRequestDiff, GitHubPullRequestsResponse, GitLogResponse, LocalUsageSnapshot,
WorkspaceEntry, WorkspaceInfo, WorkspaceSettings, WorktreeSetupStatus,
GitHubPullRequestDiff, GitHubPullRequestsResponse, GitLogResponse, GitSelectionApplyResult,
GitSelectionLine, LocalUsageSnapshot, WorkspaceEntry, WorkspaceInfo, WorkspaceSettings,
WorktreeSetupStatus,
};
use workspace_settings::apply_workspace_settings_update;

Expand Down Expand Up @@ -1087,6 +1088,40 @@ impl DaemonState {
git_ui_core::stage_git_all_core(&self.workspaces, workspace_id).await
}

async fn stage_git_selection(
&self,
workspace_id: String,
path: String,
op: String,
source: String,
lines: Vec<GitSelectionLine>,
) -> Result<GitSelectionApplyResult, String> {
git_ui_core::stage_git_selection_core(
&self.workspaces,
workspace_id,
path,
op,
source,
lines,
)
.await
}

async fn apply_git_display_hunk(
&self,
workspace_id: String,
path: String,
display_hunk_id: String,
) -> Result<GitSelectionApplyResult, String> {
git_ui_core::apply_git_display_hunk_core(
&self.workspaces,
workspace_id,
path,
display_hunk_id,
)
.await
}

async fn unstage_git_file(&self, workspace_id: String, path: String) -> Result<(), String> {
git_ui_core::unstage_git_file_core(&self.workspaces, workspace_id, path).await
}
Expand Down
45 changes: 45 additions & 0 deletions src-tauri/src/bin/codex_monitor_daemon/rpc/git.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use super::*;
use crate::shared::git_rpc;
use crate::types::GitSelectionLine;
use serde::de::DeserializeOwned;
use serde::Serialize;
use std::future::Future;
Expand Down Expand Up @@ -102,6 +103,50 @@ pub(super) async fn try_handle(
let request = parse_request_or_err!(params, git_rpc::WorkspaceIdRequest);
Some(serialize_ok(state.stage_git_all(request.workspace_id)).await)
}
git_rpc::METHOD_APPLY_GIT_DISPLAY_HUNK => {
let request = parse_request_or_err!(params, git_rpc::GitDisplayHunkActionRequest);
Some(
state
.apply_git_display_hunk(
request.workspace_id,
request.path,
request.display_hunk_id,
)
.await
.and_then(|result| serde_json::to_value(result).map_err(|err| err.to_string())),
)
}
"stage_git_selection" => {
let workspace_id = match parse_string(params, "workspaceId") {
Ok(value) => value,
Err(err) => return Some(Err(err)),
};
let path = match parse_string(params, "path") {
Ok(value) => value,
Err(err) => return Some(Err(err)),
};
let op = match parse_string(params, "op") {
Ok(value) => value,
Err(err) => return Some(Err(err)),
};
let source = match parse_string(params, "source") {
Ok(value) => value,
Err(err) => return Some(Err(err)),
};
let lines = match parse_optional_value(params, "lines")
.map(serde_json::from_value::<Vec<GitSelectionLine>>)
.transpose()
{
Ok(value) => value.unwrap_or_default(),
Err(err) => return Some(Err(format!("invalid `lines`: {err}"))),
};
Some(
state
.stage_git_selection(workspace_id, path, op, source, lines)
.await
.and_then(|result| serde_json::to_value(result).map_err(|err| err.to_string())),
)
}
git_rpc::METHOD_UNSTAGE_GIT_FILE => {
let request = parse_request_or_err!(params, git_rpc::WorkspacePathRequest);
Some(serialize_ok(state.unstage_git_file(request.workspace_id, request.path)).await)
Expand Down
61 changes: 59 additions & 2 deletions src-tauri/src/git/mod.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
use serde::de::DeserializeOwned;
use serde::Serialize;
use serde_json::Value;
use serde_json::{json, Value};
use tauri::{AppHandle, State};

use crate::remote_backend;
use crate::shared::{git_rpc, git_ui_core};
use crate::state::AppState;
use crate::types::{
GitCommitDiff, GitFileDiff, GitHubIssuesResponse, GitHubPullRequestComment,
GitHubPullRequestDiff, GitHubPullRequestsResponse, GitLogResponse,
GitHubPullRequestDiff, GitHubPullRequestsResponse, GitLogResponse, GitSelectionApplyResult,
GitSelectionLine,
};

fn git_remote_params<T: Serialize>(request: &T) -> Result<Value, String> {
Expand Down Expand Up @@ -187,6 +188,62 @@ pub(crate) async fn stage_git_all(
git_ui_core::stage_git_all_core(&state.workspaces, workspace_id).await
}

#[tauri::command]
pub(crate) async fn stage_git_selection(
workspace_id: String,
path: String,
op: String,
source: String,
lines: Vec<GitSelectionLine>,
state: State<'_, AppState>,
app: AppHandle,
) -> Result<GitSelectionApplyResult, String> {
try_remote_typed!(
state,
app,
"stage_git_selection",
json!({
"workspaceId": &workspace_id,
"path": &path,
"op": &op,
"source": &source,
"lines": &lines
}),
GitSelectionApplyResult
);
git_ui_core::stage_git_selection_core(&state.workspaces, workspace_id, path, op, source, lines)
.await
}

#[tauri::command]
pub(crate) async fn apply_git_display_hunk(
workspace_id: String,
path: String,
display_hunk_id: String,
state: State<'_, AppState>,
app: AppHandle,
) -> Result<GitSelectionApplyResult, String> {
let request = git_rpc::GitDisplayHunkActionRequest {
workspace_id: workspace_id.clone(),
path: path.clone(),
display_hunk_id: display_hunk_id.clone(),
};
try_remote_typed!(
state,
app,
git_rpc::METHOD_APPLY_GIT_DISPLAY_HUNK,
git_remote_params(&request)?,
GitSelectionApplyResult
);
git_ui_core::apply_git_display_hunk_core(
&state.workspaces,
workspace_id,
path,
display_hunk_id,
)
.await
}

#[tauri::command]
pub(crate) async fn unstage_git_file(
workspace_id: String,
Expand Down
2 changes: 2 additions & 0 deletions src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,8 @@ pub fn run() {
git::get_git_remote,
git::stage_git_file,
git::stage_git_all,
git::stage_git_selection,
git::apply_git_display_hunk,
git::unstage_git_file,
git::revert_git_file,
git::revert_git_all,
Expand Down
9 changes: 9 additions & 0 deletions src-tauri/src/shared/git_rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub(crate) const METHOD_INIT_GIT_REPO: &str = "init_git_repo";
pub(crate) const METHOD_CREATE_GITHUB_REPO: &str = "create_github_repo";
pub(crate) const METHOD_STAGE_GIT_FILE: &str = "stage_git_file";
pub(crate) const METHOD_STAGE_GIT_ALL: &str = "stage_git_all";
pub(crate) const METHOD_APPLY_GIT_DISPLAY_HUNK: &str = "apply_git_display_hunk";
pub(crate) const METHOD_UNSTAGE_GIT_FILE: &str = "unstage_git_file";
pub(crate) const METHOD_REVERT_GIT_FILE: &str = "revert_git_file";
pub(crate) const METHOD_REVERT_GIT_ALL: &str = "revert_git_all";
Expand Down Expand Up @@ -86,6 +87,14 @@ pub(crate) struct WorkspacePathRequest {
pub(crate) path: String,
}

#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub(crate) struct GitDisplayHunkActionRequest {
pub(crate) workspace_id: String,
pub(crate) path: String,
pub(crate) display_hunk_id: String,
}

#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub(crate) struct ListGitRootsRequest {
Expand Down
23 changes: 22 additions & 1 deletion src-tauri/src/shared/git_ui_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use tokio::sync::Mutex;

use crate::types::{
AppSettings, GitCommitDiff, GitFileDiff, GitHubIssuesResponse, GitHubPullRequestComment,
GitHubPullRequestDiff, GitHubPullRequestsResponse, GitLogResponse, WorkspaceEntry,
GitHubPullRequestDiff, GitHubPullRequestsResponse, GitLogResponse, GitSelectionApplyResult,
GitSelectionLine, WorkspaceEntry,
};

#[path = "git_ui_core/commands.rs"]
Expand Down Expand Up @@ -116,6 +117,26 @@ pub(crate) async fn stage_git_all_core(
commands::stage_git_all_inner(workspaces, workspace_id).await
}

pub(crate) async fn stage_git_selection_core(
workspaces: &Mutex<HashMap<String, WorkspaceEntry>>,
workspace_id: String,
path: String,
op: String,
source: String,
lines: Vec<GitSelectionLine>,
) -> Result<GitSelectionApplyResult, String> {
commands::stage_git_selection_inner(workspaces, workspace_id, path, op, source, lines).await
}

pub(crate) async fn apply_git_display_hunk_core(
workspaces: &Mutex<HashMap<String, WorkspaceEntry>>,
workspace_id: String,
path: String,
display_hunk_id: String,
) -> Result<GitSelectionApplyResult, String> {
commands::apply_git_display_hunk_inner(workspaces, workspace_id, path, display_hunk_id).await
}

pub(crate) async fn unstage_git_file_core(
workspaces: &Mutex<HashMap<String, WorkspaceEntry>>,
workspace_id: String,
Expand Down
Loading