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

Side by Side Diff: pkg/analysis_server/lib/plugin/edit/assist/assist_dart.dart

Issue 2899843002: Convert quick assist support to use AnalysisDriver (Closed)
Patch Set: Created 3 years, 7 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 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 import 'dart:async'; 5 import 'dart:async';
6 6
7 import 'package:analysis_server/plugin/edit/assist/assist_core.dart'; 7 import 'package:analysis_server/plugin/edit/assist/assist_core.dart';
8 import 'package:analyzer/dart/ast/ast.dart'; 8 import 'package:analyzer/dart/ast/ast.dart';
9 import 'package:analyzer/src/dart/analysis/ast_provider_context.dart'; 9 import 'package:analyzer/src/dart/analysis/ast_provider_driver.dart';
10 import 'package:analyzer/src/dart/analysis/driver.dart';
10 import 'package:analyzer/src/dart/element/ast_provider.dart'; 11 import 'package:analyzer/src/dart/element/ast_provider.dart';
11 import 'package:analyzer/src/generated/engine.dart'; 12 import 'package:analyzer/src/generated/engine.dart';
12 import 'package:analyzer/src/generated/source.dart'; 13 import 'package:analyzer/src/generated/source.dart';
13 14
14 /** 15 /**
15 * An object used to provide context information for [DartAssistContributor]s. 16 * An object used to provide context information for [DartAssistContributor]s.
16 * 17 *
17 * Clients may not extend, implement or mix-in this class. 18 * Clients may not extend, implement or mix-in this class.
18 */ 19 */
19 abstract class DartAssistContext { 20 abstract class DartAssistContext {
20 /** 21 /**
21 * The [AnalysisContext] to get assists in. 22 * The analysis driver used to access analysis results.
22 */ 23 */
23 AnalysisContext get analysisContext; 24 AnalysisDriver get analysisDriver;
24 25
25 /** 26 /**
26 * The provider for parsed or resolved ASTs. 27 * The provider for parsed or resolved ASTs.
27 */ 28 */
28 AstProvider get astProvider; 29 AstProvider get astProvider;
29 30
30 /** 31 /**
31 * The length of the selection. 32 * The length of the selection.
32 */ 33 */
33 int get selectionLength; 34 int get selectionLength;
(...skipping 15 matching lines...) Expand all
49 } 50 }
50 51
51 /** 52 /**
52 * An [AssistContributor] that can be used to contribute assists for Dart files. 53 * An [AssistContributor] that can be used to contribute assists for Dart files.
53 * 54 *
54 * Clients may extend this class when implementing plugins. 55 * Clients may extend this class when implementing plugins.
55 */ 56 */
56 abstract class DartAssistContributor implements AssistContributor { 57 abstract class DartAssistContributor implements AssistContributor {
57 @override 58 @override
58 Future<List<Assist>> computeAssists(AssistContext context) async { 59 Future<List<Assist>> computeAssists(AssistContext context) async {
59 AnalysisContext analysisContext = context.analysisContext; 60 AnalysisDriver driver = context.analysisDriver;
60 Source source = context.source; 61 Source source = context.source;
61 if (!AnalysisEngine.isDartFileName(source.fullName)) { 62 if (!AnalysisEngine.isDartFileName(source.fullName)) {
62 return Assist.EMPTY_LIST; 63 return Assist.EMPTY_LIST;
63 } 64 }
64 List<Source> libraries = analysisContext.getLibrariesContaining(source); 65 CompilationUnit unit = (await driver.getResult(source.fullName)).unit;
65 if (libraries.isEmpty) {
66 return Assist.EMPTY_LIST;
67 }
68 CompilationUnit unit =
69 analysisContext.getResolvedCompilationUnit2(source, libraries[0]);
70 if (unit == null) { 66 if (unit == null) {
71 return Assist.EMPTY_LIST; 67 return Assist.EMPTY_LIST;
72 } 68 }
73 DartAssistContext dartContext = new _DartAssistContextImpl( 69 DartAssistContext dartContext = new _DartAssistContextImpl(
74 new AstProviderForContext(analysisContext), context, unit); 70 new AstProviderForDriver(driver), context, unit);
75 return internalComputeAssists(dartContext); 71 return internalComputeAssists(dartContext);
76 } 72 }
77 73
78 /** 74 /**
79 * Completes with a list of assists for the given [context]. 75 * Completes with a list of assists for the given [context].
80 */ 76 */
81 Future<List<Assist>> internalComputeAssists(DartAssistContext context); 77 Future<List<Assist>> internalComputeAssists(DartAssistContext context);
82 } 78 }
83 79
84 /** 80 /**
85 * The implementation of [DartAssistContext]. 81 * The implementation of [DartAssistContext].
86 * 82 *
87 * Clients may not extend, implement or mix-in this class. 83 * Clients may not extend, implement or mix-in this class.
88 */ 84 */
89 class _DartAssistContextImpl implements DartAssistContext { 85 class _DartAssistContextImpl implements DartAssistContext {
90 /** 86 @override
91 * The provider for parsed or resolved ASTs.
92 */
93 final AstProvider astProvider; 87 final AstProvider astProvider;
94 88
95 final AssistContext _context; 89 final AssistContext _context;
96 90
97 /** 91 @override
98 * The [CompilationUnit] to compute assists in.
99 */
100 final CompilationUnit unit; 92 final CompilationUnit unit;
101 93
102 _DartAssistContextImpl(this.astProvider, this._context, this.unit); 94 _DartAssistContextImpl(this.astProvider, this._context, this.unit);
103 95
104 /** 96 @override
105 * The [AnalysisContext] to get assists in. 97 AnalysisDriver get analysisDriver => _context.analysisDriver;
106 */
107 AnalysisContext get analysisContext => _context.analysisContext;
108 98
109 /** 99 @override
110 * The length of the selection.
111 */
112 int get selectionLength => _context.selectionLength; 100 int get selectionLength => _context.selectionLength;
113 101
114 /** 102 @override
115 * The start of the selection.
116 */
117 int get selectionOffset => _context.selectionOffset; 103 int get selectionOffset => _context.selectionOffset;
118 104
119 /** 105 @override
120 * The source to get assists in.
121 */
122 Source get source => _context.source; 106 Source get source => _context.source;
123 } 107 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/plugin/edit/assist/assist_core.dart ('k') | pkg/analysis_server/lib/plugin/edit/fix/fix_core.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698