Closed makspll closed 2 years ago
The generated json is:
{
"given_types": [
{
"Record": {
"should_be_inlined": false,
"is_user_data": true,
"type_name": [
{
"Type": {
"name": "APIModule",
"type_kind": "External",
"generics": null
}
}
],
"fields": [],
"methods": [],
"mut_methods": [],
"functions": [
{
"name": "my_function",
"signature": [
{
"Symbol": "function"
},
{
"Symbol": "("
},
{
"Type": {
"name": "string",
"type_kind": "Builtin",
"generics": null
}
},
{
"Symbol": "):("
},
{
"Type": {
"name": "string",
"type_kind": "Builtin",
"generics": null
}
},
{
"Symbol": ")"
}
],
"is_meta_method": false
},
{
"name": "help",
"signature": [
{
"Symbol": "function"
},
{
"Symbol": "("
},
{
"Type": {
"name": "string",
"type_kind": "Builtin",
"generics": null
}
},
{
"Symbol": "):("
},
{
"Type": {
"name": "string",
"type_kind": "Builtin",
"generics": null
}
},
{
"Symbol": ")"
}
],
"is_meta_method": false
}
],
"mut_functions": [],
"meta_method": [],
"meta_method_mut": [],
"meta_function": [],
"meta_function_mut": [],
"documentation": {
"my_function": "Here we document the next function\n\n## Markdown!:\n\n```lua\n local hello = \"string\";\n ```\\n"
},
"type_doc": "This is module level documentation for our api, it will be shown first\n\n\n\n",
"next_docs": null,
"should_generate_help_method": true
}
}
],
"global_instances_off": [
[
"my_api",
[
{
"Type": {
"name": "APIModule",
"type_kind": "External",
"generics": null
}
}
],
true
]
]
}
And it's happening when running the tealr_doc_gen command through
GEN_SCRIPT_DOC=true cargo run --example documentation_gen_lua --features="lua54" --target-dir target
I'm assuming that you get this error from tealr_doc_gen
?
If so, did you make sure to use the latest version of it from the master branch and that it uses the correct tealr version? (Same one that you are using)
Just tested the json with a local version of tealr_doc_gen
and didn't get an error. There seems to be a problem with markdown though
Hmm,
I am using the version from: https://github.com/lenscas/tealr/pull/49
this is in my Cargo.toml file :
tealr = { git = "https://github.com/lenscas/tealr", features = ["mlua_vendored","mlua_send"], branch="feature/document_global_instances" }
serde_json = "1.0.81"
I installed tealr_doc_gen via
cargo install tealr_doc_gen
That's probably why
using cargo install --git https://github.com/lenscas/tealr_doc_gen
fixed the issue!
I found another minor issue though, if the --build_folder
does not exist the command will error out instead of creating the folder which probably shouldn't happen other than that this is great!
I found another minor issue though, if the --build_folder does not exist the command will error out instead of creating the folder which probably shouldn't happen other than that this is great!
Let me write that down as an issue in tealr_doc_gen real quick :)
Not sure what the ``` come from though, that's a bit weird,
tried without raw string literals but comes out the same:
methods.document(
"```lua
local hello = \"string\";
```");
I think it is because there are technically spaces before the closing "```" part. Not sure how to best fix that on tealr_doc_gen's end though, as removing every space/tab at the start of a line is also not at all a good strategy....
hmm,
methods.document(
"```lua
local hello = \"string\"```\n");
This sadly doesn't fix it
it would need to be
methods.document(
"```lua
local hello = \"string\"
```\n");
Yeah that fixes it
So does this actually:
methods.document(
"```lua
local hello = \"string\"
\n```");
maybe automatically inserting \n
before closing ticks and removing trailing whitespace could work
I believe more is needed, as in that example the line local hello = \"string\"
will also be pushed to the right. For reference, taken as is, github would render that codeblock like:
local hello = \"string\"
and I am making a guess and say that tealr_doc_gen
act similar (as well as it ending up in the .d.tl
file like that.
that is why I often use multiple calls to .document()
rather than making 1 big string. I'm thinking of making it easier to do that by making the calls chainable and adding a shorthand so you can just do:
methods.d("line1")
.d("line 2")
.d("line 3")
.add_function(/*params here*/);
That sounds like a good idea, you could also include a specific d_md
method which automatically surrounds the text in triple ticks to avoid spacing issues
I actually want to stay a bit neutral (as far as that is possible) with how I present the documentation. I want teal
to be able to make their own decisions on how documentation works and then have tealr_doc_gen follow.
I just had to choose something to get the project of the ground.
I suppose examples will always be a thing though no matter what format teal ends up using, so I could special case them and make nicer methods for that (an example_start
and example_end
that take a string for the language. With shorthands that already have the language set like e_tl
for teal+lua, e_t
for just teal and e_l
for just lua and of cours es
to stop the example)
Then you get something like
methods
.e_tl()
.d("local a:number = 1")
.d("local b:number = a + a")
.es()
.add_method(/*params */);
anyway, this was 3 seconds worth of thinking so.... there is probably a nicer api. Will tinker with it :)
I am getting this error while running: https://github.com/makspll/bevy_mod_scripting/blob/switch_to_mlua_tealr/bevy_mod_scripting/examples/documentation_gen_lua.rs the relevant code is:
and