fix: remove panics and unblock flows
Rust / build (macos-latest, stable) (push) Canceled after 0s
Rust / build (ubuntu-latest, stable) (push) Canceled after 0s
Rust / build (windows-latest, stable) (push) Canceled after 0s

This commit is contained in:
2026-11-25 03:20:40 +07:00
parent 0fd8ea12fb
commit 3f64b36ff4
52 changed files with 753 additions and 567 deletions
+1 -3
View File
@@ -81,12 +81,10 @@ impl AppRoot {
Self::reset_to_explore(&app, window, cx);
});
let appearance = settings.read(cx).settings().appearance;
Self {
panels,
titlebar,
appearance,
appearance: settings.read(cx).settings().appearance,
_subscriptions: subscriptions,
}
}
+5 -1
View File
@@ -108,7 +108,7 @@ impl ImportDialog {
}
impl Render for ImportDialog {
fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let state = self.state.clone();
let secret_input = self.secret_input.clone();
@@ -122,8 +122,12 @@ impl Render for ImportDialog {
let action_repass = repass_input.clone();
let action_close = self.handle.clone();
let busy = state.read(cx).progress.busy;
Dialog::new("import-dialog")
.handle(self.handle.clone())
.close_on_escape(!busy)
.close_on_backdrop(!busy)
.min_width(px(520.))
.title("Import identity")
.content(move |_window, cx| {
@@ -72,9 +72,12 @@ impl Render for OnboardingDialog {
let state = self.state.clone();
let action_state = state.clone();
let this = cx.entity().downgrade();
let busy = state.read(cx).busy;
Dialog::new("onboarding-dialog")
.handle(self.handle.clone())
.close_on_escape(!busy)
.close_on_backdrop(!busy)
.min_width(px(520.))
.title("Create identity")
.content(move |_window, cx| {
+1 -1
View File
@@ -45,7 +45,7 @@ pub fn empty_section_row(cx: &App) -> AnyElement {
.into_any_element()
}
#[allow(clippy::too_many_arguments)]
#[expect(clippy::too_many_arguments, reason = "one per column")]
pub fn thread(
prefix: &'static str,
ix: usize,
+1 -1
View File
@@ -1,7 +1,7 @@
mod app;
mod explore;
mod identity;
#[allow(dead_code)] // temporarily unlinked while the shell migrates
#[expect(dead_code, reason = "unlinked while the shell migrates")]
mod inbox;
mod issues;
mod pull_requests;
+8 -2
View File
@@ -353,7 +353,10 @@ impl Render for PullRequestsView {
.title("Pull request warning")
.message(warning)
.on_dismiss(move |cx| {
dismiss_warning_store.update(cx, |store, _| store.last_warning = None);
dismiss_warning_store.update(cx, |store, cx| {
store.last_warning = None;
cx.notify();
});
}),
)
})
@@ -364,7 +367,10 @@ impl Render for PullRequestsView {
.title("Pull request error")
.message(error)
.on_dismiss(move |cx| {
dismiss_error_store.update(cx, |store, _| store.last_error = None);
dismiss_error_store.update(cx, |store, cx| {
store.last_error = None;
cx.notify();
});
}),
)
})
+9 -4
View File
@@ -4,7 +4,7 @@ use std::sync::Arc;
use gpui::prelude::FluentBuilder as _;
use gpui::{
AnyElement, App, AppContext as _, Context, Entity, InteractiveElement as _, IntoElement,
ParentElement as _, PathPromptOptions, Render, SharedString, Styled as _, Subscription,
ParentElement as _, PathPromptOptions, Render, SharedString, Styled as _,
UniformListScrollHandle, WeakEntity, Window, div, px,
};
use nostr::prelude::Url;
@@ -56,7 +56,6 @@ pub struct NewPullRequestView {
scroll_handle: UniformListScrollHandle,
pub(super) tasks: Vec<gpui::Task<Result<(), anyhow::Error>>>,
source_open: bool,
_subscriptions: Vec<Subscription>,
}
impl NewPullRequestView {
@@ -159,7 +158,6 @@ impl NewPullRequestView {
scroll_handle: UniformListScrollHandle::new(),
tasks: Vec::new(),
source_open: false,
_subscriptions: Vec::new(),
}
}
@@ -511,7 +509,9 @@ impl NewPullRequestView {
window: &mut Window,
cx: &mut Context<Self>,
) {
self.compare_generation = self.compare_generation.wrapping_add(1);
self.fork = None;
let Some((branches, current)) = info else {
self.error = Some("The chosen folder is not a git repository".into());
self.repo_path = None;
@@ -522,6 +522,7 @@ impl NewPullRequestView {
cx.notify();
return;
};
if branches.is_empty() {
self.error = Some("The repository has no branches yet".into());
self.repo_path = None;
@@ -682,6 +683,8 @@ impl NewPullRequestView {
cx: &mut Context<Self>,
) {
self.loading = false;
self.compare_generation = self.compare_generation.wrapping_add(1);
let (base_branches, compare_branches) = match result {
Ok(branches) => branches,
Err(error) => {
@@ -690,11 +693,13 @@ impl NewPullRequestView {
return;
}
};
if compare_branches.is_empty() {
self.error = Some("The fork has no branches to compare".into());
cx.notify();
return;
}
if base_branches.is_empty() {
self.error = Some("Could not list the target repository's branches.".into());
cx.notify();
@@ -733,7 +738,7 @@ impl NewPullRequestView {
self.loading = true;
self.error = None;
self.compare_generation += 1;
self.compare_generation = self.compare_generation.wrapping_add(1);
let generation = self.compare_generation;
cx.notify();
+9 -11
View File
@@ -728,22 +728,20 @@ impl CommitDiffView {
Err(_) => return Ok(()),
};
let patch = cx
let saved = cx
.background_spawn(async move {
Repo::open(&worktree).and_then(|repo| repo.commit_patch(&id))
let patch = Repo::open(&worktree).and_then(|repo| repo.commit_patch(&id))?;
std::fs::write(&destination, patch)?;
Ok::<(), anyhow::Error>(())
})
.await;
match patch {
Ok(patch) => {
if let Err(error) = std::fs::write(&destination, patch) {
log::warn!("failed to write commit patch: {error}");
}
}
Err(error) => log::warn!("failed to build commit patch: {error}"),
if let Err(error) = saved {
this.update(cx, |this, cx| {
this.error = Some(format!("{error:#}").into());
cx.notify();
})?;
}
this.update(cx, |_, cx| cx.notify())?;
Ok(())
});
@@ -167,13 +167,18 @@ impl Render for CreateRepoDialog {
let desc_input = self.desc_input.clone();
let folder_input = self.folder_input.clone();
let relay_input = self.relay_input.clone();
let state = self.state.clone();
let busy = state.read(cx).busy;
let grasp_state = self.grasp_state.clone();
let action_state = state.clone();
let this = cx.entity().downgrade();
Dialog::new("create-repo-dialog")
.handle(self.handle.clone())
.close_on_escape(!busy)
.close_on_backdrop(!busy)
.min_width(px(520.))
.title("Create Repository")
.content(move |_window, cx| {
@@ -179,9 +179,12 @@ impl Render for InitRepoDialog {
let folder = self.local_path.display().to_string();
let branches = self.branches.clone();
let selected_branch = self.selected_branch.clone();
let busy = state.read(cx).busy;
Dialog::new("init-repo-dialog")
.handle(self.handle.clone())
.close_on_escape(!busy)
.close_on_backdrop(!busy)
.min_width(px(520.))
.title("Initialize repository")
.content(move |_, cx| {
+46 -13
View File
@@ -1,7 +1,7 @@
use gpui::prelude::FluentBuilder as _;
use gpui::{
AnyElement, App, AppContext as _, Context, Entity, IntoElement, ParentElement as _, Render,
Styled as _, Window, div, px,
App, AppContext as _, Context, Entity, IntoElement, ParentElement as _, Render, Styled as _,
Window, div, px,
};
use signed_state::RepoStore;
use ui::button::{Button, ButtonVariant};
@@ -15,32 +15,48 @@ pub struct ResetRemoteDialog {
handle: DialogHandle,
store: Entity<RepoStore>,
deleted: Vec<String>,
/// Servers that could not be listed, so their refs are missing from `deleted`.
unreachable: Vec<String>,
state: Entity<DialogProgress>,
}
impl ResetRemoteDialog {
pub fn new(store: Entity<RepoStore>, deleted: Vec<String>, cx: &mut App) -> Entity<Self> {
pub fn new(
store: Entity<RepoStore>,
deleted: Vec<String>,
unreachable: Vec<String>,
cx: &mut App,
) -> Entity<Self> {
let state = cx.new(|_| DialogProgress::default());
cx.new(|_| Self {
handle: DialogHandle::new(true),
store,
deleted,
unreachable,
state,
})
}
}
impl Render for ResetRemoteDialog {
fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
const WARNING: &str = "Grasp servers are overwritten to match the local mirror. Refs that do not exist locally are deleted from the servers. This cannot be undone.";
const ERROR: &str = "Could not reach some grasp servers, their refs are not listed:";
let deleted = self.deleted.clone();
let unreachable = self.unreachable.clone();
let action_unreachable = unreachable.clone();
let store = self.store.clone();
let cancel_close = self.handle.clone();
let confirm_close = self.handle.clone();
let content_state = self.state.clone();
let action_state = self.state.clone();
let busy = self.state.read(cx).busy;
Dialog::new("reset-remote-dialog")
.handle(self.handle.clone())
.close_on_escape(!busy)
.close_on_backdrop(!busy)
.min_width(px(480.))
.title("Reset remote to local")
.content(move |_, cx| {
@@ -49,14 +65,28 @@ impl Render for ResetRemoteDialog {
v_flex()
.gap_2()
.child(
div().text_base()
div()
.text_base()
.text_color(cx.theme().colors.muted_foreground)
.child(
"Grasp servers are overwritten to match the local mirror. Refs that do not exist locally are deleted from the servers. This cannot be undone.",
),
.child(WARNING),
)
.when(!unreachable.is_empty(), |this| {
this.child(
div()
.text_base()
.text_color(cx.theme().ramps.destructive.base)
.child(ERROR),
)
.children(unreachable.iter().map(|url| {
div()
.text_base()
.font_family(cx.theme().mono_font)
.child(url.clone())
}))
})
.child(if deleted.is_empty() {
div().text_base()
div()
.text_base()
.text_color(cx.theme().colors.muted_foreground)
.child("No server refs will be deleted.")
.into_any_element()
@@ -64,7 +94,8 @@ impl Render for ResetRemoteDialog {
v_flex()
.gap_1()
.children(deleted.iter().map(|name| {
div().text_base()
div()
.text_base()
.font_family(cx.theme().mono_font)
.child(name.clone())
}))
@@ -80,22 +111,24 @@ impl Render for ResetRemoteDialog {
let confirm_close = confirm_close.clone();
let confirm_state = action_state.clone();
let cancel: AnyElement = Button::new("cancel-reset-remote")
let cancel = Button::new("cancel-reset-remote")
.label("Cancel")
.variant(ButtonVariant::Secondary)
.disabled(busy)
.on_click(move |_, _, cx| cancel_close.close(cx))
.into_any_element();
let confirm: AnyElement = Button::new("confirm-reset-remote")
let confirm = Button::new("confirm-reset-remote")
.label("Reset remote")
.variant(ButtonVariant::Destructive)
.loading(busy)
.disabled(busy)
.disabled(busy || !action_unreachable.is_empty())
.on_click(move |_, window, cx| {
let task = store.update(cx, |store, cx| store.reset_repository(cx));
let state = confirm_state.clone();
let close = confirm_close.clone();
let handle = window.window_handle();
cx.spawn(async move |cx| match task.await {
Ok(()) => {
cx.update_window(handle, |_, _, cx| close.close(cx))
+22 -6
View File
@@ -71,6 +71,8 @@ pub struct RepoFilesView {
pending_commits: Vec<String>,
loading_commits: bool,
tasks: Vec<Task<Result<(), Error>>>,
/// Bumped when the previews are cleared, so loads started before it are dropped.
generation: u64,
}
impl EventEmitter<RepoFilesEvent> for RepoFilesView {}
@@ -96,6 +98,7 @@ impl RepoFilesView {
pending_commits: Vec::new(),
loading_commits: false,
tasks: Vec::new(),
generation: 0,
}
}
@@ -173,6 +176,7 @@ impl RepoFilesView {
self.md = None;
self.code = None;
self.readme_name = None;
self.generation = self.generation.wrapping_add(1);
}
/// Refresh after the mirror caught up with the remote.
@@ -523,8 +527,7 @@ impl RepoFilesView {
return;
};
// Tree paths originate from git, so symlink escapes are accepted; only
// crafted components are rejected, and visibly.
// Tree paths originate from git, so symlink escapes are accepted.
if unsafe_path {
self.files.insert(
path.to_string(),
@@ -539,6 +542,8 @@ impl RepoFilesView {
self.load_commit(&path, cx);
let generation = self.generation;
let task: Task<Result<(), Error>> = cx.spawn_in(window, async move |this, cx| {
let path_for_read = path.clone();
let content = cx
@@ -567,6 +572,9 @@ impl RepoFilesView {
.await;
this.update_in(cx, |this, _window, cx| {
if generation != this.generation {
return;
}
this.loading_files.remove(&path);
match content {
@@ -677,7 +685,9 @@ impl RepoFilesView {
};
self.loading_commits = true;
let paths = std::mem::take(&mut self.pending_commits);
let generation = self.generation;
let task: Task<Result<(), Error>> = cx.spawn(async move |this, cx| {
let rels: Vec<PathBuf> = paths.iter().map(PathBuf::from).collect();
@@ -688,13 +698,19 @@ impl RepoFilesView {
.await;
this.update(cx, |this, cx| {
if generation != this.generation {
return;
}
this.loading_commits = false;
if let Ok(found) = result {
for (path, commit) in found {
this.commits
.insert(path.to_string_lossy().into_owned(), commit);
match result {
Ok(found) => {
for (path, commit) in found {
this.commits
.insert(path.to_string_lossy().into_owned(), commit);
}
}
Err(error) => log::warn!("failed to load the last commits: {error}"),
}
if !this.pending_commits.is_empty() {
+1 -1
View File
@@ -443,7 +443,7 @@ pub(super) fn sync_selector(
if let Some(value) = selected
&& (items_changed || selection_changed)
{
state.set_selected(Some(value), window, cx);
state.set_selected_silent(Some(value), window, cx);
}
});
*cached = items;
+4 -9
View File
@@ -37,7 +37,8 @@ pub struct RepoHistoryView {
/// The last load failure, shown instead of the empty list.
error: Option<SharedString>,
scroll_handle: UniformListScrollHandle,
tasks: Vec<Task<Result<(), Error>>>,
/// The latest walk, assigning it cancels the previous one.
load_task: Option<Task<Result<(), Error>>>,
}
impl RepoHistoryView {
@@ -58,7 +59,7 @@ impl RepoHistoryView {
commits: Arc::new(Vec::new()),
error: None,
scroll_handle: UniformListScrollHandle::new(),
tasks: Vec::new(),
load_task: None,
}
}
@@ -82,12 +83,6 @@ impl RepoHistoryView {
self.load(cx);
}
/// Reaps finished tasks, then queues another.
fn push_task(&mut self, task: Task<Result<(), Error>>) {
self.tasks.retain(|task| !task.is_ready());
self.tasks.push(task);
}
fn load(&mut self, cx: &mut Context<Self>) {
if self.loading_all_commits || self.all_commits.is_some() {
return;
@@ -122,7 +117,7 @@ impl RepoHistoryView {
Ok(())
});
self.push_task(task);
self.load_task = Some(task);
}
pub fn open_commit_diff(
+54 -28
View File
@@ -264,6 +264,14 @@ impl RepoDetailView {
this.track_sync_status(cx);
if !this.repo_started && store.read(cx).announcement.is_some() {
this.load_repo(window, cx);
} else if this.loading
&& store.read(cx).loaded
&& store.read(cx).announcement.is_none()
&& store.read(cx).path.is_none()
{
// The store finished loading with nothing to clone from.
this.loading = false;
this.error = Some("Repository announcement not found".into());
}
cx.notify();
}));
@@ -623,21 +631,24 @@ impl RepoDetailView {
let Some(worktree) = self.worktree.clone() else {
return;
};
let name = name.into();
let previous_branch = self.refs.branch_select.read(cx).selected().cloned();
let previous_tag = self.refs.tag_select.read(cx).selected().cloned();
// Restored if the checkout fails while HEAD stays detached.
let previous_tag = match kind {
RefKind::Branch => self.refs.tag_select.read(cx).selected().cloned(),
RefKind::Tag => None,
};
match kind {
RefKind::Branch => {
self.refs
.tag_select
.update(cx, |state, cx| state.set_selected(None, window, cx));
.update(cx, |state, cx| state.set_selected_silent(None, window, cx));
}
RefKind::Tag => {
self.refs
.branch_select
.update(cx, |state, cx| state.set_selected(None, window, cx));
.update(cx, |state, cx| state.set_selected_silent(None, window, cx));
}
}
@@ -646,36 +657,42 @@ impl RepoDetailView {
let checkout_name = name.clone();
let task: Task<Result<(), Error>> = cx.spawn_in(window, async move |this, cx| {
let result = cx
let outcome = cx
.background_spawn(async move {
let repo = Repo::open(&worktree);
match kind {
// A failed checkout leaves HEAD alone; report the branch it is still on.
let current = repo.as_ref().ok().and_then(|repo| repo.current_branch());
let checkout = match kind {
RefKind::Branch => {
repo.and_then(|repo| repo.checkout_branch(&checkout_name))
}
RefKind::Tag => repo.and_then(|repo| repo.checkout_tag(&checkout_name)),
};
match checkout {
Ok(()) => Ok(current),
Err(error) => Err((error, current)),
}
})
.await;
this.update_in(cx, |this, window, cx| {
match result {
Ok(()) => this.reload_worktree(cx),
Err(error) => {
match outcome {
Ok(_) => this.reload_worktree(cx),
Err((error, current)) => {
this.error = Some(format!("Failed to check out {name}: {error}").into());
this.refs.switching_ref = false;
let detached = current.is_none();
this.refs.restore_selection(
&this.refs.branch_select,
&previous_branch,
window,
cx,
);
this.refs.restore_selection(
&this.refs.tag_select,
&previous_tag,
&current.map(Into::into),
window,
cx,
);
let tag = if detached { previous_tag } else { None };
this.refs
.restore_selection(&this.refs.tag_select, &tag, window, cx);
}
}
cx.notify();
@@ -890,6 +907,8 @@ impl RepoDetailView {
let probe = cx.background_spawn(async move {
let mut deleted: Vec<String> = Vec::new();
// A server that cannot be listed may still hold refs the reset deletes.
let mut unreachable: Vec<String> = Vec::new();
let repo = Repo::open(&mirror)?;
let local: HashSet<String> = repo
@@ -900,26 +919,33 @@ impl RepoDetailView {
.collect();
for url in &urls {
let Ok(remote_refs) = repo.ls_remote(url) else {
continue;
};
for (name, _) in remote_refs {
if !local.contains(&name) && !deleted.contains(&name) {
deleted.push(name);
match repo.ls_remote(url) {
Ok(remote_refs) => {
for (name, _) in remote_refs {
if !local.contains(&name) && !deleted.contains(&name) {
deleted.push(name);
}
}
}
Err(_) => unreachable.push(url.clone()),
}
}
deleted.sort();
Ok::<_, Error>(deleted)
Ok::<_, Error>((deleted, unreachable))
});
cx.spawn_in(window, async move |this, cx| {
let deleted = probe.await;
let probe = probe.await;
this.update_in(cx, |this, _window, cx| match deleted {
Ok(deleted) => {
this.reset = Some(dialogs::reset::ResetRemoteDialog::new(store, deleted, cx));
this.update_in(cx, |this, _window, cx| match probe {
Ok((deleted, unreachable)) => {
this.reset = Some(dialogs::reset::ResetRemoteDialog::new(
store,
deleted,
unreachable,
cx,
));
cx.notify();
}
Err(error) => {
+1 -1
View File
@@ -97,7 +97,7 @@ impl RefSwitcher {
cx: &mut App,
) {
select.update(cx, |state, cx| {
state.set_selected(previous.clone(), window, cx)
state.set_selected_silent(previous.clone(), window, cx)
});
}
}
@@ -13,7 +13,6 @@ use ui::select::{Select, SelectOption};
use ui::theme::ActiveTheme as _;
use ui::tooltip::Tooltip;
use crate::apply_appearance_mode;
use crate::repo::dialogs::grasp_servers::{normalize_server, server_host};
/// The title and description a settings row or block opens with.
@@ -80,7 +79,6 @@ pub fn appearance_select(cx: &App) -> Select<AppearanceMode> {
SettingsStore::global(cx).update(cx, |store, cx| {
store.edit(|settings| settings.appearance = mode, cx);
});
apply_appearance_mode(mode, cx);
})
}
+13
View File
@@ -1,5 +1,6 @@
mod helpers;
use gpui::prelude::FluentBuilder as _;
use gpui::{
App, AppContext as _, Context, Entity, IntoElement, ParentElement as _, Render, Styled as _,
Window, px,
@@ -9,6 +10,7 @@ use helpers::{
scan_paths_editor, setting_block, setting_row,
};
use settings::SettingsStore;
use ui::alert::{Alert, AlertSeverity};
use ui::common::v_flex;
use ui::dialog::{Dialog, DialogHandle};
use ui::input::InputState;
@@ -64,8 +66,19 @@ impl Render for SettingsDialog {
.height(px(560.))
.title("Settings")
.content(move |_, cx| {
let error = SettingsStore::global(cx).read(cx).error.clone();
v_flex()
.gap_4()
.when_some(error, |this, error| {
this.child(
Alert::new("settings-error")
.severity(AlertSeverity::Danger)
.style(ui::alert::AlertStyle::Inline)
.title("Settings are not saved")
.message(error),
)
})
.child(setting_row(
cx,
"Appearance",
+1 -2
View File
@@ -21,8 +21,7 @@ pub fn log_dropped<T>(result: Result<T, anyhow::Error>) {
}
}
/// Tracks a detail view's author, commenters, and repository owner for
/// profile prefetch.
/// Tracks a detail view's author, commenters, and owner for profile prefetch.
pub fn track_event_participants(
author: Option<PublicKey>,
owner: Option<PublicKey>,