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

Side by Side Diff: pkg/analysis_server/lib/src/services/completion/dart/completion_manager.dart

Issue 2946643002: Don't compute 'dart:core' LibraryElement during completion. (Closed)
Patch Set: Created 3 years, 6 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
« no previous file with comments | « pkg/analysis_server/lib/src/provisional/completion/dart/completion_dart.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/src/provisional/completion/completion_core.dart' 7 import 'package:analysis_server/src/provisional/completion/completion_core.dart'
8 show CompletionContributor, CompletionRequest; 8 show CompletionContributor, CompletionRequest;
9 import 'package:analysis_server/src/provisional/completion/dart/completion_dart. dart'; 9 import 'package:analysis_server/src/provisional/completion/dart/completion_dart. dart';
10 import 'package:analysis_server/src/provisional/completion/dart/completion_plugi n.dart'; 10 import 'package:analysis_server/src/provisional/completion/dart/completion_plugi n.dart';
11 import 'package:analysis_server/src/services/completion/completion_core.dart'; 11 import 'package:analysis_server/src/services/completion/completion_core.dart';
12 import 'package:analysis_server/src/services/completion/completion_performance.d art'; 12 import 'package:analysis_server/src/services/completion/completion_performance.d art';
13 import 'package:analysis_server/src/services/completion/dart/common_usage_sorter .dart'; 13 import 'package:analysis_server/src/services/completion/dart/common_usage_sorter .dart';
14 import 'package:analysis_server/src/services/completion/dart/contribution_sorter .dart'; 14 import 'package:analysis_server/src/services/completion/dart/contribution_sorter .dart';
15 import 'package:analyzer/dart/ast/ast.dart'; 15 import 'package:analyzer/dart/ast/ast.dart';
16 import 'package:analyzer/dart/ast/standard_ast_factory.dart'; 16 import 'package:analyzer/dart/ast/standard_ast_factory.dart';
17 import 'package:analyzer/dart/ast/standard_resolution_map.dart';
18 import 'package:analyzer/dart/ast/token.dart'; 17 import 'package:analyzer/dart/ast/token.dart';
19 import 'package:analyzer/dart/element/element.dart'; 18 import 'package:analyzer/dart/element/element.dart';
20 import 'package:analyzer/dart/element/type.dart'; 19 import 'package:analyzer/dart/element/type.dart';
21 import 'package:analyzer/file_system/file_system.dart'; 20 import 'package:analyzer/file_system/file_system.dart';
22 import 'package:analyzer/src/dart/analysis/driver.dart'; 21 import 'package:analyzer/src/dart/analysis/driver.dart';
23 import 'package:analyzer/src/dart/ast/token.dart'; 22 import 'package:analyzer/src/dart/ast/token.dart';
24 import 'package:analyzer/src/generated/engine.dart' hide AnalysisResult; 23 import 'package:analyzer/src/generated/engine.dart' hide AnalysisResult;
25 import 'package:analyzer/src/generated/source.dart'; 24 import 'package:analyzer/src/generated/source.dart';
26 import 'package:analyzer/task/model.dart'; 25 import 'package:analyzer/task/model.dart';
27 import 'package:analyzer_plugin/protocol/protocol_common.dart'; 26 import 'package:analyzer_plugin/protocol/protocol_common.dart';
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 } 97 }
99 98
100 /** 99 /**
101 * The information about a requested list of completions within a Dart file. 100 * The information about a requested list of completions within a Dart file.
102 */ 101 */
103 class DartCompletionRequestImpl implements DartCompletionRequest { 102 class DartCompletionRequestImpl implements DartCompletionRequest {
104 @override 103 @override
105 final AnalysisResult result; 104 final AnalysisResult result;
106 105
107 @override 106 @override
108 final LibraryElement coreLib; 107 final ResourceProvider resourceProvider;
108
109 @override
110 final InterfaceType objectType;
109 111
110 @override 112 @override
111 final Source source; 113 final Source source;
112 114
113 @override 115 @override
114 final int offset; 116 final int offset;
115 117
116 @override 118 @override
117 Expression dotTarget; 119 Expression dotTarget;
118 120
119 @override 121 @override
120 Source librarySource; 122 Source librarySource;
121 123
122 @override 124 @override
123 final ResourceProvider resourceProvider;
124
125 @override
126 CompletionTarget target; 125 CompletionTarget target;
127 126
128 /**
129 * The [DartType] for Object in dart:core
130 */
131 InterfaceType _objectType;
132
133 OpType _opType; 127 OpType _opType;
134 128
135 final CompletionRequest _originalRequest; 129 final CompletionRequest _originalRequest;
136 130
137 final CompletionPerformance performance; 131 final CompletionPerformance performance;
138 132
139 DartCompletionRequestImpl._( 133 DartCompletionRequestImpl._(
140 this.result, 134 this.result,
141 this.resourceProvider, 135 this.resourceProvider,
142 this.coreLib, 136 this.objectType,
143 this.librarySource, 137 this.librarySource,
144 this.source, 138 this.source,
145 this.offset, 139 this.offset,
146 CompilationUnit unit, 140 CompilationUnit unit,
147 this._originalRequest, 141 this._originalRequest,
148 this.performance) { 142 this.performance) {
149 _updateTargets(unit); 143 _updateTargets(unit);
150 } 144 }
151 145
152 @override 146 @override
153 bool get includeIdentifiers { 147 bool get includeIdentifiers {
154 return opType.includeIdentifiers; 148 return opType.includeIdentifiers;
155 } 149 }
156 150
157 @override 151 @override
158 LibraryElement get libraryElement { 152 LibraryElement get libraryElement {
159 //TODO(danrubel) build the library element rather than all the declarations 153 //TODO(danrubel) build the library element rather than all the declarations
160 CompilationUnit unit = target.unit; 154 CompilationUnit unit = target.unit;
161 if (unit != null) { 155 if (unit != null) {
162 CompilationUnitElement elem = unit.element; 156 CompilationUnitElement elem = unit.element;
163 if (elem != null) { 157 if (elem != null) {
164 return elem.library; 158 return elem.library;
165 } 159 }
166 } 160 }
167 return null; 161 return null;
168 } 162 }
169 163
170 @override
171 InterfaceType get objectType {
172 if (_objectType == null) {
173 _objectType = coreLib.getType('Object').type;
174 }
175 return _objectType;
176 }
177
178 OpType get opType { 164 OpType get opType {
179 if (_opType == null) { 165 if (_opType == null) {
180 _opType = new OpType.forCompletion(target, offset); 166 _opType = new OpType.forCompletion(target, offset);
181 } 167 }
182 return _opType; 168 return _opType;
183 } 169 }
184 170
185 @override 171 @override
186 String get sourceContents => result.content; 172 String get sourceContents => result.content;
187 173
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 * if the completion request has been aborted. 216 * if the completion request has been aborted.
231 */ 217 */
232 static Future<DartCompletionRequest> from(CompletionRequest request, 218 static Future<DartCompletionRequest> from(CompletionRequest request,
233 {ResultDescriptor resultDescriptor}) async { 219 {ResultDescriptor resultDescriptor}) async {
234 request.checkAborted(); 220 request.checkAborted();
235 CompletionPerformance performance = 221 CompletionPerformance performance =
236 (request as CompletionRequestImpl).performance; 222 (request as CompletionRequestImpl).performance;
237 const BUILD_REQUEST_TAG = 'build DartCompletionRequest'; 223 const BUILD_REQUEST_TAG = 'build DartCompletionRequest';
238 performance.logStartTime(BUILD_REQUEST_TAG); 224 performance.logStartTime(BUILD_REQUEST_TAG);
239 225
240 Source libSource; 226 CompilationUnit unit = request.result.unit;
241 CompilationUnit unit; 227 Source libSource = unit.element.library.source;
242 unit = request.result.unit; 228 InterfaceType objectType = request.result.typeProvider.objectType;
243 // TODO(scheglov) support for parts
244 libSource = resolutionMap.elementDeclaredByCompilationUnit(unit).source;
245
246 LibraryElement coreLib =
247 await request.result.driver.getLibraryByUri('dart:core');
248 229
249 DartCompletionRequestImpl dartRequest = new DartCompletionRequestImpl._( 230 DartCompletionRequestImpl dartRequest = new DartCompletionRequestImpl._(
250 request.result, 231 request.result,
251 request.resourceProvider, 232 request.resourceProvider,
252 coreLib, 233 objectType,
253 libSource, 234 libSource,
254 request.source, 235 request.source,
255 request.offset, 236 request.offset,
256 unit, 237 unit,
257 request, 238 request,
258 performance); 239 performance);
259 240
260 performance.logElapseTime(BUILD_REQUEST_TAG); 241 performance.logElapseTime(BUILD_REQUEST_TAG);
261 return dartRequest; 242 return dartRequest;
262 } 243 }
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 if (start <= requestOffset && requestOffset <= end) { 290 if (start <= requestOffset && requestOffset <= end) {
310 // Replacement range for import URI 291 // Replacement range for import URI
311 return new ReplacementRange(start, end - start); 292 return new ReplacementRange(start, end - start);
312 } 293 }
313 } 294 }
314 } 295 }
315 } 296 }
316 return new ReplacementRange(requestOffset, 0); 297 return new ReplacementRange(requestOffset, 0);
317 } 298 }
318 } 299 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/provisional/completion/dart/completion_dart.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698