perl_dap_breakpoint/lib.rs
1//! Breakpoint Validation for Perl DAP
2//!
3//! This crate provides AST-based breakpoint validation for the Perl Debug Adapter Protocol.
4//! It validates breakpoint locations against parsed source code to ensure breakpoints are
5//! set on executable lines, not on comments, blank lines, or inside heredoc content.
6//!
7//! # Features
8//!
9//! - **AST-Based Validation**: Uses the Perl parser AST to validate breakpoint locations
10//! - **Line Suggestion**: Suggests the nearest valid line when a breakpoint is on an invalid location
11//! - **Validation Reasons**: Provides detailed reasons for why a breakpoint was rejected or adjusted
12//!
13//! # Example
14//!
15//! ```rust,ignore
16//! use perl_dap_breakpoint::{BreakpointValidator, AstBreakpointValidator};
17//!
18//! let source = "# comment\nmy $x = 1;\n";
19//! let validator = AstBreakpointValidator::new(source)?;
20//!
21//! let result = validator.validate(1); // Line 1 is a comment
22//! assert!(!result.verified);
23//! assert_eq!(result.reason, Some(ValidationReason::CommentLine));
24//! ```
25
26mod suggestion;
27mod validator;
28
29pub use suggestion::{SearchDirection, find_nearest_valid_line};
30pub use validator::{
31 AstBreakpointValidator, BreakpointValidation, BreakpointValidator, ValidationReason,
32};
33
34/// Error type for breakpoint validation operations
35#[derive(Debug, thiserror::Error)]
36pub enum BreakpointError {
37 /// Failed to parse the source file
38 #[error("Failed to parse source: {0}")]
39 ParseError(String),
40
41 /// Line number is out of range
42 #[error("Line {0} is out of range (file has {1} lines)")]
43 LineOutOfRange(i64, usize),
44}