Test and fix for completion in a part.

R=brianwilkerson@google.com, keertip@google.com

Change-Id: I7653a24a3a315b2be51e50f223284537e5830b1d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/157469
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
Konstantin Shcheglov 2020-08-06 16:08:59 +00:00 committed by commit-bot@chromium.org
parent 7997b49285
commit 5276973b22
2 changed files with 33 additions and 7 deletions

View file

@ -416,6 +416,21 @@ part 'a.dart';
_assertHasClass(text: 'A');
}
Future<void> test_limitedResolution_inPart() async {
newFile('/workspace/dart/test/lib/a.dart', content: r'''
part 'test.dart';
class A {}
''');
await _compute(r'''
part of 'a.dart';
^
''');
_assertHasClass(text: 'int');
_assertHasClass(text: 'A');
}
Future<void> test_limitedResolution_unit_function_body() async {
_configureToCheckNotResolved(
identifiers: {'print'},

View file

@ -125,7 +125,7 @@ class LibraryAnalyzer {
});
// Resolve URIs in directives to corresponding sources.
FeatureSet featureSet = units[_library].featureSet;
FeatureSet featureSet = units.values.first.featureSet;
performance.run('resolveUriDirectives', (performance) {
units.forEach((file, unit) {
@ -139,7 +139,7 @@ class LibraryAnalyzer {
});
performance.run('resolveDirectives', (performance) {
_resolveDirectives(units, forCompletion);
_resolveDirectives(units, completionPath);
});
performance.run('resolveFiles', (performance) {
@ -529,15 +529,17 @@ class LibraryAnalyzer {
void _resolveDirectives(
Map<FileState, CompilationUnit> units,
bool forCompletion,
String completionPath,
) {
CompilationUnit definingCompilationUnit = units[_library];
definingCompilationUnit.element = _libraryElement.definingCompilationUnit;
if (forCompletion) {
if (completionPath != null) {
var completionUnit = units.values.first;
completionUnit.element = _unitElementWithPath(completionPath);
return;
}
CompilationUnit definingCompilationUnit = units[_library];
definingCompilationUnit.element = _libraryElement.definingCompilationUnit;
bool matchNodeElement(Directive node, Element element) {
return node.keyword.offset == element.nameOffset;
}
@ -757,6 +759,15 @@ class LibraryAnalyzer {
}
}
CompilationUnitElement _unitElementWithPath(String path) {
for (var unitElement in _libraryElement.units) {
if (unitElement.source.fullName == path) {
return unitElement;
}
}
return null;
}
/// Validate that the feature set associated with the compilation [unit] is
/// the same as the [expectedSet] of features supported by the library.
void _validateFeatureSet(CompilationUnit unit, FeatureSet expectedSet) {