Skip to main content

perl_lsp_code_actions/
types.rs

1//! Code action types
2//!
3//! Defines the core types for representing code actions and their edits.
4
5use perl_lsp_rename::TextEdit;
6
7/// A diagnostic with byte offset range for quick fix processing
8///
9/// This is a simplified diagnostic type used internally by the quick fix
10/// system. It uses byte offsets instead of line/column positions for
11/// efficient source text manipulation.
12#[derive(Debug, Clone)]
13pub struct QuickFixDiagnostic {
14    /// The byte offset range (start, end) in the source
15    pub range: (usize, usize),
16    /// The diagnostic message
17    pub message: String,
18    /// The diagnostic code (e.g., "undefined-variable")
19    #[allow(dead_code)]
20    pub code: Option<String>,
21}
22
23/// A code action that can be applied to fix an issue
24///
25/// Code actions represent automated fixes for common issues and refactoring
26/// operations that can be applied to Perl source code.
27#[derive(Debug, Clone)]
28pub struct CodeAction {
29    /// Human-readable title describing the action
30    pub title: String,
31    /// The kind/category of code action
32    pub kind: CodeActionKind,
33    /// Diagnostic codes this action fixes
34    pub diagnostics: Vec<String>,
35    /// The edit operations to apply
36    pub edit: CodeActionEdit,
37    /// Whether this action is the preferred choice
38    pub is_preferred: bool,
39}
40
41/// Kind of code action
42///
43/// Categorizes the type of code action to help editors organize and present
44/// actions to users appropriately.
45#[derive(Debug, Clone, PartialEq, Eq)]
46pub enum CodeActionKind {
47    /// Quick fix for a diagnostic issue
48    QuickFix,
49    /// General refactoring operation
50    Refactor,
51    /// Extract code into a new construct
52    RefactorExtract,
53    /// Inline a construct into its usage sites
54    RefactorInline,
55    /// Rewrite code using a different pattern
56    RefactorRewrite,
57    /// Source code organization action
58    Source,
59    /// Organize imports action
60    SourceOrganizeImports,
61    /// Fix all issues action
62    SourceFixAll,
63    /// Modernize Perl code action
64    SourceModernize,
65}
66
67/// Edit to apply for a code action
68///
69/// Contains the specific text changes needed to apply a code action.
70#[derive(Debug, Clone)]
71pub struct CodeActionEdit {
72    /// List of text edits to apply
73    pub changes: Vec<TextEdit>,
74}