You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: lua/tiny-code-action/edit.lua
+16-16Lines changed: 16 additions & 16 deletions
Original file line number
Diff line number
Diff line change
@@ -120,12 +120,12 @@ end
120
120
121
121
--- Applies an empty edit to the given lines.
122
122
-- This function takes a list of lines and the details of an edit, and applies the empty edit to the lines. It handles the case where the start and end lines are the same, and the case where they are different.
123
-
-- @param lines table: A table of strings, each representing a line of text. The lines are 1-indexed.
124
-
-- @param start_line number: The 1-indexed line number where the edit starts.
125
-
-- @param end_line number: The 1-indexed line number where the edit ends.
126
-
-- @param start_char number: The 0-indexed character position within the start line where the edit starts.
127
-
-- @param end_char number: The 0-indexed character position within the end line where the edit ends.
128
-
-- @return table: A table of strings, each representing a line of text after the edit has been applied. The lines are 1-indexed.
123
+
--- @paramlinestable: A table of strings, each representing a line of text. The lines are 1-indexed.
124
+
--- @paramstart_linenumber: The 1-indexed line number where the edit starts.
125
+
--- @paramend_linenumber: The 1-indexed line number where the edit ends.
126
+
--- @paramstart_charnumber: The 0-indexed character position within the start line where the edit starts.
127
+
--- @paramend_charnumber: The 0-indexed character position within the end line where the edit ends.
128
+
--- @returntable: A table of strings, each representing a line of text after the edit has been applied. The lines are 1-indexed.
129
129
-- @error This function does not explicitly throw errors, but may propagate errors thrown by called functions.
@@ -152,8 +152,8 @@ local function apply_empty_edit(lines, start_line, end_line, start_char, end_cha
152
152
end
153
153
--- Applies a single edit to the given lines.
154
154
-- This function takes a list of lines and an edit, and applies the edit to the lines. If the edit's newText is not empty, it applies a non-empty edit. Otherwise, it applies an empty edit. It ensures that the lines exist up to the end line of the edit.
155
-
-- @param lines table: A table of strings, each representing a line of text. The lines are 1-indexed.
156
-
-- @param edit table: A table representing the edit to be applied. The edit table should have the following structure:
155
+
--- @paramlinestable: A table of strings, each representing a line of text. The lines are 1-indexed.
156
+
--- @paramedittable: A table representing the edit to be applied. The edit table should have the following structure:
157
157
-- {
158
158
-- range = {
159
159
-- start = { line = <number>, character = <number> },
@@ -162,7 +162,7 @@ end
162
162
-- newText = <string>
163
163
-- }
164
164
-- The range's start and end lines are 0-indexed, and the characters are 0-indexed within their respective lines. The newText is the text to replace the range with.
165
-
-- @return table: A table of strings, each representing a line of text after the edit has been applied. The lines are 1-indexed.
165
+
--- @returntable: A table of strings, each representing a line of text after the edit has been applied. The lines are 1-indexed.
166
166
-- @error This function does not explicitly throw errors, but may propagate errors thrown by called functions.
-- Otherwise, it constructs a new range from the start and end properties of the edit. If the start offset is present,
186
186
-- it adjusts the line numbers accordingly. It also ensures that the start of the range is before the end.
187
187
--
188
-
-- @param edit table: The edit to normalize. It should have either a 'range' property or 'start' and 'end' properties.
188
+
--- @paramedittable: The edit to normalize. It should have either a 'range' property or 'start' and 'end' properties.
189
189
-- The 'start' and 'end' properties, if present, should be tables with 'line' and 'character' or 'offset' properties.
190
190
-- The 'line' property is a zero-based line number. The 'character' property is a zero-based character index.
191
191
-- The 'offset' property is a one-based index, which is converted to a zero-based index by subtracting one.
192
192
--
193
-
-- @return table: Returns a table representing the normalized range. The table has 'start' and 'end' properties,
193
+
--- @returntable: Returns a table representing the normalized range. The table has 'start' and 'end' properties,
194
194
-- each of which is a table with 'line' and 'character' properties. The 'line' property is a zero-based line number.
195
195
-- The 'character' property is a zero-based character index. If the original range was inverted (i.e., the start was
196
196
-- after the end), the returned range is swapped to ensure that the start is before the end.
@@ -226,8 +226,8 @@ local function normalize_range(edit)
226
226
end
227
227
228
228
-- This function preprocesses a list of edits. It assigns an index to each edit and normalizes its range.
229
-
-- @param edits table: A list of edits. Each edit is a table that should have a 'range' field.
230
-
-- @return table: A list of edits with preprocessed 'range' and an additional '_index' field.
229
+
--- @parameditstable: A list of edits. Each edit is a table that should have a 'range' field.
230
+
--- @returntable: A list of edits with preprocessed 'range' and an additional '_index' field.
231
231
-- @raise No specific exceptions are raised in this function.
232
232
localfunctionpreprocess_edits(edits)
233
233
localindex=0
@@ -240,9 +240,9 @@ local function preprocess_edits(edits)
240
240
end
241
241
--- Applies a series of edits to a given set of lines.
242
242
-- This function preprocesses the edits, sorts them, and then applies each edit to the lines in order.
243
-
-- @param lines table: A table of strings, where each string represents a line of text. This is the text that the edits will be applied to.
244
-
-- @param edits table: A table of edits to apply. Each edit is a table with fields 'range' and 'newText'. 'range' is a table with fields 'start' and 'end', each of which is a table with fields 'line' and 'character'. 'newText' is the text to replace the range with.
245
-
-- @return table: A table of strings, representing the lines of text after all edits have been applied.
243
+
--- @paramlinestable: A table of strings, where each string represents a line of text. This is the text that the edits will be applied to.
244
+
--- @parameditstable: A table of edits to apply. Each edit is a table with fields 'range' and 'newText'. 'range' is a table with fields 'start' and 'end', each of which is a table with fields 'line' and 'character'. 'newText' is the text to replace the range with.
245
+
--- @returntable: A table of strings, representing the lines of text after all edits have been applied.
246
246
-- @error Will throw an error if an edit's range is invalid (e.g., 'start' is after 'end', or the line or character indices are out of bounds).
0 commit comments