Remove unused dependencies and avoid instantiating FontCache in tests

This commit is contained in:
Antonio Scandurra 2021-03-25 10:42:46 +01:00
parent 5f3dbb05d6
commit 0906b2a2f4
7 changed files with 11 additions and 21 deletions

View file

@ -5,7 +5,7 @@ use crate::{
platform::{self, App as _, WindowOptions}, platform::{self, App as _, WindowOptions},
presenter::Presenter, presenter::Presenter,
util::post_inc, util::post_inc,
AssetCache, AssetSource, FontCache, AssetCache, AssetSource, FontCache, TextLayoutCache,
}; };
use anyhow::{anyhow, Result}; use anyhow::{anyhow, Result};
use keymap::MatchResult; use keymap::MatchResult;
@ -624,10 +624,11 @@ impl MutableAppContext {
) { ) {
Err(e) => log::error!("error opening window: {}", e), Err(e) => log::error!("error opening window: {}", e),
Ok(mut window) => { Ok(mut window) => {
let text_layout_cache = TextLayoutCache::new(self.platform.fonts());
let presenter = Rc::new(RefCell::new(Presenter::new( let presenter = Rc::new(RefCell::new(Presenter::new(
window_id, window_id,
self.font_cache.clone(), self.font_cache.clone(),
self.platform.fonts(), text_layout_cache,
self.assets.clone(), self.assets.clone(),
self, self,
))); )));

View file

@ -22,7 +22,7 @@ impl Presenter {
pub fn new( pub fn new(
window_id: usize, window_id: usize,
font_cache: Arc<FontCache>, font_cache: Arc<FontCache>,
fonts: Arc<dyn platform::FontSystem>, text_layout_cache: TextLayoutCache,
asset_cache: Arc<AssetCache>, asset_cache: Arc<AssetCache>,
app: &MutableAppContext, app: &MutableAppContext,
) -> Self { ) -> Self {
@ -31,7 +31,7 @@ impl Presenter {
rendered_views: app.render_views(window_id).unwrap(), rendered_views: app.render_views(window_id).unwrap(),
parents: HashMap::new(), parents: HashMap::new(),
font_cache, font_cache,
text_layout_cache: TextLayoutCache::new(fonts), text_layout_cache,
asset_cache, asset_cache,
} }
} }

View file

@ -1,24 +1,16 @@
use crate::{ use crate::{
color::ColorU, color::ColorU,
fonts::{FontCache, FontId, GlyphId}, fonts::{FontId, GlyphId},
geometry::rect::RectF, geometry::rect::RectF,
platform, scene, PaintContext, 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 ordered_float::OrderedFloat;
use parking_lot::{Mutex, RwLock, RwLockUpgradableReadGuard}; use parking_lot::{Mutex, RwLock, RwLockUpgradableReadGuard};
use pathfinder_geometry::vector::{vec2f, Vector2F}; use pathfinder_geometry::vector::Vector2F;
use smallvec::SmallVec; use smallvec::SmallVec;
use std::{ use std::{
borrow::Borrow, borrow::Borrow,
char,
collections::HashMap, collections::HashMap,
convert::TryFrom,
hash::{Hash, Hasher}, hash::{Hash, Hasher},
ops::Range, ops::Range,
sync::Arc, sync::Arc,

View file

@ -1907,7 +1907,7 @@ mod tests {
use gpui::App; use gpui::App;
use std::{cell::RefCell, rc::Rc}; 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_1_events = Rc::new(RefCell::new(Vec::new()));
let buffer_2_events = Rc::new(RefCell::new(Vec::new())); let buffer_2_events = Rc::new(RefCell::new(Vec::new()));

View file

@ -996,7 +996,6 @@ impl BufferView {
.each( .each(
layouts.chunks_mut(chunk_size as usize).enumerate(), layouts.chunks_mut(chunk_size as usize).enumerate(),
|(ix, chunk)| { |(ix, chunk)| {
let font_cache = &font_cache;
let chunk_start = rows.start as usize + ix * chunk_size; let chunk_start = rows.start as usize + ix * chunk_size;
let chunk_end = cmp::min(chunk_start + chunk_size, rows.end as usize); let chunk_end = cmp::min(chunk_start + chunk_size, rows.end as usize);
@ -1363,11 +1362,9 @@ mod tests {
#[test] #[test]
fn test_layout_line_numbers() -> Result<()> { fn test_layout_line_numbers() -> Result<()> {
use gpui::{fonts::FontCache, text_layout::TextLayoutCache};
App::test((), |mut app| async move { App::test((), |mut app| async move {
let font_cache = FontCache::new(app.platform().fonts());
let layout_cache = TextLayoutCache::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))); let buffer = app.add_model(|_| Buffer::new(0, sample_text(6, 6)));

View file

@ -53,7 +53,7 @@ fn open_paths(params: &OpenParams, app: &mut MutableAppContext) {
mod tests { mod tests {
use super::*; use super::*;
use crate::{settings, test::*}; use crate::{settings, test::*};
use gpui::{App, FontCache}; use gpui::App;
use serde_json::json; use serde_json::json;
#[test] #[test]

View file

@ -325,7 +325,7 @@ mod tests {
use super::{pane, Workspace, WorkspaceView}; use super::{pane, Workspace, WorkspaceView};
use crate::{settings, test::temp_tree, workspace::WorkspaceHandle as _}; use crate::{settings, test::temp_tree, workspace::WorkspaceHandle as _};
use anyhow::Result; use anyhow::Result;
use gpui::{App, FontCache}; use gpui::App;
use serde_json::json; use serde_json::json;
#[test] #[test]