mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-03 07:04:49 +00:00
Enable offset-encoding capability
This commit is contained in:
parent
c8b9ec8e62
commit
f3d56b89c5
5 changed files with 24 additions and 7 deletions
|
@ -8,7 +8,7 @@ use std::{convert::TryFrom, env, fs, path::PathBuf, process};
|
||||||
|
|
||||||
use lsp_server::Connection;
|
use lsp_server::Connection;
|
||||||
use project_model::ProjectManifest;
|
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;
|
use vfs::AbsPathBuf;
|
||||||
|
|
||||||
#[cfg(all(feature = "mimalloc"))]
|
#[cfg(all(feature = "mimalloc"))]
|
||||||
|
@ -127,7 +127,11 @@ fn run_server() -> Result<()> {
|
||||||
name: String::from("rust-analyzer"),
|
name: String::from("rust-analyzer"),
|
||||||
version: Some(String::from(env!("REV"))),
|
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();
|
let initialize_result = serde_json::to_value(initialize_result).unwrap();
|
||||||
|
|
|
@ -23,7 +23,10 @@ use rustc_hash::FxHashSet;
|
||||||
use serde::{de::DeserializeOwned, Deserialize};
|
use serde::{de::DeserializeOwned, Deserialize};
|
||||||
use vfs::AbsPathBuf;
|
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! {
|
config_data! {
|
||||||
struct ConfigData {
|
struct ConfigData {
|
||||||
|
@ -415,6 +418,13 @@ impl Config {
|
||||||
false
|
false
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
pub fn offset_encoding(&self) -> OffsetEncoding {
|
||||||
|
if supports_utf8(&self.caps) {
|
||||||
|
OffsetEncoding::Utf8
|
||||||
|
} else {
|
||||||
|
OffsetEncoding::Utf16
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn experimental(&self, index: &'static str) -> bool {
|
fn experimental(&self, index: &'static str) -> bool {
|
||||||
try_or!(self.caps.experimental.as_ref()?.get(index)?.as_bool()?, false)
|
try_or!(self.caps.experimental.as_ref()?.get(index)?.as_bool()?, false)
|
||||||
|
|
|
@ -22,7 +22,7 @@ use crate::{
|
||||||
diagnostics::{CheckFixes, DiagnosticCollection},
|
diagnostics::{CheckFixes, DiagnosticCollection},
|
||||||
document::DocumentData,
|
document::DocumentData,
|
||||||
from_proto,
|
from_proto,
|
||||||
line_endings::{LineEndings, LineIndex, OffsetEncoding},
|
line_endings::{LineEndings, LineIndex},
|
||||||
main_loop::Task,
|
main_loop::Task,
|
||||||
op_queue::OpQueue,
|
op_queue::OpQueue,
|
||||||
reload::SourceRootConfig,
|
reload::SourceRootConfig,
|
||||||
|
@ -274,7 +274,7 @@ impl GlobalStateSnapshot {
|
||||||
pub(crate) fn file_line_index(&self, file_id: FileId) -> Cancelable<LineIndex> {
|
pub(crate) fn file_line_index(&self, file_id: FileId) -> Cancelable<LineIndex> {
|
||||||
let endings = self.vfs.read().1[&file_id];
|
let endings = self.vfs.read().1[&file_id];
|
||||||
let index = self.analysis.file_line_index(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)
|
Ok(res)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,8 +4,7 @@
|
||||||
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
pub(crate) enum OffsetEncoding {
|
pub enum OffsetEncoding {
|
||||||
#[allow(unused)]
|
|
||||||
Utf8,
|
Utf8,
|
||||||
Utf16,
|
Utf16,
|
||||||
}
|
}
|
||||||
|
|
|
@ -385,3 +385,7 @@ pub(crate) enum CodeLensResolveData {
|
||||||
Impls(lsp_types::request::GotoImplementationParams),
|
Impls(lsp_types::request::GotoImplementationParams),
|
||||||
References(lsp_types::TextDocumentPositionParams),
|
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…
Add table
Add a link
Reference in a new issue