use crate::BreakableSpan;
use firedbg_protocol::source::LineColumn;
use syn::spanned::Spanned;
pub(crate) fn parse_body_loc(block: &syn::Block) -> BreakableSpan {
BreakableSpan {
start: parse_body_loc_start(block),
end: parse_body_loc_end(block),
}
}
pub(crate) fn parse_body_loc_start(block: &syn::Block) -> LineColumn {
let mut loc: LineColumn = block.span().start().into_loc();
if let Some(col) = loc.column.as_mut() {
*col += 2;
}
loc
}
fn parse_body_loc_end(block: &syn::Block) -> LineColumn {
let mut loc = parse_body_loc_start(block);
if let Some(first_stmt) = block.stmts.first() {
let mut first_stmt_loc: LineColumn = first_stmt.span().start().into_loc();
if let Some(col) = first_stmt_loc.column.as_mut() {
*col += 1;
}
loc = first_stmt_loc;
}
loc
}
pub(crate) trait IntoLineColumn {
fn into_loc(self) -> LineColumn;
}
impl IntoLineColumn for proc_macro2::LineColumn {
fn into_loc(self) -> LineColumn {
LineColumn {
line: self.line as u32,
column: Some(self.column as u32),
}
}
}