| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 part of repositories; | 5 part of repositories; |
| 6 | 6 |
| 7 class EditorRepository extends M.EditorRepository { | 7 class EditorRepository extends M.EditorRepository { |
| 8 final S.VM _vm; | 8 final S.VM _vm; |
| 9 final String _editor; | 9 final String _editor; |
| 10 | 10 |
| 11 bool get canOpenClass => _getService() != null; | 11 bool get canOpenClass => _getService() != null; |
| 12 | 12 |
| 13 EditorRepository(S.VM vm, {String editor}) | 13 EditorRepository(S.VM vm, {String editor}) |
| 14 : _vm = vm, | 14 : _vm = vm, |
| 15 _editor = editor { | 15 _editor = editor { |
| 16 assert(_vm != null); | 16 assert(_vm != null); |
| 17 } | 17 } |
| 18 | 18 |
| 19 S.Service _getService() { | 19 S.Service _getService() { |
| 20 if (_vm.services.isEmpty) { | 20 Iterable<M.Service> services = |
| 21 return null; | 21 _vm.services.where((s) => s.service == 'openSourceLocation'); |
| 22 if (_editor != null) { |
| 23 services = services.where((s) => s.alias == _editor); |
| 22 } | 24 } |
| 23 if (_editor == null) { | 25 if (services.isNotEmpty) { |
| 24 return _vm.services.where((s) => s.service == 'openSourceLocation').first; | 26 return services.first; |
| 25 } | 27 } |
| 26 return _vm.services | 28 return null; |
| 27 .where((s) => s.service == 'openSourceLocation' && s.alias == _editor) | |
| 28 .single; | |
| 29 } | 29 } |
| 30 | 30 |
| 31 Future openClass(M.IsolateRef i, M.ClassRef c) async { | 31 Future openClass(M.IsolateRef i, M.ClassRef c) async { |
| 32 S.Class clazz = c as S.Class; | 32 S.Class clazz = c as S.Class; |
| 33 assert(clazz != null); | 33 assert(clazz != null); |
| 34 if (!clazz.loaded) { | 34 if (!clazz.loaded) { |
| 35 await clazz.load(); | 35 await clazz.load(); |
| 36 } | 36 } |
| 37 if (clazz.location == null) { | 37 if (clazz.location == null) { |
| 38 return new Future.value(); | 38 return new Future.value(); |
| 39 } | 39 } |
| 40 return await openSourceLocation(i, clazz.location); | 40 return await openSourceLocation(i, clazz.location); |
| 41 } | 41 } |
| 42 | 42 |
| 43 Future openSourceLocation(M.IsolateRef i, M.SourceLocation l) async { | 43 Future openSourceLocation(M.IsolateRef i, M.SourceLocation l) async { |
| 44 final isolate = i as S.Isolate; | 44 final isolate = i as S.Isolate; |
| 45 assert(isolate != null); | 45 assert(isolate != null); |
| 46 assert(l != null); | 46 assert(l != null); |
| 47 return await isolate.invokeRpc(_getService().method, | 47 return await isolate.invokeRpc(_getService().method, |
| 48 {'scriptId': l.script.id, 'tokenPos': l.tokenPos}); | 48 {'scriptId': l.script.id, 'tokenPos': l.tokenPos}); |
| 49 } | 49 } |
| 50 } | 50 } |
| OLD | NEW |