Skip to content

Commit

Permalink
Cleanups preparing for WindowContext refactor (#22475)
Browse files Browse the repository at this point in the history
* Remove unnecessary WindowContext and ViewContext '_ lifetimes

* Removed some cases where WindowContext has a different name than `cx`.

Release Notes:

- N/A
  • Loading branch information
mgsloan authored Dec 28, 2024
1 parent 9815358 commit 016b5d6
Show file tree
Hide file tree
Showing 41 changed files with 127 additions and 152 deletions.
4 changes: 2 additions & 2 deletions crates/assistant/src/assistant_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4966,8 +4966,8 @@ fn fold_toggle(
) -> impl Fn(
MultiBufferRow,
bool,
Arc<dyn Fn(bool, &mut WindowContext<'_>) + Send + Sync>,
&mut WindowContext<'_>,
Arc<dyn Fn(bool, &mut WindowContext) + Send + Sync>,
&mut WindowContext,
) -> AnyElement {
move |row, is_folded, fold, _cx| {
Disclosure::new((name, row.0 as u64), !is_folded)
Expand Down
4 changes: 2 additions & 2 deletions crates/assistant/src/slash_command_picker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ enum SlashCommandEntry {
Info(SlashCommandInfo),
Advert {
name: SharedString,
renderer: fn(&mut WindowContext<'_>) -> AnyElement,
on_confirm: fn(&mut WindowContext<'_>),
renderer: fn(&mut WindowContext) -> AnyElement,
on_confirm: fn(&mut WindowContext),
},
}

Expand Down
2 changes: 1 addition & 1 deletion crates/editor/src/clangd_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fn is_c_language(language: &Language) -> bool {
pub fn switch_source_header(
editor: &mut Editor,
_: &SwitchSourceHeader,
cx: &mut ViewContext<'_, Editor>,
cx: &mut ViewContext<Editor>,
) {
let Some(project) = &editor.project else {
return;
Expand Down
12 changes: 6 additions & 6 deletions crates/editor/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3513,7 +3513,7 @@ impl Editor {
}
}

fn visible_inlay_hints(&self, cx: &ViewContext<'_, Editor>) -> Vec<Inlay> {
fn visible_inlay_hints(&self, cx: &ViewContext<Editor>) -> Vec<Inlay> {
self.display_map
.read(cx)
.current_inlays()
Expand Down Expand Up @@ -6009,7 +6009,7 @@ impl Editor {
fn gather_revert_changes(
&mut self,
selections: &[Selection<Point>],
cx: &mut ViewContext<'_, Editor>,
cx: &mut ViewContext<Editor>,
) -> HashMap<BufferId, Vec<(Range<text::Anchor>, Rope)>> {
let mut revert_changes = HashMap::default();
let snapshot = self.snapshot(cx);
Expand Down Expand Up @@ -8936,7 +8936,7 @@ impl Editor {
fn templates_with_tags(
project: &Model<Project>,
runnable: &mut Runnable,
cx: &WindowContext<'_>,
cx: &WindowContext,
) -> Vec<(TaskSourceKind, TaskTemplate)> {
let (inventory, worktree_id, file) = project.read_with(cx, |project, cx| {
let (worktree_id, file) = project
Expand Down Expand Up @@ -9248,7 +9248,7 @@ impl Editor {
&mut self,
snapshot: &EditorSnapshot,
position: Point,
cx: &mut ViewContext<'_, Editor>,
cx: &mut ViewContext<Editor>,
) -> Option<MultiBufferDiffHunk> {
for (ix, position) in [position, Point::zero()].into_iter().enumerate() {
if let Some(hunk) = self.go_to_next_hunk_in_direction(
Expand Down Expand Up @@ -9277,7 +9277,7 @@ impl Editor {
&mut self,
snapshot: &EditorSnapshot,
position: Point,
cx: &mut ViewContext<'_, Editor>,
cx: &mut ViewContext<Editor>,
) -> Option<MultiBufferDiffHunk> {
for (ix, position) in [position, snapshot.buffer_snapshot.max_point()]
.into_iter()
Expand Down Expand Up @@ -13842,7 +13842,7 @@ impl SemanticsProvider for Model<Project> {
fn inlay_hint_settings(
location: Anchor,
snapshot: &MultiBufferSnapshot,
cx: &mut ViewContext<'_, Editor>,
cx: &mut ViewContext<Editor>,
) -> InlayHintSettings {
let file = snapshot.file_at(location);
let language = snapshot.language_at(location).map(|l| l.name());
Expand Down
10 changes: 5 additions & 5 deletions crates/editor/src/element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4991,7 +4991,7 @@ fn jump_data(
block_row_start: DisplayRow,
height: u32,
for_excerpt: &ExcerptInfo,
cx: &mut WindowContext<'_>,
cx: &mut WindowContext,
) -> JumpData {
let range = &for_excerpt.range;
let buffer = &for_excerpt.buffer;
Expand Down Expand Up @@ -5066,7 +5066,7 @@ fn prepaint_gutter_button(
scroll_pixel_position: gpui::Point<Pixels>,
gutter_hitbox: &Hitbox,
rows_with_hunk_bounds: &HashMap<DisplayRow, Bounds<Pixels>>,
cx: &mut WindowContext<'_>,
cx: &mut WindowContext,
) -> AnyElement {
let mut button = button.into_any_element();
let available_space = size(
Expand Down Expand Up @@ -5099,7 +5099,7 @@ fn render_inline_blame_entry(
blame_entry: BlameEntry,
style: &EditorStyle,
workspace: Option<WeakView<Workspace>>,
cx: &mut WindowContext<'_>,
cx: &mut WindowContext,
) -> AnyElement {
let relative_timestamp = blame_entry_relative_timestamp(&blame_entry);

Expand Down Expand Up @@ -5139,7 +5139,7 @@ fn render_blame_entry(
style: &EditorStyle,
last_used_color: &mut Option<(PlayerColor, Oid)>,
editor: View<Editor>,
cx: &mut WindowContext<'_>,
cx: &mut WindowContext,
) -> AnyElement {
let mut sha_color = cx
.theme()
Expand Down Expand Up @@ -5221,7 +5221,7 @@ fn deploy_blame_entry_context_menu(
details: Option<&CommitDetails>,
editor: View<Editor>,
position: gpui::Point<Pixels>,
cx: &mut WindowContext<'_>,
cx: &mut WindowContext,
) {
let context_menu = ContextMenu::build(cx, move |menu, _| {
let sha = format!("{}", blame_entry.sha);
Expand Down
2 changes: 1 addition & 1 deletion crates/editor/src/hover_links.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ pub fn update_inlay_link_and_hover_points(
editor: &mut Editor,
secondary_held: bool,
shift_held: bool,
cx: &mut ViewContext<'_, Editor>,
cx: &mut ViewContext<Editor>,
) {
let hovered_offset = if point_for_position.column_overshoot_after_line_end == 0 {
Some(snapshot.display_point_to_inlay_offset(point_for_position.exact_unclipped, Bias::Left))
Expand Down
14 changes: 7 additions & 7 deletions crates/editor/src/hunk_diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ impl Editor {
&mut self,
diff_base_buffer: Option<Model<Buffer>>,
hunk: &HoveredHunk,
cx: &mut ViewContext<'_, Editor>,
cx: &mut ViewContext<Editor>,
) -> Option<()> {
let buffer = self.buffer.clone();
let multi_buffer_snapshot = buffer.read(cx).snapshot(cx);
Expand Down Expand Up @@ -454,7 +454,7 @@ impl Editor {
fn apply_diff_hunks_in_range(
&mut self,
range: Range<Anchor>,
cx: &mut ViewContext<'_, Editor>,
cx: &mut ViewContext<Editor>,
) -> Option<()> {
let (buffer, range, _) = self
.buffer
Expand Down Expand Up @@ -530,7 +530,7 @@ impl Editor {
fn hunk_header_block(
&self,
hunk: &HoveredHunk,
cx: &mut ViewContext<'_, Editor>,
cx: &mut ViewContext<Editor>,
) -> BlockProperties<Anchor> {
let is_branch_buffer = self
.buffer
Expand Down Expand Up @@ -801,7 +801,7 @@ impl Editor {
hunk: &HoveredHunk,
diff_base_buffer: Model<Buffer>,
deleted_text_height: u32,
cx: &mut ViewContext<'_, Editor>,
cx: &mut ViewContext<Editor>,
) -> BlockProperties<Anchor> {
let gutter_color = match hunk.status {
DiffHunkStatus::Added => unreachable!(),
Expand Down Expand Up @@ -864,7 +864,7 @@ impl Editor {
}
}

pub(super) fn clear_expanded_diff_hunks(&mut self, cx: &mut ViewContext<'_, Editor>) -> bool {
pub(super) fn clear_expanded_diff_hunks(&mut self, cx: &mut ViewContext<Editor>) -> bool {
if self.diff_map.expand_all {
return false;
}
Expand All @@ -887,7 +887,7 @@ impl Editor {
pub(super) fn sync_expanded_diff_hunks(
diff_map: &mut DiffMap,
buffer_id: BufferId,
cx: &mut ViewContext<'_, Self>,
cx: &mut ViewContext<Self>,
) {
let diff_base_state = diff_map.diff_bases.get_mut(&buffer_id);
let mut diff_base_buffer = None;
Expand Down Expand Up @@ -1134,7 +1134,7 @@ fn editor_with_deleted_text(
diff_base_buffer: Model<Buffer>,
deleted_color: Hsla,
hunk: &HoveredHunk,
cx: &mut ViewContext<'_, Editor>,
cx: &mut ViewContext<Editor>,
) -> (u32, View<Editor>) {
let parent_editor = cx.view().downgrade();
let editor = cx.new_view(|cx| {
Expand Down
10 changes: 5 additions & 5 deletions crates/editor/src/inlay_hint_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ impl InlayHintCache {
buffer_id: BufferId,
excerpt_id: ExcerptId,
id: InlayId,
cx: &mut ViewContext<'_, Editor>,
cx: &mut ViewContext<Editor>,
) {
if let Some(excerpt_hints) = self.hints.get(&excerpt_id) {
let mut guard = excerpt_hints.write();
Expand Down Expand Up @@ -640,7 +640,7 @@ fn spawn_new_update_tasks(
excerpts_to_query: HashMap<ExcerptId, (Model<Buffer>, Global, Range<usize>)>,
invalidate: InvalidationStrategy,
update_cache_version: usize,
cx: &mut ViewContext<'_, Editor>,
cx: &mut ViewContext<Editor>,
) {
for (excerpt_id, (excerpt_buffer, new_task_buffer_version, excerpt_visible_range)) in
excerpts_to_query
Expand Down Expand Up @@ -797,7 +797,7 @@ fn new_update_task(
query: ExcerptQuery,
query_ranges: QueryRanges,
excerpt_buffer: Model<Buffer>,
cx: &mut ViewContext<'_, Editor>,
cx: &mut ViewContext<Editor>,
) -> Task<()> {
cx.spawn(move |editor, mut cx| async move {
let visible_range_update_results = future::join_all(
Expand Down Expand Up @@ -1129,7 +1129,7 @@ fn apply_hint_update(
invalidate: bool,
buffer_snapshot: BufferSnapshot,
multi_buffer_snapshot: MultiBufferSnapshot,
cx: &mut ViewContext<'_, Editor>,
cx: &mut ViewContext<Editor>,
) {
let cached_excerpt_hints = editor
.inlay_hint_cache
Expand Down Expand Up @@ -3434,7 +3434,7 @@ pub mod tests {
labels
}

pub fn visible_hint_labels(editor: &Editor, cx: &ViewContext<'_, Editor>) -> Vec<String> {
pub fn visible_hint_labels(editor: &Editor, cx: &ViewContext<Editor>) -> Vec<String> {
let mut hints = editor
.visible_inlay_hints(cx)
.into_iter()
Expand Down
4 changes: 2 additions & 2 deletions crates/editor/src/rust_analyzer_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub fn apply_related_actions(editor: &View<Editor>, cx: &mut WindowContext) {
pub fn expand_macro_recursively(
editor: &mut Editor,
_: &ExpandMacroRecursively,
cx: &mut ViewContext<'_, Editor>,
cx: &mut ViewContext<Editor>,
) {
if editor.selections.count() == 0 {
return;
Expand Down Expand Up @@ -98,7 +98,7 @@ pub fn expand_macro_recursively(
.detach_and_log_err(cx);
}

pub fn open_docs(editor: &mut Editor, _: &OpenDocs, cx: &mut ViewContext<'_, Editor>) {
pub fn open_docs(editor: &mut Editor, _: &OpenDocs, cx: &mut ViewContext<Editor>) {
if editor.selections.count() == 0 {
return;
}
Expand Down
4 changes: 2 additions & 2 deletions crates/editor/src/tasks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use workspace::Workspace;

fn task_context_with_editor(
editor: &mut Editor,
cx: &mut WindowContext<'_>,
cx: &mut WindowContext,
) -> AsyncTask<Option<TaskContext>> {
let Some(project) = editor.project.clone() else {
return AsyncTask::ready(None);
Expand Down Expand Up @@ -74,7 +74,7 @@ fn task_context_with_editor(
})
}

pub fn task_context(workspace: &Workspace, cx: &mut WindowContext<'_>) -> AsyncTask<TaskContext> {
pub fn task_context(workspace: &Workspace, cx: &mut WindowContext) -> AsyncTask<TaskContext> {
let Some(editor) = workspace
.active_item(cx)
.and_then(|item| item.act_as::<Editor>(cx))
Expand Down
2 changes: 1 addition & 1 deletion crates/extensions_ui/src/extensions_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,7 @@ impl ExtensionsPage {
}
}

fn fetch_extensions_debounced(&mut self, cx: &mut ViewContext<'_, ExtensionsPage>) {
fn fetch_extensions_debounced(&mut self, cx: &mut ViewContext<ExtensionsPage>) {
self.extension_fetch_task = Some(cx.spawn(|this, mut cx| async move {
let search = this
.update(&mut cx, |this, cx| this.search_query(cx))
Expand Down
2 changes: 1 addition & 1 deletion crates/file_finder/src/file_finder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,7 @@ impl FileFinderDelegate {
fn lookup_absolute_path(
&self,
query: FileSearchQuery,
cx: &mut ViewContext<'_, Picker<Self>>,
cx: &mut ViewContext<Picker<Self>>,
) -> Task<()> {
cx.spawn(|picker, mut cx| async move {
let Some(project) = picker
Expand Down
2 changes: 1 addition & 1 deletion crates/git_ui/src/git_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1044,7 +1044,7 @@ impl GitPanel {
hunks: Rc<OnceCell<Vec<DiffHunk>>>,
change_focus: bool,
debounce: Option<Duration>,
cx: &mut ViewContext<'_, Self>,
cx: &mut ViewContext<Self>,
) {
let workspace = self.workspace.clone();
let Some(diff_editor) = self.git_diff_editor.clone() else {
Expand Down
2 changes: 1 addition & 1 deletion crates/gpui/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1490,7 +1490,7 @@ impl Context for AppContext {

fn update_window<T, F>(&mut self, handle: AnyWindowHandle, update: F) -> Result<T>
where
F: FnOnce(AnyView, &mut WindowContext<'_>) -> T,
F: FnOnce(AnyView, &mut WindowContext) -> T,
{
self.update(|cx| {
let mut window = cx
Expand Down
10 changes: 5 additions & 5 deletions crates/gpui/src/app/async_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl Context for AsyncAppContext {

fn update_window<T, F>(&mut self, window: AnyWindowHandle, f: F) -> Result<T>
where
F: FnOnce(AnyView, &mut WindowContext<'_>) -> T,
F: FnOnce(AnyView, &mut WindowContext) -> T,
{
let app = self.app.upgrade().context("app was released")?;
let mut lock = app.borrow_mut();
Expand Down Expand Up @@ -349,7 +349,7 @@ impl Context for AsyncWindowContext {

fn update_window<T, F>(&mut self, window: AnyWindowHandle, update: F) -> Result<T>
where
F: FnOnce(AnyView, &mut WindowContext<'_>) -> T,
F: FnOnce(AnyView, &mut WindowContext) -> T,
{
self.app.update_window(window, update)
}
Expand All @@ -369,7 +369,7 @@ impl Context for AsyncWindowContext {
impl VisualContext for AsyncWindowContext {
fn new_view<V>(
&mut self,
build_view_state: impl FnOnce(&mut ViewContext<'_, V>) -> V,
build_view_state: impl FnOnce(&mut ViewContext<V>) -> V,
) -> Self::Result<View<V>>
where
V: 'static + Render,
Expand All @@ -381,15 +381,15 @@ impl VisualContext for AsyncWindowContext {
fn update_view<V: 'static, R>(
&mut self,
view: &View<V>,
update: impl FnOnce(&mut V, &mut ViewContext<'_, V>) -> R,
update: impl FnOnce(&mut V, &mut ViewContext<V>) -> R,
) -> Self::Result<R> {
self.window
.update(self, |_, cx| cx.update_view(view, update))
}

fn replace_root_view<V>(
&mut self,
build_view: impl FnOnce(&mut ViewContext<'_, V>) -> V,
build_view: impl FnOnce(&mut ViewContext<V>) -> V,
) -> Self::Result<View<V>>
where
V: 'static + Render,
Expand Down
2 changes: 1 addition & 1 deletion crates/gpui/src/app/model_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ impl<'a, T> Context for ModelContext<'a, T> {

fn update_window<R, F>(&mut self, window: AnyWindowHandle, update: F) -> Result<R>
where
F: FnOnce(AnyView, &mut WindowContext<'_>) -> R,
F: FnOnce(AnyView, &mut WindowContext) -> R,
{
self.app.update_window(window, update)
}
Expand Down
Loading

0 comments on commit 016b5d6

Please sign in to comment.