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

Unified Diff: pkg/analysis_server/lib/src/edit/edit_domain.dart

Issue 2480843002: Support for Quick Assists with the new analysis driver. (Closed)
Patch Set: Created 4 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
« no previous file with comments | « pkg/analysis_server/lib/src/analysis_server.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analysis_server/lib/src/edit/edit_domain.dart
diff --git a/pkg/analysis_server/lib/src/edit/edit_domain.dart b/pkg/analysis_server/lib/src/edit/edit_domain.dart
index 14e552791f90a9c27042fc0c4e66f73c119251be..3191835249b7a11dc0641181b385fc997d240883 100644
--- a/pkg/analysis_server/lib/src/edit/edit_domain.dart
+++ b/pkg/analysis_server/lib/src/edit/edit_domain.dart
@@ -7,12 +7,14 @@ library edit.domain;
import 'dart:async';
import 'package:analysis_server/plugin/edit/assist/assist_core.dart';
+import 'package:analysis_server/plugin/edit/assist/assist_dart.dart';
import 'package:analysis_server/plugin/edit/fix/fix_core.dart';
import 'package:analysis_server/src/analysis_server.dart';
import 'package:analysis_server/src/collections.dart';
import 'package:analysis_server/src/constants.dart';
import 'package:analysis_server/src/protocol_server.dart' hide Element;
import 'package:analysis_server/src/services/correction/assist.dart';
+import 'package:analysis_server/src/services/correction/assist_internal.dart';
import 'package:analysis_server/src/services/correction/fix.dart';
import 'package:analysis_server/src/services/correction/organize_directives.dart';
import 'package:analysis_server/src/services/correction/sort_members.dart';
@@ -132,22 +134,35 @@ class EditDomainHandler implements RequestHandler {
}
Future getAssists(Request request) async {
+ EditGetAssistsParams params = new EditGetAssistsParams.fromRequest(request);
+ List<Assist> assists;
if (server.options.enableNewAnalysisDriver) {
- // TODO(scheglov) implement for the new analysis driver
- return;
+ AnalysisResult result = await server.getAnalysisResult(params.file);
+ CompilationUnit unit = result.unit;
+ DartAssistContext dartAssistContext = new _DartAssistContextForValues(
+ unit.element.source,
+ params.offset,
+ params.length,
+ unit.element.context,
+ unit);
+ try {
+ AssistProcessor processor = new AssistProcessor(dartAssistContext);
+ assists = await processor.compute();
+ } catch (_) {}
+ } else {
+ ContextSourcePair pair = server.getContextSourcePair(params.file);
+ engine.AnalysisContext context = pair.context;
+ Source source = pair.source;
+ if (context != null && source != null) {
+ assists = await computeAssists(
+ server.serverPlugin, context, source, params.offset, params.length);
+ }
}
- EditGetAssistsParams params = new EditGetAssistsParams.fromRequest(request);
- ContextSourcePair pair = server.getContextSourcePair(params.file);
- engine.AnalysisContext context = pair.context;
- Source source = pair.source;
+ // Send the assist changes.
List<SourceChange> changes = <SourceChange>[];
- if (context != null && source != null) {
- List<Assist> assists = await computeAssists(
- server.serverPlugin, context, source, params.offset, params.length);
- assists.forEach((Assist assist) {
- changes.add(assist.change);
- });
- }
+ assists?.forEach((Assist assist) {
+ changes.add(assist.change);
+ });
Response response =
new EditGetAssistsResult(changes).toResponse(request.id);
server.sendResponse(response);
@@ -390,6 +405,26 @@ class EditDomainHandler implements RequestHandler {
}
}
+class _DartAssistContextForValues implements DartAssistContext {
Paul Berry 2016/11/04 23:25:27 Can you clarify what "ForValues" means?
scheglov 2016/11/04 23:49:20 I will add a documentation comment.
+ @override
+ final Source source;
+
+ @override
+ final int selectionOffset;
+
+ @override
+ final int selectionLength;
+
+ @override
+ final engine.AnalysisContext analysisContext;
+
+ @override
+ final CompilationUnit unit;
+
+ _DartAssistContextForValues(this.source, this.selectionOffset,
+ this.selectionLength, this.analysisContext, this.unit);
+}
+
/**
* An object managing a single [Refactoring] instance.
*
« no previous file with comments | « pkg/analysis_server/lib/src/analysis_server.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698