Skip to content

Commit 28849dd

Browse files
Fix item closing overly triggering save dialogues (#21374)
Closes #12029 Allows to introspect project items inside items more deeply, checking them for being dirty. For that: * renames `project::Item` into `project::ProjectItem` * adds an `is_dirty(&self) -> bool` method to the renamed trait * changes the closing logic to only care about dirty project items when checking for save prompts conditions * save prompts are raised only if the item is singleton without a project path; or if the item has dirty project items that are not open elsewhere Release Notes: - Fixed item closing overly triggering save dialogues
1 parent c2cd84a commit 28849dd

File tree

19 files changed

+599
-84
lines changed

19 files changed

+599
-84
lines changed

crates/diagnostics/src/diagnostics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,7 @@ impl Item for ProjectDiagnosticsEditor {
716716
fn for_each_project_item(
717717
&self,
718718
cx: &AppContext,
719-
f: &mut dyn FnMut(gpui::EntityId, &dyn project::Item),
719+
f: &mut dyn FnMut(gpui::EntityId, &dyn project::ProjectItem),
720720
) {
721721
self.editor.for_each_project_item(cx, f)
722722
}

crates/editor/src/editor.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ use parking_lot::{Mutex, RwLock};
125125
use project::{
126126
lsp_store::{FormatTarget, FormatTrigger},
127127
project_settings::{GitGutterSetting, ProjectSettings},
128-
CodeAction, Completion, CompletionIntent, DocumentHighlight, InlayHint, Item, Location,
129-
LocationLink, Project, ProjectTransaction, TaskSourceKind,
128+
CodeAction, Completion, CompletionIntent, DocumentHighlight, InlayHint, Location, LocationLink,
129+
Project, ProjectItem, ProjectTransaction, TaskSourceKind,
130130
};
131131
use rand::prelude::*;
132132
use rpc::{proto::*, ErrorExt};

crates/editor/src/git/blame.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use gpui::{Model, ModelContext, Subscription, Task};
1010
use http_client::HttpClient;
1111
use language::{markdown, Bias, Buffer, BufferSnapshot, Edit, LanguageRegistry, ParsedMarkdown};
1212
use multi_buffer::MultiBufferRow;
13-
use project::{Item, Project};
13+
use project::{Project, ProjectItem};
1414
use smallvec::SmallVec;
1515
use sum_tree::SumTree;
1616
use url::Url;

crates/editor/src/items.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ use language::{
2222
use lsp::DiagnosticSeverity;
2323
use multi_buffer::AnchorRangeExt;
2424
use project::{
25-
lsp_store::FormatTrigger, project_settings::ProjectSettings, search::SearchQuery, Item as _,
26-
Project, ProjectPath,
25+
lsp_store::FormatTrigger, project_settings::ProjectSettings, search::SearchQuery, Project,
26+
ProjectItem as _, ProjectPath,
2727
};
2828
use rpc::proto::{self, update_view, PeerId};
2929
use settings::Settings;
@@ -665,7 +665,7 @@ impl Item for Editor {
665665
fn for_each_project_item(
666666
&self,
667667
cx: &AppContext,
668-
f: &mut dyn FnMut(EntityId, &dyn project::Item),
668+
f: &mut dyn FnMut(EntityId, &dyn project::ProjectItem),
669669
) {
670670
self.buffer
671671
.read(cx)

crates/image_viewer/src/image_viewer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ impl Item for ImageView {
7878
fn for_each_project_item(
7979
&self,
8080
cx: &AppContext,
81-
f: &mut dyn FnMut(gpui::EntityId, &dyn project::Item),
81+
f: &mut dyn FnMut(gpui::EntityId, &dyn project::ProjectItem),
8282
) {
8383
f(self.image_item.entity_id(), self.image_item.read(cx))
8484
}

crates/outline_panel/src/outline_panel.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use language::{BufferId, BufferSnapshot, OffsetRangeExt, OutlineItem};
3636
use menu::{Cancel, SelectFirst, SelectLast, SelectNext, SelectPrev};
3737

3838
use outline_panel_settings::{OutlinePanelDockPosition, OutlinePanelSettings, ShowIndentGuides};
39-
use project::{File, Fs, Item, Project};
39+
use project::{File, Fs, Project, ProjectItem};
4040
use search::{BufferSearchBar, ProjectSearchView};
4141
use serde::{Deserialize, Serialize};
4242
use settings::{Settings, SettingsStore};

crates/project/src/buffer_store.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::{
22
search::SearchQuery,
33
worktree_store::{WorktreeStore, WorktreeStoreEvent},
4-
Item, ProjectPath,
4+
ProjectItem as _, ProjectPath,
55
};
66
use ::git::{parse_git_remote_url, BuildPermalinkParams, GitHostingProviderRegistry};
77
use anyhow::{anyhow, Context as _, Result};

crates/project/src/image_store.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::{
22
worktree_store::{WorktreeStore, WorktreeStoreEvent},
3-
Project, ProjectEntryId, ProjectPath,
3+
Project, ProjectEntryId, ProjectItem, ProjectPath,
44
};
55
use anyhow::{Context as _, Result};
66
use collections::{hash_map, HashMap, HashSet};
@@ -114,7 +114,7 @@ impl ImageItem {
114114
}
115115
}
116116

117-
impl crate::Item for ImageItem {
117+
impl ProjectItem for ImageItem {
118118
fn try_open(
119119
project: &Model<Project>,
120120
path: &ProjectPath,
@@ -151,6 +151,10 @@ impl crate::Item for ImageItem {
151151
fn project_path(&self, cx: &AppContext) -> Option<ProjectPath> {
152152
Some(self.project_path(cx).clone())
153153
}
154+
155+
fn is_dirty(&self) -> bool {
156+
false
157+
}
154158
}
155159

156160
trait ImageStoreImpl {

crates/project/src/lsp_store.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::{
1010
toolchain_store::{EmptyToolchainStore, ToolchainStoreEvent},
1111
worktree_store::{WorktreeStore, WorktreeStoreEvent},
1212
yarn::YarnPathStore,
13-
CodeAction, Completion, CoreCompletion, Hover, InlayHint, Item as _, ProjectPath,
13+
CodeAction, Completion, CoreCompletion, Hover, InlayHint, ProjectItem as _, ProjectPath,
1414
ProjectTransaction, ResolveState, Symbol, ToolchainStore,
1515
};
1616
use anyhow::{anyhow, Context as _, Result};

crates/project/src/project.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ const MAX_PROJECT_SEARCH_HISTORY_SIZE: usize = 500;
111111
const MAX_SEARCH_RESULT_FILES: usize = 5_000;
112112
const MAX_SEARCH_RESULT_RANGES: usize = 10_000;
113113

114-
pub trait Item {
114+
pub trait ProjectItem {
115115
fn try_open(
116116
project: &Model<Project>,
117117
path: &ProjectPath,
@@ -121,6 +121,7 @@ pub trait Item {
121121
Self: Sized;
122122
fn entry_id(&self, cx: &AppContext) -> Option<ProjectEntryId>;
123123
fn project_path(&self, cx: &AppContext) -> Option<ProjectPath>;
124+
fn is_dirty(&self) -> bool;
124125
}
125126

126127
#[derive(Clone)]
@@ -4354,7 +4355,7 @@ impl ResolvedPath {
43544355
}
43554356
}
43564357

4357-
impl Item for Buffer {
4358+
impl ProjectItem for Buffer {
43584359
fn try_open(
43594360
project: &Model<Project>,
43604361
path: &ProjectPath,
@@ -4373,6 +4374,10 @@ impl Item for Buffer {
43734374
path: file.path().clone(),
43744375
})
43754376
}
4377+
4378+
fn is_dirty(&self) -> bool {
4379+
self.is_dirty()
4380+
}
43764381
}
43774382

43784383
impl Completion {

0 commit comments

Comments
 (0)