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 688 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
699 Source source = sources.first; | 699 Source source = sources.first; |
700 return new ContextSourcePair(context, source); | 700 return new ContextSourcePair(context, source); |
701 } | 701 } |
702 } | 702 } |
703 // file-based source | 703 // file-based source |
704 Source fileSource = file.createSource(); | 704 Source fileSource = file.createSource(); |
705 return new ContextSourcePair(null, fileSource); | 705 return new ContextSourcePair(null, fileSource); |
706 } | 706 } |
707 | 707 |
708 /** | 708 /** |
709 * Return the [Element] at the given [offset] of the given [file], or `null` | 709 * Return the [Future] that completes with the [Element] at the given |
Paul Berry
2016/11/22 18:06:18
s/Return the [Future]/Return a [Future]/
("Return
scheglov
2016/11/22 18:45:47
Done.
| |
710 * if there is no node at the [offset] or the node does not have an element. | 710 * [offset] of the given [file], or with `null` if there is no node at the |
711 * [offset] or the node does not have an element. | |
711 */ | 712 */ |
712 Element getElementAtOffset(String file, int offset) { | 713 Future<Element> getElementAtOffset(String file, int offset) async { |
713 AstNode node = getNodeAtOffset(file, offset); | 714 AstNode node = await getNodeAtOffset(file, offset); |
714 return getElementOfNode(node); | 715 return getElementOfNode(node); |
715 } | 716 } |
716 | 717 |
717 /** | 718 /** |
718 * Return the [Element] of the given [node], or `null` if [node] is `null` or | 719 * Return the [Element] of the given [node], or `null` if [node] is `null` or |
719 * does not have an element. | 720 * does not have an element. |
720 */ | 721 */ |
721 Element getElementOfNode(AstNode node) { | 722 Element getElementOfNode(AstNode node) { |
722 if (node == null) { | 723 if (node == null) { |
723 return null; | 724 return null; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
758 if (context == null) { | 759 if (context == null) { |
759 return null; | 760 return null; |
760 } | 761 } |
761 if (!context.exists(source)) { | 762 if (!context.exists(source)) { |
762 return null; | 763 return null; |
763 } | 764 } |
764 return context.getErrors(source); | 765 return context.getErrors(source); |
765 } | 766 } |
766 | 767 |
767 /** | 768 /** |
768 * Return the resolved [AstNode]s at the given [offset] of the given [file], | 769 * Return the [Future] that completes with the resolved [AstNode] at the |
769 * or `null` if there is no node as the [offset]. | 770 * given [offset] of the given [file], or with `null` if there is no node as |
771 * the [offset]. | |
770 */ | 772 */ |
771 AstNode getNodeAtOffset(String file, int offset) { | 773 Future<AstNode> getNodeAtOffset(String file, int offset) async { |
772 CompilationUnit unit = getResolvedCompilationUnit(file); | 774 CompilationUnit unit = await getResolvedCompilationUnit(file); |
773 if (unit != null) { | 775 if (unit != null) { |
774 return new NodeLocator(offset).searchWithin(unit); | 776 return new NodeLocator(offset).searchWithin(unit); |
775 } | 777 } |
776 return null; | 778 return null; |
777 } | 779 } |
778 | 780 |
779 /** | 781 /** |
780 * Return the resolved [CompilationUnit] for the Dart file with the given | 782 * Return the [Future] that completes with the resolved [CompilationUnit] for |
781 * [path], or `null` if the file is not a Dart file or cannot be resolved. | 783 * the Dart file with the given [path], or with `null` if the file is not a |
784 * Dart file or cannot be resolved. | |
782 */ | 785 */ |
783 CompilationUnit getResolvedCompilationUnit(String path) { | 786 Future<CompilationUnit> getResolvedCompilationUnit(String path) async { |
784 ContextSourcePair contextSource = getContextSourcePair(path); | 787 ContextSourcePair contextSource = getContextSourcePair(path); |
785 AnalysisContext context = contextSource.context; | 788 AnalysisContext context = contextSource.context; |
786 if (context == null) { | 789 if (context == null) { |
787 return null; | 790 return null; |
788 } | 791 } |
789 return runWithActiveContext(context, () { | 792 return runWithActiveContext(context, () { |
790 Source unitSource = contextSource.source; | 793 Source unitSource = contextSource.source; |
791 List<Source> librarySources = context.getLibrariesContaining(unitSource); | 794 List<Source> librarySources = context.getLibrariesContaining(unitSource); |
792 for (Source librarySource in librarySources) { | 795 for (Source librarySource in librarySources) { |
793 return context.resolveCompilationUnit2(unitSource, librarySource); | 796 return context.resolveCompilationUnit2(unitSource, librarySource); |
(...skipping 1243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2037 /** | 2040 /** |
2038 * The [PerformanceTag] for time spent in server request handlers. | 2041 * The [PerformanceTag] for time spent in server request handlers. |
2039 */ | 2042 */ |
2040 static PerformanceTag serverRequests = new PerformanceTag('serverRequests'); | 2043 static PerformanceTag serverRequests = new PerformanceTag('serverRequests'); |
2041 | 2044 |
2042 /** | 2045 /** |
2043 * The [PerformanceTag] for time spent in split store microtasks. | 2046 * The [PerformanceTag] for time spent in split store microtasks. |
2044 */ | 2047 */ |
2045 static PerformanceTag splitStore = new PerformanceTag('splitStore'); | 2048 static PerformanceTag splitStore = new PerformanceTag('splitStore'); |
2046 } | 2049 } |
OLD | NEW |