on master help sign in
LSP: Use negotiated position encoding for workspace edits (#7469)
4fab600Michael Davis
helix-term/src/application.rs+25−14
@@ -1047,20 +1047,31 @@ impl Application {
1047 Ok(serde_json::Value::Null)
1047 Ok(serde_json::Value::Null)
1048 }
1048 }
1049 Ok(MethodCall::ApplyWorkspaceEdit(params)) => {
1049 Ok(MethodCall::ApplyWorkspaceEdit(params)) => {
1050+ let language_server = language_server!();
1051+ if language_server.is_initialized() {
1052+ let offset_encoding = language_server.offset_encoding();
1050− let res = apply_workspace_edit(
1053+ let res = apply_workspace_edit(
1051− &mut self.editor,
1054+ &mut self.editor,
1052− helix_lsp::OffsetEncoding::Utf8,
1055+ offset_encoding,
1053− &params.edit,
1056+ &params.edit,
1054− );
1057+ );
1055−
1058+
1056− Ok(json!(lsp::ApplyWorkspaceEditResponse {
1059+ Ok(json!(lsp::ApplyWorkspaceEditResponse {
1057− applied: res.is_ok(),
1060+ applied: res.is_ok(),
1058− failure_reason: res.as_ref().err().map(|err| err.kind.to_string()),
1061+ failure_reason: res.as_ref().err().map(|err| err.kind.to_string()),
1059− failed_change: res
1062+ failed_change: res
1060− .as_ref()
1063+ .as_ref()
1061− .err()
1064+ .err()
1062− .map(|err| err.failed_change_idx as u32),
1065+ .map(|err| err.failed_change_idx as u32),
1066+ }))
1067+ } else {
1068+ Err(helix_lsp::jsonrpc::Error {
1069+ code: helix_lsp::jsonrpc::ErrorCode::InvalidRequest,
1070+ message: "Server must be initialized to request workspace edits"
1071+ .to_string(),
1072+ data: None,
1063− }))
1073+ })
1074+ }
1064 }
1075 }
1065 Ok(MethodCall::WorkspaceFolders) => {
1076 Ok(MethodCall::WorkspaceFolders) => {
1066 Ok(json!(&*language_server!().workspace_folders().await))
1077 Ok(json!(&*language_server!().workspace_folders().await))