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

Support References in docs #311

Closed
wants to merge 4 commits into from

Conversation

srawlins
Copy link
Member

@srawlins srawlins commented Mar 8, 2021

Work for #217. (I'm not sure what else is desired for that bug...)

@google-cla google-cla bot added the cla: yes label Mar 8, 2021
Copy link
Contributor

@matanlurey matanlurey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some thoughts. Would love @natebosch to weigh in too!

@@ -6,10 +6,10 @@ import 'package:built_collection/built_collection.dart';

abstract class HasDartDocs {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add comments here and below why Object is being used and what a valid type is (and isn't).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Class(
(b) => b
..name = 'Foo'
..docs.addAll(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Part of me wonders if docs should be a more complex class than a List, i.e.:

class DocsBuilder {
  void addText();
  void addReference();
}

... WDUT? It would be more breaking, though.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I started out with a much bigger change where I added a new class, DocComments, and everything that HasDocComments today also got a @nullable DocComments field. Then that class just had a List<Object>, so that you could add Strings, and References.

Then I looked back and saw that I had really just created this unnecessary nesting, and confusion with the existing docs field. And the emitter would probably have to have some weird logic in it saying "use one or the other." Essentially the new DocComment type did not help with the List<Object> issue.

If there was a way to hook into BuiltList, with validation logic, that would be tops. Then I could validate the type at runtime. Or add specific methods, addText and addReference. There isn't, is there? Would I subtype BuiltList/ListBuilder? ☹️

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I honestly am not sure. Let's wait and see what @natebosch says - we could also consult with @davidmorgan.

If you want this change as-is, I'm willing to approve. I do think we should consider making the interface better.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope! I am definitely in favor of getting this right. And if creating a new field and adding "don't use both" logic to emitter is ultimately the right way, I'm game.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the recommended way to do that would be to make an interface Doc and have built value classes Text and Reference that implement it. I don't think that can be a compatible change, unfortunately.

BuiltList can't do validation, you could validate in the class that has the list, a built_value can do validation in the private _ constructor, the fields are all initialized when it runs.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack

@natebosch
Copy link
Member

I do think it would be best to add a new field for this and deprecate the old one.

I think we should move away from List and call the new field doc, or docComment or maybe documentation instead of the plural docs - and it should be a built value type. We can add a convenience text constructor. Usage could migrate from docs.add('Something.') to doc = DocComment.text('Something.')

@srawlins
Copy link
Member Author

Sounds good.

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.

None yet

4 participants