From 0906b2a2f46a313b0524e5ed0b183d45e015e93a Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Thu, 25 Mar 2021 10:42:46 +0100 Subject: [PATCH] Remove unused dependencies and avoid instantiating FontCache in tests --- gpui/src/app.rs | 5 +++-- gpui/src/presenter.rs | 4 ++-- gpui/src/text_layout.rs | 12 ++---------- zed/src/editor/buffer/mod.rs | 2 +- zed/src/editor/buffer_view.rs | 5 +---- zed/src/workspace/mod.rs | 2 +- zed/src/workspace/workspace_view.rs | 2 +- 7 files changed, 11 insertions(+), 21 deletions(-) diff --git a/gpui/src/app.rs b/gpui/src/app.rs index 4da09387b89405057df00a5f6828802905fb9a71..631ae8ab2cbf842c5a29d472d36562e486956bee 100644 --- a/gpui/src/app.rs +++ b/gpui/src/app.rs @@ -5,7 +5,7 @@ use crate::{ platform::{self, App as _, WindowOptions}, presenter::Presenter, util::post_inc, - AssetCache, AssetSource, FontCache, + AssetCache, AssetSource, FontCache, TextLayoutCache, }; use anyhow::{anyhow, Result}; use keymap::MatchResult; @@ -624,10 +624,11 @@ impl MutableAppContext { ) { Err(e) => log::error!("error opening window: {}", e), Ok(mut window) => { + let text_layout_cache = TextLayoutCache::new(self.platform.fonts()); let presenter = Rc::new(RefCell::new(Presenter::new( window_id, self.font_cache.clone(), - self.platform.fonts(), + text_layout_cache, self.assets.clone(), self, ))); diff --git a/gpui/src/presenter.rs b/gpui/src/presenter.rs index dc7db6041293056197edcf4dca4b1ef78417ac48..900c9750c2ccf1185505590172b45e2428e52f50 100644 --- a/gpui/src/presenter.rs +++ b/gpui/src/presenter.rs @@ -22,7 +22,7 @@ impl Presenter { pub fn new( window_id: usize, font_cache: Arc, - fonts: Arc, + text_layout_cache: TextLayoutCache, asset_cache: Arc, app: &MutableAppContext, ) -> Self { @@ -31,7 +31,7 @@ impl Presenter { rendered_views: app.render_views(window_id).unwrap(), parents: HashMap::new(), font_cache, - text_layout_cache: TextLayoutCache::new(fonts), + text_layout_cache, asset_cache, } } diff --git a/gpui/src/text_layout.rs b/gpui/src/text_layout.rs index eda4e775e1737f98976858c5c6ac2f08330e8ea9..2c3ae12ff5f7a9902cbbd78b28f4def779d56a8f 100644 --- a/gpui/src/text_layout.rs +++ b/gpui/src/text_layout.rs @@ -1,24 +1,16 @@ use crate::{ color::ColorU, - fonts::{FontCache, FontId, GlyphId}, + fonts::{FontId, GlyphId}, geometry::rect::RectF, platform, scene, PaintContext, }; -use core_foundation::{ - attributed_string::CFMutableAttributedString, - base::{CFRange, TCFType}, - string::CFString, -}; -use core_text::{font::CTFont, line::CTLine, string_attributes::kCTFontAttributeName}; use ordered_float::OrderedFloat; use parking_lot::{Mutex, RwLock, RwLockUpgradableReadGuard}; -use pathfinder_geometry::vector::{vec2f, Vector2F}; +use pathfinder_geometry::vector::Vector2F; use smallvec::SmallVec; use std::{ borrow::Borrow, - char, collections::HashMap, - convert::TryFrom, hash::{Hash, Hasher}, ops::Range, sync::Arc, diff --git a/zed/src/editor/buffer/mod.rs b/zed/src/editor/buffer/mod.rs index 1de4f5781e199d40e3cfe6016f8f6760d834cc0d..1d476ceb27399c83fa57369f221ec64c39c72cb5 100644 --- a/zed/src/editor/buffer/mod.rs +++ b/zed/src/editor/buffer/mod.rs @@ -1907,7 +1907,7 @@ mod tests { use gpui::App; use std::{cell::RefCell, rc::Rc}; - let mut app = App::test((), |mut app| async move { + App::test((), |mut app| async move { let buffer_1_events = Rc::new(RefCell::new(Vec::new())); let buffer_2_events = Rc::new(RefCell::new(Vec::new())); diff --git a/zed/src/editor/buffer_view.rs b/zed/src/editor/buffer_view.rs index 899cda7ce3d8be3a963971f38a15b646aadba905..6c41426d9ff2b721decdef0692cdaae6bbf4ac3e 100644 --- a/zed/src/editor/buffer_view.rs +++ b/zed/src/editor/buffer_view.rs @@ -996,7 +996,6 @@ impl BufferView { .each( layouts.chunks_mut(chunk_size as usize).enumerate(), |(ix, chunk)| { - let font_cache = &font_cache; let chunk_start = rows.start as usize + ix * chunk_size; let chunk_end = cmp::min(chunk_start + chunk_size, rows.end as usize); @@ -1363,11 +1362,9 @@ mod tests { #[test] fn test_layout_line_numbers() -> Result<()> { - use gpui::{fonts::FontCache, text_layout::TextLayoutCache}; - App::test((), |mut app| async move { - let font_cache = FontCache::new(app.platform().fonts()); let layout_cache = TextLayoutCache::new(app.platform().fonts()); + let font_cache = app.font_cache(); let buffer = app.add_model(|_| Buffer::new(0, sample_text(6, 6))); diff --git a/zed/src/workspace/mod.rs b/zed/src/workspace/mod.rs index 95bb71289e032eabd820d5276a9401fda197943d..c997934d06de4c6301a1bd25491618ec75cd5f03 100644 --- a/zed/src/workspace/mod.rs +++ b/zed/src/workspace/mod.rs @@ -53,7 +53,7 @@ fn open_paths(params: &OpenParams, app: &mut MutableAppContext) { mod tests { use super::*; use crate::{settings, test::*}; - use gpui::{App, FontCache}; + use gpui::App; use serde_json::json; #[test] diff --git a/zed/src/workspace/workspace_view.rs b/zed/src/workspace/workspace_view.rs index a5b586091d5c10a749636e676b85b8ca40a03abf..feb58a39a766884c665116598cba752f783699e9 100644 --- a/zed/src/workspace/workspace_view.rs +++ b/zed/src/workspace/workspace_view.rs @@ -325,7 +325,7 @@ mod tests { use super::{pane, Workspace, WorkspaceView}; use crate::{settings, test::temp_tree, workspace::WorkspaceHandle as _}; use anyhow::Result; - use gpui::{App, FontCache}; + use gpui::App; use serde_json::json; #[test]