Add dartfix --server option
This adds a --server option for specifying the analyis server snapshot
to be used when calculating fixes.
Change-Id: I0adc3148c030d23a9a62883d842851709cb78168
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/106220
Auto-Submit: Dan Rubel <danrubel@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Dan Rubel <danrubel@google.com>
diff --git a/pkg/dartfix/lib/src/driver.dart b/pkg/dartfix/lib/src/driver.dart
index 4ef97b8..1ae0b29 100644
--- a/pkg/dartfix/lib/src/driver.dart
+++ b/pkg/dartfix/lib/src/driver.dart
@@ -261,15 +261,19 @@
}
Future<bool> startServer(Options options) async {
- if (options.verbose) {
- logger.trace('Dart SDK version ${Platform.version}');
- logger.trace(' ${Platform.resolvedExecutable}');
- logger.trace('dartfix');
- logger.trace(' ${Platform.script.toFilePath()}');
- }
// Automatically run analysis server from source
// if this command line tool is being run from source within the SDK repo.
- String serverPath = findServerPath();
+ String serverPath = options.serverSnapshot ?? findServerPath();
+ if (options.verbose) {
+ logger.trace('''
+Dart SDK version ${Platform.version}
+ ${Platform.resolvedExecutable}
+dartfix
+ ${Platform.script.toFilePath()}
+analysis server
+ $serverPath
+''');
+ }
await server.start(
clientId: 'dartfix',
clientVersion: 'unspecified',
diff --git a/pkg/dartfix/lib/src/options.dart b/pkg/dartfix/lib/src/options.dart
index 24d88ee..fc4e262 100644
--- a/pkg/dartfix/lib/src/options.dart
+++ b/pkg/dartfix/lib/src/options.dart
@@ -17,6 +17,7 @@
const requiredOption = 'required';
const _binaryName = 'dartfix';
const _colorOption = 'color';
+const _serverSnapshot = 'server';
// options only supported by server 1.22.2 and greater
const _helpOption = 'help';
@@ -29,6 +30,7 @@
List<String> targets;
final String sdkPath;
+ final String serverSnapshot;
final bool requiredFixes;
final List<String> includeFixes;
@@ -49,6 +51,7 @@
overwrite = results[overwriteOption] as bool,
requiredFixes = results[requiredOption] as bool,
sdkPath = _getSdkPath(),
+ serverSnapshot = results[_serverSnapshot],
showHelp = results[_helpOption] as bool || results.arguments.isEmpty,
targets = results.rest,
useColor = results.wasParsed(_colorOption)
@@ -92,6 +95,8 @@
help: 'Display this help message.',
defaultsTo: false,
negatable: false)
+ ..addOption(_serverSnapshot,
+ help: 'Path to the analysis server snapshot file.', valueHelp: 'path')
..addFlag(_verboseOption,
abbr: 'v',
defaultsTo: false,
@@ -109,7 +114,6 @@
} on FormatException catch (e) {
logger ??= new Logger.standard(ansi: new Ansi(Ansi.terminalSupportsAnsi));
logger.stderr(e.message);
- logger.stderr('\n');
_showUsage(parser, logger);
context.exit(15);
}
@@ -194,6 +198,7 @@
out(parser.usage);
out(showHelpHint
? '''
+
Use --$_helpOption to display the fixes that can be specified using either
--$includeOption or --$excludeOption.'''
: '');
diff --git a/pkg/dartfix/pubspec.yaml b/pkg/dartfix/pubspec.yaml
index ee16358..06f97d6 100644
--- a/pkg/dartfix/pubspec.yaml
+++ b/pkg/dartfix/pubspec.yaml
@@ -6,7 +6,7 @@
and fixing common issues.
homepage: https://github.com/dart-lang/sdk/tree/master/pkg/dartfix
environment:
- sdk: '>=2.2.0 <3.0.0'
+ sdk: '>=2.3.0 <3.0.0'
# Add the bin/dartfix.dart script to the scripts pub installs.
executables:
diff --git a/pkg/dartfix/test/src/driver_test.dart b/pkg/dartfix/test/src/driver_test.dart
index f84e20b..fc5bd29 100644
--- a/pkg/dartfix/test/src/driver_test.dart
+++ b/pkg/dartfix/test/src/driver_test.dart
@@ -27,11 +27,13 @@
test('fix example', () async {
final driver = new Driver();
final testContext = new TestContext();
- final testLogger = new TestLogger();
+ final testLogger = new TestLogger(debug: _debug);
String exampleSource = await exampleFile.readAsString();
- await driver.start([exampleDir.path],
- testContext: testContext, testLogger: testLogger);
+ await driver.start([
+ if (_debug) '-v',
+ exampleDir.path,
+ ], testContext: testContext, testLogger: testLogger);
if (_debug) {
print(testLogger.stderrBuffer.toString());
print(testLogger.stdoutBuffer.toString());
diff --git a/pkg/dartfix/test/src/options_test.dart b/pkg/dartfix/test/src/options_test.dart
index b0b74d7..c8c2713 100644
--- a/pkg/dartfix/test/src/options_test.dart
+++ b/pkg/dartfix/test/src/options_test.dart
@@ -30,6 +30,7 @@
String normalOut,
bool requiredFixes = false,
bool overwrite = false,
+ String serverSnapshot,
List<String> targetSuffixes,
bool verbose = false,
}) {
@@ -53,6 +54,7 @@
expect(options.force, force);
expect(options.requiredFixes, requiredFixes);
expect(options.overwrite, overwrite);
+ expect(options.serverSnapshot, serverSnapshot);
expect(options.showHelp, showHelp);
expect(options.includeFixes, includeFixes);
expect(options.excludeFixes, excludeFixes);
@@ -119,6 +121,10 @@
parse(['--required', 'foo'], requiredFixes: true);
});
+ test('server snapshot', () {
+ parse(['--server', 'some/path', 'foo'], serverSnapshot: 'some/path');
+ });
+
test('simple', () {
parse(['foo'], targetSuffixes: ['foo']);
});