Skip to content
Closed
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
1 change: 1 addition & 0 deletions protoc_plugin/lib/protoc.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:convert';

import 'package:dart_style/dart_style.dart';
import 'package:protobuf/protobuf.dart';

import 'const_generator.dart' show writeJsonConst;
Expand Down
13 changes: 10 additions & 3 deletions protoc_plugin/lib/src/file_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,13 @@ class FileGenerator extends ProtobufContainer {
List<CodeGeneratorResponse_File> generateFiles(OutputConfiguration config) {
if (!_linked) throw StateError('not linked');

String formatDartCode(String code) {
final formatter = DartFormatter();
Copy link
Collaborator

Choose a reason for hiding this comment

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

maybe make the formater as instance var? So it's not created every call?


final formattedCode = formatter.format(code);
return formattedCode;
}

CodeGeneratorResponse_File makeFile(String extension, String content) {
var protoUrl = Uri.file(descriptor.name);
var dartUrl = config.outputPathFor(protoUrl, extension);
Expand All @@ -235,9 +242,9 @@ class FileGenerator extends ProtobufContainer {
var enumWriter = generateEnumFile(config);

final files = [
makeFile('.pb.dart', mainWriter.toString()),
makeFile('.pbenum.dart', enumWriter.toString()),
makeFile('.pbjson.dart', generateJsonFile(config)),
makeFile('.pb.dart', formatDartCode(mainWriter.toString())),
makeFile('.pbenum.dart', formatDartCode(enumWriter.toString())),
makeFile('.pbjson.dart', formatDartCode(generateJsonFile(config))),
];

if (options.generateMetadata) {
Expand Down
5 changes: 3 additions & 2 deletions protoc_plugin/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@ environment:
sdk: '>=2.17.0 <3.0.0'

dependencies:
dart_style: ^2.2.3
fixnum: ^1.0.0
path: ^1.8.0
protobuf: ^2.0.0

dev_dependencies:
collection: ^1.15.0
lints: ^1.0.0
lints: ^2.0.0
Copy link
Collaborator

Choose a reason for hiding this comment

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

revert these changes!

matcher: ^0.12.10
test: ^1.16.0
test: ^1.21.4

executables:
protoc-gen-dart: protoc_plugin