Stop returning declaration matches from search for references.

R=brianwilkerson@google.com
BUG=

Review URL: https://codereview.chromium.org/2518183003 .
This commit is contained in:
Konstantin Shcheglov 2016-11-22 12:32:51 -08:00
parent 89cab97dd8
commit 9bc4c73e2d
2 changed files with 7 additions and 58 deletions

View file

@ -10,9 +10,7 @@ import 'package:analysis_server/src/protocol_server.dart'
show SearchResult, newSearchResult_fromMatch;
import 'package:analysis_server/src/services/search/hierarchy.dart';
import 'package:analysis_server/src/services/search/search_engine.dart';
import 'package:analysis_server/src/services/search/search_engine_internal.dart';
import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/src/generated/source.dart';
/**
* A computer for `search.findElementReferences` request results.
@ -52,12 +50,6 @@ class ElementReferencesComputer {
List<SearchResult> allResults = <SearchResult>[];
Iterable<Element> refElements = await _getRefElements(element);
for (Element refElement in refElements) {
// add declaration
if (_isDeclarationInteresting(refElement)) {
SearchResult searchResult = _newDeclarationResult(refElement);
allResults.add(searchResult);
}
// do search
List<SearchResult> elementResults =
await _findSingleElementReferences(refElement);
allResults.addAll(elementResults);
@ -90,43 +82,10 @@ class ElementReferencesComputer {
return new Future.value([element]);
}
SearchResult _newDeclarationResult(Element refElement) {
int nameOffset = refElement.nameOffset;
int nameLength = refElement.nameLength;
SearchMatch searchMatch = new SearchMatchImpl(
refElement.context,
refElement.library.source.uri.toString(),
refElement.source.uri.toString(),
MatchKind.DECLARATION,
new SourceRange(nameOffset, nameLength),
true,
false);
return newSearchResult_fromMatch(searchMatch);
}
static SearchResult toResult(SearchMatch match) {
return newSearchResult_fromMatch(match);
}
static bool _isDeclarationInteresting(Element element) {
if (element is LabelElement) {
return true;
}
if (element is LocalVariableElement) {
return true;
}
if (element is ParameterElement) {
return true;
}
if (element is PrefixElement) {
return true;
}
if (element is PropertyInducingElement) {
return !element.isSynthetic;
}
return false;
}
static bool _isMemberElement(Element element) {
if (element is ConstructorElement) {
return false;

View file

@ -153,8 +153,7 @@ main(A a) {
''');
await findElementReferences('fff; // declaration', false);
expect(searchElement.kind, ElementKind.FIELD);
expect(results, hasLength(11));
assertHasResult(SearchResultKind.DECLARATION, 'fff; // declaration');
expect(results, hasLength(10));
assertHasResult(SearchResultKind.WRITE, 'fff); // in constructor');
assertHasResult(SearchResultKind.WRITE, 'fff = 1;');
// m()
@ -216,8 +215,7 @@ class A {
''');
await findElementReferences('fff); // in constructor', false);
expect(searchElement.kind, ElementKind.FIELD);
expect(results, hasLength(4));
assertHasResult(SearchResultKind.DECLARATION, 'fff; // declaration');
expect(results, hasLength(3));
assertHasResult(SearchResultKind.WRITE, 'fff); // in constructor');
assertHasResult(SearchResultKind.WRITE, 'fff = 2;');
assertHasResult(SearchResultKind.READ, 'fff); // in m()');
@ -257,9 +255,6 @@ main() {
''');
await findElementReferences('fff; // in B', false);
expect(searchElement.kind, ElementKind.FIELD);
assertHasResult(SearchResultKind.DECLARATION, 'fff; // in A');
assertHasResult(SearchResultKind.DECLARATION, 'fff; // in B');
assertHasResult(SearchResultKind.DECLARATION, 'fff; // in C');
assertHasResult(SearchResultKind.WRITE, 'fff = 10;');
assertHasResult(SearchResultKind.WRITE, 'fff = 20;');
assertHasResult(SearchResultKind.WRITE, 'fff = 30;');
@ -326,8 +321,7 @@ myLabel:
''');
await findElementReferences('myLabel; // break', false);
expect(searchElement.kind, ElementKind.LABEL);
expect(results, hasLength(3));
assertHasResult(SearchResultKind.DECLARATION, 'myLabel:');
expect(results, hasLength(2));
assertHasResult(SearchResultKind.REFERENCE, 'myLabel; // continue');
assertHasResult(SearchResultKind.REFERENCE, 'myLabel; // break');
}
@ -344,8 +338,7 @@ main() {
''');
await findElementReferences('vvv = 1', false);
expect(searchElement.kind, ElementKind.LOCAL_VARIABLE);
expect(results, hasLength(5));
assertHasResult(SearchResultKind.DECLARATION, 'vvv = 1');
expect(results, hasLength(4));
assertHasResult(SearchResultKind.READ, 'vvv);');
assertHasResult(SearchResultKind.READ_WRITE, 'vvv += 3');
assertHasResult(SearchResultKind.WRITE, 'vvv = 2');
@ -426,8 +419,7 @@ main(ppp) {
''');
await findElementReferences('ppp) {', false);
expect(searchElement.kind, ElementKind.PARAMETER);
expect(results, hasLength(5));
assertHasResult(SearchResultKind.DECLARATION, 'ppp) {');
expect(results, hasLength(4));
assertHasResult(SearchResultKind.READ, 'ppp);');
assertHasResult(SearchResultKind.READ_WRITE, 'ppp += 3');
assertHasResult(SearchResultKind.WRITE, 'ppp = 2');
@ -594,8 +586,7 @@ main() {
expect(searchElement.kind, ElementKind.PREFIX);
expect(searchElement.name, 'ppp');
expect(searchElement.location.startLine, 1);
expect(results, hasLength(3));
assertHasResult(SearchResultKind.DECLARATION, 'ppp;');
expect(results, hasLength(2));
assertHasResult(SearchResultKind.REFERENCE, 'ppp.Future');
assertHasResult(SearchResultKind.REFERENCE, 'ppp.Stream');
}
@ -612,8 +603,7 @@ main() {
''');
await findElementReferences('vvv = 1', false);
expect(searchElement.kind, ElementKind.TOP_LEVEL_VARIABLE);
expect(results, hasLength(5));
assertHasResult(SearchResultKind.DECLARATION, 'vvv = 1;');
expect(results, hasLength(4));
assertHasResult(SearchResultKind.READ, 'vvv);');
assertHasResult(SearchResultKind.WRITE, 'vvv += 3');
assertHasResult(SearchResultKind.WRITE, 'vvv = 2');