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

Side by Side Diff: pkg/analysis_server/lib/src/analysis_server.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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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; 5 library analysis.server;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:collection'; 8 import 'dart:collection';
9 import 'dart:core'; 9 import 'dart:core';
10 import 'dart:io' as io; 10 import 'dart:io' as io;
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 ResolverProvider packageResolverProvider; 315 ResolverProvider packageResolverProvider;
316 316
317 /** 317 /**
318 * The manager of pub package summaries. 318 * The manager of pub package summaries.
319 */ 319 */
320 PubSummaryManager pubSummaryManager; 320 PubSummaryManager pubSummaryManager;
321 321
322 ByteStore byteStore; 322 ByteStore byteStore;
323 323
324 /** 324 /**
325 * The set of the files that are currently priority.
326 */
327 final Set<String> priorityFiles = new Set<String>();
328
329 /**
330 * The cached results units for [priorityFiles].
331 */
332 final Map<String, nd.AnalysisResult> priorityFileResults = {};
333
334 /**
325 * Initialize a newly created server to receive requests from and send 335 * Initialize a newly created server to receive requests from and send
326 * responses to the given [channel]. 336 * responses to the given [channel].
327 * 337 *
328 * If [rethrowExceptions] is true, then any exceptions thrown by analysis are 338 * If [rethrowExceptions] is true, then any exceptions thrown by analysis are
329 * propagated up the call stack. The default is true to allow analysis 339 * propagated up the call stack. The default is true to allow analysis
330 * exceptions to show up in unit tests, but it should be set to false when 340 * exceptions to show up in unit tests, but it should be set to false when
331 * running a full analysis server. 341 * running a full analysis server.
332 */ 342 */
333 AnalysisServer( 343 AnalysisServer(
334 this.channel, 344 this.channel,
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 */ 577 */
568 nd.AnalysisDriver getAnalysisDriver(String path) { 578 nd.AnalysisDriver getAnalysisDriver(String path) {
569 Iterable<nd.AnalysisDriver> drivers = driverMap.values; 579 Iterable<nd.AnalysisDriver> drivers = driverMap.values;
570 if (drivers.isNotEmpty) { 580 if (drivers.isNotEmpty) {
571 return drivers.firstWhere((driver) => driver.isAddedFile(path), 581 return drivers.firstWhere((driver) => driver.isAddedFile(path),
572 orElse: () => drivers.first); 582 orElse: () => drivers.first);
573 } 583 }
574 return null; 584 return null;
575 } 585 }
576 586
587 /**
588 * Return the analysis result for the file with the given [path].
589 */
590 Future<nd.AnalysisResult> getAnalysisResult(String path) async {
591 nd.AnalysisResult result = priorityFileResults[path];
592 if (result != null) {
593 return result;
594 }
595 nd.AnalysisDriver driver = getAnalysisDriver(path);
596 return driver.getResult(path);
597 }
598
577 CompilationUnitElement getCompilationUnitElement(String file) { 599 CompilationUnitElement getCompilationUnitElement(String file) {
578 ContextSourcePair pair = getContextSourcePair(file); 600 ContextSourcePair pair = getContextSourcePair(file);
579 if (pair == null) { 601 if (pair == null) {
580 return null; 602 return null;
581 } 603 }
582 // prepare AnalysisContext and Source 604 // prepare AnalysisContext and Source
583 AnalysisContext context = pair.context; 605 AnalysisContext context = pair.context;
584 Source unitSource = pair.source; 606 Source unitSource = pair.source;
585 if (context == null || unitSource == null) { 607 if (context == null || unitSource == null) {
586 return null; 608 return null;
(...skipping 637 matching lines...) Expand 10 before | Expand all | Expand 10 after
1224 prevAnalyzedFiles = null; 1246 prevAnalyzedFiles = null;
1225 } 1247 }
1226 generalAnalysisServices = newServices; 1248 generalAnalysisServices = newServices;
1227 } 1249 }
1228 1250
1229 /** 1251 /**
1230 * Set the priority files to the given [files]. 1252 * Set the priority files to the given [files].
1231 */ 1253 */
1232 void setPriorityFiles(String requestId, List<String> files) { 1254 void setPriorityFiles(String requestId, List<String> files) {
1233 if (options.enableNewAnalysisDriver) { 1255 if (options.enableNewAnalysisDriver) {
1256 // Flush results for files that are not priority anymore.
1257 priorityFiles
1258 .difference(files.toSet())
1259 .forEach(priorityFileResults.remove);
1260 priorityFiles.clear();
1261 priorityFiles.addAll(files);
1262 // Set priority files in drivers.
1234 driverMap.values.forEach((driver) { 1263 driverMap.values.forEach((driver) {
1235 driver.priorityFiles = files; 1264 driver.priorityFiles = files;
1236 }); 1265 });
1237 return; 1266 return;
1238 } 1267 }
1239 // Note: when a file is a priority file, that information needs to be 1268 // Note: when a file is a priority file, that information needs to be
1240 // propagated to all contexts that analyze the file, so that all contexts 1269 // propagated to all contexts that analyze the file, so that all contexts
1241 // will be able to do incremental resolution of the file. See 1270 // will be able to do incremental resolution of the file. See
1242 // dartbug.com/22209. 1271 // dartbug.com/22209.
1243 Map<AnalysisContext, List<Source>> sourceMap = 1272 Map<AnalysisContext, List<Source>> sourceMap =
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
1350 operation.perform(this); 1379 operation.perform(this);
1351 } 1380 }
1352 } 1381 }
1353 1382
1354 /** 1383 /**
1355 * Implementation for `analysis.updateContent`. 1384 * Implementation for `analysis.updateContent`.
1356 */ 1385 */
1357 void updateContent(String id, Map<String, dynamic> changes) { 1386 void updateContent(String id, Map<String, dynamic> changes) {
1358 if (options.enableNewAnalysisDriver) { 1387 if (options.enableNewAnalysisDriver) {
1359 changes.forEach((file, change) { 1388 changes.forEach((file, change) {
1389 priorityFileResults.remove(file);
1390
1360 // Prepare the new contents. 1391 // Prepare the new contents.
1361 String oldContents = fileContentOverlay[file]; 1392 String oldContents = fileContentOverlay[file];
1362 String newContents; 1393 String newContents;
1363 if (change is AddContentOverlay) { 1394 if (change is AddContentOverlay) {
1364 newContents = change.content; 1395 newContents = change.content;
1365 } else if (change is ChangeContentOverlay) { 1396 } else if (change is ChangeContentOverlay) {
1366 if (oldContents == null) { 1397 if (oldContents == null) {
1367 // The client may only send a ChangeContentOverlay if there is 1398 // The client may only send a ChangeContentOverlay if there is
1368 // already an existing overlay for the source. 1399 // already an existing overlay for the source.
1369 throw new RequestFailure(new Response(id, 1400 throw new RequestFailure(new Response(id,
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after
1721 resourceProvider, 1752 resourceProvider,
1722 analysisServer.byteStore, 1753 analysisServer.byteStore,
1723 analysisServer.fileContentOverlay, 1754 analysisServer.fileContentOverlay,
1724 sourceFactory, 1755 sourceFactory,
1725 analysisOptions); 1756 analysisOptions);
1726 analysisDriver.name = folder.shortName; 1757 analysisDriver.name = folder.shortName;
1727 analysisDriver.status.listen((status) { 1758 analysisDriver.status.listen((status) {
1728 // TODO(scheglov) send server status 1759 // TODO(scheglov) send server status
1729 }); 1760 });
1730 analysisDriver.results.listen((result) { 1761 analysisDriver.results.listen((result) {
1762 if (analysisServer.priorityFiles.contains(result.path)) {
1763 analysisServer.priorityFileResults[result.path] = result;
1764 }
1731 new_sendErrorNotification(analysisServer, result); 1765 new_sendErrorNotification(analysisServer, result);
1732 CompilationUnit unit = result.unit; 1766 CompilationUnit unit = result.unit;
1733 if (unit != null) { 1767 if (unit != null) {
1734 if (analysisServer._hasAnalysisServiceSubscription( 1768 if (analysisServer._hasAnalysisServiceSubscription(
1735 AnalysisService.HIGHLIGHTS, result.path)) { 1769 AnalysisService.HIGHLIGHTS, result.path)) {
1736 sendAnalysisNotificationHighlights(analysisServer, result.path, unit); 1770 sendAnalysisNotificationHighlights(analysisServer, result.path, unit);
1737 } 1771 }
1738 if (analysisServer._hasAnalysisServiceSubscription( 1772 if (analysisServer._hasAnalysisServiceSubscription(
1739 AnalysisService.NAVIGATION, result.path)) { 1773 AnalysisService.NAVIGATION, result.path)) {
1740 NavigationCollectorImpl collector = new NavigationCollectorImpl(); 1774 NavigationCollectorImpl collector = new NavigationCollectorImpl();
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
1956 /** 1990 /**
1957 * The [PerformanceTag] for time spent in server request handlers. 1991 * The [PerformanceTag] for time spent in server request handlers.
1958 */ 1992 */
1959 static PerformanceTag serverRequests = new PerformanceTag('serverRequests'); 1993 static PerformanceTag serverRequests = new PerformanceTag('serverRequests');
1960 1994
1961 /** 1995 /**
1962 * The [PerformanceTag] for time spent in split store microtasks. 1996 * The [PerformanceTag] for time spent in split store microtasks.
1963 */ 1997 */
1964 static PerformanceTag splitStore = new PerformanceTag('splitStore'); 1998 static PerformanceTag splitStore = new PerformanceTag('splitStore');
1965 } 1999 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analysis_server/lib/src/edit/edit_domain.dart » ('j') | pkg/analysis_server/lib/src/edit/edit_domain.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698