Enable offset-encoding capability
This commit is contained in:
parent
c8b9ec8e62
commit
f3d56b89c5
@ -8,7 +8,7 @@ use std::{convert::TryFrom, env, fs, path::PathBuf, process};
|
||||
|
||||
use lsp_server::Connection;
|
||||
use project_model::ProjectManifest;
|
||||
use rust_analyzer::{cli, config::Config, from_json, Result};
|
||||
use rust_analyzer::{cli, config::Config, from_json, lsp_ext::supports_utf8, Result};
|
||||
use vfs::AbsPathBuf;
|
||||
|
||||
#[cfg(all(feature = "mimalloc"))]
|
||||
@ -127,7 +127,11 @@ fn run_server() -> Result<()> {
|
||||
name: String::from("rust-analyzer"),
|
||||
version: Some(String::from(env!("REV"))),
|
||||
}),
|
||||
offset_encoding: None,
|
||||
offset_encoding: if supports_utf8(&initialize_params.capabilities) {
|
||||
Some("utf-8".to_string())
|
||||
} else {
|
||||
None
|
||||
},
|
||||
};
|
||||
|
||||
let initialize_result = serde_json::to_value(initialize_result).unwrap();
|
||||
|
@ -23,7 +23,10 @@ use rustc_hash::FxHashSet;
|
||||
use serde::{de::DeserializeOwned, Deserialize};
|
||||
use vfs::AbsPathBuf;
|
||||
|
||||
use crate::{caps::completion_item_edit_resolve, diagnostics::DiagnosticsMapConfig};
|
||||
use crate::{
|
||||
caps::completion_item_edit_resolve, diagnostics::DiagnosticsMapConfig,
|
||||
line_endings::OffsetEncoding, lsp_ext::supports_utf8,
|
||||
};
|
||||
|
||||
config_data! {
|
||||
struct ConfigData {
|
||||
@ -415,6 +418,13 @@ impl Config {
|
||||
false
|
||||
)
|
||||
}
|
||||
pub fn offset_encoding(&self) -> OffsetEncoding {
|
||||
if supports_utf8(&self.caps) {
|
||||
OffsetEncoding::Utf8
|
||||
} else {
|
||||
OffsetEncoding::Utf16
|
||||
}
|
||||
}
|
||||
|
||||
fn experimental(&self, index: &'static str) -> bool {
|
||||
try_or!(self.caps.experimental.as_ref()?.get(index)?.as_bool()?, false)
|
||||
|
@ -22,7 +22,7 @@ use crate::{
|
||||
diagnostics::{CheckFixes, DiagnosticCollection},
|
||||
document::DocumentData,
|
||||
from_proto,
|
||||
line_endings::{LineEndings, LineIndex, OffsetEncoding},
|
||||
line_endings::{LineEndings, LineIndex},
|
||||
main_loop::Task,
|
||||
op_queue::OpQueue,
|
||||
reload::SourceRootConfig,
|
||||
@ -274,7 +274,7 @@ impl GlobalStateSnapshot {
|
||||
pub(crate) fn file_line_index(&self, file_id: FileId) -> Cancelable<LineIndex> {
|
||||
let endings = self.vfs.read().1[&file_id];
|
||||
let index = self.analysis.file_line_index(file_id)?;
|
||||
let res = LineIndex { index, endings, encoding: OffsetEncoding::Utf16 };
|
||||
let res = LineIndex { index, endings, encoding: self.config.offset_encoding() };
|
||||
Ok(res)
|
||||
}
|
||||
|
||||
|
@ -4,8 +4,7 @@
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
pub(crate) enum OffsetEncoding {
|
||||
#[allow(unused)]
|
||||
pub enum OffsetEncoding {
|
||||
Utf8,
|
||||
Utf16,
|
||||
}
|
||||
|
@ -385,3 +385,7 @@ pub(crate) enum CodeLensResolveData {
|
||||
Impls(lsp_types::request::GotoImplementationParams),
|
||||
References(lsp_types::TextDocumentPositionParams),
|
||||
}
|
||||
|
||||
pub fn supports_utf8(caps: &lsp_types::ClientCapabilities) -> bool {
|
||||
caps.offset_encoding.as_deref().unwrap_or_default().iter().any(|it| it == "utf-8")
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user