1
0

The documentation for builtins will now be wrapped, to prevent extremely long lines.

This commit is contained in:
Jon Michael Aanes 2017-06-24 20:37:43 +02:00
parent 9a6a5b4b51
commit f4d6e301a1
2 changed files with 21 additions and 3 deletions

View File

@ -186,6 +186,22 @@ local function get_docs_from_function_body (func_body)
return table.concat(doc_lines, '\n')
end
local function wrap_text (text, max_width)
local l, i, last_i = {}, max_width, 1
repeat
if text:sub(i, i) == ' ' then
l[#l+1], last_i, i = text:sub(last_i, i - 1), i + 1, i + max_width
elseif i <= last_i then
-- TODO: Make sure this part works.
i = text:find(' ', last_i) or #text
else
i = i - 1
end
until i >= #text
l[#l+1] = text:sub(last_i)
return table.concat(l, '\n')
end
--------------------------------------------------------------------------------
local function format_function_with_closure (value, depth, l, format_value)
@ -290,7 +306,9 @@ return function (value, depth, l, format_value)
if info.doc then
l[#l+1] = '\n'
l[#l+1] = add_indent_to_string(info.doc, l.options.indent .. '-- ')
local indent = l.options.indent .. '-- '
local docs = not info.builtin and info.doc or wrap_text(info.doc, 80 - #indent)
l[#l+1] = add_indent_to_string(docs, indent)
end
-- source

View File

@ -204,12 +204,12 @@ format_test {
format_test {
input = math.random,
expect = 'builtin function ([m [, n])\n -- math.random\n -- When called without arguments, returns a uniform pseudo-random real number in the range [0,1). When called with an integer number m, math.random returns a uniform pseudo-random integer in the range [1, m]. When called with two integer numbers m and n, math.random returns a uniform pseudo-random integer in the range [m, n].\n\n ...\nend',
expect = 'builtin function ([m [, n])\n -- math.random\n -- When called without arguments, returns a uniform pseudo-random real\n -- number in the range [0,1). When called with an integer number m,\n -- math.random returns a uniform pseudo-random integer in the range [1, m].\n -- When called with two integer numbers m and n, math.random returns a\n -- uniform pseudo-random integer in the range [m, n].\n\n ...\nend',
}
format_test {
input = string.byte,
expect = 'builtin function (s [, i [, j]])\n -- string.byte\n -- Returns the internal numerical codes of the characters s[i], s[i+1], ..., s[j]. The default value for i is 1; the default value for j is i.\n -- Note that numerical codes are not necessarily portable across platforms.\n\n ...\nend',
expect = 'builtin function (s [, i [, j]])\n -- string.byte\n -- Returns the internal numerical codes of the characters s[i], s[i+1],\n -- ..., s[j]. The default value for i is 1; the default value for j is\n -- i.\n -- Note that numerical codes are not necessarily portable across\n -- platforms.\n\n ...\nend',
}
-- short_builtins option: If an builtin is expected to be available by some name