Skip to content

Extract fileName / fileType from ModelElement, LibraryContainer into FileStructure #3413

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

Merged
merged 10 commits into from
May 12, 2023

Conversation

jcollins-g
Copy link
Contributor

This is the first extraction to the new structure and I think it worked out well; the way we construct filenames is now much more comprehensible and all in one place rather than spread throughout the class structure. I've deprecated the old interface so we can avoid major version bumps during this intermediate phase.

Future PRs will extract href, htmlId, and the other as-yet-unimplemented members of FileStructure as appropriate and tie them in to the generator.

@jcollins-g jcollins-g requested a review from srawlins May 12, 2023 18:03
'Unrecognized LibraryContainer subtype: ${libraryContainer.runtimeType}');
}

return FileStructureImpl(
Copy link
Member

Choose a reason for hiding this comment

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

It seems to me a lot of ceremony, to declare kindAddition, and pathSafeName, maybe re-assign to them, and then just return a new FileStructureImpl. Up to you but it could just be:

switch (libraryContainer) {
  case Category():
    return FileStructureImpl(
        libraryContainer.config.format, libraryContainer.name, 'topic');
  case Package():
    return FileStructureImpl(
        libraryContainer.config.format, 'index', null);
  default:
    throw ...
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmmm. I think the fact I rewrote this several times is leaking through. Yes, that's much better. Fixing here and in _fromModelElement.

String get htmlId => throw UnimplementedError();
final String fileType;
String pathSafeName;
final String? kindAddition;
Copy link
Member

Choose a reason for hiding this comment

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

Would you mind documenting what this field is?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not at all. It's kind of hacky so definitely deserves some description.

@@ -70,23 +72,37 @@ analyzer:
packagePath, name, Uri.file('$packagePath/'));
}

Future<PackageGraph> _bootPackageFromFiles(FileGenerator files) async {
Copy link
Member

Choose a reason for hiding this comment

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

I'm a little confused by the name. files doesn't seem like something you'd invoke. fileGenerator?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. I'm a little confused by why I have a function as a parameter here at all. Deleted that, so now the name makes sense.

{String libraryPreamble = ''}) async {
await d.dir('lib', [
d.file('lib.dart', '''
{String libraryPreamble = '', FileGenerator? extraFiles}) async {
Copy link
Member

Choose a reason for hiding this comment

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

The new extraFiles parameter looks unused?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good catch, missed that in a refactor.

@jcollins-g jcollins-g merged commit 0cf21c1 into dart-lang:main May 12, 2023
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.

2 participants