| 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 20 matching lines...) Expand all Loading... |
| 31 import 'package:analyzer/dart/element/element.dart'; | 31 import 'package:analyzer/dart/element/element.dart'; |
| 32 import 'package:analyzer/exception/exception.dart'; | 32 import 'package:analyzer/exception/exception.dart'; |
| 33 import 'package:analyzer/file_system/file_system.dart'; | 33 import 'package:analyzer/file_system/file_system.dart'; |
| 34 import 'package:analyzer/instrumentation/instrumentation.dart'; | 34 import 'package:analyzer/instrumentation/instrumentation.dart'; |
| 35 import 'package:analyzer/plugin/resolver_provider.dart'; | 35 import 'package:analyzer/plugin/resolver_provider.dart'; |
| 36 import 'package:analyzer/source/pub_package_map_provider.dart'; | 36 import 'package:analyzer/source/pub_package_map_provider.dart'; |
| 37 import 'package:analyzer/src/context/builder.dart'; | 37 import 'package:analyzer/src/context/builder.dart'; |
| 38 import 'package:analyzer/src/dart/analysis/byte_store.dart'; | 38 import 'package:analyzer/src/dart/analysis/byte_store.dart'; |
| 39 import 'package:analyzer/src/dart/analysis/driver.dart' as nd; | 39 import 'package:analyzer/src/dart/analysis/driver.dart' as nd; |
| 40 import 'package:analyzer/src/dart/analysis/file_byte_store.dart'; | 40 import 'package:analyzer/src/dart/analysis/file_byte_store.dart'; |
| 41 import 'package:analyzer/src/dart/analysis/file_state.dart' as nd; |
| 41 import 'package:analyzer/src/dart/ast/utilities.dart'; | 42 import 'package:analyzer/src/dart/ast/utilities.dart'; |
| 42 import 'package:analyzer/src/generated/engine.dart'; | 43 import 'package:analyzer/src/generated/engine.dart'; |
| 43 import 'package:analyzer/src/generated/sdk.dart'; | 44 import 'package:analyzer/src/generated/sdk.dart'; |
| 44 import 'package:analyzer/src/generated/source.dart'; | 45 import 'package:analyzer/src/generated/source.dart'; |
| 45 import 'package:analyzer/src/generated/source_io.dart'; | 46 import 'package:analyzer/src/generated/source_io.dart'; |
| 46 import 'package:analyzer/src/generated/utilities_general.dart'; | 47 import 'package:analyzer/src/generated/utilities_general.dart'; |
| 47 import 'package:analyzer/src/summary/pub_summary.dart'; | 48 import 'package:analyzer/src/summary/pub_summary.dart'; |
| 48 import 'package:analyzer/src/task/dart.dart'; | 49 import 'package:analyzer/src/task/dart.dart'; |
| 49 import 'package:analyzer/src/util/glob.dart'; | 50 import 'package:analyzer/src/util/glob.dart'; |
| 50 import 'package:analyzer/task/dart.dart'; | 51 import 'package:analyzer/task/dart.dart'; |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 | 259 |
| 259 /** | 260 /** |
| 260 * The next time (milliseconds since epoch) after which the analysis server | 261 * The next time (milliseconds since epoch) after which the analysis server |
| 261 * should pause so that pending requests can be fetched by the system. | 262 * should pause so that pending requests can be fetched by the system. |
| 262 */ | 263 */ |
| 263 // Add 1 sec to prevent delay from impacting short running tests | 264 // Add 1 sec to prevent delay from impacting short running tests |
| 264 int _nextPerformOperationDelayTime = | 265 int _nextPerformOperationDelayTime = |
| 265 new DateTime.now().millisecondsSinceEpoch + 1000; | 266 new DateTime.now().millisecondsSinceEpoch + 1000; |
| 266 | 267 |
| 267 /** | 268 /** |
| 269 * The content overlay for all analysis drivers. |
| 270 */ |
| 271 final nd.FileContentOverlay fileContentOverlay = new nd.FileContentOverlay(); |
| 272 |
| 273 /** |
| 268 * The current state of overlays from the client. This is used as the | 274 * The current state of overlays from the client. This is used as the |
| 269 * content cache for all contexts. | 275 * content cache for all contexts. |
| 270 */ | 276 */ |
| 271 final ContentCache overlayState = new ContentCache(); | 277 final ContentCache overlayState = new ContentCache(); |
| 272 | 278 |
| 273 /** | 279 /** |
| 274 * The plugins that are defined outside the analysis_server package. | 280 * The plugins that are defined outside the analysis_server package. |
| 275 */ | 281 */ |
| 276 List<Plugin> userDefinedPlugins; | 282 List<Plugin> userDefinedPlugins; |
| 277 | 283 |
| (...skipping 1053 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1331 operation.perform(this); | 1337 operation.perform(this); |
| 1332 } | 1338 } |
| 1333 } | 1339 } |
| 1334 | 1340 |
| 1335 /** | 1341 /** |
| 1336 * Implementation for `analysis.updateContent`. | 1342 * Implementation for `analysis.updateContent`. |
| 1337 */ | 1343 */ |
| 1338 void updateContent(String id, Map<String, dynamic> changes) { | 1344 void updateContent(String id, Map<String, dynamic> changes) { |
| 1339 if (options.enableNewAnalysisDriver) { | 1345 if (options.enableNewAnalysisDriver) { |
| 1340 changes.forEach((file, change) { | 1346 changes.forEach((file, change) { |
| 1341 Source source = resourceProvider.getFile(file).createSource(); | |
| 1342 // Prepare the new contents. | 1347 // Prepare the new contents. |
| 1343 String oldContents = overlayState.getContents(source); | 1348 String oldContents = fileContentOverlay[file]; |
| 1344 String newContents; | 1349 String newContents; |
| 1345 if (change is AddContentOverlay) { | 1350 if (change is AddContentOverlay) { |
| 1346 newContents = change.content; | 1351 newContents = change.content; |
| 1347 } else if (change is ChangeContentOverlay) { | 1352 } else if (change is ChangeContentOverlay) { |
| 1348 if (oldContents == null) { | 1353 if (oldContents == null) { |
| 1349 // The client may only send a ChangeContentOverlay if there is | 1354 // The client may only send a ChangeContentOverlay if there is |
| 1350 // already an existing overlay for the source. | 1355 // already an existing overlay for the source. |
| 1351 throw new RequestFailure(new Response(id, | 1356 throw new RequestFailure(new Response(id, |
| 1352 error: new RequestError(RequestErrorCode.INVALID_OVERLAY_CHANGE, | 1357 error: new RequestError(RequestErrorCode.INVALID_OVERLAY_CHANGE, |
| 1353 'Invalid overlay change'))); | 1358 'Invalid overlay change'))); |
| 1354 } | 1359 } |
| 1355 try { | 1360 try { |
| 1356 newContents = SourceEdit.applySequence(oldContents, change.edits); | 1361 newContents = SourceEdit.applySequence(oldContents, change.edits); |
| 1357 } on RangeError { | 1362 } on RangeError { |
| 1358 throw new RequestFailure(new Response(id, | 1363 throw new RequestFailure(new Response(id, |
| 1359 error: new RequestError(RequestErrorCode.INVALID_OVERLAY_CHANGE, | 1364 error: new RequestError(RequestErrorCode.INVALID_OVERLAY_CHANGE, |
| 1360 'Invalid overlay change'))); | 1365 'Invalid overlay change'))); |
| 1361 } | 1366 } |
| 1362 } else if (change is RemoveContentOverlay) { | 1367 } else if (change is RemoveContentOverlay) { |
| 1363 newContents = null; | 1368 newContents = null; |
| 1364 } else { | 1369 } else { |
| 1365 // Protocol parsing should have ensured that we never get here. | 1370 // Protocol parsing should have ensured that we never get here. |
| 1366 throw new AnalysisException('Illegal change type'); | 1371 throw new AnalysisException('Illegal change type'); |
| 1367 } | 1372 } |
| 1368 | 1373 |
| 1369 overlayState.setContents(source, newContents); | 1374 fileContentOverlay[file] = newContents; |
| 1370 | 1375 |
| 1371 driverMap.values.forEach((driver) { | 1376 driverMap.values.forEach((driver) { |
| 1372 driver.changeFile(file); | 1377 driver.changeFile(file); |
| 1373 }); | 1378 }); |
| 1374 // TODO(scheglov) implement other cases | 1379 // TODO(scheglov) implement other cases |
| 1375 }); | 1380 }); |
| 1376 return; | 1381 return; |
| 1377 } | 1382 } |
| 1378 changes.forEach((file, change) { | 1383 changes.forEach((file, change) { |
| 1379 ContextSourcePair contextSource = getContextSourcePair(file); | 1384 ContextSourcePair contextSource = getContextSourcePair(file); |
| (...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1695 ContextBuilder builder = createContextBuilder(folder, options); | 1700 ContextBuilder builder = createContextBuilder(folder, options); |
| 1696 AnalysisContext context = builder.buildContext(folder.path); | 1701 AnalysisContext context = builder.buildContext(folder.path); |
| 1697 sourceFactory = context.sourceFactory; | 1702 sourceFactory = context.sourceFactory; |
| 1698 analysisOptions = context.analysisOptions; | 1703 analysisOptions = context.analysisOptions; |
| 1699 context.dispose(); | 1704 context.dispose(); |
| 1700 } | 1705 } |
| 1701 nd.AnalysisDriver analysisDriver = new nd.AnalysisDriver( | 1706 nd.AnalysisDriver analysisDriver = new nd.AnalysisDriver( |
| 1702 new nd.PerformanceLog(io.stdout), | 1707 new nd.PerformanceLog(io.stdout), |
| 1703 resourceProvider, | 1708 resourceProvider, |
| 1704 analysisServer.byteStore, | 1709 analysisServer.byteStore, |
| 1705 analysisServer.overlayState, | 1710 analysisServer.fileContentOverlay, |
| 1706 sourceFactory, | 1711 sourceFactory, |
| 1707 analysisOptions); | 1712 analysisOptions); |
| 1708 analysisDriver.name = folder.shortName; | 1713 analysisDriver.name = folder.shortName; |
| 1709 analysisDriver.status.listen((status) { | 1714 analysisDriver.status.listen((status) { |
| 1710 // TODO(scheglov) send server status | 1715 // TODO(scheglov) send server status |
| 1711 }); | 1716 }); |
| 1712 analysisDriver.results.listen((result) { | 1717 analysisDriver.results.listen((result) { |
| 1713 new_sendErrorNotification(analysisServer, result); | 1718 new_sendErrorNotification(analysisServer, result); |
| 1714 CompilationUnit unit = result.unit; | 1719 CompilationUnit unit = result.unit; |
| 1715 if (unit != null) { | 1720 if (unit != null) { |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1938 /** | 1943 /** |
| 1939 * The [PerformanceTag] for time spent in server request handlers. | 1944 * The [PerformanceTag] for time spent in server request handlers. |
| 1940 */ | 1945 */ |
| 1941 static PerformanceTag serverRequests = new PerformanceTag('serverRequests'); | 1946 static PerformanceTag serverRequests = new PerformanceTag('serverRequests'); |
| 1942 | 1947 |
| 1943 /** | 1948 /** |
| 1944 * The [PerformanceTag] for time spent in split store microtasks. | 1949 * The [PerformanceTag] for time spent in split store microtasks. |
| 1945 */ | 1950 */ |
| 1946 static PerformanceTag splitStore = new PerformanceTag('splitStore'); | 1951 static PerformanceTag splitStore = new PerformanceTag('splitStore'); |
| 1947 } | 1952 } |
| OLD | NEW |