Skip to content

Commit

Permalink
feat: implement new docgen featuring top-comment validation
Browse files Browse the repository at this point in the history
  • Loading branch information
vhyrro committed Feb 3, 2023
1 parent b4d8839 commit b77fbd5
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
23 changes: 22 additions & 1 deletion docgen/docgen.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ local ts_utils = ts.get_ts_utils()
---@return table #A list of paths to every module's `module.lua` file
docgen.aggregate_module_files = function()
return vim.fs.find("module.lua", {
path = vim.fn.fnamemodify(debug.getinfo(1, "S").source:sub(2), ":p:h"),
path = "..",
type = "file",
limit = math.huge,
})
Expand Down Expand Up @@ -106,6 +106,27 @@ docgen.parse_top_comment = function(comment)
return result
end

--- TODO
---@param top_comment TopComment #The comment to check for errors
---@return string|TopComment #An error string or the comment itself
docgen.check_top_comment_integrity = function(top_comment)
local tc = vim.tbl_deep_extend("keep", top_comment, {
title = "",
summary = "",
markdown = {},
})

if not tc.file then
return "no `File:` field provided."
elseif tc.summary:sub(tc.summary:len()) ~= "." then
return "summary does not end with a full stop."
elseif tc.title:find("neorg") then
return "`neorg` written with lowercase letter. Use uppercase instead."
end

return top_comment
end



return docgen
8 changes: 6 additions & 2 deletions docgen/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@ local docgen = require("docgen")
local modules = {}

for _, file in ipairs(docgen.aggregate_module_files()) do
local buffer = docgen.open_file(file)
local buffer = docgen.open_file(vim.fn.fnamemodify(file, ":p"))

local top_comment = docgen.get_module_top_comment(buffer)

if not top_comment then
goto continue
end

top_comment = docgen.parse_top_comment(top_comment)
local docgen_data = docgen.check_top_comment_integrity(docgen.parse_top_comment(top_comment))

if type(docgen_data) == "string" then
log.error("Error when parsing module '" .. file .. "': " .. docgen_data)
end

::continue::
end
3 changes: 2 additions & 1 deletion lua/neorg/modules/core/itero/module.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
--[[
--
File: Itero
Summary: Module designed to continue lists, headings and other iterables.
--]]

local module = neorg.modules.create("core.itero")
Expand Down

0 comments on commit b77fbd5

Please sign in to comment.