| 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 domain.execution; | 5 library domain.execution; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:collection'; | 8 import 'dart:collection'; |
| 9 | 9 |
| 10 import 'package:analysis_server/src/analysis_server.dart'; | 10 import 'package:analysis_server/src/analysis_server.dart'; |
| 11 import 'package:analysis_server/src/constants.dart'; | 11 import 'package:analysis_server/src/constants.dart'; |
| 12 import 'package:analysis_server/src/protocol.dart'; | 12 import 'package:analysis_server/src/protocol.dart'; |
| 13 import 'package:analyzer/file_system/file_system.dart'; | 13 import 'package:analyzer/file_system/file_system.dart'; |
| 14 import 'package:analyzer/src/generated/engine.dart'; | 14 import 'package:analyzer/src/generated/engine.dart'; |
| 15 import 'package:analyzer/src/generated/source.dart'; | 15 import 'package:analyzer/src/generated/source.dart'; |
| 16 import 'package:analyzer/src/generated/utilities_general.dart'; |
| 16 | 17 |
| 17 /** | 18 /** |
| 18 * Instances of the class [ExecutionDomainHandler] implement a [RequestHandler] | 19 * Instances of the class [ExecutionDomainHandler] implement a [RequestHandler] |
| 19 * that handles requests in the `execution` domain. | 20 * that handles requests in the `execution` domain. |
| 20 */ | 21 */ |
| 21 class ExecutionDomainHandler implements RequestHandler { | 22 class ExecutionDomainHandler implements RequestHandler { |
| 22 /** | 23 /** |
| 23 * The analysis server that is using this handler to process requests. | 24 * The analysis server that is using this handler to process requests. |
| 24 */ | 25 */ |
| 25 final AnalysisServer server; | 26 final AnalysisServer server; |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 } else { | 152 } else { |
| 152 if (onFileAnalyzed != null) { | 153 if (onFileAnalyzed != null) { |
| 153 onFileAnalyzed.cancel(); | 154 onFileAnalyzed.cancel(); |
| 154 onFileAnalyzed = null; | 155 onFileAnalyzed = null; |
| 155 } | 156 } |
| 156 } | 157 } |
| 157 return new ExecutionSetSubscriptionsResult().toResponse(request.id); | 158 return new ExecutionSetSubscriptionsResult().toResponse(request.id); |
| 158 } | 159 } |
| 159 | 160 |
| 160 void _fileAnalyzed(ChangeNotice notice) { | 161 void _fileAnalyzed(ChangeNotice notice) { |
| 161 Source source = notice.source; | 162 PerformanceTag prevTag = |
| 162 String filePath = source.fullName; | 163 ServerPerformanceStatistics.executionDomain.makeCurrent(); |
| 163 if (!_isInAnalysisRoot(filePath)) { | 164 try { |
| 164 return; | 165 Source source = notice.source; |
| 165 } | 166 String filePath = source.fullName; |
| 166 AnalysisContext context = server.getAnalysisContext(filePath); | 167 if (!_isInAnalysisRoot(filePath)) { |
| 167 if (AnalysisEngine.isDartFileName(filePath)) { | 168 return; |
| 168 ExecutableKind kind = ExecutableKind.NOT_EXECUTABLE; | 169 } |
| 169 if (context.isClientLibrary(source)) { | 170 AnalysisContext context = server.getAnalysisContext(filePath); |
| 170 kind = ExecutableKind.CLIENT; | 171 if (AnalysisEngine.isDartFileName(filePath)) { |
| 171 if (context.isServerLibrary(source)) { | 172 ExecutableKind kind = ExecutableKind.NOT_EXECUTABLE; |
| 172 kind = ExecutableKind.EITHER; | 173 if (context.isClientLibrary(source)) { |
| 174 kind = ExecutableKind.CLIENT; |
| 175 if (context.isServerLibrary(source)) { |
| 176 kind = ExecutableKind.EITHER; |
| 177 } |
| 178 } else if (context.isServerLibrary(source)) { |
| 179 kind = ExecutableKind.SERVER; |
| 173 } | 180 } |
| 174 } else if (context.isServerLibrary(source)) { | 181 server.sendNotification( |
| 175 kind = ExecutableKind.SERVER; | 182 new ExecutionLaunchDataParams(filePath, kind: kind).toNotification()
); |
| 183 } else if (AnalysisEngine.isHtmlFileName(filePath)) { |
| 184 List<Source> libraries = context.getLibrariesReferencedFromHtml(source); |
| 185 server.sendNotification( |
| 186 new ExecutionLaunchDataParams( |
| 187 filePath, |
| 188 referencedFiles: _getFullNames(libraries)).toNotification()); |
| 176 } | 189 } |
| 177 server.sendNotification( | 190 } finally { |
| 178 new ExecutionLaunchDataParams(filePath, kind: kind).toNotification()); | 191 prevTag.makeCurrent(); |
| 179 } else if (AnalysisEngine.isHtmlFileName(filePath)) { | |
| 180 List<Source> libraries = context.getLibrariesReferencedFromHtml(source); | |
| 181 server.sendNotification( | |
| 182 new ExecutionLaunchDataParams( | |
| 183 filePath, | |
| 184 referencedFiles: _getFullNames(libraries)).toNotification()); | |
| 185 } | 192 } |
| 186 } | 193 } |
| 187 | 194 |
| 188 /** | 195 /** |
| 189 * Return `true` if the given [filePath] represents a file that is in an | 196 * Return `true` if the given [filePath] represents a file that is in an |
| 190 * analysis root. | 197 * analysis root. |
| 191 */ | 198 */ |
| 192 bool _isInAnalysisRoot(String filePath) => | 199 bool _isInAnalysisRoot(String filePath) => |
| 193 server.contextDirectoryManager.isInAnalysisRoot(filePath); | 200 server.contextDirectoryManager.isInAnalysisRoot(filePath); |
| 194 | 201 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 if (_isInAnalysisRoot(filePath)) { | 241 if (_isInAnalysisRoot(filePath)) { |
| 235 server.sendNotification( | 242 server.sendNotification( |
| 236 new ExecutionLaunchDataParams(filePath, kind: kind).toNotification()); | 243 new ExecutionLaunchDataParams(filePath, kind: kind).toNotification()); |
| 237 } | 244 } |
| 238 } | 245 } |
| 239 | 246 |
| 240 static List<String> _getFullNames(List<Source> sources) { | 247 static List<String> _getFullNames(List<Source> sources) { |
| 241 return sources.map((Source source) => source.fullName).toList(); | 248 return sources.map((Source source) => source.fullName).toList(); |
| 242 } | 249 } |
| 243 } | 250 } |
| OLD | NEW |