| 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:math' show max; | 9 import 'dart:math' show max; |
| 10 | 10 |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 */ | 223 */ |
| 224 // Add 1 sec to prevent delay from impacting short running tests | 224 // Add 1 sec to prevent delay from impacting short running tests |
| 225 int _nextPerformOperationDelayTime = | 225 int _nextPerformOperationDelayTime = |
| 226 new DateTime.now().millisecondsSinceEpoch + | 226 new DateTime.now().millisecondsSinceEpoch + |
| 227 1000; | 227 1000; |
| 228 | 228 |
| 229 /** | 229 /** |
| 230 * The current state of overlays from the client. This is used as the | 230 * The current state of overlays from the client. This is used as the |
| 231 * content cache for all contexts. | 231 * content cache for all contexts. |
| 232 */ | 232 */ |
| 233 ContentCache _overlayState = new ContentCache(); | 233 final ContentCache overlayState = new ContentCache(); |
| 234 | 234 |
| 235 /** | 235 /** |
| 236 * Initialize a newly created server to receive requests from and send | 236 * Initialize a newly created server to receive requests from and send |
| 237 * responses to the given [channel]. | 237 * responses to the given [channel]. |
| 238 * | 238 * |
| 239 * If [rethrowExceptions] is true, then any exceptions thrown by analysis are | 239 * If [rethrowExceptions] is true, then any exceptions thrown by analysis are |
| 240 * propagated up the call stack. The default is true to allow analysis | 240 * propagated up the call stack. The default is true to allow analysis |
| 241 * exceptions to show up in unit tests, but it should be set to false when | 241 * exceptions to show up in unit tests, but it should be set to false when |
| 242 * running a full analysis server. | 242 * running a full analysis server. |
| 243 */ | 243 */ |
| (...skipping 728 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 972 } | 972 } |
| 973 | 973 |
| 974 /** | 974 /** |
| 975 * Implementation for `analysis.updateContent`. | 975 * Implementation for `analysis.updateContent`. |
| 976 */ | 976 */ |
| 977 void updateContent(String id, Map<String, dynamic> changes) { | 977 void updateContent(String id, Map<String, dynamic> changes) { |
| 978 changes.forEach((file, change) { | 978 changes.forEach((file, change) { |
| 979 Source source = getSource(file); | 979 Source source = getSource(file); |
| 980 operationQueue.sourceAboutToChange(source); | 980 operationQueue.sourceAboutToChange(source); |
| 981 // Prepare the new contents. | 981 // Prepare the new contents. |
| 982 String oldContents = _overlayState.getContents(source); | 982 String oldContents = overlayState.getContents(source); |
| 983 String newContents; | 983 String newContents; |
| 984 if (change is AddContentOverlay) { | 984 if (change is AddContentOverlay) { |
| 985 newContents = change.content; | 985 newContents = change.content; |
| 986 } else if (change is ChangeContentOverlay) { | 986 } else if (change is ChangeContentOverlay) { |
| 987 if (oldContents == null) { | 987 if (oldContents == null) { |
| 988 // The client may only send a ChangeContentOverlay if there is | 988 // The client may only send a ChangeContentOverlay if there is |
| 989 // already an existing overlay for the source. | 989 // already an existing overlay for the source. |
| 990 throw new RequestFailure( | 990 throw new RequestFailure( |
| 991 new Response( | 991 new Response( |
| 992 id, | 992 id, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1003 error: new RequestError( | 1003 error: new RequestError( |
| 1004 RequestErrorCode.INVALID_OVERLAY_CHANGE, | 1004 RequestErrorCode.INVALID_OVERLAY_CHANGE, |
| 1005 'Invalid overlay change'))); | 1005 'Invalid overlay change'))); |
| 1006 } | 1006 } |
| 1007 } else if (change is RemoveContentOverlay) { | 1007 } else if (change is RemoveContentOverlay) { |
| 1008 newContents = null; | 1008 newContents = null; |
| 1009 } else { | 1009 } else { |
| 1010 // Protocol parsing should have ensured that we never get here. | 1010 // Protocol parsing should have ensured that we never get here. |
| 1011 throw new AnalysisException('Illegal change type'); | 1011 throw new AnalysisException('Illegal change type'); |
| 1012 } | 1012 } |
| 1013 _overlayState.setContents(source, newContents); | 1013 overlayState.setContents(source, newContents); |
| 1014 // Update all contexts. | 1014 // Update all contexts. |
| 1015 for (InternalAnalysisContext context in folderMap.values) { | 1015 for (InternalAnalysisContext context in folderMap.values) { |
| 1016 if (context.handleContentsChanged( | 1016 if (context.handleContentsChanged( |
| 1017 source, | 1017 source, |
| 1018 oldContents, | 1018 oldContents, |
| 1019 newContents, | 1019 newContents, |
| 1020 true)) { | 1020 true)) { |
| 1021 schedulePerformAnalysisOperation(context); | 1021 schedulePerformAnalysisOperation(context); |
| 1022 } else { | 1022 } else { |
| 1023 // When the client sends any change for a source, we should resend | 1023 // When the client sends any change for a source, we should resend |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1187 /** | 1187 /** |
| 1188 * The stream that is notified when contexts are added or removed. | 1188 * The stream that is notified when contexts are added or removed. |
| 1189 */ | 1189 */ |
| 1190 Stream<ContextsChangedEvent> get onContextsChanged => | 1190 Stream<ContextsChangedEvent> get onContextsChanged => |
| 1191 _onContextsChangedController.stream; | 1191 _onContextsChangedController.stream; |
| 1192 | 1192 |
| 1193 @override | 1193 @override |
| 1194 AnalysisContext addContext(Folder folder, UriResolver packageUriResolver) { | 1194 AnalysisContext addContext(Folder folder, UriResolver packageUriResolver) { |
| 1195 InternalAnalysisContext context = | 1195 InternalAnalysisContext context = |
| 1196 AnalysisEngine.instance.createAnalysisContext(); | 1196 AnalysisEngine.instance.createAnalysisContext(); |
| 1197 context.contentCache = analysisServer._overlayState; | 1197 context.contentCache = analysisServer.overlayState; |
| 1198 analysisServer.folderMap[folder] = context; | 1198 analysisServer.folderMap[folder] = context; |
| 1199 context.sourceFactory = _createSourceFactory(packageUriResolver); | 1199 context.sourceFactory = _createSourceFactory(packageUriResolver); |
| 1200 context.analysisOptions = new AnalysisOptionsImpl.con1(defaultOptions); | 1200 context.analysisOptions = new AnalysisOptionsImpl.con1(defaultOptions); |
| 1201 _onContextsChangedController.add( | 1201 _onContextsChangedController.add( |
| 1202 new ContextsChangedEvent(added: [context])); | 1202 new ContextsChangedEvent(added: [context])); |
| 1203 analysisServer.schedulePerformAnalysisOperation(context); | 1203 analysisServer.schedulePerformAnalysisOperation(context); |
| 1204 return context; | 1204 return context; |
| 1205 } | 1205 } |
| 1206 | 1206 |
| 1207 @override | 1207 @override |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1353 * AnalysisServer.performOperation when the server is idle. | 1353 * AnalysisServer.performOperation when the server is idle. |
| 1354 */ | 1354 */ |
| 1355 static PerformanceTag idle = new PerformanceTag('idle'); | 1355 static PerformanceTag idle = new PerformanceTag('idle'); |
| 1356 | 1356 |
| 1357 /** | 1357 /** |
| 1358 * The [PerformanceTag] for time spent in | 1358 * The [PerformanceTag] for time spent in |
| 1359 * PerformAnalysisOperation._sendNotices. | 1359 * PerformAnalysisOperation._sendNotices. |
| 1360 */ | 1360 */ |
| 1361 static PerformanceTag notices = new PerformanceTag('notices'); | 1361 static PerformanceTag notices = new PerformanceTag('notices'); |
| 1362 } | 1362 } |
| OLD | NEW |