Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom doc builder #2807

Closed
wants to merge 0 commits into from
Closed

Custom doc builder #2807

wants to merge 0 commits into from

Conversation

skarph
Copy link
Contributor

@skarph skarph commented Aug 18, 2024

Exposes Lua.docScriptPath as a config value, which should be a path that points to a user's documentation script. This script overrides /script/cli/doc/export.lua , which is used by the server to export docs.

Here is the API, all of which can be overriden by the userscript:

  • export.getLocalPath(uri): Called when the documentation needs to get the path of a source relative to the DOC path. Returns the relative path, or the absolute path, prefixed with the string '[FOREIGN]'

  • export.positionOf(rowcol): Wrapper for guide.positionOf(rowcol[1], rowcol[2])

  • export.sortDoc(a,b): A comparison function used by table.sort that is used to sort every piece of documentation in alphabetical order.

  • export.documentObject(source, has_seen): A function that gets called on every source object. It is responsible for filtering each source to their corresponding export.makeDocObject[<TYPE>] function

  • export.makeDocObject[<TYPE>]: A table of functions that are responsible for building their corresponding <TYPE>'s documentation. TYPES include 'type', 'variable', 'doc.class', etc. 'INIT' corresponds to every documentation object before it is processed by its corresponding type.

  • export.gatherGlobals(): Called when the documentation needs an exhaustive list of the globals it should export documentation. By default this includes the result of vm.getAllGlobals(). Returns the collected variables/types.

  • export.makeDocs(globals, callback): Documents globals from export.gatherGlobals() by calling export.documentObject on each one; updates its progress by calling callback when a global is finished being documented. Returns a table of the collected documentation

  • export.serializeAndExport(docs, outputDir): Serializes documentation tables from export.makeDocs to json and markdown, Writes them to <outputDir>/doc.json and <outputDir>/doc.md, respectively. Returns these paths.

By default Lua.docScriptPath is "" and will execute the default documentation generation script at script/cli/doc/export.lua (with the above specified default behaviors).

For convenience, the script/vm/compiler.lua module now has a function vm.getSimpleClassFields, which can be used to get class fields without them recursing into other classes.

This has only been tested running the server manually with the --doc and --doc_out_path parameters, it has not been tested it by running it in VSC.

I made this because documentation was getting very unwieldy to generate, and saw doc sizes shrink by a factor of 10 when a custom documentation script was applied.

script/vm/compiler.lua Outdated Show resolved Hide resolved
script/cli/doc/export.lua Outdated Show resolved Hide resolved
script/cli/doc/init.lua Outdated Show resolved Hide resolved
@tomlau10
Copy link
Contributor

Hi @skarph , I see that you have pushed new commits to solve the line ending issues of script/vm/compiler.lua, 👍 but you did that in 2 different commits, that will just leave double of the diffs in the git history when this pr get merge. 😅

  • In your 1st commit, you changed the whole file script/vm/compiler.lua
  • And in your 2nd commit, you changed the whole file again
  • doubled the damage... 🙈 as it will leave records in git history twice

You should probably do that by squash / amend force push to completely eliminate them in the git history. 😄
Or even simpler: mix reset everything and commit them 1 by 1 from the start then force push

@skarph skarph force-pushed the master branch 4 times, most recently from faaab50 to 7c28eaa Compare August 23, 2024 15:57
@skarph skarph closed this Aug 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants