Repository: lapce/lapce
File: lapce-data/src/config.rs (Rust)

Code before:
    #[field_names(
        desc = "Whether error lens should go to the end of view line, or only to the end of the diagnostic"
    )]
    pub error_lens_end_of_line: bool,
    #[field_names(
        desc = "Set error lens font family. If empty, it uses the inlay hint font family."
    )]
    pub error_lens_font_family: String,
    #[field_names(
        desc = "Set the error lens font size. If 0 it uses the inlay hint font size."
    )]
    pub error_lens_font_size: usize,
    #[field_names(
        desc = "Set the cursor blink interval (in milliseconds). Set to 0 to completely disable."
    )]
    pub blink_interval: u64, // TODO: change to u128 when upgrading config-rs to >0.11
}

impl EditorConfig {
    pub fn line_height(&self) -> usize {
        if self.line_height == 0 {
            (self.font_size as f64 * 1.35).ceil() as usize
        } else {
            self.line_height
        }
    }

    pub fn font_family(&self) -> FontFamily {
        if self.font_family.is_empty() {
            FontFamily::SYSTEM_UI
        } else {
            FontFamily::new_unchecked(self.font_family.clone())
        }
    }

    pub fn inlay_hint_font_family(&self) -> FontFamily {
        if self.inlay_hint_font_family.is_empty() {
            self.font_family()
        } else {
            FontFamily::new_unchecked(self.inlay_hint_font_family.clone())
        }
    }

    pub fn inlay_hint_font_size(&self) -> usize {
        if self.inlay_hint_font_size < 5
            || self.inlay_hint_font_size > self.font_size
        {
            self.font_size
        } else {
            self.inlay_hint_font_size
        }

Review comment (suggestion):
Another quick win here is to ```self.line_height.max(self.font_size)``` so that text doesn't overlap. 

Code after:
    #[field_names(
        desc = "Whether error lens should go to the end of view line, or only to the end of the diagnostic"
    )]
    pub error_lens_end_of_line: bool,
    #[field_names(
        desc = "Set error lens font family. If empty, it uses the inlay hint font family."
    )]
    pub error_lens_font_family: String,
    #[field_names(
        desc = "Set the error lens font size. If 0 it uses the inlay hint font size."
    )]
    pub error_lens_font_size: usize,
    #[field_names(
        desc = "Set the cursor blink interval (in milliseconds). Set to 0 to completely disable."
    )]
    pub blink_interval: u64, // TODO: change to u128 when upgrading config-rs to >0.11
}

impl EditorConfig {
    pub fn line_height(&self) -> usize {
        const SCALE_OR_SIZE_LIMIT: f64 = 5.0;

        let line_height = if self.line_height < SCALE_OR_SIZE_LIMIT {
            self.line_height * self.font_size as f64
        } else {
            self.line_height
        };

        // Prevent overlapping lines
        (line_height.round() as usize).max(self.font_size)
    }

    pub fn font_family(&self) -> FontFamily {
        if self.font_family.is_empty() {
            FontFamily::SYSTEM_UI
        } else {
            FontFamily::new_unchecked(self.font_family.clone())
        }
    }

    pub fn inlay_hint_font_family(&self) -> FontFamily {
        if self.inlay_hint_font_family.is_empty() {
            self.font_family()
        } else {
            FontFamily::new_unchecked(self.inlay_hint_font_family.clone())
        }
    }

    pub fn inlay_hint_font_size(&self) -> usize {
        if self.inlay_hint_font_size < 5
            || self.inlay_hint_font_size > self.font_size