Index: pkg/analysis_server/lib/src/services/completion/dart/common_usage_sorter.dart |
diff --git a/pkg/analysis_server/lib/src/services/completion/dart/common_usage_sorter.dart b/pkg/analysis_server/lib/src/services/completion/dart/common_usage_sorter.dart |
index 719221e8f035bfaaaaa12bb07cc689028338dd64..67f7137d12af24fcf58ce74e07a30b2be9325690 100644 |
--- a/pkg/analysis_server/lib/src/services/completion/dart/common_usage_sorter.dart |
+++ b/pkg/analysis_server/lib/src/services/completion/dart/common_usage_sorter.dart |
@@ -46,18 +46,24 @@ class CommonUsageSorter implements DartContributionSorter { |
} |
CompletionTarget _getCompletionTarget(CompletionRequest request) { |
- // TODO (danrubel) get cached completion target |
- var libSrcs = request.context.getLibrariesContaining(request.source); |
- if (libSrcs.length == 0) { |
- return null; |
- } |
- var libElem = request.context.getResult(libSrcs[0], LIBRARY_ELEMENT1); |
- if (libElem is LibraryElement) { |
- var unit = request.context.getResult( |
- new LibrarySpecificUnit(libElem.source, request.source), |
- RESOLVED_UNIT5); |
- if (unit is CompilationUnit) { |
- return new CompletionTarget.forOffset(unit, request.offset); |
+ if (request.result != null) { |
+ var unit = request.result.unit; |
+ return new CompletionTarget.forOffset(unit, request.offset); |
+ } else { |
+ // TODO (danrubel) get cached completion target |
+ var libSrcs = request.context.getLibrariesContaining(request.source); |
+ if (libSrcs.length == 0) { |
+ return null; |
+ } |
+ LibraryElement libElem = |
+ request.context.getResult(libSrcs[0], LIBRARY_ELEMENT1); |
+ if (libElem is LibraryElement) { |
+ var unit = request.context.getResult( |
+ new LibrarySpecificUnit(libElem.source, request.source), |
+ RESOLVED_UNIT5); |
+ if (unit is CompilationUnit) { |
+ return new CompletionTarget.forOffset(unit, request.offset); |
+ } |
} |
} |
return null; |