Chromium Code Reviews| Index: pkg/analysis_server/lib/src/analysis_server.dart |
| diff --git a/pkg/analysis_server/lib/src/analysis_server.dart b/pkg/analysis_server/lib/src/analysis_server.dart |
| index da2510b0a0ce5f865f5cadeaea96a8085a984ad1..7c8fd523b45ed3a0a669fa979f6bb0b20f83a6d5 100644 |
| --- a/pkg/analysis_server/lib/src/analysis_server.dart |
| +++ b/pkg/analysis_server/lib/src/analysis_server.dart |
| @@ -398,25 +398,21 @@ class AnalysisServer { |
| List<AnalysisError> errors = analysisContext.getErrors(source).errors; |
| sendAnalysisNotificationErrors(this, file, errors); |
| } |
| - // TODO(scheglov) |
| - // 1. implement resolveCompilationUnit() |
| - // 2. Share "if (dartUnit != null)" |
| - if (service == AnalysisService.HIGHLIGHTS) { |
| - CompilationUnit dartUnit = test_getResolvedCompilationUnit(file); |
| + // Dart unit notifications. |
| + if (AnalysisEngine.isDartFileName(file)) { |
| + CompilationUnit dartUnit = resolveCompilationUnit(file); |
|
Brian Wilkerson
2014/06/18 16:25:11
I think we need to only get the compilation unit i
scheglov
2014/06/18 17:38:27
Agree.
Done.
|
| if (dartUnit != null) { |
| - sendAnalysisNotificationHighlights(this, file, dartUnit); |
| - } |
| - } |
| - if (service == AnalysisService.NAVIGATION) { |
| - CompilationUnit dartUnit = test_getResolvedCompilationUnit(file); |
| - if (dartUnit != null) { |
| - sendAnalysisNotificationNavigation(this, file, dartUnit); |
| - } |
| - } |
| - if (service == AnalysisService.OUTLINE) { |
| - CompilationUnit dartUnit = test_getResolvedCompilationUnit(file); |
| - if (dartUnit != null) { |
| - sendAnalysisNotificationOutline(this, file, dartUnit); |
| + switch (service) { |
| + case AnalysisService.HIGHLIGHTS: |
| + sendAnalysisNotificationHighlights(this, file, dartUnit); |
| + break; |
| + case AnalysisService.NAVIGATION: |
| + sendAnalysisNotificationNavigation(this, file, dartUnit); |
| + break; |
| + case AnalysisService.OUTLINE: |
| + sendAnalysisNotificationOutline(this, file, dartUnit); |
| + break; |
| + } |
| } |
| } |
| } |
| @@ -450,6 +446,26 @@ class AnalysisServer { |
| * Return the [CompilationUnit] of the Dart file with the given [path]. |
| * Return `null` if the file is not a part of any context. |
| */ |
| + CompilationUnit resolveCompilationUnit(String path) { |
| + // prepare AnalysisContext |
| + AnalysisContext context = _getAnalysisContext(path); |
| + if (context == null) { |
| + return null; |
| + } |
| + // prepare sources |
| + Source unitSource = _getSource(path); |
| + List<Source> librarySources = context.getLibrariesContaining(unitSource); |
| + if (librarySources.isEmpty) { |
| + return null; |
| + } |
| + // resolve the unit |
| + return context.resolveCompilationUnit2(unitSource, librarySources[0]); |
|
Brian Wilkerson
2014/06/18 16:25:11
We need to handle the case where a file is in more
scheglov
2014/06/18 17:38:27
AFAIK multiple libraries matter only for navigatio
|
| + } |
| + |
| + /** |
| + * Return the [CompilationUnit] of the Dart file with the given [path]. |
| + * Return `null` if the file is not a part of any context. |
| + */ |
| CompilationUnit test_getResolvedCompilationUnit(String path) { |
| // prepare AnalysisContext |
| AnalysisContext context = _getAnalysisContext(path); |