6805bb52ea
Fixes https://github.com/dart-lang/sdk/issues/36896 Change-Id: Ie450c6c5257ac13aa3c7b48343aa8b015b1dc4d8 Tweak tests to require all, plus fix empty classes Change-Id: Iefff7e24c6b965f0a1bc5abf8adbac26ad38e3a0 Add implementation/tests for textDocument/Implementation Change-Id: I640379d83aeb9baa73d04d98d39147e2b748d6c3 Bug: https://github.com/dart-lang/sdk/issues/36896 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/102366 Commit-Queue: Danny Tuppeny <dantup@google.com> Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
184 lines
4.1 KiB
Dart
184 lines
4.1 KiB
Dart
// Copyright (c) 2019, 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/lsp_protocol/protocol_generated.dart';
|
|
import 'package:test/test.dart';
|
|
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
|
|
|
import 'server_abstract.dart';
|
|
|
|
main() {
|
|
defineReflectiveSuite(() {
|
|
defineReflectiveTests(ImplementationTest);
|
|
});
|
|
}
|
|
|
|
@reflectiveTest
|
|
class ImplementationTest extends AbstractLspAnalysisServerTest {
|
|
test_class_excludesSelf() => _testMarkedContent('''
|
|
abstract class ^[[A]] {}
|
|
class B extends A {}
|
|
class C extends A {}
|
|
''', shouldMatch: false);
|
|
|
|
test_class_excludesSuper() => _testMarkedContent('''
|
|
abstract class [[A]] {}
|
|
class ^B extends A {}
|
|
class C extends A {}
|
|
''', shouldMatch: false);
|
|
|
|
test_class_sub() => _testMarkedContent('''
|
|
abstract class ^A {}
|
|
class [[B]] extends A {}
|
|
class [[C]] extends A {}
|
|
''');
|
|
|
|
test_class_subSub() => _testMarkedContent('''
|
|
abstract class ^A {}
|
|
class [[B]] extends A {}
|
|
class [[C]] extends A {}
|
|
class [[D]] extends B {}
|
|
class [[E]] extends B {}
|
|
class [[F]] extends E {}
|
|
''');
|
|
|
|
test_emptyResults() async {
|
|
final content = '';
|
|
|
|
await initialize();
|
|
await openFile(mainFileUri, content);
|
|
final res = await getImplementations(
|
|
mainFileUri,
|
|
startOfDocPos,
|
|
);
|
|
|
|
expect(res, isEmpty);
|
|
}
|
|
|
|
test_method_excludesClassesWithoutImplementations() => _testMarkedContent('''
|
|
abstract class A {
|
|
void ^b();
|
|
}
|
|
|
|
class B extends A {}
|
|
|
|
class [[E]] extends B {}
|
|
''', shouldMatch: false);
|
|
|
|
test_method_excludesSelf() => _testMarkedContent('''
|
|
abstract class A {
|
|
void ^[[b]]();
|
|
}
|
|
|
|
class B extends A {
|
|
void b() {}
|
|
}
|
|
''', shouldMatch: false);
|
|
|
|
test_method_excludesSuper() => _testMarkedContent('''
|
|
abstract class A {
|
|
void [[b]]();
|
|
}
|
|
|
|
class B extends A {
|
|
void ^b() {}
|
|
}
|
|
''', shouldMatch: false);
|
|
|
|
test_method_fromCallSite() => _testMarkedContent('''
|
|
abstract class A {
|
|
void b();
|
|
}
|
|
|
|
class B extends A {
|
|
void [[b]]() {}
|
|
}
|
|
|
|
class C extends A {
|
|
void [[b]]() {}
|
|
}
|
|
|
|
class D extends B {
|
|
void [[b]]() {}
|
|
}
|
|
|
|
class E extends B {}
|
|
|
|
class F extends E {
|
|
void [[b]]() {}
|
|
}
|
|
|
|
void fromCallSite() {
|
|
A e = new E();
|
|
e.^b();
|
|
}
|
|
''');
|
|
|
|
test_method_sub() => _testMarkedContent('''
|
|
abstract class A {
|
|
void ^b();
|
|
}
|
|
|
|
class B extends A {
|
|
void [[b]]() {}
|
|
}
|
|
|
|
class C extends A {
|
|
void [[b]]() {}
|
|
}
|
|
''');
|
|
|
|
test_method_subSub() => _testMarkedContent('''
|
|
abstract class A {
|
|
void ^b();
|
|
}
|
|
|
|
class B extends A {
|
|
void [[b]]() {}
|
|
}
|
|
|
|
class D extends B {
|
|
void [[b]]() {}
|
|
}
|
|
|
|
class E extends B {}
|
|
|
|
class F extends E {
|
|
void [[b]]() {}
|
|
}
|
|
''');
|
|
|
|
test_nonDartFile() async {
|
|
newFile(pubspecFilePath, content: simplePubspecContent);
|
|
await initialize();
|
|
|
|
final res = await getImplementations(pubspecFileUri, startOfDocPos);
|
|
expect(res, isEmpty);
|
|
}
|
|
|
|
/// Takes an input string that contains ^ at the location to invoke the
|
|
/// textDocument/implementations command and has ranges marked with
|
|
/// `[[brackets]]` that are expected to be included (or not, if [shouldMatch]
|
|
/// is set to `false`) in the results.
|
|
Future<void> _testMarkedContent(String content,
|
|
{bool shouldMatch = true}) async {
|
|
await initialize();
|
|
await openFile(mainFileUri, withoutMarkers(content));
|
|
|
|
final res = await getImplementations(
|
|
mainFileUri,
|
|
positionFromMarker(content),
|
|
);
|
|
|
|
final expectedLocations = rangesFromMarkers(content)
|
|
.map((r) => Location(mainFileUri.toString(), r));
|
|
|
|
if (shouldMatch) {
|
|
expect(res, equals(expectedLocations));
|
|
} else {
|
|
expectedLocations.forEach((l) => expect(res, isNot(contains(res))));
|
|
}
|
|
}
|
|
}
|