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

Side by Side Diff: pkg/analysis_server/lib/plugin/edit/assist/assist_dart.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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library analysis_server.plugin.edit.assist.assist_dart; 5 library analysis_server.plugin.edit.assist.assist_dart;
6 6
7 import 'dart:async';
8
7 import 'package:analysis_server/plugin/edit/assist/assist_core.dart'; 9 import 'package:analysis_server/plugin/edit/assist/assist_core.dart';
8 import 'package:analyzer/src/generated/ast.dart'; 10 import 'package:analyzer/src/generated/ast.dart';
9 import 'package:analyzer/src/generated/engine.dart'; 11 import 'package:analyzer/src/generated/engine.dart';
10 import 'package:analyzer/src/generated/source.dart'; 12 import 'package:analyzer/src/generated/source.dart';
11 13
12 /** 14 /**
13 * An [AssistContributor] that can be used to contribute assists for Dart 15 * An object used to provide context information for [DartAssistContributor]s.
14 * files. 16 *
17 * Clients may not extend, implement or mix-in this class.
18 */
19 class DartAssistContext {
Brian Wilkerson 2015/11/20 19:10:11 It would be better for this to be an interface tha
20 final AssistContext _context;
21
22 /**
23 * The [CompilationUnit] to compute assists in.
24 */
25 final CompilationUnit unit;
26
27 DartAssistContext(this._context, this.unit);
28
29 /**
30 * The [AnalysisContext] to get assists in.
31 */
32 AnalysisContext get analysisContext => _context.analysisContext;
33
34 /**
35 * The length of the selection.
36 */
37 int get selectionLength => _context.selectionLength;
38
39 /**
40 * The start of the selection.
41 */
42 int get selectionOffset => _context.selectionOffset;
43
44 /**
45 * The source to get assists in.
46 */
47 Source get source => _context.source;
48 }
49
50 /**
51 * An [AssistContributor] that can be used to contribute assists for Dart files.
15 * 52 *
16 * Clients may extend this class when implementing plugins. 53 * Clients may extend this class when implementing plugins.
17 */ 54 */
18 abstract class DartAssistContributor implements AssistContributor { 55 abstract class DartAssistContributor implements AssistContributor {
19 @override 56 @override
20 List<Assist> computeAssists( 57 Future<List<Assist>> computeAssists(AssistContext context) {
21 AnalysisContext context, Source source, int offset, int length) { 58 AnalysisContext analysisContext = context.analysisContext;
59 Source source = context.source;
22 if (!AnalysisEngine.isDartFileName(source.fullName)) { 60 if (!AnalysisEngine.isDartFileName(source.fullName)) {
23 return Assist.EMPTY_LIST; 61 return new Future.value(Assist.EMPTY_LIST);
24 } 62 }
25 List<Source> libraries = context.getLibrariesContaining(source); 63 List<Source> libraries = analysisContext.getLibrariesContaining(source);
26 if (libraries.isEmpty) { 64 if (libraries.isEmpty) {
27 return Assist.EMPTY_LIST; 65 return new Future.value(Assist.EMPTY_LIST);
28 } 66 }
29 CompilationUnit unit = 67 CompilationUnit unit =
30 context.resolveCompilationUnit2(source, libraries[0]); 68 analysisContext.resolveCompilationUnit2(source, libraries[0]);
Brian Wilkerson 2015/11/20 19:10:11 At some future date we should make this be an asyn
31 if (unit == null) { 69 if (unit == null) {
32 return Assist.EMPTY_LIST; 70 return new Future.value(Assist.EMPTY_LIST);
33 } 71 }
34 return internalComputeAssists(unit, offset, length); 72 DartAssistContext dartContext = new DartAssistContext(context, unit);
73 return internalComputeAssists(dartContext);
35 } 74 }
36 75
37 /** 76 /**
38 * Return a list of assists for a location in the given [source]. The location 77 * Completes with a list of assists for the given [context].
39 * is specified by the [offset] and [length] of the selected region. The
40 * [context] can be used to get additional information that is useful for
41 * computing assists.
42 */ 78 */
43 List<Assist> internalComputeAssists( 79 Future<List<Assist>> internalComputeAssists(DartAssistContext context);
44 CompilationUnit unit, int offset, int length);
45 } 80 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/plugin/edit/assist/assist_core.dart ('k') | pkg/analysis_server/lib/src/edit/edit_domain.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698