diff --git a/crates/hir/husky-hir-eager-expr/src/helpers/codespan.rs b/crates/hir/husky-hir-eager-expr/src/helpers/codespan.rs index cd4813a21d..34039abed0 100644 --- a/crates/hir/husky-hir-eager-expr/src/helpers/codespan.rs +++ b/crates/hir/husky-hir-eager-expr/src/helpers/codespan.rs @@ -17,7 +17,7 @@ use husky_sem_expr::{ SemExprIdx, SemExprRegionData, }; use husky_text::{HasText, Text}; -use husky_text_protocol::offset::OffsetRange; +use husky_text_protocol::offset::TextOffsetRange; use husky_token::{RangedTokenSheet, TokenDb}; use husky_vfs::path::module_path::ModulePath; @@ -146,7 +146,7 @@ impl<'a> HirEagerExprCodespanEmitter<'a> { /// # getters impl<'a> HirEagerExprCodespanEmitter<'a> { - fn expr_offset_range(&self, expr: HirEagerExprIdx) -> OffsetRange { + fn expr_offset_range(&self, expr: HirEagerExprIdx) -> TextOffsetRange { let expr: SemExprIdx = self .hir_eager_expr_source_map_data .hir_eager_to_sem_expr_idx(expr); diff --git a/crates/lex/husky-text/src/lib.rs b/crates/lex/husky-text/src/lib.rs index fc37ddac24..6fc1fef165 100644 --- a/crates/lex/husky-text/src/lib.rs +++ b/crates/lex/husky-text/src/lib.rs @@ -8,7 +8,7 @@ mod tests; use self::jar::*; #[cfg(test)] use self::tests::*; -use husky_text_protocol::{line_map::*, offset::OffsetRange, position::TextLine, range::*}; +use husky_text_protocol::{line_map::*, offset::TextOffsetRange, position::TextLine, range::*}; use husky_vfs::path::module_path::ModulePath; use line_map::module_text_line_map; @@ -50,7 +50,7 @@ impl<'a> std::fmt::Debug for Text<'a> { } impl<'a> Text<'a> { - pub fn offset_range(self, range: TextRange) -> OffsetRange { + pub fn offset_range(self, range: TextRange) -> TextOffsetRange { self.line_map.offset_range(range) } } diff --git a/crates/protocols/husky-text-protocol/src/line_map.rs b/crates/protocols/husky-text-protocol/src/line_map.rs index 7fc1c2138d..d955130dd9 100644 --- a/crates/protocols/husky-text-protocol/src/line_map.rs +++ b/crates/protocols/husky-text-protocol/src/line_map.rs @@ -3,10 +3,10 @@ mod lsp; mod text_bytes_len; mod wide_char; -use offset::{OffsetRange, OffsetRangeFrom, OffsetRangeTo}; +use offset::{TextOffsetRange, TextOffsetRangeFrom, TextOffsetRangeTo}; pub use text_bytes_len::*; -use crate::offset::Offset; +use crate::offset::TextOffset; use crate::*; use rustc_hash::FxHashMap; use std::{ @@ -19,7 +19,7 @@ use wide_char::*; pub struct LineMap { text_len_in_bytes: usize, /// Offset the the beginning of each line, zero-based - pub(crate) newlines: Vec, + pub(crate) newlines: Vec, /// List of non-ASCII characters on each line pub(crate) wide_chars_line_map: FxHashMap>, } @@ -38,7 +38,7 @@ impl LineMap { let mut wide_chars_line_map = FxHashMap::default(); let mut wide_chars_buffer: Vec = vec![]; - let mut newlines: Vec = vec![0.into()]; + let mut newlines: Vec = vec![0.into()]; let mut curr_row: usize = 0; let mut curr_col: u32 = 0; let mut line = 0; @@ -46,7 +46,7 @@ impl LineMap { let c_len = c.text_bytes_len(); curr_row += c_len as usize; if c == '\n' { - newlines.push(Offset::from(curr_row)); + newlines.push(TextOffset::from(curr_row)); // Save any utf-16 characters seen in the previous line if !wide_chars_buffer.is_empty() { @@ -86,7 +86,7 @@ impl LineMap { (0.into())..(self.newlines.len().into()) } - pub fn position_from_offset(&self, offset: Offset) -> TextPosition { + pub fn position_from_offset(&self, offset: TextOffset) -> TextPosition { let row = self.newlines.partition_point(|&it| it <= offset) - 1; let line_start_offset = self.newlines[row]; let col = offset - line_start_offset; @@ -97,7 +97,7 @@ impl LineMap { } /// the byte index - pub fn offset(&self, pos: TextPosition) -> Offset { + pub fn offset(&self, pos: TextPosition) -> TextOffset { if pos.line.index() == self.newlines.len() { if pos.col.index32() == 0 { return self.text_len_in_bytes.into(); @@ -108,16 +108,16 @@ impl LineMap { self.newlines[pos.line.index()] + usize::from(pos.col.index()) } - pub fn offset_range(&self, range: impl Into) -> OffsetRange { + pub fn offset_range(&self, range: impl Into) -> TextOffsetRange { let range = range.into(); (self.offset(range.start)..self.offset(range.end)).into() } - pub fn offset_range_from(&self, range_from: RangeFrom) -> OffsetRangeFrom { + pub fn offset_range_from(&self, range_from: RangeFrom) -> TextOffsetRangeFrom { (self.offset(range_from.start)..).into() } - pub fn offset_range_to(&self, range_to: RangeTo) -> OffsetRangeTo { + pub fn offset_range_to(&self, range_to: RangeTo) -> TextOffsetRangeTo { (..self.offset(range_to.end)).into() } @@ -135,7 +135,7 @@ impl LineMap { // (..=self.offset(range_to_inclusive.end)).into() // } - pub fn text_line_offset_range(&self, line: TextLine) -> OffsetRange { + pub fn text_line_offset_range(&self, line: TextLine) -> TextOffsetRange { let end = if (line.0 as usize) < self.newlines.len() { self.offset(TextPosition { line: line + 1, @@ -151,7 +151,10 @@ impl LineMap { .into() } - pub fn text_line_range_offset_range(&self, text_line_range: Range) -> OffsetRange { + pub fn text_line_range_offset_range( + &self, + text_line_range: Range, + ) -> TextOffsetRange { (self.offset(TextPosition { line: text_line_range.start, col: 0.into(), @@ -165,7 +168,7 @@ impl LineMap { pub fn offset_range_from_text_line( &self, range_from_text_line: RangeFrom, - ) -> OffsetRangeFrom { + ) -> TextOffsetRangeFrom { (self.offset(TextPosition { line: range_from_text_line.start, col: 0.into(), @@ -176,7 +179,7 @@ impl LineMap { pub fn offset_range_to_text_line( &self, range_from_text_line: RangeTo, - ) -> OffsetRangeTo { + ) -> TextOffsetRangeTo { (..self.offset(TextPosition { line: range_from_text_line.end, col: 0.into(), @@ -187,7 +190,7 @@ impl LineMap { pub fn offset_range_inclusive_text_line( &self, range_from_text_line: RangeInclusive, - ) -> OffsetRange { + ) -> TextOffsetRange { (self.offset(TextPosition { line: *range_from_text_line.start(), col: 0.into(), @@ -201,7 +204,7 @@ impl LineMap { pub fn offset_range_to_inclusive_text_line( &self, range_from_text_line: RangeToInclusive, - ) -> OffsetRangeTo { + ) -> TextOffsetRangeTo { (..self.offset(TextPosition { line: range_from_text_line.end + 1, col: 0.into(), @@ -225,7 +228,7 @@ impl LineMap { } } - pub fn lines(&self, range: OffsetRange) -> impl Iterator + '_ { + pub fn lines(&self, range: TextOffsetRange) -> impl Iterator + '_ { let lo = self.newlines.partition_point(|&it| it < range.start()); let hi = self.newlines.partition_point(|&it| it <= range.end()); let all = iter::once(range.start()) @@ -234,7 +237,7 @@ impl LineMap { all.clone() .zip(all.skip(1)) - .map(|(lo, hi)| -> OffsetRange { (lo..hi).into() }) + .map(|(lo, hi)| -> TextOffsetRange { (lo..hi).into() }) .filter(|it| !it.is_empty()) } diff --git a/crates/protocols/husky-text-protocol/src/line_map/lsp.rs b/crates/protocols/husky-text-protocol/src/line_map/lsp.rs index 0fdc55d1ce..f51db753dc 100644 --- a/crates/protocols/husky-text-protocol/src/line_map/lsp.rs +++ b/crates/protocols/husky-text-protocol/src/line_map/lsp.rs @@ -3,13 +3,13 @@ use super::*; #[cfg(feature = "lsp_support")] impl LineMap { #[cfg(feature = "lsp_support")] - pub fn string_range(line_map: &LineMap, range: lsp_types::Range) -> OffsetRange { + pub fn string_range(line_map: &LineMap, range: lsp_types::Range) -> TextOffsetRange { let start = line_map.lsp_offset(range.start); let end = line_map.lsp_offset(range.end); (start..end).into() } - pub(crate) fn lsp_offset(&self, position: lsp_types::Position) -> Offset { + pub(crate) fn lsp_offset(&self, position: lsp_types::Position) -> TextOffset { let line_col = TextPosition { line: position.line.into(), col: position.character.into(), diff --git a/crates/protocols/husky-text-protocol/src/offset.rs b/crates/protocols/husky-text-protocol/src/offset.rs index a4dc397671..2e66508e68 100644 --- a/crates/protocols/husky-text-protocol/src/offset.rs +++ b/crates/protocols/husky-text-protocol/src/offset.rs @@ -9,47 +9,47 @@ use shifted_unsigned_int::ShiftedU32; Debug, PartialEq, Default, Eq, PartialOrd, Ord, Clone, Copy, Hash, Serialize, Deserialize, )] #[serde(transparent)] -pub struct Offset(ShiftedU32); +pub struct TextOffset(ShiftedU32); -impl Offset { +impl TextOffset { pub fn index(self) -> usize { self.0.index() } } -impl From for Offset { +impl From for TextOffset { fn from(raw: i32) -> Self { - Offset(ShiftedU32::from(raw)) + TextOffset(ShiftedU32::from(raw)) } } -impl From for Offset { +impl From for TextOffset { fn from(raw: usize) -> Self { - Offset(ShiftedU32::from(raw)) + TextOffset(ShiftedU32::from(raw)) } } -impl From for Offset { +impl From for TextOffset { fn from(raw: u32) -> Self { - Offset(ShiftedU32::from(raw)) + TextOffset(ShiftedU32::from(raw)) } } -impl std::ops::Add for Offset { - type Output = Offset; +impl std::ops::Add for TextOffset { + type Output = TextOffset; fn add(self, rhs: usize) -> Self::Output { - Offset(self.0 + rhs) + TextOffset(self.0 + rhs) } } -impl std::ops::AddAssign for Offset { +impl std::ops::AddAssign for TextOffset { fn add_assign(&mut self, rhs: usize) { self.0 += rhs; } } -impl std::ops::Sub for Offset { +impl std::ops::Sub for TextOffset { type Output = usize; fn sub(self, rhs: Self) -> Self::Output { @@ -62,13 +62,13 @@ impl std::ops::Sub for Offset { #[derive( Debug, PartialEq, Default, Eq, PartialOrd, Ord, Clone, Copy, Hash, Serialize, Deserialize, )] -pub struct OffsetRange { - start: Offset, - end: Offset, +pub struct TextOffsetRange { + start: TextOffset, + end: TextOffset, } -impl From> for OffsetRange { - fn from(range: Range) -> Self { +impl From> for TextOffsetRange { + fn from(range: Range) -> Self { Self { start: range.start, end: range.end, @@ -76,14 +76,14 @@ impl From> for OffsetRange { } } -impl Into> for OffsetRange { +impl Into> for TextOffsetRange { fn into(self) -> Range { self.raw() } } -impl OffsetRange { - pub fn new(start: Offset, end: Offset) -> Self { +impl TextOffsetRange { + pub fn new(start: TextOffset, end: TextOffset) -> Self { Self { start, end } } @@ -92,12 +92,12 @@ impl OffsetRange { } } -impl OffsetRange { - pub fn start(self) -> Offset { +impl TextOffsetRange { + pub fn start(self) -> TextOffset { self.start } - pub fn end(self) -> Offset { + pub fn end(self) -> TextOffset { self.end } @@ -106,30 +106,30 @@ impl OffsetRange { } } -impl std::ops::Index for str { +impl std::ops::Index for str { type Output = str; - fn index(&self, range: OffsetRange) -> &Self::Output { + fn index(&self, range: TextOffsetRange) -> &Self::Output { &self[range.start.index()..range.end.index()] } } #[derive(Debug, PartialEq, Eq, Clone, Copy, Hash, Serialize, Deserialize)] #[serde(transparent)] -pub struct OffsetRangeFrom { - start: Offset, +pub struct TextOffsetRangeFrom { + start: TextOffset, } -impl From> for OffsetRangeFrom { - fn from(range: RangeFrom) -> Self { +impl From> for TextOffsetRangeFrom { + fn from(range: RangeFrom) -> Self { Self { start: range.start } } } -impl std::ops::Index for str { +impl std::ops::Index for str { type Output = str; - fn index(&self, range: OffsetRangeFrom) -> &Self::Output { + fn index(&self, range: TextOffsetRangeFrom) -> &Self::Output { &self[range.start.index()..] } } @@ -138,18 +138,18 @@ impl std::ops::Index for str { Debug, PartialEq, Default, Eq, PartialOrd, Ord, Clone, Copy, Hash, Serialize, Deserialize, )] #[serde(transparent)] -pub struct OffsetRangeTo { - end: Offset, +pub struct TextOffsetRangeTo { + end: TextOffset, } -impl From> for OffsetRangeTo { - fn from(range: RangeTo) -> Self { +impl From> for TextOffsetRangeTo { + fn from(range: RangeTo) -> Self { Self { end: range.end } } } -impl OffsetRangeTo { - pub fn end(self) -> Offset { +impl TextOffsetRangeTo { + pub fn end(self) -> TextOffset { self.end } @@ -158,10 +158,10 @@ impl OffsetRangeTo { } } -impl std::ops::Index for str { +impl std::ops::Index for str { type Output = str; - fn index(&self, range: OffsetRangeTo) -> &Self::Output { + fn index(&self, range: TextOffsetRangeTo) -> &Self::Output { &self[range.raw()] } } diff --git a/crates/semantics/husky-sem-expr/src/helpers/codespan.rs b/crates/semantics/husky-sem-expr/src/helpers/codespan.rs index 9f153dc715..3f0c6bdd1e 100644 --- a/crates/semantics/husky-sem-expr/src/helpers/codespan.rs +++ b/crates/semantics/husky-sem-expr/src/helpers/codespan.rs @@ -11,7 +11,7 @@ use husky_entity_path::region::RegionPath; use husky_entity_tree::helpers::tokra_region::HasRegionalTokenIdxBase; use husky_regional_token::RegionalTokenIdxBase; use husky_text::{HasText, Text}; -use husky_text_protocol::offset::OffsetRange; +use husky_text_protocol::offset::TextOffsetRange; use husky_token::{RangedTokenSheet, TokenDb}; use husky_vfs::path::module_path::ModulePath; use salsa::DisplayWithDb; @@ -134,7 +134,7 @@ impl<'a> SemExprCodespanEmitter<'a> { /// # getters impl<'a> SemExprCodespanEmitter<'a> { - fn expr_offset_range(&self, expr: SemExprIdx) -> OffsetRange { + fn expr_offset_range(&self, expr: SemExprIdx) -> TextOffsetRange { let token_idx_range = self.sem_expr_range_region_data[expr].token_idx_range(self.regional_token_idx_base); let text_range = self.ranged_token_sheet.tokens_text_range(token_idx_range); diff --git a/crates/syntax/husky-syn-expr/src/helpers/codespan.rs b/crates/syntax/husky-syn-expr/src/helpers/codespan.rs index 16dcb4fb0f..960cf0784b 100644 --- a/crates/syntax/husky-syn-expr/src/helpers/codespan.rs +++ b/crates/syntax/husky-syn-expr/src/helpers/codespan.rs @@ -17,7 +17,7 @@ use husky_entity_tree::{ }; use husky_regional_token::RegionalTokenIdxBase; use husky_text::{HasText, Text}; -use husky_text_protocol::offset::OffsetRange; +use husky_text_protocol::offset::TextOffsetRange; use husky_token::{RangedTokenSheet, TokenDb}; use husky_vfs::path::module_path::ModulePath; use salsa::DisplayWithDb; @@ -170,14 +170,14 @@ impl<'a> SynExprCodespanEmitter<'a> { /// # getters impl<'a> SynExprCodespanEmitter<'a> { - fn expr_offset_range(&self, expr: SynExprIdx) -> OffsetRange { + fn expr_offset_range(&self, expr: SynExprIdx) -> TextOffsetRange { let token_idx_range = self.syn_expr_range_region[expr].token_idx_range(self.regional_token_idx_base); let text_range = self.ranged_token_sheet.tokens_text_range(token_idx_range); self.text.offset_range(text_range) } - fn pattern_offset_range(&self, pattern: SynPatternIdx) -> OffsetRange { + fn pattern_offset_range(&self, pattern: SynPatternIdx) -> TextOffsetRange { let token_idx_range = self.syn_expr_range_region[pattern].token_idx_range(self.regional_token_idx_base); let text_range = self.ranged_token_sheet.tokens_text_range(token_idx_range);