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

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

Issue 1685653002: abort completion request - fixes #24271 (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: address comment Created 4 years, 10 months 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/completion_core.dart
diff --git a/pkg/analysis_server/lib/src/services/completion/completion_core.dart b/pkg/analysis_server/lib/src/services/completion/completion_core.dart
index e0635aa9e062fe422306bd295515bf18224a085a..b79a9d84567ebc8c4efa47255357dae4244e8b97 100644
--- a/pkg/analysis_server/lib/src/services/completion/completion_core.dart
+++ b/pkg/analysis_server/lib/src/services/completion/completion_core.dart
@@ -21,6 +21,14 @@ class CompletionRequestImpl implements CompletionRequest {
@override
final Source source;
+ /**
+ * The content cache modification stamp of the associated [source],
+ * or `null` if the content cache does not override the [source] content.
+ * This is used to determine if the [source] contents have been modified
+ * after the completion request was made.
+ */
+ final int sourceModificationStamp;
+
@override
final int offset;
@@ -48,16 +56,21 @@ class CompletionRequestImpl implements CompletionRequest {
@override
final SearchEngine searchEngine;
+ bool _aborted = false;
+
final CompletionPerformance performance;
/**
* Initialize a newly created completion request based on the given arguments.
*/
- CompletionRequestImpl(this.context, this.resourceProvider, this.searchEngine,
- this.source, this.offset, this.performance) {
- replacementOffset = offset;
- replacementLength = 0;
- }
+ CompletionRequestImpl(AnalysisContext context, this.resourceProvider,
+ this.searchEngine, Source source, int offset, this.performance)
+ : this.context = context,
+ this.source = source,
+ this.offset = offset,
+ replacementOffset = offset,
+ replacementLength = 0,
+ sourceModificationStamp = context.getModificationStamp(source);
/**
* Return the original text from the [replacementOffset] to the [offset]
@@ -69,4 +82,22 @@ class CompletionRequestImpl implements CompletionRequest {
.data
.substring(replacementOffset, offset);
}
+
+ /**
+ * Abort the current completion request.
+ */
+ void abort() {
+ _aborted = true;
+ }
+
+ @override
+ void checkAborted() {
+ if (_aborted) {
+ throw new AbortCompletion();
+ }
+ if (sourceModificationStamp != context.getModificationStamp(source)) {
+ _aborted = true;
+ throw new AbortCompletion();
+ }
+ }
}

Powered by Google App Engine
This is Rietveld 408576698