Skip to main content

register_builtin_signs

Function register_builtin_signs 

Source
pub fn register_builtin_signs(
    registry: &mut SignRegistry,
    glyphs: DiagnosticGlyphs,
) -> BuiltinSignIds
Expand description

Register the built-in signs into registry and return their ids (SG.4a).

glyphs supplies the four diagnostic glyphs, which are live typed options (ui.diagnostic-*-glyph) rather than constants — so this is called again when one changes. Redefinition KEEPS the id (SG.1), which is what makes re-registering safe with placements already in flight: they simply start painting the new glyph. That property was built before anything needed it; this is the thing that needed it.

Diff glyphs stay + ~ - ? — cross-editor convention, and no option has ever exposed them.

§Examples

use lattice_mode::{
    register_builtin_signs, DiagnosticGlyphs, GutterSeverityLevel, SignRegistry,
    SIGN_COLUMN_DIFF,
};

let mut signs = SignRegistry::new();
let ids = register_builtin_signs(&mut signs, DiagnosticGlyphs::default());
let error = signs.get(ids.for_severity(GutterSeverityLevel::Error)).unwrap();
assert_eq!(error.glyph_char(false), '■');
assert_eq!(signs.get(ids.diff_add).unwrap().column, SIGN_COLUMN_DIFF);

// Re-registering with a new glyph keeps every id.
let glyphs = DiagnosticGlyphs { error: 'E', ..DiagnosticGlyphs::default() };
assert_eq!(register_builtin_signs(&mut signs, glyphs), ids);
assert_eq!(signs.get(ids.diagnostic_error).unwrap().glyph_char(false), 'E');