Make utf8 default, implement utf16 in terms of it

This commit is contained in:
Aleksey Kladov 2021-02-12 22:09:53 +03:00
parent 00cc778c8c
commit 95209aa3f8
6 changed files with 28 additions and 11 deletions

View file

@ -5,7 +5,7 @@ use std::{env, path::PathBuf, str::FromStr, sync::Arc, time::Instant};
use anyhow::{bail, format_err, Result};
use hir::PrefixKind;
use ide::{
Analysis, AnalysisHost, Change, CompletionConfig, DiagnosticsConfig, FilePosition, LineColUtf16,
Analysis, AnalysisHost, Change, CompletionConfig, DiagnosticsConfig, FilePosition, LineCol,
};
use ide_db::{
base_db::{
@ -97,7 +97,7 @@ impl BenchCmd {
let offset = host
.analysis()
.file_line_index(file_id)?
.offset(LineColUtf16 { line: pos.line - 1, col: pos.column });
.offset(LineCol { line: pos.line - 1, col: pos.column });
let file_position = FilePosition { file_id, offset };
if is_completion {

View file

@ -19,6 +19,7 @@ pub(crate) fn vfs_path(url: &lsp_types::Url) -> Result<vfs::VfsPath> {
pub(crate) fn offset(line_index: &LineIndex, position: lsp_types::Position) -> TextSize {
let line_col = LineColUtf16 { line: position.line as u32, col: position.character as u32 };
let line_col = line_index.to_utf8(line_col);
line_index.offset(line_col)
}

View file

@ -22,6 +22,7 @@ use crate::{
pub(crate) fn position(line_index: &LineIndex, offset: TextSize) -> lsp_types::Position {
let line_col = line_index.line_col(offset);
let line_col = line_index.to_utf16(line_col);
lsp_types::Position::new(line_col.line, line_col.col)
}