Skip to content

Commit

Permalink
feature: add support for the @inherit tag!
Browse files Browse the repository at this point in the history
  • Loading branch information
4x8Matrix committed Jun 19, 2024
1 parent 5a2211a commit fd74268
Show file tree
Hide file tree
Showing 26 changed files with 1,152 additions and 48 deletions.
3 changes: 3 additions & 0 deletions .lune/generator/init.luau
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
local Moonwave = require("moonwave")
local Generator = require("generator")
local Markdown = require("markdown")
local Processor = require("processor")

Generator.removeLegacyFiles()

local packageCommentJson = Moonwave.extractCommentsIntoJson()

packageCommentJson = Processor.processInheritedObjects(packageCommentJson)

for _, classDocumentation in packageCommentJson do
local documentPath = Generator.writeClassName(classDocumentation.name)
local documentContent = Markdown.generateMarkdownDocumentFor(classDocumentation)
Expand Down
80 changes: 76 additions & 4 deletions .lune/generator/markdown.luau
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
local Moonwave = require("moonwave")
local Types = require("types")

local Markdown = {}

Expand Down Expand Up @@ -72,6 +71,25 @@ function Markdown.generateMarkdownDocumentFor(classDocumentation: Moonwave.moonw
local classMethods = Moonwave.getFunctionsOfFunctionType(classDocumentation.functions, "method")
local classFunctions = Moonwave.getFunctionsOfFunctionType(classDocumentation.functions, "static")

local sizeOfClassProperties = #classProperties

local sizeOfClassMethods = #classMethods
local sizeOfClassFunctions = #classFunctions

local inheritedClasses = classDocumentation.inherited ~= nil and classDocumentation.inherited or { }

for _, classObject in inheritedClasses do
sizeOfClassProperties += #classObject.properties

for _, functionObject in classObject.functions do
if functionObject.function_type == "method" then
sizeOfClassMethods += 1
else
sizeOfClassFunctions += 1
end
end
end

markdownFile ..= frontmatter({
name = className,
description = `DiscordLuau docs for {className}.`,
Expand Down Expand Up @@ -113,7 +131,7 @@ function Markdown.generateMarkdownDocumentFor(classDocumentation: Moonwave.moonw

markdownFile ..= h2(`Properties`)

if #classProperties > 0 then
if sizeOfClassProperties > 0 then
for _, prop in classProperties do
markdownFile ..= h3(prop.name)
markdownFile ..= property(`{className}.{prop.name}`, prop.lua_type)
Expand All @@ -124,6 +142,22 @@ function Markdown.generateMarkdownDocumentFor(classDocumentation: Moonwave.moonw
markdownFile ..= input(prop.desc)
end
end

for inheritedClassName, classInheritedData in inheritedClasses do
for _, inheritedProperty in classInheritedData.properties do
markdownFile ..= h3(inheritedProperty.name)
markdownFile ..= property(`{className}.{inheritedProperty.name}`, inheritedProperty.lua_type)
markdownFile ..= newline()

if inheritedProperty.desc ~= "" then
markdownFile ..= separator()
markdownFile ..= input(inheritedProperty.desc)
end

markdownFile ..= newline()
markdownFile ..= input(`> This property was inherited from [{inheritedClassName}]({inheritedClassName})`)
end
end
else
markdownFile ..= input(`The {className} instance has no set properties!`)
end
Expand All @@ -136,7 +170,7 @@ function Markdown.generateMarkdownDocumentFor(classDocumentation: Moonwave.moonw

markdownFile ..= h2(`Methods`)

if #classMethods > 0 then
if sizeOfClassMethods > 0 then
for _, method in classMethods do
markdownFile ..= h3(method.name)
markdownFile ..= declaration(method.name, className, true, method.params, (method.returns[1] or {lua_type = nil}).lua_type)
Expand All @@ -146,6 +180,25 @@ function Markdown.generateMarkdownDocumentFor(classDocumentation: Moonwave.moonw
markdownFile ..= input(method.desc)
end
end

for inheritedClassName, classInheritedData in inheritedClasses do
for _, inheritedFunction in classInheritedData.functions do
if inheritedFunction.function_type ~= "method" then
continue
end

markdownFile ..= h3(inheritedFunction.name)
markdownFile ..= declaration(inheritedFunction.name, className, true, inheritedFunction.params, (inheritedFunction.returns[1] or {lua_type = nil}).lua_type)

if inheritedFunction.desc then
markdownFile ..= newline()
markdownFile ..= input(inheritedFunction.desc)
end

markdownFile ..= newline()
markdownFile ..= input(`> This function was inherited from [{inheritedClassName}]({inheritedClassName})`)
end
end
else
markdownFile ..= input(`The {className} instance has no set methods!`)
end
Expand All @@ -158,7 +211,7 @@ function Markdown.generateMarkdownDocumentFor(classDocumentation: Moonwave.moonw

markdownFile ..= h2(`Functions`)

if #classFunctions > 0 then
if sizeOfClassFunctions > 0 then
for _, func in classFunctions do
markdownFile ..= h3(func.name)
markdownFile ..= declaration(func.name, className, false, func.params)
Expand All @@ -168,6 +221,25 @@ function Markdown.generateMarkdownDocumentFor(classDocumentation: Moonwave.moonw
markdownFile ..= input(func.desc)
end
end

for inheritedClassName, classInheritedData in inheritedClasses do
for _, inheritedFunction in classInheritedData.functions do
if inheritedFunction.function_type ~= "static" then
continue
end

markdownFile ..= h3(inheritedFunction.name)
markdownFile ..= declaration(inheritedFunction.name, className, false, inheritedFunction.params)

if inheritedFunction.desc then
markdownFile ..= newline()
markdownFile ..= input(inheritedFunction.desc)
end

markdownFile ..= newline()
markdownFile ..= input(`> This function was inherited from [{inheritedClassName}]({inheritedClassName})`)
end
end
else
markdownFile ..= input(`The {className} instance has no set functions!`)
end
Expand Down
7 changes: 3 additions & 4 deletions .lune/generator/moonwave.luau
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,12 @@ export type moonwaveFunctionData = {
export type moonwaveDataExportObject = {
name: string,
functions: { moonwaveFunctionData? },
source: {
path: string,
line: number,
},
source: { path: string, line: number },
properties: { moonwavePropertyData? },
inherited: { [string]: { functions: { moonwaveFunctionData? }, properties: { moonwavePropertyData? } } }?,
desc: string,
types: unknown,
tags: { string }?
}

export type moonwaveDataExportArray = {
Expand Down
69 changes: 69 additions & 0 deletions .lune/generator/processor.luau
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
local Moonwave = require("moonwave")
local Tags = require("tags")

local Processor = {}

function Processor.getObjectFromName(packageCommentJson: Moonwave.moonwaveDataExportArray, packageName: string): processedMoonwaveDataExportObject?
for _, object in packageCommentJson do
if object.name == packageName then
return object
end
end

return nil
end

function Processor.processInheritedObject(packageCommentJson: Moonwave.moonwaveDataExportArray, packageObject: processedMoonwaveDataExportObject)
if packageObject._processed then
return packageObject
end

local packageTags, tagCount = Tags.getTags(packageObject)

if tagCount == 0 then
packageObject._processed = true

return packageObject
end

for tagName, tagArguments in packageTags do
if tagName == "inherit" then
local inheritedPackageObject = Processor.getObjectFromName(packageCommentJson, tagArguments[1])

assert(packageObject, `Object '{packageObject.name}' attempted to inherit from invalid class: '{inheritedPackageObject}'`)

local processedPackageObject = Processor.processInheritedObject(packageCommentJson, inheritedPackageObject)

if not packageObject.inherited then
packageObject.inherited = {}
end

(packageObject.inherited :: { })[processedPackageObject.name] = {
properties = processedPackageObject.properties,
functions = processedPackageObject.functions
}

print(`{packageObject.name} INHERITS FROM {processedPackageObject.name}`)
else
warn(`Unknown tag '{packageTags}'`)
end
end

packageObject._processed = true

return packageObject
end

function Processor.processInheritedObjects(packageCommentJson: Moonwave.moonwaveDataExportArray)
for _, object in packageCommentJson do
Processor.processInheritedObject(packageCommentJson, object)
end

return packageCommentJson
end

type processedMoonwaveDataExportObject = Moonwave.moonwaveDataExportObject & {
_processed: boolean?
}

return Processor
22 changes: 22 additions & 0 deletions .lune/generator/tags.luau
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
local Moonwave = require("moonwave")

local Tags = {}

function Tags.getTags(packageObject: Moonwave.moonwaveDataExportObject)
local tagObjects: { [string]: {string} } = {}
local tagCount = 0

if packageObject.tags then
for _, tagString in packageObject.tags do
local tagMetadata = string.split(tagString, " ")
local tagName = table.remove(tagMetadata, 1)

tagCount += 1
tagObjects[tagName] = tagMetadata
end
end

return tagObjects, tagCount
end

return Tags
8 changes: 4 additions & 4 deletions src/content/docs/classes/Builders/MessageBuilder.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ The MessageBuilder instance has no set properties!

## Methods

### toPayloadObject

> <LuaDeclaration name="toPayloadObject" className="MessageBuilder" args={[ ]} returnType="Network.Resolvable" isMethod />
Converts the message to a JSON object that can be sent to the Discord API.
### setContent

> <LuaDeclaration name="setContent" className="MessageBuilder" args={[ { name: "content", type: "string" } ]} returnType="Builders.MessageBuilder" isMethod />
Expand Down Expand Up @@ -74,10 +78,6 @@ Add a file to the Message object
Converts the message to a JSON object that can be sent to the Discord API.
### toPayloadObject

> <LuaDeclaration name="toPayloadObject" className="MessageBuilder" args={[ ]} returnType="Network.Resolvable" isMethod />
Converts the message to a JSON object that can be sent to the Discord API.
### toPayloadObject

> <LuaDeclaration name="toPayloadObject" className="MessageBuilder" args={[ ]} returnType="Network.Resolvable" isMethod />
Converts the message to a JSON object that can be sent to the Discord API.

Expand Down
10 changes: 5 additions & 5 deletions src/content/docs/classes/Network/WebsocketBuffer.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ This class is internal and should not be used directly by developers. Instead, u

### data

<LuaProperty name="WebsocketBuffer.data" type="string" />
---

### data

<LuaProperty name="WebsocketBuffer.data" type="any" />
---

Expand All @@ -49,11 +54,6 @@ This class is internal and should not be used directly by developers. Instead, u
<LuaProperty name="WebsocketBuffer.metadata" type="{ headers: { [string]: string }, attachments: { any }, }," />
---

### data

<LuaProperty name="WebsocketBuffer.data" type="string" />
---


[//]: # (----- DOCUMENT METHODS ----- )

Expand Down
21 changes: 20 additions & 1 deletion src/content/docs/classes/Objects/BaseDiscordGuildChannel.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,20 @@ Represents a base object for any/all guild channels.

## Properties

The BaseDiscordGuildChannel instance has no set properties!
### id

<LuaProperty name="BaseDiscordGuildChannel.id" type="string" />
---


> This property was inherited from [Objects.BaseDiscordChannel](Objects.BaseDiscordChannel)
### type

<LuaProperty name="BaseDiscordGuildChannel.type" type="number" />
---


> This property was inherited from [Objects.BaseDiscordChannel](Objects.BaseDiscordChannel)
[//]: # (----- DOCUMENT METHODS ----- )

Expand Down Expand Up @@ -66,6 +79,12 @@ Gets all archived private threads in the guild channel asynchronously.

> <LuaDeclaration name="getJoinedPrivateArchivedThreads" className="BaseDiscordGuildChannel" args={[ { name: "epoch", type: "number?" }, { name: "limit", type: "number?" } ]} returnType="Vendor.Future<{ number }>" isMethod />
Gets all archived private threads that the bot is a member of, in the guild channel asynchronously.
### deleteAsync

> <LuaDeclaration name="deleteAsync" className="BaseDiscordGuildChannel" args={[ ]} returnType="Vendor.Future" isMethod />
Deletes the channel asynchronously.

> This function was inherited from [Objects.BaseDiscordChannel](Objects.BaseDiscordChannel)
[//]: # (----- DOCUMENT FUNCTIONS ----- )

Expand Down
Loading

0 comments on commit fd74268

Please sign in to comment.