Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/pigeon/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 27.1.1

* [dart] Adds usage documentation to generated event channel methods, and
emits the user's documentation comments on them.

## 27.1.0

* [swift] Adds `CaseIterable` conformance to generated enums.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,12 @@ class _PigeonCodec extends StandardMessageCodec {

const StandardMethodCodec pigeonMethodCodec = StandardMethodCodec(_PigeonCodec());

/// Returns a broadcast [Stream] of events from the `streamEvents` event channel.
///
/// Each call to this method creates a new [EventChannel], so it should
/// not be called multiple times for the same `instanceName`. To deliver
/// events to multiple listeners, call this method once and listen to the
/// returned broadcast stream multiple times instead.
Stream<PlatformEvent> streamEvents({String instanceName = ''}) {
if (instanceName.isNotEmpty) {
instanceName = '.$instanceName';
Expand Down
13 changes: 13 additions & 0 deletions packages/pigeon/lib/src/dart/dart_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,19 @@ final BinaryMessenger? ${varNamePrefix}binaryMessenger;
indent.newln();
addDocumentationComments(indent, api.documentationComments, docCommentSpec);
for (final Method func in api.methods) {
addDocumentationComments(
indent,
func.documentationComments,
docCommentSpec,
generatorComments: <String>[
'Returns a broadcast [Stream] of events from the `${func.name}` event channel.',
'',
'Each call to this method creates a new [EventChannel], so it should',
'not be called multiple times for the same `instanceName`. To deliver',
'events to multiple listeners, call this method once and listen to the',
'returned broadcast stream multiple times instead.',
],
);
indent.format('''
Stream<${func.returnType.baseName}> ${func.name}(${_getMethodParameterSignature(func.parameters, addTrailingComma: true)} {String instanceName = ''}) {
if (instanceName.isNotEmpty) {
Expand Down
2 changes: 1 addition & 1 deletion packages/pigeon/lib/src/generator_tools.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import 'generator.dart';
/// The current version of pigeon.
///
/// This must match the version in pubspec.yaml.
const String pigeonVersion = '27.1.0';
const String pigeonVersion = '27.1.1';

/// Default plugin package name.
const String defaultPluginPackageName = 'dev.flutter.pigeon';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,12 @@ class _PigeonCodec extends StandardMessageCodec {

const StandardMethodCodec pigeonMethodCodec = StandardMethodCodec(_PigeonCodec());

/// Returns a broadcast [Stream] of events from the `streamInts` event channel.
///
/// Each call to this method creates a new [EventChannel], so it should
/// not be called multiple times for the same `instanceName`. To deliver
/// events to multiple listeners, call this method once and listen to the
/// returned broadcast stream multiple times instead.
Stream<int> streamInts({String instanceName = ''}) {
if (instanceName.isNotEmpty) {
instanceName = '.$instanceName';
Expand All @@ -676,6 +682,12 @@ Stream<int> streamInts({String instanceName = ''}) {
});
}

/// Returns a broadcast [Stream] of events from the `streamEvents` event channel.
///
/// Each call to this method creates a new [EventChannel], so it should
/// not be called multiple times for the same `instanceName`. To deliver
/// events to multiple listeners, call this method once and listen to the
/// returned broadcast stream multiple times instead.
Stream<PlatformEvent> streamEvents({String instanceName = ''}) {
if (instanceName.isNotEmpty) {
instanceName = '.$instanceName';
Expand All @@ -689,6 +701,12 @@ Stream<PlatformEvent> streamEvents({String instanceName = ''}) {
});
}

/// Returns a broadcast [Stream] of events from the `streamConsistentNumbers` event channel.
///
/// Each call to this method creates a new [EventChannel], so it should
/// not be called multiple times for the same `instanceName`. To deliver
/// events to multiple listeners, call this method once and listen to the
/// returned broadcast stream multiple times instead.
Stream<int> streamConsistentNumbers({String instanceName = ''}) {
if (instanceName.isNotEmpty) {
instanceName = '.$instanceName';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ class _PigeonCodec extends StandardMessageCodec {

const StandardMethodCodec pigeonMethodCodec = StandardMethodCodec(_PigeonCodec());

/// Returns a broadcast [Stream] of events from the `streamIntsAgain` event channel.
///
/// Each call to this method creates a new [EventChannel], so it should
/// not be called multiple times for the same `instanceName`. To deliver
/// events to multiple listeners, call this method once and listen to the
/// returned broadcast stream multiple times instead.
Stream<int> streamIntsAgain({String instanceName = ''}) {
if (instanceName.isNotEmpty) {
instanceName = '.$instanceName';
Expand Down
2 changes: 1 addition & 1 deletion packages/pigeon/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: pigeon
description: Code generator tool to make communication between Flutter and the host platform type-safe and easier.
repository: https://github.com/flutter/packages/tree/main/packages/pigeon
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+pigeon%22
version: 27.1.0 # This must match the version in lib/src/generator_tools.dart
version: 27.1.1 # This must match the version in lib/src/generator_tools.dart

environment:
sdk: ^3.10.0
Expand Down
40 changes: 40 additions & 0 deletions packages/pigeon/test/dart_generator_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,46 @@ void main() {
expect(code, contains(' two,'));
});

test('gen event channel api with usage docs on the generated method', () {
final api = AstEventChannelApi(
name: 'EventApi',
methods: <Method>[
Method(
name: 'streamEvents',
location: ApiLocation.host,
returnType: const TypeDeclaration(baseName: 'int', isNullable: false),
parameters: <Parameter>[],
documentationComments: <String>[' An example event stream.'],
),
],
);
final root = Root(apis: <Api>[api], classes: <Class>[], enums: <Enum>[]);
final sink = StringBuffer();
const generator = DartGenerator();
generator.generate(
const InternalDartOptions(ignoreLints: false),
root,
sink,
dartPackageName: DEFAULT_PACKAGE_NAME,
);
final code = sink.toString();
expect(code, contains('Stream<int> streamEvents('));
// The user's own documentation comments are emitted.
expect(code, contains('/// An example event stream.'));
// The generated usage documentation explains the channel-owning and
// broadcast semantics.
expect(
code,
contains('/// Returns a broadcast [Stream] of events from the `streamEvents` event channel.'),
);
expect(code, contains('not be called multiple times for the same `instanceName`'));
// The usage documentation is attached directly above the generated method.
expect(
code.indexOf('not be called multiple times'),
lessThan(code.indexOf('Stream<int> streamEvents(')),
);
});

test('gen one host api', () {
final root = Root(
apis: <Api>[
Expand Down