diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-11-16 11:22:40 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-11-16 11:22:40 +0000 |
commit | 97532c8bf74b96336c1c553171b3ee787edbc66a (patch) | |
tree | ec9b9ab4d9849cfbe30127eaf4f984dd97571e63 /crates/ra_lsp_server | |
parent | 923483e321acace3bbf38688bd70d4d38f49b35e (diff) | |
parent | acd51cb361720458615bd1ceb909b0f4461328df (diff) |
Merge #227
227: Correctly map between UTF-8 and UTF-16 positions r=aochagavia a=aochagavia
Fixes #202
Co-authored-by: Adolfo OchagavĂa <[email protected]>
Co-authored-by: Adolfo OchagavĂa <[email protected]>
Diffstat (limited to 'crates/ra_lsp_server')
-rw-r--r-- | crates/ra_lsp_server/src/conv.rs | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/crates/ra_lsp_server/src/conv.rs b/crates/ra_lsp_server/src/conv.rs index e5a2449c2..5d5a0c55e 100644 --- a/crates/ra_lsp_server/src/conv.rs +++ b/crates/ra_lsp_server/src/conv.rs | |||
@@ -49,10 +49,9 @@ impl ConvWith for Position { | |||
49 | type Output = TextUnit; | 49 | type Output = TextUnit; |
50 | 50 | ||
51 | fn conv_with(self, line_index: &LineIndex) -> TextUnit { | 51 | fn conv_with(self, line_index: &LineIndex) -> TextUnit { |
52 | // TODO: UTF-16 | ||
53 | let line_col = LineCol { | 52 | let line_col = LineCol { |
54 | line: self.line as u32, | 53 | line: self.line as u32, |
55 | col: (self.character as u32).into(), | 54 | col_utf16: self.character as u32, |
56 | }; | 55 | }; |
57 | line_index.offset(line_col) | 56 | line_index.offset(line_col) |
58 | } | 57 | } |
@@ -64,8 +63,10 @@ impl ConvWith for TextUnit { | |||
64 | 63 | ||
65 | fn conv_with(self, line_index: &LineIndex) -> Position { | 64 | fn conv_with(self, line_index: &LineIndex) -> Position { |
66 | let line_col = line_index.line_col(self); | 65 | let line_col = line_index.line_col(self); |
67 | // TODO: UTF-16 | 66 | Position::new( |
68 | Position::new(u64::from(line_col.line), u64::from(u32::from(line_col.col))) | 67 | u64::from(line_col.line), |
68 | u64::from(u32::from(line_col.col_utf16)), | ||
69 | ) | ||
69 | } | 70 | } |
70 | } | 71 | } |
71 | 72 | ||
@@ -203,8 +204,10 @@ impl TryConvWith for SourceChange { | |||
203 | .map(|it| it.edits.as_slice()) | 204 | .map(|it| it.edits.as_slice()) |
204 | .unwrap_or(&[]); | 205 | .unwrap_or(&[]); |
205 | let line_col = translate_offset_with_edit(&*line_index, pos.offset, edits); | 206 | let line_col = translate_offset_with_edit(&*line_index, pos.offset, edits); |
206 | let position = | 207 | let position = Position::new( |
207 | Position::new(u64::from(line_col.line), u64::from(u32::from(line_col.col))); | 208 | u64::from(line_col.line), |
209 | u64::from(u32::from(line_col.col_utf16)), | ||
210 | ); | ||
208 | Some(TextDocumentPositionParams { | 211 | Some(TextDocumentPositionParams { |
209 | text_document: TextDocumentIdentifier::new(pos.file_id.try_conv_with(world)?), | 212 | text_document: TextDocumentIdentifier::new(pos.file_id.try_conv_with(world)?), |
210 | position, | 213 | position, |
@@ -247,12 +250,12 @@ fn translate_offset_with_edit( | |||
247 | if in_edit_line_col.line == 0 { | 250 | if in_edit_line_col.line == 0 { |
248 | LineCol { | 251 | LineCol { |
249 | line: edit_line_col.line, | 252 | line: edit_line_col.line, |
250 | col: edit_line_col.col + in_edit_line_col.col, | 253 | col_utf16: edit_line_col.col_utf16 + in_edit_line_col.col_utf16, |
251 | } | 254 | } |
252 | } else { | 255 | } else { |
253 | LineCol { | 256 | LineCol { |
254 | line: edit_line_col.line + in_edit_line_col.line, | 257 | line: edit_line_col.line + in_edit_line_col.line, |
255 | col: in_edit_line_col.col, | 258 | col_utf16: in_edit_line_col.col_utf16, |
256 | } | 259 | } |
257 | } | 260 | } |
258 | } | 261 | } |