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

@ -1,4 +1,5 @@
use crate::{range_to_lsp, Diagnostic};
use anyhow::Result;
use collections::HashMap;
use lsp::LanguageServerId;
use std::{
@ -54,16 +55,16 @@ pub struct Summary {
impl DiagnosticEntry<PointUtf16> {
/// Returns a raw LSP diagnostic used to provide diagnostic context to LSP
/// codeAction request
pub fn to_lsp_diagnostic_stub(&self) -> lsp::Diagnostic {
pub fn to_lsp_diagnostic_stub(&self) -> Result<lsp::Diagnostic> {
let code = self
.diagnostic
.code
.clone()
.map(lsp::NumberOrString::String);
let range = range_to_lsp(self.range.clone());
let range = range_to_lsp(self.range.clone())?;
lsp::Diagnostic {
Ok(lsp::Diagnostic {
code,
range,
severity: Some(self.diagnostic.severity),
@ -71,7 +72,7 @@ impl DiagnosticEntry<PointUtf16> {
message: self.diagnostic.message.clone(),
data: self.diagnostic.data.clone(),
..Default::default()
}
})
}
}