diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ide/src/lib.rs | 2 | ||||
-rw-r--r-- | crates/ide_db/src/line_index.rs | 12 | ||||
-rw-r--r-- | crates/ide_db/src/line_index/tests.rs | 28 | ||||
-rw-r--r-- | crates/rust-analyzer/src/cli/analysis_bench.rs | 4 | ||||
-rw-r--r-- | crates/rust-analyzer/src/cli/analysis_stats.rs | 8 | ||||
-rw-r--r-- | crates/rust-analyzer/src/from_proto.rs | 4 | ||||
-rw-r--r-- | crates/rust-analyzer/src/to_proto.rs | 2 |
7 files changed, 30 insertions, 30 deletions
diff --git a/crates/ide/src/lib.rs b/crates/ide/src/lib.rs index 89e7bef7d..68756f78a 100644 --- a/crates/ide/src/lib.rs +++ b/crates/ide/src/lib.rs | |||
@@ -95,7 +95,7 @@ pub use ide_db::{ | |||
95 | }, | 95 | }, |
96 | call_info::CallInfo, | 96 | call_info::CallInfo, |
97 | label::Label, | 97 | label::Label, |
98 | line_index::{LineCol, LineIndex}, | 98 | line_index::{LineColUtf16, LineIndex}, |
99 | search::{ReferenceAccess, SearchScope}, | 99 | search::{ReferenceAccess, SearchScope}, |
100 | source_change::{FileSystemEdit, SourceChange}, | 100 | source_change::{FileSystemEdit, SourceChange}, |
101 | symbol_index::Query, | 101 | symbol_index::Query, |
diff --git a/crates/ide_db/src/line_index.rs b/crates/ide_db/src/line_index.rs index 41226305e..490c172e3 100644 --- a/crates/ide_db/src/line_index.rs +++ b/crates/ide_db/src/line_index.rs | |||
@@ -15,11 +15,11 @@ pub struct LineIndex { | |||
15 | } | 15 | } |
16 | 16 | ||
17 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] | 17 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] |
18 | pub struct LineCol { | 18 | pub struct LineColUtf16 { |
19 | /// Zero-based | 19 | /// Zero-based |
20 | pub line: u32, | 20 | pub line: u32, |
21 | /// Zero-based | 21 | /// Zero-based |
22 | pub col_utf16: u32, | 22 | pub col: u32, |
23 | } | 23 | } |
24 | 24 | ||
25 | #[derive(Clone, Debug, Hash, PartialEq, Eq)] | 25 | #[derive(Clone, Debug, Hash, PartialEq, Eq)] |
@@ -88,17 +88,17 @@ impl LineIndex { | |||
88 | LineIndex { newlines, utf16_lines } | 88 | LineIndex { newlines, utf16_lines } |
89 | } | 89 | } |
90 | 90 | ||
91 | pub fn line_col(&self, offset: TextSize) -> LineCol { | 91 | pub fn line_col(&self, offset: TextSize) -> LineColUtf16 { |
92 | let line = partition_point(&self.newlines, |&it| it <= offset) - 1; | 92 | let line = partition_point(&self.newlines, |&it| it <= offset) - 1; |
93 | let line_start_offset = self.newlines[line]; | 93 | let line_start_offset = self.newlines[line]; |
94 | let col = offset - line_start_offset; | 94 | let col = offset - line_start_offset; |
95 | 95 | ||
96 | LineCol { line: line as u32, col_utf16: self.utf8_to_utf16_col(line as u32, col) as u32 } | 96 | LineColUtf16 { line: line as u32, col: self.utf8_to_utf16_col(line as u32, col) as u32 } |
97 | } | 97 | } |
98 | 98 | ||
99 | pub fn offset(&self, line_col: LineCol) -> TextSize { | 99 | pub fn offset(&self, line_col: LineColUtf16) -> TextSize { |
100 | //FIXME: return Result | 100 | //FIXME: return Result |
101 | let col = self.utf16_to_utf8_col(line_col.line, line_col.col_utf16); | 101 | let col = self.utf16_to_utf8_col(line_col.line, line_col.col); |
102 | self.newlines[line_col.line as usize] + col | 102 | self.newlines[line_col.line as usize] + col |
103 | } | 103 | } |
104 | 104 | ||
diff --git a/crates/ide_db/src/line_index/tests.rs b/crates/ide_db/src/line_index/tests.rs index 05f7484e8..1a109654e 100644 --- a/crates/ide_db/src/line_index/tests.rs +++ b/crates/ide_db/src/line_index/tests.rs | |||
@@ -4,23 +4,23 @@ use super::*; | |||
4 | fn test_line_index() { | 4 | fn test_line_index() { |
5 | let text = "hello\nworld"; | 5 | let text = "hello\nworld"; |
6 | let index = LineIndex::new(text); | 6 | let index = LineIndex::new(text); |
7 | assert_eq!(index.line_col(0.into()), LineCol { line: 0, col_utf16: 0 }); | 7 | assert_eq!(index.line_col(0.into()), LineColUtf16 { line: 0, col: 0 }); |
8 | assert_eq!(index.line_col(1.into()), LineCol { line: 0, col_utf16: 1 }); | 8 | assert_eq!(index.line_col(1.into()), LineColUtf16 { line: 0, col: 1 }); |
9 | assert_eq!(index.line_col(5.into()), LineCol { line: 0, col_utf16: 5 }); | 9 | assert_eq!(index.line_col(5.into()), LineColUtf16 { line: 0, col: 5 }); |
10 | assert_eq!(index.line_col(6.into()), LineCol { line: 1, col_utf16: 0 }); | 10 | assert_eq!(index.line_col(6.into()), LineColUtf16 { line: 1, col: 0 }); |
11 | assert_eq!(index.line_col(7.into()), LineCol { line: 1, col_utf16: 1 }); | 11 | assert_eq!(index.line_col(7.into()), LineColUtf16 { line: 1, col: 1 }); |
12 | assert_eq!(index.line_col(8.into()), LineCol { line: 1, col_utf16: 2 }); | 12 | assert_eq!(index.line_col(8.into()), LineColUtf16 { line: 1, col: 2 }); |
13 | assert_eq!(index.line_col(10.into()), LineCol { line: 1, col_utf16: 4 }); | 13 | assert_eq!(index.line_col(10.into()), LineColUtf16 { line: 1, col: 4 }); |
14 | assert_eq!(index.line_col(11.into()), LineCol { line: 1, col_utf16: 5 }); | 14 | assert_eq!(index.line_col(11.into()), LineColUtf16 { line: 1, col: 5 }); |
15 | assert_eq!(index.line_col(12.into()), LineCol { line: 1, col_utf16: 6 }); | 15 | assert_eq!(index.line_col(12.into()), LineColUtf16 { line: 1, col: 6 }); |
16 | 16 | ||
17 | let text = "\nhello\nworld"; | 17 | let text = "\nhello\nworld"; |
18 | let index = LineIndex::new(text); | 18 | let index = LineIndex::new(text); |
19 | assert_eq!(index.line_col(0.into()), LineCol { line: 0, col_utf16: 0 }); | 19 | assert_eq!(index.line_col(0.into()), LineColUtf16 { line: 0, col: 0 }); |
20 | assert_eq!(index.line_col(1.into()), LineCol { line: 1, col_utf16: 0 }); | 20 | assert_eq!(index.line_col(1.into()), LineColUtf16 { line: 1, col: 0 }); |
21 | assert_eq!(index.line_col(2.into()), LineCol { line: 1, col_utf16: 1 }); | 21 | assert_eq!(index.line_col(2.into()), LineColUtf16 { line: 1, col: 1 }); |
22 | assert_eq!(index.line_col(6.into()), LineCol { line: 1, col_utf16: 5 }); | 22 | assert_eq!(index.line_col(6.into()), LineColUtf16 { line: 1, col: 5 }); |
23 | assert_eq!(index.line_col(7.into()), LineCol { line: 2, col_utf16: 0 }); | 23 | assert_eq!(index.line_col(7.into()), LineColUtf16 { line: 2, col: 0 }); |
24 | } | 24 | } |
25 | 25 | ||
26 | #[test] | 26 | #[test] |
diff --git a/crates/rust-analyzer/src/cli/analysis_bench.rs b/crates/rust-analyzer/src/cli/analysis_bench.rs index 6735b6388..edf12faa4 100644 --- a/crates/rust-analyzer/src/cli/analysis_bench.rs +++ b/crates/rust-analyzer/src/cli/analysis_bench.rs | |||
@@ -5,7 +5,7 @@ use std::{env, path::PathBuf, str::FromStr, sync::Arc, time::Instant}; | |||
5 | use anyhow::{bail, format_err, Result}; | 5 | use anyhow::{bail, format_err, Result}; |
6 | use hir::PrefixKind; | 6 | use hir::PrefixKind; |
7 | use ide::{ | 7 | use ide::{ |
8 | Analysis, AnalysisHost, Change, CompletionConfig, DiagnosticsConfig, FilePosition, LineCol, | 8 | Analysis, AnalysisHost, Change, CompletionConfig, DiagnosticsConfig, FilePosition, LineColUtf16, |
9 | }; | 9 | }; |
10 | use ide_db::{ | 10 | use ide_db::{ |
11 | base_db::{ | 11 | base_db::{ |
@@ -97,7 +97,7 @@ impl BenchCmd { | |||
97 | let offset = host | 97 | let offset = host |
98 | .analysis() | 98 | .analysis() |
99 | .file_line_index(file_id)? | 99 | .file_line_index(file_id)? |
100 | .offset(LineCol { line: pos.line - 1, col_utf16: pos.column }); | 100 | .offset(LineColUtf16 { line: pos.line - 1, col: pos.column }); |
101 | let file_position = FilePosition { file_id, offset }; | 101 | let file_position = FilePosition { file_id, offset }; |
102 | 102 | ||
103 | if is_completion { | 103 | if is_completion { |
diff --git a/crates/rust-analyzer/src/cli/analysis_stats.rs b/crates/rust-analyzer/src/cli/analysis_stats.rs index 3417af687..6d6f398f4 100644 --- a/crates/rust-analyzer/src/cli/analysis_stats.rs +++ b/crates/rust-analyzer/src/cli/analysis_stats.rs | |||
@@ -218,9 +218,9 @@ impl AnalysisStatsCmd { | |||
218 | bar.println(format!( | 218 | bar.println(format!( |
219 | "{}:{}-{}:{}: {}", | 219 | "{}:{}-{}:{}: {}", |
220 | start.line + 1, | 220 | start.line + 1, |
221 | start.col_utf16, | 221 | start.col, |
222 | end.line + 1, | 222 | end.line + 1, |
223 | end.col_utf16, | 223 | end.col, |
224 | ty.display(db) | 224 | ty.display(db) |
225 | )); | 225 | )); |
226 | } else { | 226 | } else { |
@@ -250,9 +250,9 @@ impl AnalysisStatsCmd { | |||
250 | "{} {}:{}-{}:{}: Expected {}, got {}", | 250 | "{} {}:{}-{}:{}: Expected {}, got {}", |
251 | path, | 251 | path, |
252 | start.line + 1, | 252 | start.line + 1, |
253 | start.col_utf16, | 253 | start.col, |
254 | end.line + 1, | 254 | end.line + 1, |
255 | end.col_utf16, | 255 | end.col, |
256 | mismatch.expected.display(db), | 256 | mismatch.expected.display(db), |
257 | mismatch.actual.display(db) | 257 | mismatch.actual.display(db) |
258 | )); | 258 | )); |
diff --git a/crates/rust-analyzer/src/from_proto.rs b/crates/rust-analyzer/src/from_proto.rs index 6676eebf4..82e7cfa81 100644 --- a/crates/rust-analyzer/src/from_proto.rs +++ b/crates/rust-analyzer/src/from_proto.rs | |||
@@ -1,7 +1,7 @@ | |||
1 | //! Conversion lsp_types types to rust-analyzer specific ones. | 1 | //! Conversion lsp_types types to rust-analyzer specific ones. |
2 | use std::convert::TryFrom; | 2 | use std::convert::TryFrom; |
3 | 3 | ||
4 | use ide::{Annotation, AnnotationKind, AssistKind, LineCol, LineIndex}; | 4 | use ide::{Annotation, AnnotationKind, AssistKind, LineColUtf16, LineIndex}; |
5 | use ide_db::base_db::{FileId, FilePosition, FileRange}; | 5 | use ide_db::base_db::{FileId, FilePosition, FileRange}; |
6 | use syntax::{TextRange, TextSize}; | 6 | use syntax::{TextRange, TextSize}; |
7 | use vfs::AbsPathBuf; | 7 | use vfs::AbsPathBuf; |
@@ -18,7 +18,7 @@ pub(crate) fn vfs_path(url: &lsp_types::Url) -> Result<vfs::VfsPath> { | |||
18 | } | 18 | } |
19 | 19 | ||
20 | pub(crate) fn offset(line_index: &LineIndex, position: lsp_types::Position) -> TextSize { | 20 | pub(crate) fn offset(line_index: &LineIndex, position: lsp_types::Position) -> TextSize { |
21 | let line_col = LineCol { line: position.line as u32, col_utf16: position.character as u32 }; | 21 | let line_col = LineColUtf16 { line: position.line as u32, col: position.character as u32 }; |
22 | line_index.offset(line_col) | 22 | line_index.offset(line_col) |
23 | } | 23 | } |
24 | 24 | ||
diff --git a/crates/rust-analyzer/src/to_proto.rs b/crates/rust-analyzer/src/to_proto.rs index 8a2b4d9bd..599b5207c 100644 --- a/crates/rust-analyzer/src/to_proto.rs +++ b/crates/rust-analyzer/src/to_proto.rs | |||
@@ -22,7 +22,7 @@ use crate::{ | |||
22 | 22 | ||
23 | pub(crate) fn position(line_index: &LineIndex, offset: TextSize) -> lsp_types::Position { | 23 | pub(crate) fn position(line_index: &LineIndex, offset: TextSize) -> lsp_types::Position { |
24 | let line_col = line_index.line_col(offset); | 24 | let line_col = line_index.line_col(offset); |
25 | lsp_types::Position::new(line_col.line, line_col.col_utf16) | 25 | lsp_types::Position::new(line_col.line, line_col.col) |
26 | } | 26 | } |
27 | 27 | ||
28 | pub(crate) fn range(line_index: &LineIndex, range: TextRange) -> lsp_types::Range { | 28 | pub(crate) fn range(line_index: &LineIndex, range: TextRange) -> lsp_types::Range { |