mirror of
https://github.com/dart-lang/sdk
synced 2024-09-21 15:21:18 +00:00
extract LibraryPrefixContributor from imported reference contributor
R=scheglov@google.com Review URL: https://codereview.chromium.org/1517693004 .
This commit is contained in:
parent
30c4c2b86e
commit
7ad6c0f1f9
|
@ -67,6 +67,11 @@ abstract class DartCompletionRequest extends CompletionRequest {
|
|||
*/
|
||||
Expression get dotTarget;
|
||||
|
||||
/**
|
||||
* Return `true` if free standing identifiers should be suggested
|
||||
*/
|
||||
bool get includeIdentifiers;
|
||||
|
||||
/**
|
||||
* Return the library element which contains the unit in which the completion
|
||||
* is occurring. This may return `null` if the library cannot be determined
|
||||
|
|
|
@ -13,6 +13,7 @@ import 'package:analysis_server/src/services/completion/dart/completion_manager.
|
|||
import 'package:analysis_server/src/services/completion/dart/field_formal_contributor.dart';
|
||||
import 'package:analysis_server/src/services/completion/dart/keyword_contributor.dart';
|
||||
import 'package:analysis_server/src/services/completion/dart/library_member_contributor.dart';
|
||||
import 'package:analysis_server/src/services/completion/dart/library_prefix_contributor.dart';
|
||||
import 'package:analysis_server/src/services/completion/dart/named_constructor_contributor.dart';
|
||||
import 'package:analysis_server/src/services/completion/dart/static_member_contributor.dart';
|
||||
import 'package:analysis_server/src/services/completion/dart/type_member_contributor.dart';
|
||||
|
@ -82,6 +83,8 @@ class DartCompletionPlugin implements Plugin {
|
|||
() => new KeywordContributor());
|
||||
registerExtension(DART_COMPLETION_CONTRIBUTOR_EXTENSION_POINT_ID,
|
||||
() => new LibraryMemberContributor());
|
||||
registerExtension(DART_COMPLETION_CONTRIBUTOR_EXTENSION_POINT_ID,
|
||||
() => new LibraryPrefixContributor());
|
||||
registerExtension(DART_COMPLETION_CONTRIBUTOR_EXTENSION_POINT_ID,
|
||||
() => new NamedConstructorContributor());
|
||||
registerExtension(DART_COMPLETION_CONTRIBUTOR_EXTENSION_POINT_ID,
|
||||
|
|
|
@ -23,6 +23,7 @@ import 'package:analyzer/src/generated/engine.dart' hide AnalysisContextImpl;
|
|||
import 'package:analyzer/src/generated/source.dart';
|
||||
import 'package:analyzer/src/task/dart.dart';
|
||||
import 'package:analyzer/task/dart.dart';
|
||||
import 'package:analysis_server/src/services/completion/optype.dart';
|
||||
|
||||
/**
|
||||
* [DartCompletionManager] determines if a completion request is Dart specific
|
||||
|
@ -111,9 +112,23 @@ class DartCompletionRequestImpl extends CompletionRequestImpl
|
|||
@override
|
||||
Source librarySource;
|
||||
|
||||
OpType _opType;
|
||||
|
||||
@override
|
||||
CompletionTarget target;
|
||||
|
||||
@override
|
||||
bool get includeIdentifiers {
|
||||
if (_opType == null) {
|
||||
_opType = new OpType.forCompletion(target, offset);
|
||||
}
|
||||
return !_opType.isPrefixed &&
|
||||
(_opType.includeReturnValueSuggestions ||
|
||||
_opType.includeTypeNameSuggestions ||
|
||||
_opType.includeVoidReturnSuggestions ||
|
||||
_opType.includeConstructorSuggestions);
|
||||
}
|
||||
|
||||
@override
|
||||
LibraryElement get libraryElement {
|
||||
//TODO(danrubel) build the library element rather than all the declarations
|
||||
|
@ -190,6 +205,7 @@ class DartCompletionRequestImpl extends CompletionRequestImpl
|
|||
* Update the completion [target] and [dotTarget] based on the given [unit].
|
||||
*/
|
||||
void _updateTargets(CompilationUnit unit) {
|
||||
_opType = null;
|
||||
dotTarget = null;
|
||||
target = new CompletionTarget.forOffset(unit, offset);
|
||||
AstNode node = target.containingNode;
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
// Copyright (c) 2014, 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.
|
||||
|
||||
library services.completion.contributor.dart.library_prefix;
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:analysis_server/src/provisional/completion/dart/completion_dart.dart';
|
||||
import 'package:analysis_server/src/services/completion/dart/suggestion_builder.dart';
|
||||
import 'package:analyzer/src/generated/ast.dart';
|
||||
import 'package:analyzer/src/generated/element.dart';
|
||||
|
||||
import '../../../protocol_server.dart'
|
||||
show CompletionSuggestion, CompletionSuggestionKind;
|
||||
|
||||
/**
|
||||
* A contributor for calculating prefixed import library member suggestions
|
||||
* `completion.getSuggestions` request results.
|
||||
*/
|
||||
class LibraryPrefixContributor extends DartCompletionContributor {
|
||||
@override
|
||||
Future<List<CompletionSuggestion>> computeSuggestions(
|
||||
DartCompletionRequest request) async {
|
||||
if (!request.includeIdentifiers) {
|
||||
return EMPTY_LIST;
|
||||
}
|
||||
|
||||
List<Directive> directives = await request.resolveDirectives();
|
||||
if (directives == null) {
|
||||
return EMPTY_LIST;
|
||||
}
|
||||
|
||||
List<CompletionSuggestion> suggestions = <CompletionSuggestion>[];
|
||||
for (Directive directive in directives) {
|
||||
if (directive is ImportDirective) {
|
||||
SimpleIdentifier prefix = directive.prefix;
|
||||
ImportElement element = directive.element;
|
||||
if (prefix != null && element != null) {
|
||||
String completion = prefix.name;
|
||||
LibraryElement libElem = element.importedLibrary;
|
||||
if (completion != null && completion.length > 0 && libElem != null) {
|
||||
CompletionSuggestion suggestion = createSuggestion(libElem,
|
||||
completion: completion,
|
||||
kind: CompletionSuggestionKind.IDENTIFIER);
|
||||
if (suggestion != null) {
|
||||
suggestions.add(suggestion);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return suggestions;
|
||||
}
|
||||
}
|
|
@ -30,12 +30,6 @@ class DartCompletionCache extends CompletionCache {
|
|||
*/
|
||||
String _importKey;
|
||||
|
||||
/**
|
||||
* Library prefix suggestions based upon imports,
|
||||
* or `null` if nothing has been cached.
|
||||
*/
|
||||
List<CompletionSuggestion> libraryPrefixSuggestions;
|
||||
|
||||
/**
|
||||
* Type suggestions based upon imports,
|
||||
* or `null` if nothing has been cached.
|
||||
|
@ -114,7 +108,6 @@ class DartCompletionCache extends CompletionCache {
|
|||
Future<bool> computeImportInfo(CompilationUnit unit,
|
||||
SearchEngine searchEngine, bool shouldWaitForLowPrioritySuggestions) {
|
||||
importedTypeSuggestions = <CompletionSuggestion>[];
|
||||
libraryPrefixSuggestions = <CompletionSuggestion>[];
|
||||
otherImportedSuggestions = <CompletionSuggestion>[];
|
||||
importedConstructorSuggestions = <CompletionSuggestion>[];
|
||||
importedVoidReturnSuggestions = <CompletionSuggestion>[];
|
||||
|
@ -240,8 +233,9 @@ class DartCompletionCache extends CompletionCache {
|
|||
} else {
|
||||
// Exclude elements from prefixed imports
|
||||
// because they are provided by PrefixedElementContributor
|
||||
_addLibraryPrefixSuggestion(importElem);
|
||||
excludedLibs.add(importElem.importedLibrary);
|
||||
// Suggested by LibraryPrefixContributor
|
||||
// _addLibraryPrefixSuggestion(importElem);
|
||||
// excludedLibs.add(importElem.importedLibrary);
|
||||
}
|
||||
}
|
||||
} else if (directive is PartDirective) {
|
||||
|
@ -257,27 +251,6 @@ class DartCompletionCache extends CompletionCache {
|
|||
}
|
||||
}
|
||||
|
||||
void _addLibraryPrefixSuggestion(ImportElement importElem) {
|
||||
CompletionSuggestion suggestion = null;
|
||||
String completion = importElem.prefix.displayName;
|
||||
if (completion != null && completion.length > 0) {
|
||||
suggestion = new CompletionSuggestion(
|
||||
CompletionSuggestionKind.INVOCATION,
|
||||
DART_RELEVANCE_DEFAULT,
|
||||
completion,
|
||||
completion.length,
|
||||
0,
|
||||
importElem.isDeprecated,
|
||||
false);
|
||||
LibraryElement lib = importElem.importedLibrary;
|
||||
if (lib != null) {
|
||||
suggestion.element = convertElement(lib);
|
||||
}
|
||||
libraryPrefixSuggestions.add(suggestion);
|
||||
_importedCompletions.add(suggestion.completion);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add suggestions for all top level elements in the context
|
||||
* excluding those elemnents for which suggestions have already been added.
|
||||
|
|
|
@ -143,7 +143,6 @@ class _ImportedSuggestionBuilder extends ElementSuggestionBuilder
|
|||
}
|
||||
DartCompletionCache cache = request.cache;
|
||||
_addFilteredSuggestions(filterText, cache.importedConstructorSuggestions);
|
||||
_addFilteredSuggestions(filterText, cache.libraryPrefixSuggestions);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -258,7 +257,6 @@ class _ImportedSuggestionBuilder extends ElementSuggestionBuilder
|
|||
DartCompletionCache cache = request.cache;
|
||||
if (optype.includeTypeNameSuggestions) {
|
||||
_addFilteredSuggestions(filterText, cache.importedTypeSuggestions);
|
||||
_addFilteredSuggestions(filterText, cache.libraryPrefixSuggestions);
|
||||
}
|
||||
if (optype.includeReturnValueSuggestions) {
|
||||
_addFilteredSuggestions(filterText, cache.otherImportedSuggestions);
|
||||
|
|
|
@ -472,7 +472,7 @@ class CompletionTest extends AbstractAnalysisTest {
|
|||
expect(replacementOffset, equals(completionOffset));
|
||||
expect(replacementLength, equals(0));
|
||||
assertHasResult(CompletionSuggestionKind.INVOCATION, 'Object');
|
||||
assertHasResult(CompletionSuggestionKind.INVOCATION, 'foo');
|
||||
assertHasResult(CompletionSuggestionKind.IDENTIFIER, 'foo');
|
||||
assertNoResult('HtmlElement');
|
||||
assertNoResult('test');
|
||||
});
|
||||
|
|
|
@ -1290,7 +1290,8 @@ abstract class AbstractSelectorSuggestionTest extends AbstractCompletionTest {
|
|||
assertSuggestImportedClass('EE');
|
||||
// hidden element suggested as low relevance
|
||||
//assertSuggestImportedClass('F', COMPLETION_RELEVANCE_LOW);
|
||||
assertSuggestLibraryPrefix('g');
|
||||
// Suggested by LibraryPrefixContributor
|
||||
assertNotSuggested('g');
|
||||
assertNotSuggested('G');
|
||||
//assertSuggestImportedClass('H', COMPLETION_RELEVANCE_LOW);
|
||||
assertSuggestImportedClass('Object');
|
||||
|
@ -1401,7 +1402,8 @@ abstract class AbstractSelectorSuggestionTest extends AbstractCompletionTest {
|
|||
assertSuggestImportedClass('EE');
|
||||
// hidden element suggested as low relevance
|
||||
//assertSuggestImportedClass('F', COMPLETION_RELEVANCE_LOW);
|
||||
assertSuggestLibraryPrefix('g');
|
||||
// Suggested by LibraryPrefixContributor
|
||||
assertNotSuggested('g');
|
||||
assertNotSuggested('G');
|
||||
//assertSuggestImportedClass('H', COMPLETION_RELEVANCE_LOW);
|
||||
assertSuggestImportedClass('Object');
|
||||
|
@ -1524,7 +1526,8 @@ abstract class AbstractSelectorSuggestionTest extends AbstractCompletionTest {
|
|||
assertSuggestImportedClass('EE');
|
||||
// hidden element suggested as low relevance
|
||||
//assertSuggestImportedClass('F', COMPLETION_RELEVANCE_LOW);
|
||||
assertSuggestLibraryPrefix('g');
|
||||
// Suggested by LibraryPrefixContributor
|
||||
assertNotSuggested('g');
|
||||
assertNotSuggested('G');
|
||||
//assertSuggestImportedClass('H', COMPLETION_RELEVANCE_LOW);
|
||||
assertSuggestImportedClass('Object');
|
||||
|
@ -1631,7 +1634,8 @@ abstract class AbstractSelectorSuggestionTest extends AbstractCompletionTest {
|
|||
assertSuggestImportedClass('EE');
|
||||
// hidden element suggested as low relevance
|
||||
//assertSuggestImportedClass('F', COMPLETION_RELEVANCE_LOW);
|
||||
assertSuggestLibraryPrefix('g');
|
||||
// Suggested by LibraryPrefixContributor
|
||||
assertNotSuggested('g');
|
||||
assertNotSuggested('G');
|
||||
//assertSuggestImportedClass('H', COMPLETION_RELEVANCE_LOW);
|
||||
assertSuggestImportedClass('Object');
|
||||
|
@ -2078,7 +2082,8 @@ abstract class AbstractSelectorSuggestionTest extends AbstractCompletionTest {
|
|||
expect(suggestionO.element.isPrivate, isFalse);
|
||||
}
|
||||
assertNotSuggested('T');
|
||||
assertSuggestLibraryPrefix('x');
|
||||
// Suggested by LibraryPrefixContributor
|
||||
assertNotSuggested('x');
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -2101,7 +2106,8 @@ abstract class AbstractSelectorSuggestionTest extends AbstractCompletionTest {
|
|||
assertSuggestLocalClass('_B');
|
||||
assertSuggestImportedClass('Object');
|
||||
assertNotSuggested('T');
|
||||
assertSuggestLibraryPrefix('x');
|
||||
// Suggested by LibraryPrefixContributor
|
||||
assertNotSuggested('x');
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -2124,7 +2130,8 @@ abstract class AbstractSelectorSuggestionTest extends AbstractCompletionTest {
|
|||
assertSuggestLocalClass('_B');
|
||||
assertSuggestImportedClass('String');
|
||||
assertNotSuggested('T');
|
||||
assertSuggestLibraryPrefix('x');
|
||||
// Suggested by LibraryPrefixContributor
|
||||
assertNotSuggested('x');
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -2147,7 +2154,8 @@ abstract class AbstractSelectorSuggestionTest extends AbstractCompletionTest {
|
|||
assertSuggestLocalClass('_B');
|
||||
assertSuggestImportedClass('String');
|
||||
assertNotSuggested('Sew');
|
||||
assertSuggestLibraryPrefix('Soo');
|
||||
// Suggested by LibraryPrefixContributor
|
||||
assertNotSuggested('Soo');
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -2170,7 +2178,8 @@ abstract class AbstractSelectorSuggestionTest extends AbstractCompletionTest {
|
|||
assertSuggestLocalClass('_B');
|
||||
assertSuggestImportedClass('Object');
|
||||
assertNotSuggested('T');
|
||||
assertSuggestLibraryPrefix('x');
|
||||
// Suggested by LibraryPrefixContributor
|
||||
assertNotSuggested('x');
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -2193,7 +2202,8 @@ abstract class AbstractSelectorSuggestionTest extends AbstractCompletionTest {
|
|||
assertSuggestLocalClass('_B');
|
||||
assertSuggestImportedClass('Object');
|
||||
assertNotSuggested('T');
|
||||
assertSuggestLibraryPrefix('x');
|
||||
// Suggested by LibraryPrefixContributor
|
||||
assertNotSuggested('x');
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,377 @@
|
|||
// Copyright (c) 2015, 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.
|
||||
|
||||
library test.services.completion.contributor.dart.library_prefix;
|
||||
|
||||
import 'package:analysis_server/src/protocol_server.dart';
|
||||
import 'package:analysis_server/src/provisional/completion/dart/completion_dart.dart';
|
||||
import 'package:analysis_server/src/services/completion/dart/library_prefix_contributor.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
import 'package:unittest/unittest.dart';
|
||||
|
||||
import '../../../utils.dart';
|
||||
import 'completion_contributor_util.dart';
|
||||
|
||||
main() {
|
||||
initializeTestEnvironment();
|
||||
defineReflectiveTests(LibraryPrefixContributorTest);
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class LibraryPrefixContributorTest extends DartCompletionContributorTest {
|
||||
void assertSuggestLibraryPrefixes(List<String> expectedPrefixes) {
|
||||
for (String prefix in expectedPrefixes) {
|
||||
CompletionSuggestion cs = assertSuggest(prefix,
|
||||
csKind: CompletionSuggestionKind.IDENTIFIER,
|
||||
relevance: DART_RELEVANCE_DEFAULT);
|
||||
Element element = cs.element;
|
||||
expect(element, isNotNull);
|
||||
expect(element.kind, equals(ElementKind.LIBRARY));
|
||||
expect(element.parameters, isNull);
|
||||
expect(element.returnType, isNull);
|
||||
assertHasNoParameterInfo(cs);
|
||||
}
|
||||
if (suggestions.length != expectedPrefixes.length) {
|
||||
failedCompletion('expected only ${expectedPrefixes.length} suggestions');
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
DartCompletionContributor createContributor() {
|
||||
return new LibraryPrefixContributor();
|
||||
}
|
||||
|
||||
test_Block() async {
|
||||
// Block BlockFunctionBody MethodDeclaration
|
||||
addSource(
|
||||
'/testAB.dart',
|
||||
'''
|
||||
export "dart:math" hide max;
|
||||
class A {int x;}
|
||||
@deprecated D1() {int x;}
|
||||
class _B {boo() { partBoo() {}} }''');
|
||||
addSource(
|
||||
'/testCD.dart',
|
||||
'''
|
||||
String T1;
|
||||
var _T2;
|
||||
class C { }
|
||||
class D { }''');
|
||||
addSource(
|
||||
'/testEEF.dart',
|
||||
'''
|
||||
class EE { }
|
||||
class F { }''');
|
||||
addSource('/testG.dart', 'class G { }');
|
||||
addSource(
|
||||
'/testH.dart',
|
||||
'''
|
||||
class H { }
|
||||
int T3;
|
||||
var _T4;'''); // not imported
|
||||
addTestSource('''
|
||||
import "/testAB.dart";
|
||||
import "/testCD.dart" hide D;
|
||||
import "/testEEF.dart" show EE;
|
||||
import "/testG.dart" as g;
|
||||
int T5;
|
||||
var _T6;
|
||||
String get T7 => 'hello';
|
||||
set T8(int value) { partT8() {} }
|
||||
Z D2() {int x;}
|
||||
class X {
|
||||
int get clog => 8;
|
||||
set blog(value) { }
|
||||
a() {
|
||||
var f;
|
||||
localF(int arg1) { }
|
||||
{var x;}
|
||||
^ var r;
|
||||
}
|
||||
void b() { }}
|
||||
class Z { }''');
|
||||
await computeSuggestions();
|
||||
expect(replacementOffset, completionOffset);
|
||||
expect(replacementLength, 0);
|
||||
assertSuggestLibraryPrefixes(['g']);
|
||||
}
|
||||
|
||||
test_Block_final_final() async {
|
||||
// Block BlockFunctionBody MethodDeclaration
|
||||
addSource(
|
||||
'/testAB.dart',
|
||||
'''
|
||||
export "dart:math" hide max;
|
||||
class A {int x;}
|
||||
@deprecated D1() {int x;}
|
||||
class _B {boo() { partBoo() {}} }''');
|
||||
addSource(
|
||||
'/testCD.dart',
|
||||
'''
|
||||
String T1;
|
||||
var _T2;
|
||||
class C { }
|
||||
class D { }''');
|
||||
addSource(
|
||||
'/testEEF.dart',
|
||||
'''
|
||||
class EE { }
|
||||
class F { }''');
|
||||
addSource('/testG.dart', 'class G { }');
|
||||
addSource(
|
||||
'/testH.dart',
|
||||
'''
|
||||
class H { }
|
||||
int T3;
|
||||
var _T4;'''); // not imported
|
||||
addTestSource('''
|
||||
import "/testAB.dart";
|
||||
import "/testCD.dart" hide D;
|
||||
import "/testEEF.dart" show EE;
|
||||
import "/testG.dart" as g;
|
||||
int T5;
|
||||
var _T6;
|
||||
String get T7 => 'hello';
|
||||
set T8(int value) { partT8() {} }
|
||||
Z D2() {int x;}
|
||||
class X {
|
||||
int get clog => 8;
|
||||
set blog(value) { }
|
||||
a() {
|
||||
final ^
|
||||
final var f;
|
||||
localF(int arg1) { }
|
||||
{var x;}
|
||||
}
|
||||
void b() { }}
|
||||
class Z { }''');
|
||||
await computeSuggestions();
|
||||
expect(replacementOffset, completionOffset);
|
||||
expect(replacementLength, 0);
|
||||
assertSuggestLibraryPrefixes(['g']);
|
||||
}
|
||||
|
||||
test_Block_final_var() async {
|
||||
// Block BlockFunctionBody MethodDeclaration
|
||||
addSource(
|
||||
'/testAB.dart',
|
||||
'''
|
||||
export "dart:math" hide max;
|
||||
class A {int x;}
|
||||
@deprecated D1() {int x;}
|
||||
class _B {boo() { partBoo() {}} }''');
|
||||
addSource(
|
||||
'/testCD.dart',
|
||||
'''
|
||||
String T1;
|
||||
var _T2;
|
||||
class C { }
|
||||
class D { }''');
|
||||
addSource(
|
||||
'/testEEF.dart',
|
||||
'''
|
||||
class EE { }
|
||||
class F { }''');
|
||||
addSource('/testG.dart', 'class G { }');
|
||||
addSource(
|
||||
'/testH.dart',
|
||||
'''
|
||||
class H { }
|
||||
int T3;
|
||||
var _T4;'''); // not imported
|
||||
addTestSource('''
|
||||
import "/testAB.dart";
|
||||
import "/testCD.dart" hide D;
|
||||
import "/testEEF.dart" show EE;
|
||||
import "/testG.dart" as g;
|
||||
int T5;
|
||||
var _T6;
|
||||
String get T7 => 'hello';
|
||||
set T8(int value) { partT8() {} }
|
||||
Z D2() {int x;}
|
||||
class X {
|
||||
int get clog => 8;
|
||||
set blog(value) { }
|
||||
a() {
|
||||
final ^
|
||||
var f;
|
||||
localF(int arg1) { }
|
||||
{var x;}
|
||||
}
|
||||
void b() { }}
|
||||
class Z { }''');
|
||||
await computeSuggestions();
|
||||
expect(replacementOffset, completionOffset);
|
||||
expect(replacementLength, 0);
|
||||
assertSuggestLibraryPrefixes(['g']);
|
||||
}
|
||||
|
||||
test_ClassDeclaration_body() async {
|
||||
// ClassDeclaration CompilationUnit
|
||||
addSource(
|
||||
'/testB.dart',
|
||||
'''
|
||||
class B { }''');
|
||||
addTestSource('''
|
||||
import "testB.dart" as x;
|
||||
@deprecated class A {^}
|
||||
class _B {}
|
||||
A T;''');
|
||||
await computeSuggestions();
|
||||
expect(replacementOffset, completionOffset);
|
||||
expect(replacementLength, 0);
|
||||
assertSuggestLibraryPrefixes(['x']);
|
||||
}
|
||||
|
||||
test_ClassDeclaration_body_final() async {
|
||||
// ClassDeclaration CompilationUnit
|
||||
addSource(
|
||||
'/testB.dart',
|
||||
'''
|
||||
class B { }''');
|
||||
addTestSource('''
|
||||
import "testB.dart" as x;
|
||||
class A {final ^}
|
||||
class _B {}
|
||||
A T;''');
|
||||
await computeSuggestions();
|
||||
expect(replacementOffset, completionOffset);
|
||||
expect(replacementLength, 0);
|
||||
assertSuggestLibraryPrefixes(['x']);
|
||||
}
|
||||
|
||||
test_ClassDeclaration_body_final_field() async {
|
||||
// ClassDeclaration CompilationUnit
|
||||
addSource(
|
||||
'/testB.dart',
|
||||
'''
|
||||
class B { }''');
|
||||
addTestSource('''
|
||||
import "testB.dart" as x;
|
||||
class A {final ^ A(){}}
|
||||
class _B {}
|
||||
A T;''');
|
||||
await computeSuggestions();
|
||||
expect(replacementOffset, completionOffset);
|
||||
expect(replacementLength, 0);
|
||||
assertSuggestLibraryPrefixes(['x']);
|
||||
}
|
||||
|
||||
test_ClassDeclaration_body_final_field2() async {
|
||||
// ClassDeclaration CompilationUnit
|
||||
addSource(
|
||||
'/testB.dart',
|
||||
'''
|
||||
class B { }''');
|
||||
addTestSource('''
|
||||
import "testB.dart" as Soo;
|
||||
class A {final S^ A();}
|
||||
class _B {}
|
||||
A Sew;''');
|
||||
await computeSuggestions();
|
||||
expect(replacementOffset, completionOffset - 1);
|
||||
expect(replacementLength, 1);
|
||||
assertSuggestLibraryPrefixes(['Soo']);
|
||||
}
|
||||
|
||||
test_ClassDeclaration_body_final_final() async {
|
||||
// ClassDeclaration CompilationUnit
|
||||
addSource(
|
||||
'/testB.dart',
|
||||
'''
|
||||
class B { }''');
|
||||
addTestSource('''
|
||||
import "testB.dart" as x;
|
||||
class A {final ^ final foo;}
|
||||
class _B {}
|
||||
A T;''');
|
||||
await computeSuggestions();
|
||||
expect(replacementOffset, completionOffset);
|
||||
expect(replacementLength, 0);
|
||||
assertSuggestLibraryPrefixes(['x']);
|
||||
}
|
||||
|
||||
test_ClassDeclaration_body_final_var() async {
|
||||
// ClassDeclaration CompilationUnit
|
||||
addSource(
|
||||
'/testB.dart',
|
||||
'''
|
||||
class B { }''');
|
||||
addTestSource('''
|
||||
import "testB.dart" as x;
|
||||
class A {final ^ var foo;}
|
||||
class _B {}
|
||||
A T;''');
|
||||
await computeSuggestions();
|
||||
expect(replacementOffset, completionOffset);
|
||||
expect(replacementLength, 0);
|
||||
assertSuggestLibraryPrefixes(['x']);
|
||||
}
|
||||
|
||||
test_InstanceCreationExpression() async {
|
||||
addSource(
|
||||
'/testA.dart',
|
||||
'''
|
||||
class A {foo(){var f; {var x;}}}
|
||||
class B {B(this.x, [String boo]) { } int x;}
|
||||
class C {C.bar({boo: 'hoo', int z: 0}) { } }''');
|
||||
addTestSource('''
|
||||
import "/testA.dart" as t;
|
||||
import "dart:math" as math;
|
||||
main() {new ^ String x = "hello";}''');
|
||||
await computeSuggestions();
|
||||
assertSuggestLibraryPrefixes(['math', 't']);
|
||||
}
|
||||
|
||||
test_InstanceCreationExpression2() async {
|
||||
addTestSource('import "dart:convert" as json;f() {var x=new js^}');
|
||||
await computeSuggestions();
|
||||
assertSuggestLibraryPrefixes(['json']);
|
||||
}
|
||||
|
||||
test_InstanceCreationExpression_inPart() async {
|
||||
addSource(
|
||||
'/testA.dart',
|
||||
'''
|
||||
class A {foo(){var f; {var x;}}}
|
||||
class B {B(this.x, [String boo]) { } int x;}
|
||||
class C {C.bar({boo: 'hoo', int z: 0}) { } }''');
|
||||
addSource(
|
||||
'/testB.dart',
|
||||
'''
|
||||
library testB;
|
||||
import "/testA.dart" as t;
|
||||
import "dart:math" as math;
|
||||
part "$testFile"
|
||||
main() {new ^ String x = "hello";}''');
|
||||
addTestSource('''
|
||||
part of testB;
|
||||
main() {new ^ String x = "hello";}''');
|
||||
await computeLibrariesContaining();
|
||||
await computeSuggestions();
|
||||
assertSuggestLibraryPrefixes(['math', 't']);
|
||||
}
|
||||
|
||||
test_InstanceCreationExpression_inPart_detached() async {
|
||||
addSource(
|
||||
'/testA.dart',
|
||||
'''
|
||||
class A {foo(){var f; {var x;}}}
|
||||
class B {B(this.x, [String boo]) { } int x;}
|
||||
class C {C.bar({boo: 'hoo', int z: 0}) { } }''');
|
||||
addSource(
|
||||
'/testB.dart',
|
||||
'''
|
||||
library testB;
|
||||
import "/testA.dart" as t;
|
||||
import "dart:math" as math;
|
||||
//part "$testFile"
|
||||
main() {new ^ String x = "hello";}''');
|
||||
addTestSource('''
|
||||
//part of testB;
|
||||
main() {new ^ String x = "hello";}''');
|
||||
await computeSuggestions();
|
||||
assertNoSuggestions();
|
||||
}
|
||||
}
|
|
@ -13,7 +13,8 @@ import 'common_usage_sorter_test.dart' as common_usage_test;
|
|||
import 'field_formal_contributor_test.dart' as field_formal_contributor_test;
|
||||
import 'inherited_contributor_test.dart' as inherited_contributor_test;
|
||||
import 'keyword_contributor_test.dart' as keyword_test;
|
||||
import 'library_member_contributor_test.dart' as library_test;
|
||||
import 'library_member_contributor_test.dart' as library_member_test;
|
||||
import 'library_prefix_contributor_test.dart' as library_prefix_test;
|
||||
import 'named_constructor_contributor_test.dart' as named_contributor_test;
|
||||
import 'static_member_contributor_test.dart' as static_contributor_test;
|
||||
import 'type_member_contributor_test.dart' as type_member_contributor_test;
|
||||
|
@ -29,7 +30,8 @@ main() {
|
|||
field_formal_contributor_test.main();
|
||||
inherited_contributor_test.main();
|
||||
keyword_test.main();
|
||||
library_test.main();
|
||||
library_member_test.main();
|
||||
library_prefix_test.main();
|
||||
named_contributor_test.main();
|
||||
static_contributor_test.main();
|
||||
type_member_contributor_test.main();
|
||||
|
|
|
@ -4,8 +4,6 @@
|
|||
|
||||
library test.services.completion.toplevel;
|
||||
|
||||
import 'package:analysis_server/plugin/protocol/protocol.dart' as protocol
|
||||
show Element, ElementKind;
|
||||
import 'package:analysis_server/plugin/protocol/protocol.dart'
|
||||
hide Element, ElementKind;
|
||||
import 'package:analysis_server/src/services/completion/dart_completion_cache.dart';
|
||||
|
@ -33,7 +31,6 @@ class ImportedReferenceContributorTest extends AbstractSelectorSuggestionTest {
|
|||
DartCompletionCache cache = request.cache;
|
||||
if (!isCached(cache.importedTypeSuggestions, completion) &&
|
||||
!isCached(cache.importedVoidReturnSuggestions, completion) &&
|
||||
!isCached(cache.libraryPrefixSuggestions, completion) &&
|
||||
!isCached(cache.otherImportedSuggestions, completion)) {
|
||||
fail('expected $completion to be cached');
|
||||
}
|
||||
|
@ -116,7 +113,6 @@ class ImportedReferenceContributorTest extends AbstractSelectorSuggestionTest {
|
|||
DartCompletionCache cache = request.cache;
|
||||
if (isCached(cache.importedTypeSuggestions, completion) ||
|
||||
isCached(cache.importedVoidReturnSuggestions, completion) ||
|
||||
isCached(cache.libraryPrefixSuggestions, completion) ||
|
||||
isCached(cache.otherImportedSuggestions, completion)) {
|
||||
fail('expected $completion NOT to be cached');
|
||||
}
|
||||
|
@ -203,21 +199,6 @@ class ImportedReferenceContributorTest extends AbstractSelectorSuggestionTest {
|
|||
name, returnType, relevance, kind, importUri);
|
||||
}
|
||||
|
||||
@override
|
||||
CompletionSuggestion assertSuggestLibraryPrefix(String prefix,
|
||||
[int relevance = DART_RELEVANCE_DEFAULT,
|
||||
CompletionSuggestionKind kind = CompletionSuggestionKind.INVOCATION]) {
|
||||
CompletionSuggestion cs =
|
||||
assertSuggest(prefix, csKind: kind, relevance: relevance);
|
||||
protocol.Element element = cs.element;
|
||||
expect(element, isNotNull);
|
||||
expect(element.kind, equals(protocol.ElementKind.LIBRARY));
|
||||
expect(element.parameters, isNull);
|
||||
expect(element.returnType, isNull);
|
||||
assertHasNoParameterInfo(cs);
|
||||
return cs;
|
||||
}
|
||||
|
||||
fail_enum_deprecated() {
|
||||
addSource('/libA.dart', 'library A; @deprecated enum E { one, two }');
|
||||
addTestSource('import "/libA.dart"; main() {^}');
|
||||
|
@ -552,7 +533,8 @@ main() {new ^ String x = "hello";}''');
|
|||
expect(suggestion.requiredParameterCount, 0);
|
||||
expect(suggestion.hasNamedParameters, true);
|
||||
|
||||
assertSuggestLibraryPrefix('math');
|
||||
// Suggested by LibraryPrefixContributor
|
||||
assertNotSuggested('math');
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue