Skip to content

Commit f7d3e5b

Browse files
danrubelcommit-bot@chromium.org
authored andcommitted
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 <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Dan Rubel <[email protected]>
1 parent 3619d26 commit f7d3e5b

5 files changed

Lines changed: 29 additions & 12 deletions

File tree

pkg/dartfix/lib/src/driver.dart

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -261,15 +261,19 @@ These fixes are NOT automatically applied, but may be enabled using --$includeOp
261261
}
262262

263263
Future<bool> startServer(Options options) async {
264-
if (options.verbose) {
265-
logger.trace('Dart SDK version ${Platform.version}');
266-
logger.trace(' ${Platform.resolvedExecutable}');
267-
logger.trace('dartfix');
268-
logger.trace(' ${Platform.script.toFilePath()}');
269-
}
270264
// Automatically run analysis server from source
271265
// if this command line tool is being run from source within the SDK repo.
272-
String serverPath = findServerPath();
266+
String serverPath = options.serverSnapshot ?? findServerPath();
267+
if (options.verbose) {
268+
logger.trace('''
269+
Dart SDK version ${Platform.version}
270+
${Platform.resolvedExecutable}
271+
dartfix
272+
${Platform.script.toFilePath()}
273+
analysis server
274+
$serverPath
275+
''');
276+
}
273277
await server.start(
274278
clientId: 'dartfix',
275279
clientVersion: 'unspecified',

pkg/dartfix/lib/src/options.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const overwriteOption = 'overwrite';
1717
const requiredOption = 'required';
1818
const _binaryName = 'dartfix';
1919
const _colorOption = 'color';
20+
const _serverSnapshot = 'server';
2021

2122
// options only supported by server 1.22.2 and greater
2223
const _helpOption = 'help';
@@ -29,6 +30,7 @@ class Options {
2930

3031
List<String> targets;
3132
final String sdkPath;
33+
final String serverSnapshot;
3234

3335
final bool requiredFixes;
3436
final List<String> includeFixes;
@@ -49,6 +51,7 @@ class Options {
4951
overwrite = results[overwriteOption] as bool,
5052
requiredFixes = results[requiredOption] as bool,
5153
sdkPath = _getSdkPath(),
54+
serverSnapshot = results[_serverSnapshot],
5255
showHelp = results[_helpOption] as bool || results.arguments.isEmpty,
5356
targets = results.rest,
5457
useColor = results.wasParsed(_colorOption)
@@ -92,6 +95,8 @@ class Options {
9295
help: 'Display this help message.',
9396
defaultsTo: false,
9497
negatable: false)
98+
..addOption(_serverSnapshot,
99+
help: 'Path to the analysis server snapshot file.', valueHelp: 'path')
95100
..addFlag(_verboseOption,
96101
abbr: 'v',
97102
defaultsTo: false,
@@ -109,7 +114,6 @@ class Options {
109114
} on FormatException catch (e) {
110115
logger ??= new Logger.standard(ansi: new Ansi(Ansi.terminalSupportsAnsi));
111116
logger.stderr(e.message);
112-
logger.stderr('\n');
113117
_showUsage(parser, logger);
114118
context.exit(15);
115119
}
@@ -194,6 +198,7 @@ Usage: $_binaryName [options...] <directory paths>
194198
out(parser.usage);
195199
out(showHelpHint
196200
? '''
201+
197202
Use --$_helpOption to display the fixes that can be specified using either
198203
--$includeOption or --$excludeOption.'''
199204
: '');

pkg/dartfix/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ description:
66
and fixing common issues.
77
homepage: https://github.com/dart-lang/sdk/tree/master/pkg/dartfix
88
environment:
9-
sdk: '>=2.2.0 <3.0.0'
9+
sdk: '>=2.3.0 <3.0.0'
1010

1111
# Add the bin/dartfix.dart script to the scripts pub installs.
1212
executables:

pkg/dartfix/test/src/driver_test.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,13 @@ main() {
2727
test('fix example', () async {
2828
final driver = new Driver();
2929
final testContext = new TestContext();
30-
final testLogger = new TestLogger();
30+
final testLogger = new TestLogger(debug: _debug);
3131
String exampleSource = await exampleFile.readAsString();
3232

33-
await driver.start([exampleDir.path],
34-
testContext: testContext, testLogger: testLogger);
33+
await driver.start([
34+
if (_debug) '-v',
35+
exampleDir.path,
36+
], testContext: testContext, testLogger: testLogger);
3537
if (_debug) {
3638
print(testLogger.stderrBuffer.toString());
3739
print(testLogger.stdoutBuffer.toString());

pkg/dartfix/test/src/options_test.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ main() {
3030
String normalOut,
3131
bool requiredFixes = false,
3232
bool overwrite = false,
33+
String serverSnapshot,
3334
List<String> targetSuffixes,
3435
bool verbose = false,
3536
}) {
@@ -53,6 +54,7 @@ main() {
5354
expect(options.force, force);
5455
expect(options.requiredFixes, requiredFixes);
5556
expect(options.overwrite, overwrite);
57+
expect(options.serverSnapshot, serverSnapshot);
5658
expect(options.showHelp, showHelp);
5759
expect(options.includeFixes, includeFixes);
5860
expect(options.excludeFixes, excludeFixes);
@@ -119,6 +121,10 @@ main() {
119121
parse(['--required', 'foo'], requiredFixes: true);
120122
});
121123

124+
test('server snapshot', () {
125+
parse(['--server', 'some/path', 'foo'], serverSnapshot: 'some/path');
126+
});
127+
122128
test('simple', () {
123129
parse(['foo'], targetSuffixes: ['foo']);
124130
});

0 commit comments

Comments
 (0)