fix combinator contributor

gracefully degrade given partially element information
better reporting of exceptions during testing

R=scheglov@google.com

Review URL: https://codereview.chromium.org/1506623002 .
This commit is contained in:
danrubel 2015-12-06 15:34:19 -05:00
parent 109ccdaf97
commit 372cb6be58
5 changed files with 29 additions and 23 deletions

View file

@ -52,9 +52,12 @@ CompletionSuggestion createSuggestion(Element element,
suggestion.parameterNames = element.parameters
.map((ParameterElement parameter) => parameter.name)
.toList();
suggestion.parameterTypes = element.parameters
.map((ParameterElement parameter) => parameter.type.displayName)
.toList();
suggestion.parameterTypes =
element.parameters.map((ParameterElement parameter) {
DartType paramType = parameter.type;
// Gracefully degrade if type not resolved yet
return paramType != null ? paramType.displayName : 'var';
}).toList();
suggestion.requiredParameterCount = element.parameters
.where((ParameterElement parameter) =>
parameter.parameterKind == ParameterKind.REQUIRED)

View file

@ -1121,44 +1121,38 @@ main(A a) {
buildTests(
'testCompletion_combinator_afterComma',
'''
"import 'dart:math' show cos, !1;''',
<String>["1+PI", "1+sin", "1+Random", "1-String"],
failingTests: '1');
import 'dart:math' show cos, !1;''',
<String>["1+PI", "1+sin", "1+Random", "1-String"]);
buildTests(
'testCompletion_combinator_ended',
'''
import 'dart:math' show !1;"''',
<String>["1+PI", "1+sin", "1+Random", "1-String"],
failingTests: '1');
<String>["1+PI", "1+sin", "1+Random", "1-String"]);
buildTests(
'testCompletion_combinator_export',
'''
export 'dart:math' show !1;"''',
<String>["1+PI", "1+sin", "1+Random", "1-String"],
failingTests: '1');
<String>["1+PI", "1+sin", "1+Random", "1-String"]);
buildTests(
'testCompletion_combinator_hide',
'''
import 'dart:math' hide !1;"''',
<String>["1+PI", "1+sin", "1+Random", "1-String"],
failingTests: '1');
<String>["1+PI", "1+sin", "1+Random", "1-String"]);
buildTests(
'testCompletion_combinator_notEnded',
'''
import 'dart:math' show !1"''',
<String>["1+PI", "1+sin", "1+Random", "1-String"],
failingTests: '1');
<String>["1+PI", "1+sin", "1+Random", "1-String"]);
buildTests(
'testCompletion_combinator_usePrefix',
'''
import 'dart:math' show s!1"''',
<String>["1+sin", "1+sqrt", "1-cos", "1-String"],
failingTests: '1');
<String>["1+sin", "1+sqrt", "1-cos", "1-String"]);
buildTests(
'testCompletion_constructor_field',

View file

@ -358,6 +358,8 @@ class CompletionTest extends AbstractAnalysisTest {
expect(suggestionsDone, isNotNull);
suggestions = params.results;
}
} else if (notification.event == SERVER_ERROR) {
fail('server error: ${notification.toJson()}');
}
}

View file

@ -76,8 +76,8 @@ class CombinatorContributorTest extends DartCompletionContributorTest {
assertSuggestClass('PB',
relevance: DART_RELEVANCE_DEFAULT,
kind: CompletionSuggestionKind.IDENTIFIER);
assertSuggestTopLevelVar('T1', null, DART_RELEVANCE_DEFAULT,
CompletionSuggestionKind.IDENTIFIER);
assertSuggestTopLevelVar('T1', null,
kind: CompletionSuggestionKind.IDENTIFIER);
assertSuggestFunction('F1', 'PB',
kind: CompletionSuggestionKind.IDENTIFIER);
assertNotSuggested('C');
@ -127,8 +127,8 @@ class CombinatorContributorTest extends DartCompletionContributorTest {
assertSuggestClass('PB',
relevance: DART_RELEVANCE_DEFAULT,
kind: CompletionSuggestionKind.IDENTIFIER);
assertSuggestTopLevelVar('T1', null, DART_RELEVANCE_DEFAULT,
CompletionSuggestionKind.IDENTIFIER);
assertSuggestTopLevelVar('T1', null,
kind: CompletionSuggestionKind.IDENTIFIER);
assertSuggestFunction('F1', 'PB',
kind: CompletionSuggestionKind.IDENTIFIER);
assertSuggestClass('Clz',
@ -141,4 +141,11 @@ class CombinatorContributorTest extends DartCompletionContributorTest {
assertNotSuggested('X');
assertNotSuggested('Object');
}
test_Combinator_show_PI() async {
addTestSource('import "dart:math" show ^;');
await computeSuggestions();
assertSuggestTopLevelVar('PI', 'double',
kind: CompletionSuggestionKind.IDENTIFIER);
}
}

View file

@ -215,9 +215,9 @@ abstract class DartCompletionContributorTest extends AbstractContextTest {
}
CompletionSuggestion assertSuggestTopLevelVar(String name, String returnType,
[int relevance = DART_RELEVANCE_DEFAULT,
CompletionSuggestionKind kind = CompletionSuggestionKind.INVOCATION,
String importUri]) {
{int relevance: DART_RELEVANCE_DEFAULT,
CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION,
String importUri}) {
CompletionSuggestion cs = assertSuggest(name,
csKind: kind, relevance: relevance, importUri: importUri);
expect(cs.returnType, returnType != null ? returnType : 'dynamic');