@@ -3,6 +3,7 @@ local M = {}
3
3
local utils = require (" wrapping.utils" )
4
4
local treesitter = require (" wrapping.treesitter" )
5
5
6
+ --- @type Options
6
7
local OPTION_DEFAULTS = {
7
8
set_nvim_opt_defaults = true ,
8
9
softener = {
@@ -42,6 +43,8 @@ local OPTION_DEFAULTS = {
42
43
local VERY_LONG_TEXTWIDTH_FOR_SOFT = 999999
43
44
local opts
44
45
46
+ --- @param str string
47
+ --- @return nil
45
48
local function log (str )
46
49
if opts .log_path ~= nil then
47
50
local bufname = vim .fn .bufname ()
@@ -58,6 +61,7 @@ local function log(str)
58
61
end
59
62
end
60
63
64
+ --- @return boolean
61
65
local function soft_wrap_mode_quiet ()
62
66
if vim .b .wrapmode == " soft" then
63
67
return false
@@ -95,6 +99,7 @@ local function soft_wrap_mode_quiet()
95
99
return true
96
100
end
97
101
102
+ --- @return boolean
98
103
local function hard_wrap_mode_quiet ()
99
104
if vim .b .wrapmode == " hard" then
100
105
return false
@@ -122,18 +127,21 @@ local function hard_wrap_mode_quiet()
122
127
return true
123
128
end
124
129
130
+ --- @return nil
125
131
M .soft_wrap_mode = function ()
126
132
if soft_wrap_mode_quiet () and opts .notify_on_switch then
127
133
vim .notify (" Soft wrap mode." )
128
134
end
129
135
end
130
136
137
+ --- @return nil
131
138
M .hard_wrap_mode = function ()
132
139
if hard_wrap_mode_quiet () and opts .notify_on_switch then
133
140
vim .notify (" Hard wrap mode." )
134
141
end
135
142
end
136
143
144
+ --- @return nil
137
145
M .toggle_wrap_mode = function ()
138
146
if M .get_current_mode () == " hard" then
139
147
M .soft_wrap_mode ()
@@ -142,6 +150,7 @@ M.toggle_wrap_mode = function()
142
150
end
143
151
end
144
152
153
+ --- @return number
145
154
local function get_softener ()
146
155
local filetype = vim .api .nvim_get_option_value (" filetype" , { buf = 0 })
147
156
local value = vim .tbl_get (opts .softener , filetype )
@@ -153,6 +162,7 @@ local function get_softener()
153
162
end
154
163
end
155
164
165
+ --- @return boolean
156
166
local function likely_nontextual_language ()
157
167
-- If an LSP provider supports these capabilities it's almost certainly not
158
168
-- a textual language, and therefore we should use hard wrapping
@@ -177,6 +187,7 @@ local function likely_nontextual_language()
177
187
return false
178
188
end
179
189
190
+ --- @return boolean
180
191
local function likely_textwidth_set_deliberately ()
181
192
local textwidth_global =
182
193
vim .api .nvim_get_option_value (" textwidth" , { scope = " global" })
@@ -202,6 +213,7 @@ local function likely_textwidth_set_deliberately()
202
213
return false
203
214
end
204
215
216
+ --- @return integer , integer
205
217
local function get_excluded_treesitter ()
206
218
local filetype = vim .api .nvim_get_option_value (" filetype" , { buf = 0 })
207
219
local exclusions = opts .excluded_treesitter_queries [filetype ]
@@ -222,6 +234,7 @@ local function get_excluded_treesitter()
222
234
end
223
235
224
236
--- @param reason string
237
+ --- @return nil
225
238
local function auto_heuristic (reason )
226
239
log (" Testing for auto heuristic because of event " .. reason )
227
240
@@ -247,6 +260,7 @@ local function auto_heuristic(reason)
247
260
end
248
261
end
249
262
263
+ --- @return nil
250
264
M .set_mode_heuristically = function ()
251
265
local buftype = vim .api .nvim_get_option_value (" buftype" , { buf = 0 })
252
266
@@ -333,6 +347,7 @@ M.set_mode_heuristically = function()
333
347
end
334
348
end
335
349
350
+ --- @return string | nil
336
351
M .get_current_mode = function ()
337
352
if vim .b .wrapmode then
338
353
return vim .b .wrapmode
@@ -341,6 +356,8 @@ M.get_current_mode = function()
341
356
end
342
357
end
343
358
359
+ --- @param o Options
360
+ --- @return nil
344
361
M .setup = function (o )
345
362
opts = vim .tbl_deep_extend (" force" , OPTION_DEFAULTS , o or {})
346
363
0 commit comments