use lsp_types::Position;
pub trait Ext {
const MAX: Self;
const MIN: Self;
fn offset(&mut self, lines: i32, characters: i32);
fn set_line(&mut self, line: u32);
fn set_character(&mut self, character: u32);
fn is_in_bounds(&self, start: Self, end: Self) -> bool;
fn is_after(&self, position: Self) -> bool;
fn is_before(&self, position: Self) -> bool;
}
impl Ext for Position {
const MAX: Self = Self {
line: u32::MAX,
character: u32::MAX,
};
const MIN: Self = Self {
line: u32::MIN,
character: u32::MIN,
};
#[inline]
fn offset(&mut self, lines: i32, characters: i32) {
self.line = self.line.saturating_add_signed(lines);
self.character = self.character.saturating_add_signed(characters);
}
#[inline]
fn set_line(&mut self, line: u32) {
self.line = line;
}
#[inline]
fn set_character(&mut self, character: u32) {
self.character = character;
}
#[inline]
fn is_in_bounds(&self, start: Self, end: Self) -> bool {
self.is_after(start) & self.is_before(end)
}
#[inline]
fn is_after(&self, position: Self) -> bool {
self.line > position.line
|| position.line == self.line && self.character >= position.character
}
#[inline]
fn is_before(&self, position: Self) -> bool {
self.line < position.line
|| position.line == self.line && self.character <= position.character
}
}