Skip to content

Commit 1e843ba

Browse files
committed
little emmylua tweaks
1 parent 97595cf commit 1e843ba

File tree

3 files changed

+32
-32
lines changed

3 files changed

+32
-32
lines changed

lua/Comment/ft.lua

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ local M = {
1919
}
2020

2121
---Lang table that contains commentstring (linewise/blockwise) for mutliple filetypes
22-
---@type table { filetype = { linewise, blockwise } }
22+
---Structure = { filetype = { linewise, blockwise } }
23+
---@type table<string,string[]>
2324
local L = {
2425
bash = { M.hash },
2526
bib = { M.latex },
@@ -123,7 +124,7 @@ end
123124

124125
---Get the commentstring(s) from the filtype list
125126
---@param lang CommentLang
126-
---@return string
127+
---@return string[]
127128
function ft.lang(lang)
128129
return L[lang]
129130
end
@@ -132,7 +133,7 @@ end
132133
---NOTE: This ignores `comment` parser as this is useless
133134
---@param tree userdata Tree to be walked
134135
---@param range number[] Range to check for
135-
---@return userdata
136+
---@return userdata _ See `:h treesitter-languagetree`
136137
function ft.contains(tree, range)
137138
for lang, child in pairs(tree:children()) do
138139
if lang ~= 'comment' and child:contains(range) then

lua/Comment/opfunc.lua

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,13 @@ local A = vim.api
66

77
local Op = {}
88

9-
---@alias OpMode 'line'|'char'|'v'|'V' Vim operator-mode motions. Read `:h map-operator`
9+
---Vim operator-mode motions.
10+
---Read `:h :map-operator`
11+
---@alias OpMode
12+
---| 'line' # Vertical motion
13+
---| 'char' # Horizontal motion
14+
---| 'v' # Visual Block motion
15+
---| 'V' # Visual Line motion
1016

1117
---@class CommentCtx Comment context
1218
---@field ctype number CommentType
@@ -30,24 +36,6 @@ local Op = {}
3036
---@param ctype number CommentType
3137
---@param cmotion number CommentMotion
3238
function Op.opfunc(opmode, cfg, cmode, ctype, cmotion)
33-
-- comment/uncomment logic
34-
--
35-
-- 1. type == line
36-
-- * decide whether to comment or not, if all the lines are commented then uncomment otherwise comment
37-
-- * also, store the minimum indent from all the lines (exclude empty line)
38-
-- * if comment the line, use cstr LHS and also considering the min indent
39-
-- * if uncomment the line, remove cstr LHS from lines
40-
-- * update the lines
41-
-- 2. type == block
42-
-- * check if the first and last is commented or not with cstr LHS and RHS respectively.
43-
-- * if both lines commented
44-
-- - remove cstr LHS from the first line
45-
-- - remove cstr RHS to end of the last line
46-
-- * if both lines uncommented
47-
-- - add cstr LHS after the leading whitespace and before the first char of the first line
48-
-- - add cstr RHS to end of the last line
49-
-- * update the lines
50-
5139
cmotion = cmotion == U.cmotion._ and U.cmotion[opmode] or cmotion
5240

5341
local range = U.get_region(opmode)
@@ -161,7 +149,7 @@ function Op.linewise(param)
161149
return cmode
162150
end
163151

164-
---Full/Partial/Current-line Block commenting
152+
---Full/Partial/Current-Line Block commenting
165153
---@param param OpFnParams
166154
---@param partial? boolean Comment the partial region (visual mode)
167155
---@return number
@@ -198,8 +186,8 @@ function Op.blockwise(param, partial)
198186
return cmode
199187
end
200188

201-
---Toggle line comment with count i.e vim.v.count
202-
---Example: `10gl` will comment 10 lines
189+
---Line commenting with count i.e vim.v.count
190+
---Example: '10gl' will comment 10 lines
203191
---@param count number Number of lines
204192
---@param cfg CommentConfig
205193
---@param ctype number CommentType

lua/Comment/utils.lua

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,15 @@ U.cmotion = {
5555
V = 5,
5656
}
5757

58+
---@private
5859
---Check whether the line is empty
5960
---@param iter string|string[]
6061
---@return boolean
6162
function U.is_empty(iter)
6263
return #iter == 0
6364
end
6465

66+
---@private
6567
---Get the length of the indentation
6668
---@param str string
6769
---@return integer integer Length of indent chars
@@ -97,6 +99,7 @@ function U.is_fn(fn, ...)
9799
return fn
98100
end
99101

102+
---@private
100103
---Check if the given line is ignored or not with the given pattern
101104
---@param ln string Line to be ignored
102105
---@param pat string Lua regex
@@ -160,10 +163,10 @@ function U.unwrap_cstr(cstr)
160163
return vim.trim(left), vim.trim(right)
161164
end
162165

163-
---Unwraps the commentstring by taking it from the following places
164-
--- 1. `pre_hook` (optionally a string can be returned)
165-
--- 2. `ft.lua` (extra commentstring table in the plugin)
166-
--- 3. `commentstring` (already set or added in pre_hook)
166+
---Parses commentstring from the following places in the respective order
167+
--- 1. pre_hook - commentstring returned from the function
168+
--- 2. ft.lua - commentstring table bundled with the plugin
169+
--- 3. commentstring - Neovim's native. See `:h 'commentstring'`
167170
---@param cfg CommentConfig
168171
---@param ctx CommentCtx
169172
---@return string string Left side of the commentstring
@@ -179,9 +182,10 @@ function U.parse_cstr(cfg, ctx)
179182
return U.unwrap_cstr(cstr)
180183
end
181184

182-
---Returns a closure which is used to comment a line
183-
---If given {string[]} to the closure then it will do blockwise
184-
---else it will do linewise
185+
---Returns a closure which is used to do comments
186+
---
187+
---If given {string[]} to the closure then it will do blockwise comment
188+
---else linewise comment will be done with the given {string}
185189
---@param left string Left side of the commentstring
186190
---@param right string Right side of the commentstring
187191
---@param padding boolean Is padding enabled?
@@ -243,6 +247,9 @@ function U.commenter(left, right, padding, scol, ecol)
243247
end
244248

245249
---Returns a closure which is used to uncomment a line
250+
---
251+
---If given {string[]} to the closure then it will block uncomment
252+
---else linewise uncomment will be done with the given {string}
246253
---@param left string Left side of the commentstring
247254
---@param right string Right side of the commentstring
248255
---@param padding boolean Is padding enabled?
@@ -299,6 +306,10 @@ function U.uncommenter(left, right, padding, scol, ecol)
299306
end
300307

301308
---Check if the given string is commented or not
309+
---
310+
---If given {string[]} to the closure, it will check the first and last line
311+
---with LHS and RHS of commentstring respectively else it will check the given
312+
---line with LHS and RHS (if given) of the commenstring
302313
---@param left string Left side of the commentstring
303314
---@param right string Right side of the commentstring
304315
---@param padding boolean Is padding enabled?

0 commit comments

Comments
 (0)