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:
parent
1c223d8940
commit
141393232e
6 changed files with 134 additions and 162 deletions
|
@ -1849,14 +1849,19 @@ pub fn point_from_lsp(point: lsp::Position) -> Unclipped<PointUtf16> {
|
|||
Unclipped(PointUtf16::new(point.line, point.character))
|
||||
}
|
||||
|
||||
pub fn range_to_lsp(range: Range<PointUtf16>) -> lsp::Range {
|
||||
let mut start = point_to_lsp(range.start);
|
||||
let mut end = point_to_lsp(range.end);
|
||||
if start > end {
|
||||
log::error!("range_to_lsp called with inverted range {start:?}-{end:?}");
|
||||
mem::swap(&mut start, &mut end);
|
||||
pub fn range_to_lsp(range: Range<PointUtf16>) -> Result<lsp::Range> {
|
||||
if range.start > range.end {
|
||||
Err(anyhow!(
|
||||
"Inverted range provided to an LSP request: {:?}-{:?}",
|
||||
range.start,
|
||||
range.end
|
||||
))
|
||||
} else {
|
||||
Ok(lsp::Range {
|
||||
start: point_to_lsp(range.start),
|
||||
end: point_to_lsp(range.end),
|
||||
})
|
||||
}
|
||||
lsp::Range { start, end }
|
||||
}
|
||||
|
||||
pub fn range_from_lsp(range: lsp::Range) -> Range<Unclipped<PointUtf16>> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue