Unnamed repository; edit this file 'description' to name the repository.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
use crate::compositor::{Component, Context};
use tui::buffer::Buffer as Surface;

use helix_view::graphics::Rect;

pub struct Text {
    contents: String,
    size: (u16, u16),
    viewport: (u16, u16),
}

impl Text {
    pub fn new(contents: String) -> Self {
        Self {
            contents,
            size: (0, 0),
            viewport: (0, 0),
        }
    }
}
impl Component for Text {
    fn render(&mut self, area: Rect, surface: &mut Surface, _cx: &mut Context) {
        use tui::widgets::{Paragraph, Widget, Wrap};
        let contents = tui::text::Text::from(self.contents.clone());

        let par = Paragraph::new(contents).wrap(Wrap { trim: false });
        // .scroll(x, y) offsets

        par.render(area, surface);
    }

    fn required_size(&mut self, viewport: (u16, u16)) -> Option<(u16, u16)> {
        if viewport != self.viewport {
            let contents = tui::text::Text::from(self.contents.clone());
            let width = std::cmp::min(contents.width() as u16, viewport.0);
            let height = std::cmp::min(contents.height() as u16, viewport.1);
            self.size = (width, height);
            self.viewport = viewport;
        }
        Some(self.size)
    }
}
e. there is no API to change the intent of a thread once it has been spawned. //! //! As a system, rust-analyzer should have the property that //! old manual scheduling APIs are replaced entirely by `QoS`. //! To maintain this invariant, we panic when it is clear that //! old scheduling APIs have been used. //! //! Moreover, we also want to ensure that every thread has an intent set explicitly //! to force a decision about its importance to the system. //! Thus, [`ThreadIntent`] has no default value //! and every entry point to creating a thread requires a [`ThreadIntent`] upfront. use std::fmt; mod intent; mod pool; pub use intent::ThreadIntent; pub use pool::Pool; /// # Panics /// /// Panics if failed to spawn the thread. pub fn spawn<F, T>(intent: ThreadIntent, name: String, f: F) -> JoinHandle<T> where F: (FnOnce() -> T) + Send + 'static, T: Send + 'static, { Builder::new(intent, name).spawn(f).expect("failed to spawn thread") } pub struct Builder { intent: ThreadIntent, inner: jod_thread::Builder, allow_leak: bool, } impl Builder { #[must_use] pub fn new(intent: ThreadIntent, name: impl Into<String>) -> Self { Self { intent, inner: jod_thread::Builder::new().name(name.into()), allow_leak: false } } #[must_use] pub fn stack_size(self, size: usize) -> Self { Self { inner: self.inner.stack_size(size), ..self } } /// Whether dropping should detach the thread /// instead of joining it. #[must_use] pub fn allow_leak(self, allow_leak: bool) -> Self { Self { allow_leak, ..self } } pub fn spawn<F, T>(self, f: F) -> std::io::Result<JoinHandle<T>> where F: (FnOnce() -> T) + Send + 'static, T: Send + 'static, { let inner_handle = self.inner.spawn(move || { self.intent.apply_to_current_thread(); f() })?; Ok(JoinHandle { inner: Some(inner_handle), allow_leak: self.allow_leak }) } } pub struct JoinHandle<T = ()> { // `inner` is an `Option` so that we can // take ownership of the contained `JoinHandle`. inner: Option<jod_thread::JoinHandle<T>>, allow_leak: bool, } impl<T> JoinHandle<T> { /// # Panics /// /// Panics if there is no thread to join. #[must_use] pub fn join(mut self) -> T { self.inner.take().unwrap().join() } } impl<T> Drop for JoinHandle<T> { fn drop(&mut self) { if !self.allow_leak { return; } if let Some(join_handle) = self.inner.take() { join_handle.detach(); } } } #[expect(clippy::min_ident_chars, reason = "trait impl")] impl<T> fmt::Debug for JoinHandle<T> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.pad("JoinHandle { .. }") } }