| OLD | NEW |
| 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 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 nd.PerformanceLog _analysisPerformanceLogger; | 325 nd.PerformanceLog _analysisPerformanceLogger; |
| 326 ByteStore byteStore; | 326 ByteStore byteStore; |
| 327 nd.AnalysisDriverScheduler analysisDriverScheduler; | 327 nd.AnalysisDriverScheduler analysisDriverScheduler; |
| 328 | 328 |
| 329 /** | 329 /** |
| 330 * The set of the files that are currently priority. | 330 * The set of the files that are currently priority. |
| 331 */ | 331 */ |
| 332 final Set<String> priorityFiles = new Set<String>(); | 332 final Set<String> priorityFiles = new Set<String>(); |
| 333 | 333 |
| 334 /** | 334 /** |
| 335 * The cached results for [priorityFiles]. | |
| 336 * These results must have not `null` units. | |
| 337 */ | |
| 338 final Map<String, nd.AnalysisResult> priorityFileResults = {}; | |
| 339 | |
| 340 /** | |
| 341 * Initialize a newly created server to receive requests from and send | 335 * Initialize a newly created server to receive requests from and send |
| 342 * responses to the given [channel]. | 336 * responses to the given [channel]. |
| 343 * | 337 * |
| 344 * If [rethrowExceptions] is true, then any exceptions thrown by analysis are | 338 * If [rethrowExceptions] is true, then any exceptions thrown by analysis are |
| 345 * 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 |
| 346 * 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 |
| 347 * running a full analysis server. | 341 * running a full analysis server. |
| 348 */ | 342 */ |
| 349 AnalysisServer( | 343 AnalysisServer( |
| 350 this.channel, | 344 this.channel, |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 623 } | 617 } |
| 624 return null; | 618 return null; |
| 625 } | 619 } |
| 626 | 620 |
| 627 /** | 621 /** |
| 628 * Return the analysis result for the file with the given [path]. The file is | 622 * Return the analysis result for the file with the given [path]. The file is |
| 629 * analyzed in one of the analysis drivers to which the file was added, | 623 * analyzed in one of the analysis drivers to which the file was added, |
| 630 * otherwise in the first driver, otherwise `null` is returned. | 624 * otherwise in the first driver, otherwise `null` is returned. |
| 631 */ | 625 */ |
| 632 Future<nd.AnalysisResult> getAnalysisResult(String path) async { | 626 Future<nd.AnalysisResult> getAnalysisResult(String path) async { |
| 633 nd.AnalysisResult result = priorityFileResults[path]; | |
| 634 if (result != null) { | |
| 635 return result; | |
| 636 } | |
| 637 try { | 627 try { |
| 638 nd.AnalysisDriver driver = getAnalysisDriver(path); | 628 nd.AnalysisDriver driver = getAnalysisDriver(path); |
| 639 return await driver?.getResult(path); | 629 return await driver?.getResult(path); |
| 640 } catch (e) { | 630 } catch (e) { |
| 641 // Ignore the exception. | 631 // Ignore the exception. |
| 642 // We don't want to log the same exception again and again. | 632 // We don't want to log the same exception again and again. |
| 643 return null; | 633 return null; |
| 644 } | 634 } |
| 645 } | 635 } |
| 646 | 636 |
| (...skipping 679 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1326 prevAnalyzedFiles = null; | 1316 prevAnalyzedFiles = null; |
| 1327 } | 1317 } |
| 1328 generalAnalysisServices = newServices; | 1318 generalAnalysisServices = newServices; |
| 1329 } | 1319 } |
| 1330 | 1320 |
| 1331 /** | 1321 /** |
| 1332 * Set the priority files to the given [files]. | 1322 * Set the priority files to the given [files]. |
| 1333 */ | 1323 */ |
| 1334 void setPriorityFiles(String requestId, List<String> files) { | 1324 void setPriorityFiles(String requestId, List<String> files) { |
| 1335 if (options.enableNewAnalysisDriver) { | 1325 if (options.enableNewAnalysisDriver) { |
| 1336 // Flush results for files that are not priority anymore. | |
| 1337 priorityFiles | |
| 1338 .difference(files.toSet()) | |
| 1339 .forEach(priorityFileResults.remove); | |
| 1340 priorityFiles.clear(); | 1326 priorityFiles.clear(); |
| 1341 priorityFiles.addAll(files); | 1327 priorityFiles.addAll(files); |
| 1342 // Set priority files in drivers. | 1328 // Set priority files in drivers. |
| 1343 driverMap.values.forEach((driver) { | 1329 driverMap.values.forEach((driver) { |
| 1344 driver.priorityFiles = files; | 1330 driver.priorityFiles = files; |
| 1345 }); | 1331 }); |
| 1346 return; | 1332 return; |
| 1347 } | 1333 } |
| 1348 // Note: when a file is a priority file, that information needs to be | 1334 // Note: when a file is a priority file, that information needs to be |
| 1349 // propagated to all contexts that analyze the file, so that all contexts | 1335 // propagated to all contexts that analyze the file, so that all contexts |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1459 operation.perform(this); | 1445 operation.perform(this); |
| 1460 } | 1446 } |
| 1461 } | 1447 } |
| 1462 | 1448 |
| 1463 /** | 1449 /** |
| 1464 * Implementation for `analysis.updateContent`. | 1450 * Implementation for `analysis.updateContent`. |
| 1465 */ | 1451 */ |
| 1466 void updateContent(String id, Map<String, dynamic> changes) { | 1452 void updateContent(String id, Map<String, dynamic> changes) { |
| 1467 if (options.enableNewAnalysisDriver) { | 1453 if (options.enableNewAnalysisDriver) { |
| 1468 changes.forEach((file, change) { | 1454 changes.forEach((file, change) { |
| 1469 priorityFileResults.remove(file); | |
| 1470 | |
| 1471 // Prepare the new contents. | 1455 // Prepare the new contents. |
| 1472 String oldContents = fileContentOverlay[file]; | 1456 String oldContents = fileContentOverlay[file]; |
| 1473 String newContents; | 1457 String newContents; |
| 1474 if (change is AddContentOverlay) { | 1458 if (change is AddContentOverlay) { |
| 1475 newContents = change.content; | 1459 newContents = change.content; |
| 1476 } else if (change is ChangeContentOverlay) { | 1460 } else if (change is ChangeContentOverlay) { |
| 1477 if (oldContents == null) { | 1461 if (oldContents == null) { |
| 1478 // The client may only send a ChangeContentOverlay if there is | 1462 // The client may only send a ChangeContentOverlay if there is |
| 1479 // already an existing overlay for the source. | 1463 // already an existing overlay for the source. |
| 1480 throw new RequestFailure(new Response(id, | 1464 throw new RequestFailure(new Response(id, |
| (...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1839 resourceProvider, | 1823 resourceProvider, |
| 1840 analysisServer.byteStore, | 1824 analysisServer.byteStore, |
| 1841 analysisServer.fileContentOverlay, | 1825 analysisServer.fileContentOverlay, |
| 1842 sourceFactory, | 1826 sourceFactory, |
| 1843 analysisOptions); | 1827 analysisOptions); |
| 1844 analysisDriver.name = folder.shortName; | 1828 analysisDriver.name = folder.shortName; |
| 1845 analysisDriver.status.listen((status) { | 1829 analysisDriver.status.listen((status) { |
| 1846 // TODO(scheglov) send server status | 1830 // TODO(scheglov) send server status |
| 1847 }); | 1831 }); |
| 1848 analysisDriver.results.listen((result) { | 1832 analysisDriver.results.listen((result) { |
| 1849 if (analysisServer.priorityFiles.contains(result.path) && | |
| 1850 result.unit != null) { | |
| 1851 analysisServer.priorityFileResults[result.path] = result; | |
| 1852 } | |
| 1853 new_sendErrorNotification(analysisServer, result); | 1833 new_sendErrorNotification(analysisServer, result); |
| 1854 String path = result.path; | 1834 String path = result.path; |
| 1855 CompilationUnit unit = result.unit; | 1835 CompilationUnit unit = result.unit; |
| 1856 if (unit != null) { | 1836 if (unit != null) { |
| 1857 if (analysisServer._hasAnalysisServiceSubscription( | 1837 if (analysisServer._hasAnalysisServiceSubscription( |
| 1858 AnalysisService.HIGHLIGHTS, path)) { | 1838 AnalysisService.HIGHLIGHTS, path)) { |
| 1859 _runDelayed(() { | 1839 _runDelayed(() { |
| 1860 sendAnalysisNotificationHighlights(analysisServer, path, unit); | 1840 sendAnalysisNotificationHighlights(analysisServer, path, unit); |
| 1861 }); | 1841 }); |
| 1862 } | 1842 } |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1992 // This method is mostly for tests. | 1972 // This method is mostly for tests. |
| 1993 // Context managers manage folders and contexts themselves. | 1973 // Context managers manage folders and contexts themselves. |
| 1994 } | 1974 } |
| 1995 | 1975 |
| 1996 @override | 1976 @override |
| 1997 void removeContext(Folder folder, List<String> flushedFiles) { | 1977 void removeContext(Folder folder, List<String> flushedFiles) { |
| 1998 if (analysisServer.options.enableNewAnalysisDriver) { | 1978 if (analysisServer.options.enableNewAnalysisDriver) { |
| 1999 sendAnalysisNotificationFlushResults(analysisServer, flushedFiles); | 1979 sendAnalysisNotificationFlushResults(analysisServer, flushedFiles); |
| 2000 nd.AnalysisDriver driver = analysisServer.driverMap.remove(folder); | 1980 nd.AnalysisDriver driver = analysisServer.driverMap.remove(folder); |
| 2001 driver.dispose(); | 1981 driver.dispose(); |
| 2002 // Remove cached priority results for the driver. | |
| 2003 var results = analysisServer.priorityFileResults; | |
| 2004 results.keys | |
| 2005 .where((key) => results[key].driver == driver) | |
| 2006 .forEach(results.remove); | |
| 2007 } else { | 1982 } else { |
| 2008 AnalysisContext context = analysisServer.folderMap.remove(folder); | 1983 AnalysisContext context = analysisServer.folderMap.remove(folder); |
| 2009 sendAnalysisNotificationFlushResults(analysisServer, flushedFiles); | 1984 sendAnalysisNotificationFlushResults(analysisServer, flushedFiles); |
| 2010 | 1985 |
| 2011 analysisServer.operationQueue.contextRemoved(context); | 1986 analysisServer.operationQueue.contextRemoved(context); |
| 2012 analysisServer._onContextsChangedController | 1987 analysisServer._onContextsChangedController |
| 2013 .add(new ContextsChangedEvent(removed: [context])); | 1988 .add(new ContextsChangedEvent(removed: [context])); |
| 2014 analysisServer.sendContextAnalysisDoneNotifications( | 1989 analysisServer.sendContextAnalysisDoneNotifications( |
| 2015 context, AnalysisDoneReason.CONTEXT_REMOVED); | 1990 context, AnalysisDoneReason.CONTEXT_REMOVED); |
| 2016 context.dispose(); | 1991 context.dispose(); |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2138 /** | 2113 /** |
| 2139 * The [PerformanceTag] for time spent in server request handlers. | 2114 * The [PerformanceTag] for time spent in server request handlers. |
| 2140 */ | 2115 */ |
| 2141 static PerformanceTag serverRequests = new PerformanceTag('serverRequests'); | 2116 static PerformanceTag serverRequests = new PerformanceTag('serverRequests'); |
| 2142 | 2117 |
| 2143 /** | 2118 /** |
| 2144 * The [PerformanceTag] for time spent in split store microtasks. | 2119 * The [PerformanceTag] for time spent in split store microtasks. |
| 2145 */ | 2120 */ |
| 2146 static PerformanceTag splitStore = new PerformanceTag('splitStore'); | 2121 static PerformanceTag splitStore = new PerformanceTag('splitStore'); |
| 2147 } | 2122 } |
| OLD | NEW |