Skip to content

Commit 9ed9ada

Browse files
Exchange a view or ViewContext for a scope, never a raw window id
1 parent 3000d7b commit 9ed9ada

3 files changed

Lines changed: 20 additions & 14 deletions

File tree

app/src/settings_view/warp_agent_page.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5543,7 +5543,7 @@ impl AwsBedrockWidget {
55435543
let user_workspaces = UserWorkspaces::as_ref(ctx);
55445544
AISettings::as_ref(ctx).is_any_ai_enabled(ctx)
55455545
&& user_workspaces.is_aws_bedrock_credentials_enabled(
5546-
&user_workspaces.team_context_for_window(ctx.window_id()),
5546+
&user_workspaces.team_context_for_view(ctx),
55475547
ctx,
55485548
)
55495549
}
@@ -6029,7 +6029,7 @@ impl GeminiEnterpriseWidget {
60296029
fn is_refresh_enabled_during_construction(ctx: &ViewContext<WarpAgentPageView>) -> bool {
60306030
let user_workspaces = UserWorkspaces::as_ref(ctx);
60316031
let are_credentials_enabled = user_workspaces.is_gemini_enterprise_credentials_enabled(
6032-
&user_workspaces.team_context_for_window(ctx.window_id()),
6032+
&user_workspaces.team_context_for_view(ctx),
60336033
ctx,
60346034
);
60356035
Self::is_refresh_enabled_for_credentials(are_credentials_enabled, ctx)

app/src/workspaces/user_workspaces.rs

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -495,21 +495,27 @@ impl UserWorkspaces {
495495
view: &WeakViewHandle<T>,
496496
app: &AppContext,
497497
) -> Option<TeamContext<'a>> {
498-
Some(self.team_context_for_window(view.window_id(app)?))
498+
Some(self.team_context_for_window_id(view.window_id(app)?))
499499
}
500500

501-
/// [`Self::team_context`] for a caller that holds a [`WindowId`] rather than a view handle:
502-
/// a model owned by a window's view tree, or a view still inside its own constructor.
501+
/// [`Self::team_context`] for a view still inside its own constructor.
503502
///
504-
/// Same borrow discipline, so a caller still re-resolves on every read and follows the
505-
/// window. Unlike [`Self::team_context`] it cannot fail: a `WindowId` names a window
506-
/// whether or not this model has a team assignment for it, and a window with no team
507-
/// selected yields a scope whose `team_uid()` is `None`.
503+
/// A view is not in `view_to_window` until its build closure returns, so its own
504+
/// [`WeakViewHandle`] resolves no window yet and [`Self::team_context`] would report no
505+
/// scope. A `ViewContext` already names the window, and it is the same one the handle
506+
/// resolves to from the first render onward, so this cannot fail. Prefer
507+
/// [`Self::team_context`] everywhere else: a handle keeps following the view if it later
508+
/// moves between windows.
509+
pub(crate) fn team_context_for_view<T: Entity>(&self, ctx: &ViewContext<T>) -> TeamContext<'_> {
510+
self.team_context_for_window_id(ctx.window_id())
511+
}
512+
513+
/// The resolution both scope accessors above share.
508514
///
509-
/// A stored `WindowId` is weaker evidence than a live [`ViewContext`]: dragging a tab
510-
/// between windows re-parents the pane and the models it owns, so whoever stores one owes
511-
/// it an update on re-parent.
512-
pub(crate) fn team_context_for_window(&self, window_id: WindowId) -> TeamContext<'_> {
515+
/// Deliberately private. The exchange for a scope is a view or a [`ViewContext`], never a
516+
/// raw id, so that no caller is offered a `WindowId`-shaped hole to carry one around in
517+
/// place of the view it came from.
518+
fn team_context_for_window_id(&self, window_id: WindowId) -> TeamContext<'_> {
513519
TeamContext {
514520
team_uid: self
515521
.team_uid_for_window(window_id)

app/src/workspaces/user_workspaces_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1362,7 +1362,7 @@ impl ConstructionTimeScopeProbe {
13621362
let user_workspaces = UserWorkspaces::as_ref(ctx);
13631363
Self {
13641364
bedrock_enabled_from_view_context: user_workspaces.is_aws_bedrock_credentials_enabled(
1365-
&user_workspaces.team_context_for_window(ctx.window_id()),
1365+
&user_workspaces.team_context_for_view(ctx),
13661366
ctx,
13671367
),
13681368
team_uid_from_own_handle: user_workspaces

0 commit comments

Comments
 (0)