Add validation in LspCommand::to_lsp + check for inverted ranges (#22731)

#22690 logged errors and flipped the range in this case. Instead it
brings more visibility to the issue to return errors.

Release Notes:

- N/A
This commit is contained in:
Michael Sloan 2025-01-06 15:00:36 -07:00 committed by GitHub
parent 1c223d8940
commit 141393232e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 134 additions and 162 deletions

View file

@ -3487,7 +3487,18 @@ impl LspStore {
};
let file = File::from_dyn(buffer.file()).and_then(File::as_local);
if let (Some(file), Some(language_server)) = (file, language_server) {
let lsp_params = request.to_lsp(&file.abs_path(cx), buffer, &language_server, cx);
let lsp_params = match request.to_lsp(&file.abs_path(cx), buffer, &language_server, cx)
{
Ok(lsp_params) => lsp_params,
Err(err) => {
log::error!(
"Preparing LSP request to {} failed: {}",
language_server.name(),
err
);
return Task::ready(Err(err));
}
};
let status = request.status();
return cx.spawn(move |this, cx| async move {
if !request.check_capabilities(language_server.adapter_server_capabilities()) {
@ -3536,11 +3547,7 @@ impl LspStore {
let result = lsp_request.await;
let response = result.map_err(|err| {
log::warn!(
"Generic lsp request to {} failed: {}",
language_server.name(),
err
);
log::warn!("LSP request to {} failed: {}", language_server.name(), err);
err
})?;