Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(910)

Unified Diff: pkg/analysis_server/lib/src/services/completion/dart/completion_manager.dart

Issue 1516883002: do not suggest completions for cascade on library prefix - fixes #25215 (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: merge Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: pkg/analysis_server/lib/src/services/completion/dart/completion_manager.dart
diff --git a/pkg/analysis_server/lib/src/services/completion/dart/completion_manager.dart b/pkg/analysis_server/lib/src/services/completion/dart/completion_manager.dart
index c188b7c8b2f081a7d1050b4df6d6a93964448554..759a74156949c829c095fd69c3c5df376af2c122 100644
--- a/pkg/analysis_server/lib/src/services/completion/dart/completion_manager.dart
+++ b/pkg/analysis_server/lib/src/services/completion/dart/completion_manager.dart
@@ -68,11 +68,6 @@ class DartCompletionRequestImpl extends CompletionRequestImpl
Source _librarySource;
/**
- * The cached completion target or `null` if not computed yet.
- */
- CompletionTarget _target;
-
- /**
* The [DartType] for Object in dart:core
*/
InterfaceType _objectType;
@@ -83,6 +78,12 @@ class DartCompletionRequestImpl extends CompletionRequestImpl
*/
bool _haveResolveDeclarationsInScope = false;
+ @override
+ Expression dotTarget;
+
+ @override
+ CompletionTarget target;
+
/**
* Initialize a newly created completion request based on the given request.
*/
@@ -102,6 +103,7 @@ class DartCompletionRequestImpl extends CompletionRequestImpl
Source source,
int offset)
: super(context, resourceProvider, searchEngine, source, offset) {
+ _updateTargets(context.computeResult(source, PARSED_UNIT));
if (target.unit.directives.any((d) => d is PartOfDirective)) {
List<Source> libraries = context.getLibrariesContaining(source);
if (libraries.isNotEmpty) {
@@ -136,15 +138,6 @@ class DartCompletionRequestImpl extends CompletionRequestImpl
}
@override
- CompletionTarget get target {
- if (_target == null) {
- CompilationUnit unit = context.computeResult(source, PARSED_UNIT);
- _target = new CompletionTarget.forOffset(unit, offset);
- }
- return _target;
- }
-
- @override
Future<CompilationUnit> resolveDeclarationsInScope() async {
CompilationUnit unit = target.unit;
if (_haveResolveDeclarationsInScope) {
@@ -172,7 +165,7 @@ class DartCompletionRequestImpl extends CompletionRequestImpl
}
// Recompute the target for the newly resolved unit
- _target = new CompletionTarget.forOffset(resolvedUnit, offset);
+ _updateTargets(resolvedUnit);
_haveResolveDeclarationsInScope = true;
return resolvedUnit;
}
@@ -183,12 +176,11 @@ class DartCompletionRequestImpl extends CompletionRequestImpl
if (_librarySource == source) {
libUnit = await resolveDeclarationsInScope();
} else if (_librarySource != null) {
- libUnit =
- await new AnalysisFutureHelper<CompilationUnit>(
- context,
- new LibrarySpecificUnit(_librarySource, _librarySource),
- RESOLVED_UNIT3)
- .computeAsync();
+ libUnit = await new AnalysisFutureHelper<CompilationUnit>(
+ context,
+ new LibrarySpecificUnit(_librarySource, _librarySource),
+ RESOLVED_UNIT3)
+ .computeAsync();
}
return libUnit?.directives;
}
@@ -219,7 +211,35 @@ class DartCompletionRequestImpl extends CompletionRequestImpl
}
// Recompute the target for the newly resolved unit
- _target = new CompletionTarget.forOffset(resolvedUnit, offset);
+ _updateTargets(resolvedUnit);
_haveResolveDeclarationsInScope = true;
}
+
+ /**
+ * Update the completion [target] and [dotTarget] based on the given [unit].
+ */
+ void _updateTargets(CompilationUnit unit) {
+ dotTarget = null;
+ target = new CompletionTarget.forOffset(unit, offset);
+ AstNode node = target.containingNode;
+ if (node is MethodInvocation) {
+ if (identical(node.methodName, target.entity)) {
+ dotTarget = node.realTarget;
+ } else if (node.isCascaded && node.operator.offset + 1 == target.offset) {
+ dotTarget = node.realTarget;
+ }
+ }
+ if (node is PropertyAccess) {
+ if (identical(node.propertyName, target.entity)) {
+ dotTarget = node.realTarget;
+ } else if (node.isCascaded && node.operator.offset + 1 == target.offset) {
+ dotTarget = node.realTarget;
+ }
+ }
+ if (node is PrefixedIdentifier) {
+ if (identical(node.identifier, target.entity)) {
+ dotTarget = node.prefix;
+ }
+ }
+ }
}

Powered by Google App Engine
This is Rietveld 408576698