@@ -3,6 +3,7 @@ local M = {}
33local utils = require (" wrapping.utils" )
44local treesitter = require (" wrapping.treesitter" )
55
6+ --- @type Options
67local OPTION_DEFAULTS = {
78 set_nvim_opt_defaults = true ,
89 softener = {
@@ -42,6 +43,8 @@ local OPTION_DEFAULTS = {
4243local VERY_LONG_TEXTWIDTH_FOR_SOFT = 999999
4344local opts
4445
46+ --- @param str string
47+ --- @return nil
4548local function log (str )
4649 if opts .log_path ~= nil then
4750 local bufname = vim .fn .bufname ()
@@ -58,6 +61,7 @@ local function log(str)
5861 end
5962end
6063
64+ --- @return boolean
6165local function soft_wrap_mode_quiet ()
6266 if vim .b .wrapmode == " soft" then
6367 return false
@@ -95,6 +99,7 @@ local function soft_wrap_mode_quiet()
9599 return true
96100end
97101
102+ --- @return boolean
98103local function hard_wrap_mode_quiet ()
99104 if vim .b .wrapmode == " hard" then
100105 return false
@@ -122,18 +127,21 @@ local function hard_wrap_mode_quiet()
122127 return true
123128end
124129
130+ --- @return nil
125131M .soft_wrap_mode = function ()
126132 if soft_wrap_mode_quiet () and opts .notify_on_switch then
127133 vim .notify (" Soft wrap mode." )
128134 end
129135end
130136
137+ --- @return nil
131138M .hard_wrap_mode = function ()
132139 if hard_wrap_mode_quiet () and opts .notify_on_switch then
133140 vim .notify (" Hard wrap mode." )
134141 end
135142end
136143
144+ --- @return nil
137145M .toggle_wrap_mode = function ()
138146 if M .get_current_mode () == " hard" then
139147 M .soft_wrap_mode ()
@@ -142,6 +150,7 @@ M.toggle_wrap_mode = function()
142150 end
143151end
144152
153+ --- @return number
145154local function get_softener ()
146155 local filetype = vim .api .nvim_get_option_value (" filetype" , { buf = 0 })
147156 local value = vim .tbl_get (opts .softener , filetype )
@@ -153,6 +162,7 @@ local function get_softener()
153162 end
154163end
155164
165+ --- @return boolean
156166local function likely_nontextual_language ()
157167 -- If an LSP provider supports these capabilities it's almost certainly not
158168 -- a textual language, and therefore we should use hard wrapping
@@ -177,6 +187,7 @@ local function likely_nontextual_language()
177187 return false
178188end
179189
190+ --- @return boolean
180191local function likely_textwidth_set_deliberately ()
181192 local textwidth_global =
182193 vim .api .nvim_get_option_value (" textwidth" , { scope = " global" })
@@ -202,6 +213,7 @@ local function likely_textwidth_set_deliberately()
202213 return false
203214end
204215
216+ --- @return integer , integer
205217local function get_excluded_treesitter ()
206218 local filetype = vim .api .nvim_get_option_value (" filetype" , { buf = 0 })
207219 local exclusions = opts .excluded_treesitter_queries [filetype ]
@@ -222,6 +234,7 @@ local function get_excluded_treesitter()
222234end
223235
224236--- @param reason string
237+ --- @return nil
225238local function auto_heuristic (reason )
226239 log (" Testing for auto heuristic because of event " .. reason )
227240
@@ -247,6 +260,7 @@ local function auto_heuristic(reason)
247260 end
248261end
249262
263+ --- @return nil
250264M .set_mode_heuristically = function ()
251265 local buftype = vim .api .nvim_get_option_value (" buftype" , { buf = 0 })
252266
@@ -333,6 +347,7 @@ M.set_mode_heuristically = function()
333347 end
334348end
335349
350+ --- @return string | nil
336351M .get_current_mode = function ()
337352 if vim .b .wrapmode then
338353 return vim .b .wrapmode
@@ -341,6 +356,8 @@ M.get_current_mode = function()
341356 end
342357end
343358
359+ --- @param o Options
360+ --- @return nil
344361M .setup = function (o )
345362 opts = vim .tbl_deep_extend (" force" , OPTION_DEFAULTS , o or {})
346363
0 commit comments