Skip to content

Commit 7e7609f

Browse files
committed
feat(docs): add proper code documentation
1 parent c9a6fa8 commit 7e7609f

File tree

16 files changed

+144
-33
lines changed

16 files changed

+144
-33
lines changed

lua/tiny-code-action/action.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ local utils = require("tiny-code-action.utils")
44
local apply_edit = require("tiny-code-action.edit").apply_edit
55

66
--- Applies a given action in the context of a client and a context.
7-
-- @param action The action to be applied. If nil, an error message is displayed.
8-
-- @param client The client in which the action is applied. It is used to apply workspace edits and execute commands.
9-
-- @param ctx The context in which the action is applied. If not provided, an empty context is used.
10-
-- @return No return value. The function operates by side effects, applying the action in the given context.
7+
--- @param action The action to be applied. If nil, an error message is displayed.
8+
--- @param client The client in which the action is applied. It is used to apply workspace edits and execute commands.
9+
--- @param ctx The context in which the action is applied. If not provided, an empty context is used.
10+
--- @return No return value. The function operates by side effects, applying the action in the given context.
1111
function M.apply(action, client, ctx)
1212
if action == nil then
1313
vim.notify("Error: No action to apply/action can't be applied", vim.log.levels.ERROR)

lua/tiny-code-action/base/picker.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ local M = {}
33
local utils = require("tiny-code-action.utils")
44

55
--- Helper function to check if a picker dependency is available
6-
-- @param name string: Name of the picker
7-
-- @param module_path string: Path to the module to check
8-
-- @return boolean: True if the dependency is available
6+
--- @param name string: Name of the picker
7+
--- @param module_path string: Path to the module to check
8+
--- @returnboolean: True if the dependency is available
99
local function has_dependency(name, module_path)
1010
local has_module, _ = pcall(require, module_path)
1111
if not has_module then
@@ -19,7 +19,7 @@ local function has_dependency(name, module_path)
1919
end
2020

2121
--- Initialize a new picker base
22-
-- @param opts table: Options to configure the picker
22+
--- @param opts table: Options to configure the picker
2323
function M.new(opts)
2424
local picker = {
2525
-- Common properties that all pickers should have

lua/tiny-code-action/base/previewer.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ local terminal = require("tiny-code-action.terminal")
55
local utils = require("tiny-code-action.utils")
66

77
--- Initialize a new previewer base
8-
-- @param opts table: Options to configure the previewer
8+
--- @param opts table: Options to configure the previewer
99
function M.new(opts)
1010
local previewer = {
1111
config = opts or {},

lua/tiny-code-action/edit.lua

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,12 @@ end
120120

121121
--- Applies an empty edit to the given lines.
122122
-- 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+
--- @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+
--- @returntable: A table of strings, each representing a line of text after the edit has been applied. The lines are 1-indexed.
129129
-- @error This function does not explicitly throw errors, but may propagate errors thrown by called functions.
130130
local function apply_empty_edit(lines, start_line, end_line, start_char, end_char)
131131
local first = lines[start_line]
@@ -152,8 +152,8 @@ local function apply_empty_edit(lines, start_line, end_line, start_char, end_cha
152152
end
153153
--- Applies a single edit to the given lines.
154154
-- 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+
--- @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:
157157
-- {
158158
-- range = {
159159
-- start = { line = <number>, character = <number> },
@@ -162,7 +162,7 @@ end
162162
-- newText = <string>
163163
-- }
164164
-- 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.
166166
-- @error This function does not explicitly throw errors, but may propagate errors thrown by called functions.
167167
local function apply_single_edit(lines, edit)
168168
local start_line, end_line = get_line_start_end(edit)
@@ -185,12 +185,12 @@ end
185185
-- Otherwise, it constructs a new range from the start and end properties of the edit. If the start offset is present,
186186
-- it adjusts the line numbers accordingly. It also ensures that the start of the range is before the end.
187187
--
188-
-- @param edit table: The edit to normalize. It should have either a 'range' property or 'start' and 'end' properties.
188+
--- @param edit table: The edit to normalize. It should have either a 'range' property or 'start' and 'end' properties.
189189
-- The 'start' and 'end' properties, if present, should be tables with 'line' and 'character' or 'offset' properties.
190190
-- The 'line' property is a zero-based line number. The 'character' property is a zero-based character index.
191191
-- The 'offset' property is a one-based index, which is converted to a zero-based index by subtracting one.
192192
--
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,
194194
-- each of which is a table with 'line' and 'character' properties. The 'line' property is a zero-based line number.
195195
-- The 'character' property is a zero-based character index. If the original range was inverted (i.e., the start was
196196
-- 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)
226226
end
227227

228228
-- 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+
--- @param edits table: 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.
231231
-- @raise No specific exceptions are raised in this function.
232232
local function preprocess_edits(edits)
233233
local index = 0
@@ -240,9 +240,9 @@ local function preprocess_edits(edits)
240240
end
241241
--- Applies a series of edits to a given set of lines.
242242
-- 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+
--- @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+
--- @returntable: A table of strings, representing the lines of text after all edits have been applied.
246246
-- @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).
247247
function M.apply_edit(lines, edits)
248248
local processed_edits = preprocess_edits(edits)

lua/tiny-code-action/filters.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,3 @@ function M.filter_code_actions(results, filters)
4040
end
4141

4242
return M
43-

lua/tiny-code-action/finder.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ local function get_line_diagnostics(bufnr)
2020
end
2121

2222
-- Find code actions from all LSP clients
23+
--- Finds code actions from all LSP clients for the given options and invokes the callback with results.
24+
--- @param opts table: Options including bufnr, range, and context
25+
--- @param callback function: Function to call with the results
2326
function M.code_action_finder(opts, callback)
2427
local results = {}
2528
local position_encoding = vim.api.nvim_get_option_value("encoding", { scope = "local" })
@@ -99,6 +102,9 @@ function M.code_action_finder(opts, callback)
99102
end
100103

101104
-- Sort code actions based on priority with isPreferred at the top
105+
--- Sorts code actions by priority, placing preferred actions at the top.
106+
--- @param results table: List of code action results
107+
--- @returntable: Sorted results
102108
function M.sort_by_preferred(results)
103109
if not results or #results == 0 then
104110
return results

lua/tiny-code-action/highlights.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
local M = {}
22

3+
--- Sets up highlight groups for code action kinds based on provided signs.
4+
--- @param signs table: Mapping of kind names to sign definitions
35
function M.setup_highlights(signs)
46
for kind_name, sign in pairs(signs) do
57
vim.api.nvim_set_hl(0, "TinyCodeActionKind" .. kind_name, sign[2])

lua/tiny-code-action/init.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ M.picker_config = config.picker_config
1212

1313
--- Get the code actions for the current buffer
1414
--- @param opts table: The options for the code actions (compatible with vim.lsp.buf.code_action).
15+
--- Gets and displays code actions for the current buffer, applying filters and using the configured picker.
16+
--- @param opts table: Options for code actions (compatible with vim.lsp.buf.code_action)
1517
function M.code_action(opts)
1618
local bufnr = vim.api.nvim_get_current_buf()
1719
local finder_opts = {
@@ -107,6 +109,8 @@ local function init_backend(backend_name)
107109
return require("tiny-code-action.backend." .. backend_name)
108110
end
109111

112+
--- Sets up the plugin configuration, picker, highlights, and backend.
113+
--- @param opts table: User configuration options
110114
function M.setup(opts)
111115
M.config = vim.tbl_deep_extend("force", {}, M.config, opts or {})
112116

lua/tiny-code-action/picker.lua

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ local config = require("tiny-code-action.config")
22
local M = {}
33

44
-- Get a picker module by name, with fallbacks
5+
--- Retrieves a picker module by name, with fallbacks to defaults if unavailable.
6+
--- @param picker_name string: Name of the picker module
7+
--- @returntable|nil: Picker module or nil if not found
58
function M.get_picker_module(picker_name)
69
if not config.VALID_PICKERS[picker_name] then
710
vim.notify(
@@ -15,7 +18,10 @@ function M.get_picker_module(picker_name)
1518
return picker_module
1619
end
1720
if picker_name == "telescope" then
18-
vim.notify("Telescope picker is not available. Falling back to vim.ui.select.", vim.log.levels.WARN)
21+
vim.notify(
22+
"Telescope picker is not available. Falling back to vim.ui.select.",
23+
vim.log.levels.WARN
24+
)
1925
return M.get_picker_module("select")
2026
elseif picker_name == "snacks" then
2127
vim.notify("Snacks picker is not available. Falling back to telescope.", vim.log.levels.WARN)
@@ -32,6 +38,9 @@ function M.get_picker_module(picker_name)
3238
end
3339
end
3440

41+
--- Initializes the specified picker, loading extensions if necessary.
42+
--- @param picker string|table: Picker name or config table
43+
--- @returnboolean: True if initialization succeeded
3544
function M.init_picker(picker)
3645
local picker_name
3746
if type(picker) == "table" then
@@ -56,4 +65,3 @@ function M.init_picker(picker)
5665
end
5766

5867
return M
59-

lua/tiny-code-action/pickers/buffer.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ local M = BasePicker.new()
88

99
local ns = vim.api.nvim_create_namespace("tiny_code_action_buffer")
1010

11+
--- Creates and displays the buffer picker window for code actions.
12+
--- @param config table: Picker configuration
13+
--- @param results table: List of code action results
14+
--- @param bufnr number: Buffer number
1115
function M.create(config, results, bufnr)
1216
hotkeys.add_config_keymaps_to_reserved(config)
1317

0 commit comments

Comments
 (0)