mirror of
https://github.com/zed-industries/zed.git
synced 2024-09-19 10:29:35 +03:00
Resolve more todos
This commit is contained in:
parent
80790d921d
commit
ed263a7b5c
@ -25,6 +25,7 @@ pub struct TestAppContext {
|
|||||||
pub dispatcher: TestDispatcher,
|
pub dispatcher: TestDispatcher,
|
||||||
test_platform: Rc<TestPlatform>,
|
test_platform: Rc<TestPlatform>,
|
||||||
text_system: Arc<TextSystem>,
|
text_system: Arc<TextSystem>,
|
||||||
|
fn_name: Option<&'static str>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Context for TestAppContext {
|
impl Context for TestAppContext {
|
||||||
@ -85,7 +86,7 @@ impl Context for TestAppContext {
|
|||||||
|
|
||||||
impl TestAppContext {
|
impl TestAppContext {
|
||||||
/// Creates a new `TestAppContext`. Usually you can rely on `#[gpui::test]` to do this for you.
|
/// Creates a new `TestAppContext`. Usually you can rely on `#[gpui::test]` to do this for you.
|
||||||
pub fn new(dispatcher: TestDispatcher) -> Self {
|
pub fn new(dispatcher: TestDispatcher, fn_name: Option<&'static str>) -> Self {
|
||||||
let arc_dispatcher = Arc::new(dispatcher.clone());
|
let arc_dispatcher = Arc::new(dispatcher.clone());
|
||||||
let background_executor = BackgroundExecutor::new(arc_dispatcher.clone());
|
let background_executor = BackgroundExecutor::new(arc_dispatcher.clone());
|
||||||
let foreground_executor = ForegroundExecutor::new(arc_dispatcher);
|
let foreground_executor = ForegroundExecutor::new(arc_dispatcher);
|
||||||
@ -101,12 +102,18 @@ impl TestAppContext {
|
|||||||
dispatcher: dispatcher.clone(),
|
dispatcher: dispatcher.clone(),
|
||||||
test_platform: platform,
|
test_platform: platform,
|
||||||
text_system,
|
text_system,
|
||||||
|
fn_name,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The name of the test function that created this `TestAppContext`
|
||||||
|
pub fn test_function_name(&self) -> Option<&'static str> {
|
||||||
|
self.fn_name
|
||||||
|
}
|
||||||
|
|
||||||
/// returns a new `TestAppContext` re-using the same executors to interleave tasks.
|
/// returns a new `TestAppContext` re-using the same executors to interleave tasks.
|
||||||
pub fn new_app(&self) -> TestAppContext {
|
pub fn new_app(&self) -> TestAppContext {
|
||||||
Self::new(self.dispatcher.clone())
|
Self::new(self.dispatcher.clone(), self.fn_name)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Simulates quitting the app.
|
/// Simulates quitting the app.
|
||||||
|
@ -1003,7 +1003,7 @@ impl Interactivity {
|
|||||||
if let Some(text) = cx
|
if let Some(text) = cx
|
||||||
.text_system()
|
.text_system()
|
||||||
.shape_text(
|
.shape_text(
|
||||||
&element_id,
|
element_id.into(),
|
||||||
FONT_SIZE,
|
FONT_SIZE,
|
||||||
&[cx.text_style().to_run(str_len)],
|
&[cx.text_style().to_run(str_len)],
|
||||||
None,
|
None,
|
||||||
@ -1055,22 +1055,11 @@ impl Interactivity {
|
|||||||
};
|
};
|
||||||
|
|
||||||
eprintln!(
|
eprintln!(
|
||||||
"This element is created at:\n{}:{}:{}",
|
"This element was created at:\n{}:{}:{}",
|
||||||
location.file(),
|
dir.join(location.file()).to_string_lossy(),
|
||||||
location.line(),
|
location.line(),
|
||||||
location.column()
|
location.column()
|
||||||
);
|
);
|
||||||
|
|
||||||
std::process::Command::new("zed")
|
|
||||||
.arg(format!(
|
|
||||||
"{}/{}:{}:{}",
|
|
||||||
dir.to_string_lossy(),
|
|
||||||
location.file(),
|
|
||||||
location.line(),
|
|
||||||
location.column()
|
|
||||||
))
|
|
||||||
.spawn()
|
|
||||||
.ok();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -202,7 +202,10 @@ impl TextState {
|
|||||||
let Some(lines) = cx
|
let Some(lines) = cx
|
||||||
.text_system()
|
.text_system()
|
||||||
.shape_text(
|
.shape_text(
|
||||||
&text, font_size, &runs, wrap_width, // Wrap if we know the width.
|
text.clone(),
|
||||||
|
font_size,
|
||||||
|
&runs,
|
||||||
|
wrap_width, // Wrap if we know the width.
|
||||||
)
|
)
|
||||||
.log_err()
|
.log_err()
|
||||||
else {
|
else {
|
||||||
|
@ -165,7 +165,8 @@ impl Default for TextStyle {
|
|||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
TextStyle {
|
TextStyle {
|
||||||
color: black(),
|
color: black(),
|
||||||
font_family: "Helvetica".into(), // todo!("Get a font we know exists on the system")
|
// Helvetica is a web safe font, so it should be available
|
||||||
|
font_family: "Helvetica".into(),
|
||||||
font_features: FontFeatures::default(),
|
font_features: FontFeatures::default(),
|
||||||
font_size: rems(1.).into(),
|
font_size: rems(1.).into(),
|
||||||
line_height: phi(),
|
line_height: phi(),
|
||||||
|
@ -39,7 +39,6 @@ pub fn run_test(
|
|||||||
max_retries: usize,
|
max_retries: usize,
|
||||||
test_fn: &mut (dyn RefUnwindSafe + Fn(TestDispatcher, u64)),
|
test_fn: &mut (dyn RefUnwindSafe + Fn(TestDispatcher, u64)),
|
||||||
on_fail_fn: Option<fn()>,
|
on_fail_fn: Option<fn()>,
|
||||||
_fn_name: String, // todo!("re-enable fn_name")
|
|
||||||
) {
|
) {
|
||||||
let starting_seed = env::var("SEED")
|
let starting_seed = env::var("SEED")
|
||||||
.map(|seed| seed.parse().expect("invalid SEED variable"))
|
.map(|seed| seed.parse().expect("invalid SEED variable"))
|
||||||
|
@ -258,7 +258,7 @@ impl TextSystem {
|
|||||||
|
|
||||||
pub fn shape_text(
|
pub fn shape_text(
|
||||||
&self,
|
&self,
|
||||||
text: &str, // todo!("pass a SharedString and preserve it when passed a single line?")
|
text: SharedString,
|
||||||
font_size: Pixels,
|
font_size: Pixels,
|
||||||
runs: &[TextRun],
|
runs: &[TextRun],
|
||||||
wrap_width: Option<Pixels>,
|
wrap_width: Option<Pixels>,
|
||||||
@ -268,8 +268,8 @@ impl TextSystem {
|
|||||||
|
|
||||||
let mut lines = SmallVec::new();
|
let mut lines = SmallVec::new();
|
||||||
let mut line_start = 0;
|
let mut line_start = 0;
|
||||||
for line_text in text.split('\n') {
|
|
||||||
let line_text = SharedString::from(line_text.to_string());
|
let mut process_line = |line_text: SharedString| {
|
||||||
let line_end = line_start + line_text.len();
|
let line_end = line_start + line_text.len();
|
||||||
|
|
||||||
let mut last_font: Option<Font> = None;
|
let mut last_font: Option<Font> = None;
|
||||||
@ -335,6 +335,24 @@ impl TextSystem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
font_runs.clear();
|
font_runs.clear();
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut split_lines = text.split('\n');
|
||||||
|
let mut processed = false;
|
||||||
|
|
||||||
|
if let Some(first_line) = split_lines.next() {
|
||||||
|
if let Some(second_line) = split_lines.next() {
|
||||||
|
processed = true;
|
||||||
|
process_line(first_line.to_string().into());
|
||||||
|
process_line(second_line.to_string().into());
|
||||||
|
for line_text in split_lines {
|
||||||
|
process_line(line_text.to_string().into());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !processed {
|
||||||
|
process_line(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.font_runs_pool.lock().push(font_runs);
|
self.font_runs_pool.lock().push(font_runs);
|
||||||
|
@ -143,7 +143,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_wrap_line() {
|
fn test_wrap_line() {
|
||||||
let dispatcher = TestDispatcher::new(StdRng::seed_from_u64(0));
|
let dispatcher = TestDispatcher::new(StdRng::seed_from_u64(0));
|
||||||
let cx = TestAppContext::new(dispatcher);
|
let cx = TestAppContext::new(dispatcher, None);
|
||||||
|
|
||||||
cx.update(|cx| {
|
cx.update(|cx| {
|
||||||
let text_system = cx.text_system().clone();
|
let text_system = cx.text_system().clone();
|
||||||
|
@ -106,7 +106,8 @@ pub fn test(args: TokenStream, function: TokenStream) -> TokenStream {
|
|||||||
let cx_varname = format_ident!("cx_{}", ix);
|
let cx_varname = format_ident!("cx_{}", ix);
|
||||||
cx_vars.extend(quote!(
|
cx_vars.extend(quote!(
|
||||||
let mut #cx_varname = gpui::TestAppContext::new(
|
let mut #cx_varname = gpui::TestAppContext::new(
|
||||||
dispatcher.clone()
|
dispatcher.clone(),
|
||||||
|
Some(stringify!(#outer_fn_name)),
|
||||||
);
|
);
|
||||||
));
|
));
|
||||||
cx_teardowns.extend(quote!(
|
cx_teardowns.extend(quote!(
|
||||||
@ -140,8 +141,7 @@ pub fn test(args: TokenStream, function: TokenStream) -> TokenStream {
|
|||||||
executor.block_test(#inner_fn_name(#inner_fn_args));
|
executor.block_test(#inner_fn_name(#inner_fn_args));
|
||||||
#cx_teardowns
|
#cx_teardowns
|
||||||
},
|
},
|
||||||
#on_failure_fn_name,
|
#on_failure_fn_name
|
||||||
stringify!(#outer_fn_name).to_string(),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -169,7 +169,8 @@ pub fn test(args: TokenStream, function: TokenStream) -> TokenStream {
|
|||||||
let cx_varname_lock = format_ident!("cx_{}_lock", ix);
|
let cx_varname_lock = format_ident!("cx_{}_lock", ix);
|
||||||
cx_vars.extend(quote!(
|
cx_vars.extend(quote!(
|
||||||
let mut #cx_varname = gpui::TestAppContext::new(
|
let mut #cx_varname = gpui::TestAppContext::new(
|
||||||
dispatcher.clone()
|
dispatcher.clone(),
|
||||||
|
Some(stringify!(#outer_fn_name))
|
||||||
);
|
);
|
||||||
let mut #cx_varname_lock = #cx_varname.app.borrow_mut();
|
let mut #cx_varname_lock = #cx_varname.app.borrow_mut();
|
||||||
));
|
));
|
||||||
@ -186,7 +187,8 @@ pub fn test(args: TokenStream, function: TokenStream) -> TokenStream {
|
|||||||
let cx_varname = format_ident!("cx_{}", ix);
|
let cx_varname = format_ident!("cx_{}", ix);
|
||||||
cx_vars.extend(quote!(
|
cx_vars.extend(quote!(
|
||||||
let mut #cx_varname = gpui::TestAppContext::new(
|
let mut #cx_varname = gpui::TestAppContext::new(
|
||||||
dispatcher.clone()
|
dispatcher.clone(),
|
||||||
|
Some(stringify!(#outer_fn_name))
|
||||||
);
|
);
|
||||||
));
|
));
|
||||||
cx_teardowns.extend(quote!(
|
cx_teardowns.extend(quote!(
|
||||||
@ -222,7 +224,6 @@ pub fn test(args: TokenStream, function: TokenStream) -> TokenStream {
|
|||||||
#cx_teardowns
|
#cx_teardowns
|
||||||
},
|
},
|
||||||
#on_failure_fn_name,
|
#on_failure_fn_name,
|
||||||
stringify!(#outer_fn_name).to_string(),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user