1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
//! Lua span helpers for `aip.file`.
//!
//! ---
//!
//! ## Lua documentation for `aip.file` span helpers
//!
//! ### Functions
//!
//! - `aip.file.line_spans(path: string): [start,end][]`
//! - `aip.file.csv_row_spans(path: string): [start,end][]`
//! - `aip.file.read_span(path: string, start: integer, end: integer): string`
//!
//! The `path` is resolved relative to the workspace root.
use crateError;
use cratePathResolver;
use crateRuntime;
use ;
use ;
// region: --- Lua Spans
/// ## Lua Documentation
///
/// Returns the byte spans for each line in a text file resolved from the workspace root.
///
/// ```lua
/// -- API Signature
/// aip.file.line_spans(path: string): [start,end][]
/// ```
///
/// - `path: string`: File path relative to the workspace root (pack refs supported).
///
/// The resulting Lua table contains `[start, end]` pairs (1-indexed array) describing each line's
/// byte range in the source file.
///
/// ### Example
///
/// ```lua
/// local spans = aip.file.line_spans("notes/todo.txt")
/// for i, span in ipairs(spans) do
/// print(("line %d: %d -> %d"):format(i, span[1], span[2]))
/// end
/// ```
///
/// ### Error
///
/// Returns an error if the path cannot be resolved, the file cannot be read, or line spans cannot be computed.
pub
/// ## Lua Documentation
///
/// Returns the byte spans for each CSV row of the given file.
///
/// ```lua
/// -- API Signature
/// aip.file.csv_row_spans(path: string): [start,end][]
/// ```
///
/// - `path: string`: CSV file path relative to the workspace root (pack refs supported).
///
/// The returned Lua table contains `[start, end]` byte offset pairs describing each row, which is helpful
/// when mapping Lua data back to exact CSV locations.
///
/// ### Example
///
/// ```lua
/// local spans = aip.file.csv_row_spans("data/example.csv")
/// local first = spans[1]
/// print(("row 1 bytes: %d -> %d"):format(first[1], first[2]))
/// ```
///
/// ### Error
///
/// Returns an error if the path cannot be resolved, the file is missing, or row spans cannot be computed.
pub
/// ## Lua Documentation
///
/// Reads a byte range from a file and returns the captured UTF-8 string.
///
/// ```lua
/// -- API Signature
/// aip.file.read_span(path: string, start: integer, end: integer): string
/// ```
///
/// - `path: string`: File path relative to the workspace root (pack refs supported).
/// - `start: integer`: Inclusive byte offset where reading begins (zero-based).
/// - `end: integer`: Exclusive byte offset where reading stops (zero-based).
///
/// The function returns the substring defined by `[start, end)` which is useful alongside the span helpers.
///
/// ### Example
///
/// ```lua
/// local spans = aip.file.line_spans("notes/todo.txt")
/// local snippet = aip.file.read_span("notes/todo.txt", spans[1][1], spans[1][2])
/// print(snippet)
/// ```
///
/// ### Error
///
/// Returns an error if the offsets are negative, `end` is smaller than `start`, the path cannot be resolved,
/// the file is missing, or the requested slice cannot be read.
pub
// endregion: --- Lua Spans
// region: --- Support
// endregion: --- Support