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

Connect up augmentations from macro output through to host. #21

Merged
merged 1 commit into from
Aug 7, 2024

Conversation

davidmorgan
Copy link
Contributor

Hook up macro augmentation output end to end.

Add the capability to reference the dart_model schema from the macro_service schema, because Augmentation is in dart_model.

The wire format still does not carry the actual request type because it's not needed yet, there are few enough request types to always "guess" correctly. It will need the request type very soon :)

Copy link
Contributor

@jakemac53 jakemac53 left a comment

Choose a reason for hiding this comment

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

Sorry apparently I never actually send my review comments from last week, now they are on outdated commits I think due to the force push but lets see if it does anything reasonable...

pkgs/_macro_client/lib/macro_client.dart Outdated Show resolved Hide resolved
pkgs/_macro_client/test/macro_client_test.dart Outdated Show resolved Hide resolved
final augmentRequest =
AugmentRequest.fromJson(json.decode(request) as Map<String, Object?>);
// TODO(davidmorgan): support multiple macros.
final response = await macros.single.augment(host, augmentRequest);
Copy link
Contributor

Choose a reason for hiding this comment

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

Related to my comment in the previous PR but I don't think this is the correct API for us to expose, it is too low level. I would like to see macros look more like they do in the current API.

Also, I think this makes merging augmentations from multiple macros together more difficult, which is partly why the augmentation library generation is done by the host right now and not the macro.

@@ -61,18 +66,35 @@ class MacroHost implements MacroService {
return _macroPhases!;
}

/// Sends it [request] to the macro with [name].
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/// Sends it [request] to the macro with [name].
/// Sends [request] to the macro with [name].

pkgs/_macro_host/lib/macro_host.dart Outdated Show resolved Hide resolved
pkgs/_macro_host/lib/macro_host.dart Outdated Show resolved Hide resolved
pkgs/_macro_host/lib/macro_host.dart Outdated Show resolved Hide resolved
});

/// Augmentation code.
String get code => node['code'] as String;
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems wrong that this assumes code exists, but the constructor does not require it to be non-null. Should this be typed as String?? Similar question for below.


@override
SyncJsonProvider get provide => (String path) {
if (path != 'file:///dart_model.schema.json') {
Copy link
Contributor

Choose a reason for hiding this comment

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

should we have a custom scheme for this?

@@ -12,7 +12,10 @@ void main() {
for (final package in ['dart_model', 'macro_service']) {
test('$package output is up to date', () {
final expected = dart_model_generator.generate(
File('../../schemas/$package.schema.json').readAsStringSync());
File('../../schemas/$package.schema.json').readAsStringSync(),
importDartModel: package == 'macro_service',
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be good if we could somehow make this a more general thing, similar to how it works in protos where the dependencies live in the schema file. Is there an eventual path towards that?

@davidmorgan davidmorgan changed the base branch from macro-builder to main August 6, 2024 07:45
@davidmorgan davidmorgan force-pushed the augment branch 4 times, most recently from 08f457e to 7d757a2 Compare August 6, 2024 09:48
@davidmorgan
Copy link
Contributor Author

Thanks, PTAL.

Copy link
Contributor

@jakemac53 jakemac53 left a comment

Choose a reason for hiding this comment

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

Feel free to leave TODOs for anything outstanding so we can get out of the chained PR state :)

throw StateError('request is already pending');
}
_responseCompleter = Completer<AugmentResponse>();
final result = await _responseCompleter!.future;
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this local variable here actually do anything? Maybe you are getting type promotion actually since its private so you don't need this (since the completer has a more specific type?).

What I actually had in mind was assigning the completer to a local variable (as well as the field) and returning the future from the local variable since it would have a better type. But if the promotion works here that is better.

@davidmorgan davidmorgan merged commit 693f52e into dart-lang:main Aug 7, 2024
39 checks passed
@davidmorgan davidmorgan deleted the augment branch August 7, 2024 07:09
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