From 5be2ec5ced8dd4089e112e344f3bf67c8ebfdb83 Mon Sep 17 00:00:00 2001 From: konstin Date: Tue, 26 Sep 2023 14:21:03 +0200 Subject: [PATCH] Review --- crates/ruff_source_file/src/locator.rs | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/crates/ruff_source_file/src/locator.rs b/crates/ruff_source_file/src/locator.rs index fb059c04df..31c5ab3c10 100644 --- a/crates/ruff_source_file/src/locator.rs +++ b/crates/ruff_source_file/src/locator.rs @@ -504,17 +504,13 @@ impl<'a> Locator<'a> { /// assert_eq!(&source[TextRange::new(offset, source.text_len())], "腐'"); /// ``` pub fn convert_row_and_column_utf16(&self, row: usize, column: usize) -> Option { - let line_range = *self.to_index().line_range(row) - let line_contents = &self.contents[TextRange::from(line_start..next_line_start)]; + let line_range = self + .to_index() + .line_range(OneIndexed::from_zero_indexed(row), self.contents); let mut len_bytes = TextSize::default(); let mut len_utf16 = 0; - for char in line_contents - .chars() - // Since the range goes to the next line start, `line_contents` contains the line - // break - .take_while(|c| *c != '\n' && *c != '\r') - { + for char in self.contents[line_range].chars() { // This check must be first for the 0 column case if len_utf16 >= column { break; @@ -526,7 +522,7 @@ impl<'a> Locator<'a> { return None; } - Some(line_start + len_bytes) + Some(line_range.start() + len_bytes) } /// Take the source code between the given [`TextRange`].