Update dartfix to check analysis server protocol version

This updates dartfix to more narrowly verify the analysis server
protocol version and print instructions for the user if the protocol
version expected by dartfix is incompatible with the current Dart SDK.
This is necessary because the edit.dartfix protocol is experimental
and will continue to evolve.

Change-Id: Ib31eb594a8a94416cb4fc676e7da9150f8c99b6a
Reviewed-on: https://dart-review.googlesource.com/c/84780
Commit-Queue: Dan Rubel <danrubel@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
Dan Rubel 2018-11-19 21:14:28 +00:00 committed by commit-bot@chromium.org
parent 06c89287b9
commit 784ad29470
8 changed files with 76 additions and 10 deletions

View file

@ -1,3 +1,6 @@
# 1.1.1
* Update ConnectionHandler to call checkServerProtocolVersion
# 1.1.0
* Add analysis server protocol consts and classes
* Overhaul the Server class

View file

@ -28,16 +28,21 @@ mixin ConnectionHandler implements NotificationHandler {
/// established or if a server error occurs after connecting.
Server get server;
/// Return `true` if the server's protocol is compatible.
bool checkServerProtocolVersion(Version version) {
final minVersion = new Version.parse(PROTOCOL_VERSION);
final maxVersion = minVersion.nextBreaking;
return minVersion <= version && version < maxVersion;
}
void onFailedToConnect() {}
void onProtocolNotSupported(Version version) {}
@override
void onServerConnected(ServerConnectedParams params) {
final minVersion = new Version.parse(PROTOCOL_VERSION);
final maxVersion = minVersion.nextBreaking;
final version = new Version.parse(params.version);
if (minVersion <= version && version < maxVersion) {
Version version = new Version.parse(params.version);
if (checkServerProtocolVersion(version)) {
_connected.complete(true);
} else {
onProtocolNotSupported(version);

View file

@ -1,5 +1,5 @@
name: analysis_server_client
version: 1.1.0
version: 1.1.1
author: Dart Team <misc@dartlang.org>
description:
A client wrapper over analysis_server.

View file

@ -1,7 +1,13 @@
# dartfix
dartfix is a tool for migrating Dart source to newer versions of the Dart SDK,
and fixing common issues.
and fixing common issues including:
* Converting classes used as mixins to use the
[new mixin syntax](https://github.com/dart-lang/language/issues/7)
* Converting [double literals to int literals](https://github.com/dart-lang/language/issues/4)
where applicable
* Moving named constructor type arguments from the name to the type
## Usage

View file

@ -5,11 +5,11 @@
import 'dart:async';
import 'dart:io' show File, Platform;
import 'package:analysis_server_client/server.dart';
import 'package:analysis_server_client/handler/connection_handler.dart';
import 'package:analysis_server_client/handler/notification_handler.dart';
import 'package:analysis_server_client/listener/server_listener.dart';
import 'package:analysis_server_client/protocol.dart';
import 'package:analysis_server_client/server.dart';
import 'package:cli_util/cli_logging.dart';
import 'package:dartfix/handler/analysis_complete_handler.dart';
import 'package:dartfix/listener/bad_message_listener.dart';
@ -19,6 +19,8 @@ import 'package:dartfix/src/util.dart';
import 'package:pub_semver/pub_semver.dart';
class Driver {
static final expectedProtocolVersion = new Version.parse('1.21.1');
Context context;
_Handler handler;
Logger logger;
@ -216,8 +218,32 @@ class _Handler
@override
void onProtocolNotSupported(Version version) {
logger.stderr('Expected protocol version $PROTOCOL_VERSION,'
logger.stderr('Expected protocol version ${Driver.expectedProtocolVersion},'
' but found $version');
if (version > Driver.expectedProtocolVersion) {
logger.stdout('''
This version of dartfix is incompatible with the current Dart SDK.
Try installing a newer version of dartfix by running
pub global activate dartfix
''');
} else {
logger.stdout('''
This version of dartfix is too new to be used with the current Dart SDK.
Try upgrading the Dart SDK to a newer version
or installing an older version of dartfix using
pub global activate dartfix <version>
''');
}
}
@override
bool checkServerProtocolVersion(Version version) {
// This overrides the default protocol version check to be more narrow
// because the edit.dartfix protocol is experimental
// and will continue to evolve.
return version == Driver.expectedProtocolVersion;
}
@override

View file

@ -8,9 +8,13 @@ homepage: https://github.com/dart-lang/sdk/tree/master/pkg/dartfix
executables:
dartfix: fix
environment:
sdk: '>=2.1.0-dev.9.2 <2.1.0'
# pin to a narrow SDK range because there will be future versions of dartfix
# which are more appropriate for those future versions of the SDK
sdk: '>=2.1.0-dev.9.2 <2.3.0'
dependencies:
analysis_server_client: ^1.1.0
# pin to an exact version of analysis_server_client because the edit.dartfix protocol
# is experimental and will continue to evolve
analysis_server_client: 1.1.1
args: ^1.4.0
cli_util: ^0.1.3
path: ^1.6.0
@ -18,3 +22,5 @@ dependencies:
dev_dependencies:
analyzer: ^0.33.0
test: ^1.3.0
dependency_overrides:
analysis_server_client: {path: ../analysis_server_client}

View file

@ -4,8 +4,10 @@
import 'package:test/test.dart';
import 'src/driver_test.dart' as driver_test;
import 'src/options_test.dart' as options_test;
main() {
group('driver', driver_test.main);
group('options', options_test.main);
}

View file

@ -0,0 +1,18 @@
// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:analysis_server_client/protocol.dart';
import 'package:dartfix/src/driver.dart';
import 'package:pub_semver/pub_semver.dart';
import 'package:test/test.dart';
main() {
test('protocol version', () {
// The edit.dartfix protocol is experimental and will continue to evolve
// an so dartfix will only work with this specific version of the protocol.
// If the protocol changes, then a new version of both the
// analysis_server_client and dartfix packages must be published.
expect(new Version.parse(PROTOCOL_VERSION), Driver.expectedProtocolVersion);
});
}