fix: Handle unicode in codespan_lsp outside of the first line

This commit is contained in:
Markus Westerlind
2020-07-12 22:22:21 +02:00
parent cfd3878c3d
commit 696f1d2dbb
+13 -2
View File
@@ -229,8 +229,9 @@ where
let source = source.as_ref();
let line_span = files.line_range(file_id, position.line as usize).unwrap();
let line_str = source.get(line_span.clone()).unwrap();
let byte_offset = character_to_line_offset(source, position.character)?;
let byte_offset = character_to_line_offset(line_str, position.character)?;
Ok(line_span.start + byte_offset)
}
@@ -314,7 +315,8 @@ test
#[test]
fn unicode_get_position() {
let mut files = SimpleFiles::new();
let file_id = files.add("unicode", UNICODE);
let file_id = files.add("unicode", UNICODE.to_string());
let file_id2 = files.add("unicode newline", "\n".to_string() + UNICODE);
let result = byte_index_to_position(&files, file_id, 5);
assert_eq!(
@@ -333,5 +335,14 @@ test
character: 6,
})
);
let result = byte_index_to_position(&files, file_id2, 11);
assert_eq!(
result,
Ok(LspPosition {
line: 1,
character: 6,
})
);
}
}