Skip to content

Commit

Permalink
LSP: Use negotiated position encoding for workspace edits (helix-edit…
Browse files Browse the repository at this point in the history
…or#7469)

Previously this was hard-coded to UTF-8 but we might have negotiated
another position encoding.
  • Loading branch information
the-mikedavis authored and Schuyler Mortimer committed Jul 10, 2024
1 parent fe0e9a2 commit 2036c65
Showing 1 changed file with 24 additions and 13 deletions.
37 changes: 24 additions & 13 deletions helix-term/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1051,20 +1051,31 @@ impl Application {
Some(Ok(serde_json::Value::Null))
}
Ok(MethodCall::ApplyWorkspaceEdit(params)) => {
let res = apply_workspace_edit(
&mut self.editor,
helix_lsp::OffsetEncoding::Utf8,
&params.edit,
);
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,
);

Some(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),
})))
Some(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) => {
let language_server =
Expand Down

0 comments on commit 2036c65

Please sign in to comment.