diff --git a/pkg/dartdev/lib/src/analysis_server.dart b/pkg/dartdev/lib/src/analysis_server.dart index 0e0f59c280156..9768d39992b97 100644 --- a/pkg/dartdev/lib/src/analysis_server.dart +++ b/pkg/dartdev/lib/src/analysis_server.dart @@ -9,6 +9,7 @@ import 'dart:io'; import 'package:analysis_server/src/server/driver.dart' show Driver; import 'package:analysis_server_client/protocol.dart' show EditBulkFixesResult, ResponseDecoder; +import 'package:args/args.dart'; import 'package:meta/meta.dart'; import 'package:path/path.dart' as path; @@ -16,17 +17,23 @@ import 'core.dart'; import 'sdk.dart'; import 'utils.dart'; +/// When set, this function is executed just before the Analysis Server starts. +void Function(String cmdName, List analysisRoots, + ArgResults argResults) preAnalysisServerStart; + /// A class to provide an API wrapper around an analysis server process. class AnalysisServer { AnalysisServer( this.sdkPath, this.analysisRoots, { @required this.commandName, + @required this.argResults, }); final Directory sdkPath; final List analysisRoots; final String commandName; + final ArgResults argResults; Process _process; @@ -69,6 +76,7 @@ class AnalysisServer { final Map>> _requestCompleters = {}; Future start() async { + preAnalysisServerStart?.call(commandName, analysisRoots, argResults); final List command = [ sdk.analysisServerSnapshot, '--${Driver.SUPPRESS_ANALYTICS_FLAG}', diff --git a/pkg/dartdev/lib/src/commands/analyze.dart b/pkg/dartdev/lib/src/commands/analyze.dart index a4c02bec04119..0c1d925345b9f 100644 --- a/pkg/dartdev/lib/src/commands/analyze.dart +++ b/pkg/dartdev/lib/src/commands/analyze.dart @@ -100,6 +100,7 @@ class AnalyzeCommand extends DartdevCommand { io.Directory(sdk.sdkPath), targets, commandName: 'analyze', + argResults: argResults, ); server.onErrors.listen((FileAnalysisErrors fileErrors) { diff --git a/pkg/dartdev/lib/src/commands/fix.dart b/pkg/dartdev/lib/src/commands/fix.dart index 60d2e46e86aac..08d4d36532482 100644 --- a/pkg/dartdev/lib/src/commands/fix.dart +++ b/pkg/dartdev/lib/src/commands/fix.dart @@ -93,6 +93,7 @@ To use the tool, run either ['dart fix --dry-run'] for a preview of the proposed io.Directory(sdk.sdkPath), [dir], commandName: 'fix', + argResults: argResults, ); await server.start(); diff --git a/pkg/dartdev/lib/src/core.dart b/pkg/dartdev/lib/src/core.dart index 2da96fcf0e6b1..b84cd862e3e3f 100644 --- a/pkg/dartdev/lib/src/core.dart +++ b/pkg/dartdev/lib/src/core.dart @@ -18,6 +18,10 @@ import 'utils.dart'; Logger log; bool isDiagnostics = false; +/// When set, this function is executed from the [DartdevCommand] constructor to +/// contribute additional flags. +void Function(ArgParser argParser, String cmdName) flagContributor; + abstract class DartdevCommand extends Command { final String _name; final String _description; @@ -29,7 +33,9 @@ abstract class DartdevCommand extends Command { final bool hidden; DartdevCommand(this._name, this._description, this._verbose, - {this.hidden = false}); + {this.hidden = false}) { + flagContributor?.call(argParser, _name); + } @override String get name => _name; diff --git a/pkg/dartdev/test/analysis_server_test.dart b/pkg/dartdev/test/analysis_server_test.dart index dba2cccb4c8cd..05f7597e421a9 100644 --- a/pkg/dartdev/test/analysis_server_test.dart +++ b/pkg/dartdev/test/analysis_server_test.dart @@ -25,14 +25,14 @@ void main() { test('can start', () async { AnalysisServer server = AnalysisServer(io.Directory(sdk.sdkPath), [p.dir], - commandName: 'testing'); + commandName: 'testing', argResults: null); await server.start(); await server.shutdown(); }); test('can send message', () async { AnalysisServer server = AnalysisServer(io.Directory(sdk.sdkPath), [p.dir], - commandName: 'testing'); + commandName: 'testing', argResults: null); await server.start(); final response = await server.getVersion(); diff --git a/tools/VERSION b/tools/VERSION index d3f29b95ef893..2713250c47720 100644 --- a/tools/VERSION +++ b/tools/VERSION @@ -27,5 +27,5 @@ CHANNEL dev MAJOR 2 MINOR 14 PATCH 0 -PRERELEASE 370 +PRERELEASE 371 PRERELEASE_PATCH 0 \ No newline at end of file