//! Line and column positions. //! //! LSP counts columns in UTF-16 code units by default //! () //! and CodeMirror addresses text in UTF-16 code units //! (), so UTF-16 is the unit //! that crosses the frontend and LSP boundaries. Chars (Unicode scalar //! values) are offered for Rust-side code that walks text by `char`. /// The unit a column is counted in. #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub enum ColumnUnit { /// UTF-16 code units: characters outside the Basic Multilingual Plane, /// such as most emoji, count two. Utf16, /// Unicode scalar values (Rust `char`s): every code point counts one, /// including each combining mark. Char, } /// A zero-based line and column. /// /// The column's unit is not stored; conversions take a [`ColumnUnit`]. A /// column never reaches into the line break: the largest valid column is /// the line's length without its line break. #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] pub struct Position { /// Zero-based line index. pub line: usize, /// Zero-based column in the unit given to the conversion. pub column: usize, } impl Position { /// Creates a position from a zero-based line and column. pub const fn new(line: usize, column: usize) -> Self { Self { line, column } } }