Skip to content

Commit 1606997

Browse files
committed
docs: update doc file
1 parent 9c62c9c commit 1606997

File tree

7 files changed

+97
-102
lines changed

7 files changed

+97
-102
lines changed

doc/tags

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
TextTransform.config text-transform.txt /*TextTransform.config*
22
TextTransform.get_visual_selection_details() text-transform.txt /*TextTransform.get_visual_selection_details()*
3-
TextTransform.init_commands() text-transform.txt /*TextTransform.init_commands()*
4-
TextTransform.init_keymaps() text-transform.txt /*TextTransform.init_keymaps()*
53
TextTransform.merge() text-transform.txt /*TextTransform.merge()*
64
TextTransform.replace_columns() text-transform.txt /*TextTransform.replace_columns()*
75
TextTransform.replace_range() text-transform.txt /*TextTransform.replace_range()*

doc/text-transform.txt

+61-49
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,3 @@
1-
==============================================================================
2-
------------------------------------------------------------------------------
3-
*TextTransform.init_commands()*
4-
`TextTransform.init_commands`()
5-
Initializes user commands
6-
@private
7-
8-
------------------------------------------------------------------------------
9-
*TextTransform.init_keymaps()*
10-
`TextTransform.init_keymaps`()
11-
Initializes user keymaps
12-
@private
13-
14-
151
==============================================================================
162
------------------------------------------------------------------------------
173
*TextTransform.config*
@@ -77,21 +63,24 @@ Usage ~
7763
*find_word_boundaries()*
7864
`find_word_boundaries`({line}, {start_col})
7965
Finds the boundaries of the surrounding word around `start_col` within `line`.
80-
@param line number
81-
@param start_col number
82-
@return number start_col, number end_col
66+
Parameters ~
67+
{line} `(number)`
68+
{start_col} `(number)`
69+
Return ~
70+
`(number)` start_col, number end_col
8371

8472
------------------------------------------------------------------------------
8573
*TextTransform.replace_range()*
8674
`TextTransform.replace_range`({start_line}, {start_col}, {end_line}, {end_col}, {transform_name})
8775
Replace the range between the given positions with the given transform.
8876
Acts on the lines between the given positions, replacing the text between the given columns.
8977

90-
@param start_line number The starting line
91-
@param start_col number The starting column
92-
@param end_line number The ending line
93-
@param end_col number The ending column
94-
@param transform_name string The transformer name
78+
Parameters ~
79+
{start_line} `(number)` The starting line
80+
{start_col} `(number)` The starting column
81+
{end_line} `(number)` The ending line
82+
{end_col} `(number)` The ending column
83+
{transform_name} `(string)` The transformer name
9584

9685
------------------------------------------------------------------------------
9786
*TextTransform.replace_word()*
@@ -100,16 +89,18 @@ Replace the word under the cursor with the given transform.
10089
If `position` is provided, replace the word under the given position.
10190
Otherwise, attempts to find the word under the cursor.
10291

103-
@param transform_name string The transformer name
104-
@param position table|nil A table containing the position of the word to replace
92+
Parameters ~
93+
{transform_name} `(string)` The transformer name
94+
{position} `(table|nil)` A table containing the position of the word to replace
10595

10696
------------------------------------------------------------------------------
10797
*TextTransform.replace_columns()*
10898
`TextTransform.replace_columns`({transform_name})
10999
Replaces each column in visual block mode selection with the given transform.
110100
Assumes that the each selection is 1 character and operates on the whole word under each cursor.
111101

112-
@param transform_name string The transformer name
102+
Parameters ~
103+
{transform_name} `(string)` The transformer name
113104

114105
------------------------------------------------------------------------------
115106
*TextTransform.replace_selection()*
@@ -118,7 +109,8 @@ Replaces a selection with the given transform. This function attempts to infer t
118109
type based on the cursor positiono and visual selections, and passes information to relevant
119110
range replacement functions.
120111

121-
@param transform_name string The transformer name
112+
Parameters ~
113+
{transform_name} `(string)` The transformer name
122114

123115
------------------------------------------------------------------------------
124116
*TextTransform.get_visual_selection_details()*
@@ -148,8 +140,10 @@ or a given modified state, if passed as the first argument
148140
*TextTransform.to_words()*
149141
`TextTransform.to_words`({string})
150142
Splits a string into words.
151-
@param string string
152-
@return table
143+
Parameters ~
144+
{string} `(string)`
145+
Return ~
146+
`(table)`
153147

154148
------------------------------------------------------------------------------
155149
*TextTransform.transform_words()*
@@ -158,59 +152,75 @@ Transforms a table of strings into a string using a callback and separator.
158152
The callback is called with the word, the index, and the table of words.
159153
The separator is added between each word.
160154

161-
@param words string|table string or table of strings
162-
@param with_word_cb function (word: string, index: number, words: table) -> string
163-
@param separator string|nil (optional)
164-
@return string
155+
Parameters ~
156+
{words} `(string|table)` string or table of strings
157+
{with_word_cb} `(function)` (word: string, index: number, words: table) -> string
158+
{separator} `(string|nil)` (optional)
159+
Return ~
160+
`(string)`
165161

166162
------------------------------------------------------------------------------
167163
*TextTransform.to_camel_case()*
168164
`TextTransform.to_camel_case`({string})
169165
Transforms a string into camelCase.
170-
@param string string
171-
@return string
166+
Parameters ~
167+
{string} `(string)`
168+
Return ~
169+
`(string)`
172170

173171
------------------------------------------------------------------------------
174172
*TextTransform.to_snake_case()*
175173
`TextTransform.to_snake_case`({string})
176174
Transfroms a string into snake_case.
177-
@param string any
178-
@return string
175+
Parameters ~
176+
{string} `(any)`
177+
Return ~
178+
`(string)`
179179

180180
------------------------------------------------------------------------------
181181
*TextTransform.to_pascal_case()*
182182
`TextTransform.to_pascal_case`({string})
183183
Transforms a string into PascalCase.
184-
@param string string
185-
@return string
184+
Parameters ~
185+
{string} `(string)`
186+
Return ~
187+
`(string)`
186188

187189
------------------------------------------------------------------------------
188190
*TextTransform.to_title_case()*
189191
`TextTransform.to_title_case`({string})
190192
Transforms a string into Title Case.
191-
@param string string
192-
@return string
193+
Parameters ~
194+
{string} `(string)`
195+
Return ~
196+
`(string)`
193197

194198
------------------------------------------------------------------------------
195199
*TextTransform.to_kebab_case()*
196200
`TextTransform.to_kebab_case`({string})
197201
Transforms a string into kebab-case.
198-
@param string string
199-
@return string
202+
Parameters ~
203+
{string} `(string)`
204+
Return ~
205+
`(string)`
200206

201207
------------------------------------------------------------------------------
202208
*TextTransform.to_dot_case()*
203209
`TextTransform.to_dot_case`({string})
204210
Transforms a string into dot.case.
205-
@param string string
206-
@return string
211+
Parameters ~
212+
{string} `(string)`
213+
Return ~
214+
`(string)`
207215

208216
------------------------------------------------------------------------------
209217
*TextTransform.to_const_case()*
210218
`TextTransform.to_const_case`({string})
211219
Transforms a string into CONSTANT_CASE.
212-
@param string string
213-
@return string
220+
Parameters ~
221+
{string} `(string)`
222+
Return ~
223+
`(string)`
214224

215225

216226
==============================================================================
@@ -258,9 +268,11 @@ Mutates the first table.
258268

259269
TODO accept multiple tables to merge
260270

261-
@param t1 table
262-
@param t2 table
263-
@return table
271+
Parameters ~
272+
{t1} `(table)`
273+
{t2} `(table)`
274+
Return ~
275+
`(table)`
264276

265277

266278
vim:tw=78:ts=8:noet:ft=help:norl:

lua/text-transform/commands.lua

-4
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ local common = require("text-transform.popup.common")
77

88
local TextTransform = {}
99

10-
--- Initializes user commands
11-
--- @private
1210
function TextTransform.init_commands()
1311
local map = {
1412
TtCamel = "camel_case",
@@ -56,8 +54,6 @@ function TextTransform.init_commands()
5654
vim.api.nvim_create_user_command("TextTransform", popup.show_popup, opts("Change Case"))
5755
end
5856

59-
--- Initializes user keymaps
60-
--- @private
6157
function TextTransform.init_keymaps()
6258
local keymaps = _G.TextTransform.config.keymap
6359
D.log("init_keymaps", "Initializing keymaps, config %s", vim.inspect(_G.TextTransform))

lua/text-transform/replacers.lua

+13-13
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ local t = require("text-transform.transformers")
55
local TextTransform = {}
66

77
--- Finds the boundaries of the surrounding word around `start_col` within `line`.
8-
--- @param line number
9-
--- @param start_col number
10-
--- @return number start_col, number end_col
8+
---@param line number
9+
---@param start_col number
10+
---@return number start_col, number end_col
1111
local function find_word_boundaries(line, start_col)
1212
local line_text = vim.fn.getline(line)
1313
-- dashes, underscores, and periods are considered part of a word
@@ -31,15 +31,15 @@ end
3131
--- Replace the range between the given positions with the given transform.
3232
--- Acts on the lines between the given positions, replacing the text between the given columns.
3333
---
34-
--- @param start_line number The starting line
35-
--- @param start_col number The starting column
36-
--- @param end_line number The ending line
37-
--- @param end_col number The ending column
38-
--- @param transform_name string The transformer name
34+
---@param start_line number The starting line
35+
---@param start_col number The starting column
36+
---@param end_line number The ending line
37+
---@param end_col number The ending column
38+
---@param transform_name string The transformer name
3939
function TextTransform.replace_range(start_line, start_col, end_line, end_col, transform_name)
4040
D.log("replace_range", "Replacing range with %s", transform_name)
4141
local transform = t["to_" .. transform_name]
42-
local lines = vim.fn.getline(start_line, end_line) --- @type any
42+
local lines = vim.fn.getline(start_line, end_line) ---@type any
4343
local transformed = {}
4444
if #lines == 1 then
4545
local line = lines[1]
@@ -66,8 +66,8 @@ end
6666
--- If `position` is provided, replace the word under the given position.
6767
--- Otherwise, attempts to find the word under the cursor.
6868
---
69-
--- @param transform_name string The transformer name
70-
--- @param position table|nil A table containing the position of the word to replace
69+
---@param transform_name string The transformer name
70+
---@param position table|nil A table containing the position of the word to replace
7171
function TextTransform.replace_word(transform_name, position)
7272
D.log("replace_word", "Replacing word with %s", transform_name)
7373
local word, line, col, start_col, end_col
@@ -93,7 +93,7 @@ end
9393
--- Replaces each column in visual block mode selection with the given transform.
9494
--- Assumes that the each selection is 1 character and operates on the whole word under each cursor.
9595
---
96-
--- @param transform_name string The transformer name
96+
---@param transform_name string The transformer name
9797
function TextTransform.replace_columns(transform_name)
9898
local selections = TextTransform.get_visual_selection_details()
9999
D.log("replace_columns", "Replacing columns with %s", transform_name)
@@ -106,7 +106,7 @@ end
106106
--- type based on the cursor positiono and visual selections, and passes information to relevant
107107
--- range replacement functions.
108108
---
109-
--- @param transform_name string The transformer name
109+
---@param transform_name string The transformer name
110110
function TextTransform.replace_selection(transform_name)
111111
D.log("replace_selection", "Replacing selection with %s", transform_name)
112112
-- determine if cursor is a 1-width column across multiple lines or a normal selection

lua/text-transform/transformers.lua

+20-20
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ local TextTransform = {}
66
TextTransform.WORD_BOUNDRY = "[%_%-%s%.]"
77

88
--- Splits a string into words.
9-
--- @param string string
10-
--- @return table
9+
---@param string string
10+
---@return table
1111
function TextTransform.to_words(string)
1212
local words = {}
1313
local word = ""
@@ -60,10 +60,10 @@ end
6060
--- The callback is called with the word, the index, and the table of words.
6161
--- The separator is added between each word.
6262
---
63-
--- @param words string|table string or table of strings
64-
--- @param with_word_cb function (word: string, index: number, words: table) -> string
65-
--- @param separator string|nil (optional)
66-
--- @return string
63+
---@param words string|table string or table of strings
64+
---@param with_word_cb function (word: string, index: number, words: table) -> string
65+
---@param separator string|nil (optional)
66+
---@return string
6767
function TextTransform.transform_words(words, with_word_cb, separator)
6868
if type(words) ~= "table" then
6969
words = TextTransform.to_words(words)
@@ -81,8 +81,8 @@ function TextTransform.transform_words(words, with_word_cb, separator)
8181
end
8282

8383
--- Transforms a string into camelCase.
84-
--- @param string string
85-
--- @return string
84+
---@param string string
85+
---@return string
8686
function TextTransform.to_camel_case(string)
8787
return TextTransform.transform_words(string, function(word, i)
8888
if i == 1 then
@@ -93,8 +93,8 @@ function TextTransform.to_camel_case(string)
9393
end
9494

9595
--- Transfroms a string into snake_case.
96-
--- @param string any
97-
--- @return string
96+
---@param string any
97+
---@return string
9898
function TextTransform.to_snake_case(string)
9999
return TextTransform.transform_words(string, function(word, i)
100100
if i == 1 then
@@ -105,43 +105,43 @@ function TextTransform.to_snake_case(string)
105105
end
106106

107107
--- Transforms a string into PascalCase.
108-
--- @param string string
109-
--- @return string
108+
---@param string string
109+
---@return string
110110
function TextTransform.to_pascal_case(string)
111111
local cc = TextTransform.to_camel_case(string)
112112
return cc:sub(1, 1):upper() .. cc:sub(2)
113113
end
114114

115115
--- Transforms a string into Title Case.
116-
--- @param string string
117-
--- @return string
116+
---@param string string
117+
---@return string
118118
function TextTransform.to_title_case(string)
119119
return TextTransform.transform_words(string, function(word)
120120
return word:sub(1, 1):upper() .. word:sub(2):lower()
121121
end, " ")
122122
end
123123

124124
--- Transforms a string into kebab-case.
125-
--- @param string string
126-
--- @return string
125+
---@param string string
126+
---@return string
127127
function TextTransform.to_kebab_case(string)
128128
return TextTransform.transform_words(string, function(word)
129129
return word:lower()
130130
end, "-")
131131
end
132132

133133
--- Transforms a string into dot.case.
134-
--- @param string string
135-
--- @return string
134+
---@param string string
135+
---@return string
136136
function TextTransform.to_dot_case(string)
137137
return TextTransform.transform_words(string, function(word)
138138
return word:lower()
139139
end, ".")
140140
end
141141

142142
--- Transforms a string into CONSTANT_CASE.
143-
--- @param string string
144-
--- @return string
143+
---@param string string
144+
---@return string
145145
function TextTransform.to_const_case(string)
146146
return TextTransform.transform_words(string, function(word)
147147
return word:upper()

0 commit comments

Comments
 (0)