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

Unified Diff: pkg/analysis_server/lib/src/services/correction/assist_internal.dart

Issue 1461343002: Make AssistContributor asynchronous. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 1 month 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/correction/assist_internal.dart
diff --git a/pkg/analysis_server/lib/src/services/correction/assist_internal.dart b/pkg/analysis_server/lib/src/services/correction/assist_internal.dart
index 4e207d610d19c4deee0790f51a0cde29ef34f9c5..a7de360200aabe2703b34f28b68c9733b8fe9120 100644
--- a/pkg/analysis_server/lib/src/services/correction/assist_internal.dart
+++ b/pkg/analysis_server/lib/src/services/correction/assist_internal.dart
@@ -4,6 +4,7 @@
library services.src.correction.assist;
+import 'dart:async';
import 'dart:collection';
import 'package:analysis_server/plugin/edit/assist/assist_core.dart';
@@ -30,38 +31,49 @@ typedef _SimpleIdentifierVisitor(SimpleIdentifier node);
* The computer for Dart assists.
*/
class AssistProcessor {
+ AnalysisContext analysisContext;
+
Source source;
String file;
int fileStamp;
- final CompilationUnit unit;
- final int selectionOffset;
- final int selectionLength;
- AnalysisContext context;
+
+ CompilationUnit unit;
CompilationUnitElement unitElement;
+
LibraryElement unitLibraryElement;
String unitLibraryFile;
String unitLibraryFolder;
+ int selectionOffset;
+ int selectionLength;
+ int selectionEnd;
+
final List<Assist> assists = <Assist>[];
final Map<String, LinkedEditGroup> linkedPositionGroups =
<String, LinkedEditGroup>{};
Position exitPosition = null;
- int selectionEnd;
CorrectionUtils utils;
AstNode node;
SourceChange change = new SourceChange('<message>');
- AssistProcessor(this.unit, this.selectionOffset, this.selectionLength) {
- source = unit.element.source;
- file = source.fullName;
- unitElement = unit.element;
- context = unitElement.context;
- unitLibraryElement = unitElement.library;
+ AssistProcessor(DartAssistContext dartContext) {
+ analysisContext = dartContext.analysisContext;
+ // source
+ source = dartContext.source;
+ file = dartContext.source.fullName;
+ fileStamp = analysisContext.getModificationStamp(source);
+ // unit
+ unit = dartContext.unit;
+ unitElement = dartContext.unit.element;
+ // library
+ unitLibraryElement = dartContext.unit.element.library;
unitLibraryFile = unitLibraryElement.source.fullName;
unitLibraryFolder = dirname(unitLibraryFile);
- fileStamp = unitElement.context.getModificationStamp(source);
+ // selection
+ selectionOffset = dartContext.selectionOffset;
+ selectionLength = dartContext.selectionLength;
selectionEnd = selectionOffset + selectionLength;
}
@@ -70,7 +82,7 @@ class AssistProcessor {
*/
String get eol => utils.endOfLine;
- List<Assist> compute() {
+ Future<List<Assist>> compute() async {
utils = new CorrectionUtils(unit);
node = new NodeLocator(selectionOffset, selectionEnd).searchWithin(unit);
if (node == null) {
@@ -606,7 +618,7 @@ class AssistProcessor {
// iterable should be List
{
DartType iterableType = iterable.bestType;
- InterfaceType listType = context.typeProvider.listType;
+ InterfaceType listType = analysisContext.typeProvider.listType;
if (iterableType is! InterfaceType ||
iterableType.element != listType.element) {
_coverageMarker();
@@ -2074,9 +2086,8 @@ class AssistProcessor {
*/
class DefaultAssistContributor extends DartAssistContributor {
@override
- List<Assist> internalComputeAssists(
- CompilationUnit unit, int offset, int length) {
- AssistProcessor processor = new AssistProcessor(unit, offset, length);
+ Future<List<Assist>> internalComputeAssists(DartAssistContext context) {
+ AssistProcessor processor = new AssistProcessor(context);
return processor.compute();
}
}

Powered by Google App Engine
This is Rietveld 408576698