From 07996542bccea4e7d5bc430df8836fa2d6d45cf6 Mon Sep 17 00:00:00 2001 From: tens0rfl0w Date: Sat, 1 Jun 2024 04:39:57 +0200 Subject: [PATCH] fix(natives/rpc): Keep code fencing in doc summary * Removing leading and trailing backticks from the native summary section breaks formatting if the summary only contains formatted code. * Keep RPC native summary in sync with client native summary. --- ext/natives/codegen.lua | 6 ++++-- ext/natives/codegen_out_markdown.lua | 27 +++++++++++++-------------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/ext/natives/codegen.lua b/ext/natives/codegen.lua index 5c800e6d75..35a6441cd1 100644 --- a/ext/natives/codegen.lua +++ b/ext/natives/codegen.lua @@ -500,7 +500,7 @@ function trim(s) return s:gsub("^%s*(.-)%s*$", "%1") end -function parseDocString(native) +function parseDocString(native, keepCodeFencing) local docString = native.doc if not docString then @@ -515,7 +515,9 @@ function parseDocString(native) summary = '' end - summary = trim(summary:gsub('^```(.+)```$', '%1')) + if not keepCodeFencing then + summary = trim(summary:gsub('^```(.+)```$', '%1')) + end local paramsData = {} local hasParams = false diff --git a/ext/natives/codegen_out_markdown.lua b/ext/natives/codegen_out_markdown.lua index 49b5058bd1..f09ef2bc55 100644 --- a/ext/natives/codegen_out_markdown.lua +++ b/ext/natives/codegen_out_markdown.lua @@ -1,11 +1,10 @@ - local json = require('dkjson') local function printFunctionName(native) - return native.name:lower():gsub('0x', 'n_0x'):gsub('_(%a)', string.upper):gsub('(%a)(.+)', function(a, b) - return a:upper() .. b - end) + return native.name:lower():gsub('0x', 'n_0x'):gsub('_(%a)', string.upper):gsub('(%a)(.+)', function(a, b) + return a:upper() .. b + end) end local function printCName(native) @@ -13,13 +12,13 @@ local function printCName(native) end local function printCType(t, v) - local s = t.name:gsub('Ptr', '*') + local s = t.name:gsub('Ptr', '*') - if v and v.pointer then - s = s .. '*' - end + if v and v.pointer then + s = s .. '*' + end - return s + return s end local keywords = { @@ -194,7 +193,7 @@ local function printNative(native) str = str .. ');\n```\n\n' - local d = parseDocString(native) + local d = parseDocString(native, true) if d and d.summary then d.summary = d.summary:gsub('>', '>'):gsub('<', '<'):gsub('&', '&') @@ -213,7 +212,7 @@ local function printNative(native) firstIndent = line:match("^%s+") end - line = line:gsub(firstIndent or '', '')--:gsub('^-+', '') + line = line:gsub(firstIndent or '', '') --:gsub('^-+', '') str = str .. line .. " \n" end @@ -231,10 +230,10 @@ local function printNative(native) if d and d.hasParams then for _, v in ipairs(d.params) do - args[v[1]] = v[2] + args[v[1]] = v[2] end end - + if #native.arguments > 0 then str = str .. '## Parameters\n' @@ -263,4 +262,4 @@ for _, v in pairs(_natives) do if matchApiSet(v) then printNative(v) end -end \ No newline at end of file +end