@@ -6,6 +6,7 @@ use crate::{
7use helix_core::{find_root, ChangeSet, Rope};
7use helix_core::{find_root, ChangeSet, Rope};
8use helix_loader::{self, VERSION_AND_GIT_HASH};
8use helix_loader::{self, VERSION_AND_GIT_HASH};
9+use lsp::PositionEncodingKind;
9use lsp_types as lsp;
10use lsp_types as lsp;
10use serde::Deserialize;
11use serde::Deserialize;
11use serde_json::Value;
12use serde_json::Value;
@@ -32,7 +33,6 @@ pub struct Client {
32 server_tx: UnboundedSender<Payload>,
33 server_tx: UnboundedSender<Payload>,
33 request_counter: AtomicU64,
34 request_counter: AtomicU64,
34 pub(crate) capabilities: OnceCell<lsp::ServerCapabilities>,
35 pub(crate) capabilities: OnceCell<lsp::ServerCapabilities>,
35− offset_encoding: OffsetEncoding,
36 config: Option<Value>,
36 config: Option<Value>,
37 root_path: std::path::PathBuf,
37 root_path: std::path::PathBuf,
38 root_uri: Option<lsp::Url>,
38 root_uri: Option<lsp::Url>,
@@ -104,7 +104,6 @@ impl Client {
104 server_tx,
104 server_tx,
105 request_counter: AtomicU64::new(0),
105 request_counter: AtomicU64::new(0),
106 capabilities: OnceCell::new(),
106 capabilities: OnceCell::new(),
107− offset_encoding: OffsetEncoding::Utf16,
109 req_timeout,
108 req_timeout,
@@ -147,7 +146,19 @@ impl Client {
149 pub fn offset_encoding(&self) -> OffsetEncoding {
148 pub fn offset_encoding(&self) -> OffsetEncoding {
150− self.offset_encoding
149+ self.capabilities()
152+ .and_then(|encoding| match encoding.as_str() {
153+ "utf-8" => Some(OffsetEncoding::Utf8),
154+ "utf-16" => Some(OffsetEncoding::Utf16),
155+ "utf-32" => Some(OffsetEncoding::Utf32),
157+ log::error!("Server provided invalid position encording {encoding}, defaulting to utf-16");
161+ .unwrap_or_default()
153 pub fn config(&self) -> Option<&Value> {
164 pub fn config(&self) -> Option<&Value> {
@@ -377,6 +388,14 @@ impl Client {
377 work_done_progress: Some(true),
388 work_done_progress: Some(true),
378 ..Default::default()
389 ..Default::default()
391+ general: Some(lsp::GeneralClientCapabilities {
392+ position_encodings: Some(vec![
393+ PositionEncodingKind::UTF32,
394+ PositionEncodingKind::UTF8,
395+ PositionEncodingKind::UTF16,
397+ ..Default::default()
380 ..Default::default()
399 ..Default::default()
382 trace: None,
401 trace: None,
@@ -577,7 +596,7 @@ impl Client {
579 lsp::TextDocumentSyncKind::INCREMENTAL => {
598 lsp::TextDocumentSyncKind::INCREMENTAL => {
580− Self::changeset_to_changes(old_text, new_text, changes, self.offset_encoding)
599+ Self::changeset_to_changes(old_text, new_text, changes, self.offset_encoding())
582 lsp::TextDocumentSyncKind::NONE => return None,
601 lsp::TextDocumentSyncKind::NONE => return None,
583 kind => unimplemented!("{:?}", kind),
602 kind => unimplemented!("{:?}", kind),
@@ -1027,7 +1046,7 @@ impl Client {
1027 partial_result_params: lsp::PartialResultParams::default(),
1046 partial_result_params: lsp::PartialResultParams::default(),
1030− Some(self.call::<lsp::request::WorkspaceSymbol>(params))
1049+ Some(self.call::<lsp::request::WorkspaceSymbolRequest>(params))
1033 pub fn code_actions(
1052 pub fn code_actions(