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 test.analysis_server; | 5 library test.analysis_server; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 | 8 |
9 import 'package:analysis_server/plugin/protocol/protocol.dart'; | 9 import 'package:analysis_server/plugin/protocol/protocol.dart'; |
10 import 'package:analysis_server/src/analysis_server.dart'; | 10 import 'package:analysis_server/src/analysis_server.dart'; |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 ExtensionManager manager = new ExtensionManager(); | 130 ExtensionManager manager = new ExtensionManager(); |
131 manager.processPlugins(plugins); | 131 manager.processPlugins(plugins); |
132 } | 132 } |
133 | 133 |
134 void setUp() { | 134 void setUp() { |
135 ExtensionManager manager = new ExtensionManager(); | 135 ExtensionManager manager = new ExtensionManager(); |
136 ServerPlugin plugin = new ServerPlugin(); | 136 ServerPlugin plugin = new ServerPlugin(); |
137 manager.processPlugins([plugin]); | 137 manager.processPlugins([plugin]); |
138 channel = new MockServerChannel(); | 138 channel = new MockServerChannel(); |
139 resourceProvider = new MemoryResourceProvider(); | 139 resourceProvider = new MemoryResourceProvider(); |
| 140 MockSdk sdk = new MockSdk(resourceProvider: resourceProvider); |
140 packageMapProvider = new MockPackageMapProvider(); | 141 packageMapProvider = new MockPackageMapProvider(); |
141 server = new AnalysisServer( | 142 server = new AnalysisServer( |
142 channel, | 143 channel, |
143 resourceProvider, | 144 resourceProvider, |
144 packageMapProvider, | 145 packageMapProvider, |
145 null, | 146 null, |
146 plugin, | 147 plugin, |
147 new AnalysisServerOptions(), | 148 new AnalysisServerOptions(), |
148 new DartSdkManager('', false, (_) => new MockSdk()), | 149 new DartSdkManager('/', false, (_) => sdk), |
149 InstrumentationService.NULL_SERVICE, | 150 InstrumentationService.NULL_SERVICE, |
150 rethrowExceptions: true); | 151 rethrowExceptions: true); |
151 processRequiredPlugins(); | 152 processRequiredPlugins(); |
152 } | 153 } |
153 | 154 |
154 Future test_contextDisposed() { | 155 Future test_contextDisposed() { |
155 resourceProvider.newFolder('/foo'); | 156 resourceProvider.newFolder('/foo'); |
156 resourceProvider.newFile('/foo/bar.dart', 'library lib;'); | 157 resourceProvider.newFile('/foo/bar.dart', 'library lib;'); |
157 server.setAnalysisRoots('0', ['/foo'], [], {}); | 158 server.setAnalysisRoots('0', ['/foo'], [], {}); |
158 AnalysisContext context; | 159 AnalysisContext context; |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 AnalysisContext context = AnalysisEngine.instance.createAnalysisContext(); | 280 AnalysisContext context = AnalysisEngine.instance.createAnalysisContext(); |
280 _configureSourceFactory(context); | 281 _configureSourceFactory(context); |
281 server.folderMap[dir] = context; | 282 server.folderMap[dir] = context; |
282 | 283 |
283 ContextSourcePair pair = server.getContextSourcePair(dirPath); | 284 ContextSourcePair pair = server.getContextSourcePair(dirPath); |
284 expect(pair, isNotNull); | 285 expect(pair, isNotNull); |
285 expect(pair.context, isNull); | 286 expect(pair.context, isNull); |
286 expect(pair.source, isNull); | 287 expect(pair.source, isNull); |
287 } | 288 } |
288 | 289 |
289 test_getContextSourcePair_package_inRoot() { | |
290 String rootPath = '/my_package'; | |
291 String filePath = rootPath + '/lib/file.dart'; | |
292 Folder rootFolder = resourceProvider.newFolder(rootPath); | |
293 resourceProvider.newFile(filePath, 'library lib;'); | |
294 | |
295 packageMapProvider.packageMap = <String, List<Folder>>{ | |
296 'my_package': <Folder>[rootFolder] | |
297 }; | |
298 // create contexts | |
299 server.setAnalysisRoots('0', [rootPath], [], {}); | |
300 // get pair | |
301 ContextSourcePair pair = server.getContextSourcePair(filePath); | |
302 _assertContextOfFolder(pair.context, rootPath); | |
303 Source source = pair.source; | |
304 expect(source, isNotNull); | |
305 expect(source.uri.scheme, 'package'); | |
306 expect(source.fullName, filePath); | |
307 } | |
308 | |
309 test_getContextSourcePair_simple() { | 290 test_getContextSourcePair_simple() { |
310 String dirPath = '/dir'; | 291 String dirPath = '/dir'; |
311 String filePath = dirPath + '/file.dart'; | 292 String filePath = dirPath + '/file.dart'; |
312 resourceProvider.newFile(filePath, 'library lib;'); | 293 resourceProvider.newFile(filePath, 'library lib;'); |
313 // create contexts | 294 // create contexts |
314 server.setAnalysisRoots('0', [dirPath], [], {}); | 295 server.setAnalysisRoots('0', [dirPath], [], {}); |
| 296 // get pair |
| 297 ContextSourcePair pair = server.getContextSourcePair(filePath); |
| 298 _assertContextOfFolder(pair.context, dirPath); |
| 299 Source source = pair.source; |
| 300 expect(source, isNotNull); |
| 301 expect(source.uri.scheme, 'file'); |
| 302 expect(source.fullName, filePath); |
| 303 } |
| 304 |
| 305 test_getContextSourcePair_withPackagesFile() { |
| 306 String dirPath = '/dir'; |
| 307 String packagesFilePath = dirPath + '/.packages'; |
| 308 resourceProvider.newFile(packagesFilePath, 'dir:lib/'); |
| 309 String filePath = dirPath + '/lib/file.dart'; |
| 310 resourceProvider.newFile(filePath, 'library lib;'); |
| 311 // create contexts |
| 312 server.setAnalysisRoots('0', [dirPath], [], {}); |
315 // get pair | 313 // get pair |
316 ContextSourcePair pair = server.getContextSourcePair(filePath); | 314 ContextSourcePair pair = server.getContextSourcePair(filePath); |
317 _assertContextOfFolder(pair.context, dirPath); | 315 _assertContextOfFolder(pair.context, dirPath); |
318 Source source = pair.source; | 316 Source source = pair.source; |
319 expect(source, isNotNull); | 317 expect(source, isNotNull); |
320 expect(source.uri.scheme, 'file'); | 318 expect(source.uri.scheme, 'package'); |
321 expect(source.fullName, filePath); | 319 expect(source.fullName, filePath); |
322 } | 320 } |
323 | 321 |
324 /** | 322 /** |
325 * Test that having multiple analysis contexts analyze the same file doesn't | 323 * Test that having multiple analysis contexts analyze the same file doesn't |
326 * cause that file to receive duplicate notifications when it's modified. | 324 * cause that file to receive duplicate notifications when it's modified. |
327 */ | 325 */ |
328 Future test_no_duplicate_notifications() async { | 326 Future test_no_duplicate_notifications() async { |
329 // Subscribe to STATUS so we'll know when analysis is done. | 327 // Subscribe to STATUS so we'll know when analysis is done. |
330 server.serverServices = [ServerService.STATUS].toSet(); | 328 server.serverServices = [ServerService.STATUS].toSet(); |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
593 _MockServerOperation(this.context); | 591 _MockServerOperation(this.context); |
594 | 592 |
595 @override | 593 @override |
596 ServerOperationPriority get priority => ServerOperationPriority.ANALYSIS; | 594 ServerOperationPriority get priority => ServerOperationPriority.ANALYSIS; |
597 | 595 |
598 @override | 596 @override |
599 void perform(AnalysisServer server) { | 597 void perform(AnalysisServer server) { |
600 isComplete = true; | 598 isComplete = true; |
601 } | 599 } |
602 } | 600 } |
OLD | NEW |