-
Notifications
You must be signed in to change notification settings - Fork 234
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
Support for generation of documentation comments for bindings #1498
Closed
Closed
Changes from 30 commits
Commits
Show all changes
84 commits
Select commit
Hold shift + click to select a range
c32a73f
added docs to ruby and kotlin
MeerKatDev d1aca97
added docs to ruby and kotlin
MeerKatDev bb3c9ab
added python docs
MeerKatDev 47e9121
swift documentation for ddoc
MeerKatDev 4f464fd
fix
MeerKatDev 86dc502
fix
MeerKatDev a3e809f
Add documentation comments extraction feature.
zduny 677276b
Update templates.
zduny f57a39f
Add documentation example.
zduny 2bed958
Add initial version of Function::from_str() (#6)
eloylp 6a11e01
Update doc comments.
zduny 70acde6
Add documentation member to enum.
zduny 2072413
Implement attaching documentation to enums.
zduny 0b243aa
Add methods to Structure.
zduny c3960b1
Add documentation field to objects and constructors.
zduny 1ffe8c1
Implement attaching docs to objects.
zduny a07e8f8
Slight refactor, bug fix.
zduny 2790097
Add a test for extract_documentation.
zduny 0c00a32
Update templates.
zduny 932970f
Update documentation example.
zduny cce8288
Add README.md to uniffi_docs.
zduny 7594b3f
Implement type_name askama filter for Ruby.
zduny 2b8fb15
Update templates.
zduny 2c98ead
Implement extraction of doc comments for members.
zduny dd5fb26
Implement attaching documentation to struct fields/enum variants.
zduny dd0a250
Update templates.
zduny b841de3
Use derives.
zduny 2e369d6
Fix non-optimal code.
zduny e4c4150
Implement module traversal.
zduny c936e7f
Update examples README.md.
zduny b7f0327
Clippy and format.
zduny 3e04e2f
Merge pull request #7 from eigerco/pr-fixes
zduny 80fcd3a
added docs to ruby and kotlin
MeerKatDev a23f6ef
added docs to ruby and kotlin
MeerKatDev 0337dfa
added python docs
MeerKatDev be40200
swift documentation for ddoc
MeerKatDev 9c8ad99
fix
MeerKatDev fd1f126
fix
MeerKatDev b2de688
Add documentation comments extraction feature.
zduny 3478514
Update templates.
zduny abb312b
Add documentation example.
zduny 70bda23
Add initial version of Function::from_str() (#6)
eloylp 48c7db5
Update doc comments.
zduny 788a3bd
Add documentation member to enum.
zduny 74aef50
Implement attaching documentation to enums.
zduny 0a70a7a
Add methods to Structure.
zduny ec824a2
Add documentation field to objects and constructors.
zduny fa7f9a4
Implement attaching docs to objects.
zduny 3b6481f
Slight refactor, bug fix.
zduny 4fe1e1a
Add a test for extract_documentation.
zduny f91861f
Update templates.
zduny 1495ef2
Update documentation example.
zduny 7a1593b
Add README.md to uniffi_docs.
zduny a1a3a7a
Implement type_name askama filter for Ruby.
zduny b1f736a
Update templates.
zduny 4f7a379
Implement extraction of doc comments for members.
zduny 5157909
Implement attaching documentation to struct fields/enum variants.
zduny 44a149c
Update templates.
zduny 69d758f
Use derives.
zduny 8c833a1
Fix non-optimal code.
zduny 26a794a
Implement module traversal.
zduny 2c36515
Update examples README.md.
zduny 3d768cb
Clippy and format.
zduny 5ca5ee6
lock update
MeerKatDev fc57daa
fixing stuff
MeerKatDev d93d68b
fixes
MeerKatDev 8fd22fe
fixed funcs
MeerKatDev c9b284a
fixing ruby templates
MeerKatDev 394a054
testing fix
MeerKatDev b4f7831
Merge branch 'main' into new-upstream
MeerKatDev deeffb8
Merge remote-tracking branch 'upstream/main'
MeerKatDev 10c37b4
cargo fmt'ed
MeerKatDev 3116377
solved merge
MeerKatDev 0d39d41
fixes
MeerKatDev a26981f
suggested changes to iter_mut
MeerKatDev 4b5e018
clippy and fmt
MeerKatDev 3968891
Merge branch 'main' into mozilla-main
MeerKatDev b1f6019
Merge release v0.25
MeerKatDev 434ae5d
fixed deps for v0.25
MeerKatDev 74fc05c
Merge branch 'mozilla:main' into main
MeerKatDev 76be1da
Merge remote-tracking branch 'upstream/main' into merge-upstream
MeerKatDev e8e4d9c
updated docs version
MeerKatDev 2e7a9ae
reverted nonsense change
MeerKatDev 2e22cb2
Merge pull request #16 from eigerco/merge-upstream
MeerKatDev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
[package] | ||
name = "uniffi-example-documentation" | ||
edition = "2021" | ||
version = "0.23.0" | ||
license = "MPL-2.0" | ||
publish = false | ||
|
||
[lib] | ||
crate-type = ["lib", "cdylib"] | ||
name = "uniffi_documentation" | ||
|
||
[dependencies] | ||
uniffi = { path = "../../uniffi"} | ||
|
||
[build-dependencies] | ||
uniffi = { path = "../../uniffi", features = ["build"] } | ||
|
||
[dev-dependencies] | ||
uniffi = { path = "../../uniffi", features = ["bindgen-tests"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
fn main() { | ||
uniffi::generate_scaffolding("./src/documentation.udl").unwrap(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
namespace documentation { | ||
string hello(Pet pet); | ||
u64 add(u64 a, u64 b); | ||
}; | ||
|
||
dictionary Pet { | ||
string name; | ||
}; | ||
|
||
interface Person { | ||
constructor(string name); | ||
void set_name(string name); | ||
string get_name(); | ||
}; | ||
|
||
enum TestEnum { | ||
"A", | ||
"B", | ||
"C", | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
use std::sync::RwLock; | ||
|
||
/// Pet with a name. | ||
pub struct Pet { | ||
/// Pet's name. | ||
pub name: String, | ||
} | ||
|
||
/// Create hello message to a `pet`. | ||
pub fn hello(pet: Pet) -> String { | ||
let name = pet.name; | ||
format!("Hello {name}!") | ||
} | ||
|
||
/// Person with a name. | ||
pub struct Person { | ||
name: RwLock<String>, | ||
} | ||
|
||
impl Person { | ||
/// Create new person with [name]. | ||
pub fn new(name: String) -> Self { | ||
Person { | ||
name: RwLock::new(name), | ||
} | ||
} | ||
|
||
/// Set person name. | ||
pub fn set_name(&self, name: String) { | ||
*self.name.write().unwrap() = name; | ||
} | ||
|
||
/// Get person's name. | ||
pub fn get_name(&self) -> String { | ||
self.name.read().unwrap().clone() | ||
} | ||
} | ||
|
||
/// Add two integers together. | ||
pub fn add(left: u64, right: u64) -> u64 { | ||
left + right | ||
} | ||
|
||
/// Test enum. | ||
pub enum TestEnum { | ||
/// Variant A. | ||
A, | ||
|
||
/// Variant B. | ||
B, | ||
|
||
/// Variant C. | ||
C, | ||
} | ||
|
||
uniffi::include_scaffolding!("documentation"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import uniffi.documentation.* | ||
|
||
assert(hello(Pet("Tom")) == "Hello Tom!") | ||
assert(Person("Daniel").getName() == "Daniel") | ||
assert(add(2UL, 4UL) == 6UL) |
19 changes: 19 additions & 0 deletions
19
examples/documentation/tests/bindings/test_documentation.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import unittest | ||
import documentation | ||
|
||
class TestHello(unittest.TestCase): | ||
def test_hello(self): | ||
self.assertEqual(documentation.hello(documentation.Pet("Tom")), | ||
"Hello Tom!", "Should be `Hello Tom!`") | ||
|
||
class TestGetName(unittest.TestCase): | ||
def test_get_name(self): | ||
self.assertEqual(documentation.Person("Daniel").get_name(), "Daniel", "Should be Daniel") | ||
|
||
class TestAdd(unittest.TestCase): | ||
def test_add(self): | ||
self.assertEqual(documentation.add(2, 4), 6, "Should be 6") | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() | ||
10 changes: 10 additions & 0 deletions
10
examples/documentation/tests/bindings/test_documentation.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'test/unit' | ||
require 'documentation' | ||
|
||
include Test::Unit::Assertions | ||
|
||
assert_equal Documentation.hello(Documentation::Pet.new("Tom")), "Hello Tom!" | ||
assert_equal Documentation::Person.new("Daniel").get_name(), "Daniel" | ||
assert_equal Documentation.add(2, 4), 6 |
5 changes: 5 additions & 0 deletions
5
examples/documentation/tests/bindings/test_documentation.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import documentation | ||
|
||
assert(hello(pet: Pet(name: "Tom")) == "Hello Tom!", "hello works") | ||
assert(Person(name: "Daniel").getName() == "Daniel", "getName works") | ||
assert(add(a: 2, b: 4) == 6, "add works") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
uniffi::build_foreign_language_testcases!( | ||
"tests/bindings/test_documentation.py", | ||
"tests/bindings/test_documentation.rb", | ||
"tests/bindings/test_documentation.kts", | ||
"tests/bindings/test_documentation.swift", | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[bindings] | ||
doc_comments = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
uniffi_bindgen/src/bindings/kotlin/templates/EnumVariantDocsTemplate.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{% match variant.documentation() -%} | ||
{% when Some with (docs) %} | ||
/** | ||
{% for line in docs.lines() %} * {{ line }} | ||
{% endfor %} */ | ||
{%- when None %} | ||
{%- endmatch %} |
20 changes: 20 additions & 0 deletions
20
uniffi_bindgen/src/bindings/kotlin/templates/FunctionDocsTemplate.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
|
||
{% match func.documentation() -%} | ||
{% when Some with (docs) %} | ||
/** | ||
{% for line in docs.description.lines() %} * {{ line }} | ||
{% endfor %} | ||
|
||
{%- if docs.arguments_descriptions.len() > 0 %} * | ||
{% for arg in func.arguments() -%} | ||
* @param [{{ arg.name() }}] {{ docs.arguments_descriptions[arg.name()] }} | ||
{% endfor -%} | ||
{% endif -%} | ||
|
||
{%- match docs.return_description -%} | ||
{% when Some with (desc) %} * | ||
* @return {{ desc }} | ||
{%- when None %} | ||
{%- endmatch %} */ | ||
{%- when None %} | ||
{%- endmatch %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
uniffi_bindgen/src/bindings/kotlin/templates/RecordDocsTemplate.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{% match struct.documentation() -%} | ||
{% when Some with (docs) %} | ||
/** | ||
{% for line in docs.description.lines() %} * {{ line }} | ||
{% endfor %} | ||
{%- if struct.has_fields_documentation() %} * | ||
{% endif -%} | ||
{% for f in struct.fields() -%} | ||
{% match f.documentation() -%} | ||
{% when Some with (docs) %} * @property {{ f.name() }} {{ docs }} | ||
{% when None %} | ||
{%- endmatch %} | ||
{%- endfor %} */ | ||
{%- when None %} | ||
{%- endmatch %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
uniffi_bindgen/src/bindings/kotlin/templates/StructureDocsTemplate.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{% match struct.documentation() -%} | ||
{% when Some with (docs) %} | ||
/** | ||
{% for line in docs.description.lines() %} * {{ line }} | ||
{% endfor %} */ | ||
{%- when None %} | ||
{%- endmatch %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
uniffi_bindgen/src/bindings/python/templates/EnumVariantDocsTemplate.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{% match variant.documentation() -%} | ||
{% when Some with (docs) %}""" | ||
{% for line in docs.lines() %} {{ line }} | ||
{% endfor %} """ | ||
{%- when None %} | ||
{%- endmatch %} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
It seems like this is testing the functionality rather than the doc generation.
What if we made these tests work more like the trybuild tests? We check source files that have the classes/functions/whatever, with the docstrings, but with stub code for their bodies. Then test that the generated code has docstrings that match the expected ones. I think that's testing this change better and also users can browse the checked in files to get a feeling of what the generated docs look like.
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.
I agree - as written this test doesn't seem to have any value - it's testing things with already good coverage and doesn't seem to be testing the new functionality added here.
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.
I have implemented a "unit" test to ensure that generated bindings contain appropriate docstrings. The test is written in a fixture. Inside the UDL file, each uniffi node (
function
,object
,enum
, etc..) has a different docstring attached to it. The test generates bindings from the UDL file. Then, the test doescat|grep
to ensure that docstrings are being generated for all nodes. While this test doesn't check that docstrings are placed in the appropriate location, it does at least ensure that all nodes attempt to generate some form of their docstrings.You can check the code here: https://github.com/NordSecurity/uniffi-rs/compare/kristupas/docstrings...NordSecurity:uniffi-rs:kristupas/docstring-templates?expand=1
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.
Unit test is just a part of an example - it does not test doc generation.
IMO doc comments generation should be tested separately, outside of examples (you shouldn't be confusing
uniffi-rs
users withuniffi-rs
internal functionality testing inside examples) - how to do it is still TBD.