-
-
Notifications
You must be signed in to change notification settings - Fork 93
chore: improve interpolation documentation by making it an syntax-enum
#1400
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
base: main
Are you sure you want to change the base?
Changes from all commits
35088f2
b30dbf5
446cd69
d1719bc
87c0da0
26e80de
1ef6397
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -195,33 +195,77 @@ function expressionSyntaxToMarkdown(key: string, syntax: JsonExpressionSyntax) { | |
| }); | ||
| markdown += `${codeBlockMarkdown(codeBlockLines.join('\n'), 'js')}\n`; | ||
| for (const parameter of syntax.parameters ?? []) { | ||
| const type = parameterTypeToType(parameter.type) | ||
| .replaceAll('<', '<') | ||
| .replaceAll('>', '>'); | ||
| const type = parameterTypeToType(parameter.type); | ||
| markdown += `- \`${parameter.name}\`: \`${type}\``; | ||
| if (parameter.doc) { | ||
| markdown += `- ${parameter.doc}`; | ||
| } | ||
| if (typeof parameter.type !== 'string' && !Array.isArray(parameter.type)) { | ||
| // the type is an object type => we can attach more documentation about the contained variables | ||
| markdown += ' \nParameters:'; | ||
| Object.entries(parameter.type).forEach(([key, val]) => { | ||
| const type = jsonObjectToType(val).replaceAll('<', '<').replaceAll('>', '>'); | ||
| markdown += `\n - \`${key}\`: \`${type}\` - ${val.doc}`; | ||
| if (val.type === 'enum' && val.values) { | ||
| markdown += ' \n Possible values are:'; | ||
| for (const [enumKey, enumValue] of Object.entries(val.values)) { | ||
| const defaultIndicator = val.default === enumKey ? ' *default*' : ''; | ||
| markdown += `\n - \`"${enumKey}"\`${defaultIndicator} - ${enumValue.doc}`; | ||
| } | ||
| } | ||
| }); | ||
| const containedVariables = containedVariablesToMarkdown(parameter.type); | ||
| for (const line of containedVariables.split('\n')) { | ||
| markdown += `\n ${line}`; | ||
| } | ||
| } | ||
| if (parameter.type === 'interpolation') { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a different way to achieve this? I prefer to be as generic as possible here...
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The other "length1-array with syntax-enum as value" is expressions. Also, the indentation and newline requirement (those two spaces before \n) would be a bit tricky to do this way. Unless you want a major change to how this system works (which might make sense, but would be a larger change)
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In saying the same thing in both comments basically: is there a more generalized way to achieve the same thing? Or maybe reuse some code?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Generalised? Not without basically rewriting the entire thing. I moved the two things you commented on to a function each. |
||
| markdown += " "; | ||
| const interpolationSyntax = interpolationSyntaxToMarkdown(); | ||
| for (const line of interpolationSyntax.split('\n')) { | ||
| markdown += `\n ${line}`; | ||
| } | ||
| } | ||
| markdown += '\n'; | ||
| } | ||
| return markdown; | ||
| } | ||
|
|
||
| /** | ||
| * Converts the contained variables object to markdown format. | ||
| * @param type - the contained variables object | ||
| * @returns the markdown string for the interpolation's syntax section | ||
| */ | ||
| function containedVariablesToMarkdown(type: {[key: string]: JsonObject}) { | ||
| let markdown = ""; | ||
| Object.entries(type).forEach(([key, val]) => { | ||
| const type = jsonObjectToType(val); | ||
| markdown += `\n- \`${key}\`: \`${type}\` - ${val.doc}`; | ||
| if (val.type === 'enum' && val.values) { | ||
| markdown += ' \n Possible values are:'; | ||
| for (const [enumKey, enumValue] of Object.entries(val.values)) { | ||
| const defaultIndicator = val.default === enumKey ? ' *default*' : ''; | ||
| markdown += `\n - \`"${enumKey}"\`${defaultIndicator} - ${enumValue.doc}`; | ||
| } | ||
| } | ||
| }); | ||
| return markdown | ||
| } | ||
|
|
||
| /** | ||
| * Converts the interpolation syntax object to markdown format. | ||
| * @returns the markdown string for the interpolation's syntax section | ||
| */ | ||
| function interpolationSyntaxToMarkdown() { | ||
| const interpolation = v8.interpolation; | ||
| let markdown = interpolation.doc; | ||
| const interpolation_name=v8.interpolation_name; | ||
| markdown += ` \nPossible values are:`; | ||
| for (const [key,val] of Object.entries(interpolation_name.values)) { | ||
| markdown += ` \n - \`["${key}"` | ||
| for (const param of val.syntax.overloads[0].parameters) { | ||
| markdown += `, ${param}` | ||
| } | ||
| markdown += `]\`: ${val.doc}`; | ||
| if (val.syntax.parameters.length) { | ||
| markdown += ` \n Parameters are:` | ||
| for (const param of val.syntax.parameters) { | ||
| markdown += ` \n \`${param.name}\`: ${param.doc}` | ||
| } | ||
| } | ||
| } | ||
| return markdown | ||
| } | ||
|
|
||
| /** | ||
| * The requires field has some syntax which can contain "!" and "source". | ||
| * @param requires - a list of requirements for the property | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unrelated, but was a bad idea to include.