aboutsummaryrefslogtreecommitdiff
path: root/helix-term/src
diff options
context:
space:
mode:
authorMichael Davis2023-06-29 15:24:13 +0000
committerGitHub2023-06-29 15:24:13 +0000
commit4fab60030fbf5b44d770618336f21897226db4cd (patch)
treeaf51ac157543dcb99b16db3259a3b46254ca3c25 /helix-term/src
parentd3f8e0592bd577489369e5bd00cddf159f107a24 (diff)
LSP: Use negotiated position encoding for workspace edits (#7469)
Previously this was hard-coded to UTF-8 but we might have negotiated another position encoding.
Diffstat (limited to 'helix-term/src')
-rw-r--r--helix-term/src/application.rs39
1 files changed, 25 insertions, 14 deletions
diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs
index b0f9e3ac..e1a622f9 100644
--- a/helix-term/src/application.rs
+++ b/helix-term/src/application.rs
@@ -1047,20 +1047,31 @@ impl Application {
Ok(serde_json::Value::Null)
}
Ok(MethodCall::ApplyWorkspaceEdit(params)) => {
- let res = apply_workspace_edit(
- &mut self.editor,
- helix_lsp::OffsetEncoding::Utf8,
- &params.edit,
- );
-
- Ok(json!(lsp::ApplyWorkspaceEditResponse {
- applied: res.is_ok(),
- failure_reason: res.as_ref().err().map(|err| err.kind.to_string()),
- failed_change: res
- .as_ref()
- .err()
- .map(|err| err.failed_change_idx as u32),
- }))
+ let language_server = language_server!();
+ if language_server.is_initialized() {
+ let offset_encoding = language_server.offset_encoding();
+ let res = apply_workspace_edit(
+ &mut self.editor,
+ offset_encoding,
+ &params.edit,
+ );
+
+ Ok(json!(lsp::ApplyWorkspaceEditResponse {
+ applied: res.is_ok(),
+ failure_reason: res.as_ref().err().map(|err| err.kind.to_string()),
+ failed_change: res
+ .as_ref()
+ .err()
+ .map(|err| err.failed_change_idx as u32),
+ }))
+ } else {
+ Err(helix_lsp::jsonrpc::Error {
+ code: helix_lsp::jsonrpc::ErrorCode::InvalidRequest,
+ message: "Server must be initialized to request workspace edits"
+ .to_string(),
+ data: None,
+ })
+ }
}
Ok(MethodCall::WorkspaceFolders) => {
Ok(json!(&*language_server!().workspace_folders().await))