@@ -6,6 +6,7 @@ use crate::{
66
77use helix_core::{find_root, ChangeSet, Rope};
88use helix_loader::{self, VERSION_AND_GIT_HASH};
9+use lsp::PositionEncodingKind;
910use lsp_types as lsp;
1011use serde::Deserialize;
1112use serde_json::Value;
@@ -32,7 +33,6 @@ pub struct Client {
3233 server_tx: UnboundedSender<Payload>,
3334 request_counter: AtomicU64,
3435 pub(crate) capabilities: OnceCell<lsp::ServerCapabilities>,
35− offset_encoding: OffsetEncoding,
3636 config: Option<Value>,
3737 root_path: std::path::PathBuf,
3838 root_uri: Option<lsp::Url>,
@@ -104,7 +104,6 @@ impl Client {
104104 server_tx,
105105 request_counter: AtomicU64::new(0),
106106 capabilities: OnceCell::new(),
107− offset_encoding: OffsetEncoding::Utf16,
108107 config,
109108 req_timeout,
110109
@@ -147,7 +146,19 @@ impl Client {
147146 }
148147
149148 pub fn offset_encoding(&self) -> OffsetEncoding {
150− self.offset_encoding
149+ self.capabilities()
150+ .position_encoding
151+ .as_ref()
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),
156+ encoding => {
157+ log::error!("Server provided invalid position encording {encoding}, defaulting to utf-16");
158+ None
159+ },
160+ })
161+ .unwrap_or_default()
151162 }
152163
153164 pub fn config(&self) -> Option<&Value> {
@@ -377,6 +388,14 @@ impl Client {
377388 work_done_progress: Some(true),
378389 ..Default::default()
379390 }),
391+ general: Some(lsp::GeneralClientCapabilities {
392+ position_encodings: Some(vec![
393+ PositionEncodingKind::UTF32,
394+ PositionEncodingKind::UTF8,
395+ PositionEncodingKind::UTF16,
396+ ]),
397+ ..Default::default()
398+ }),
380399 ..Default::default()
381400 },
382401 trace: None,
@@ -577,7 +596,7 @@ impl Client {
577596 }]
578597 }
579598 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())
581600 }
582601 lsp::TextDocumentSyncKind::NONE => return None,
583602 kind => unimplemented!("{:?}", kind),
@@ -1027,7 +1046,7 @@ impl Client {
10271046 partial_result_params: lsp::PartialResultParams::default(),
10281047 };
10291048
1030− Some(self.call::<lsp::request::WorkspaceSymbol>(params))
1049+ Some(self.call::<lsp::request::WorkspaceSymbolRequest>(params))
10311050 }
10321051
10331052 pub fn code_actions(