Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(779)

Unified Diff: pkg/analysis_server/lib/src/analysis_server.dart

Issue 392693002: Initial implementation for 'search.findElementReferences'. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add comments Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/analysis_server/lib/src/computer/element.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 ad93085ceb23d1d4ba7a897a719392f01c84fd81..8976a09054ac222643f9845129557431737c6a24 100644
--- a/pkg/analysis_server/lib/src/analysis_server.dart
+++ b/pkg/analysis_server/lib/src/analysis_server.dart
@@ -28,6 +28,8 @@ import 'package:analyzer/src/generated/sdk_io.dart';
import 'package:analyzer/src/generated/source_io.dart';
import 'package:analyzer/src/generated/java_engine.dart';
import 'package:analysis_services/index/index.dart';
+import 'package:analysis_services/search/search_engine.dart';
+import 'package:analyzer/src/generated/element.dart';
/**
@@ -109,6 +111,11 @@ class AnalysisServer {
final Index index;
/**
+ * The [SearchEngine] for this server.
+ */
+ SearchEngine searchEngine;
+
+ /**
* [ContextDirectoryManager] which handles the mapping from analysis roots
* to context directories.
*/
@@ -183,6 +190,7 @@ class AnalysisServer {
AnalysisServer(this.channel, ResourceProvider resourceProvider,
PackageMapProvider packageMapProvider, this.index,
{this.rethrowExceptions: true}) {
+ searchEngine = createSearchEngine(index);
operationQueue = new ServerOperationQueue(this);
contextDirectoryManager = new AnalysisServerContextDirectoryManager(
this, resourceProvider, packageMapProvider);
@@ -548,6 +556,50 @@ class AnalysisServer {
}
/**
+ * Returns resolved [CompilationUnit]s of the Dart file with the given [path].
+ *
+ * May be empty, but not `null`.
+ */
+ List<CompilationUnit> getResolvedCompilationUnits(String path) {
+ List<CompilationUnit> units = <CompilationUnit>[];
+ // prepare AnalysisContext
+ AnalysisContext context = getAnalysisContext(path);
+ if (context == null) {
+ return units;
+ }
+ // add a unit for each unit/library combination
+ Source unitSource = getSource(path);
+ List<Source> librarySources = context.getLibrariesContaining(unitSource);
+ for (Source librarySource in librarySources) {
+ CompilationUnit unit = context.getResolvedCompilationUnit2(unitSource, librarySource);
+ if (unit != null) {
+ units.add(unit);
+ }
+ }
+ // done
+ return units;
+ }
+
+ /**
+ * Returns [Element]s of the Dart file with the given [path], at the given
+ * offset.
+ *
+ * May be empty, but not `null`.
+ */
+ List<Element> getElementsAtOffset(String path, int offset) {
+ List<CompilationUnit> units = getResolvedCompilationUnits(path);
+ List<Element> elements = <Element>[];
+ for (CompilationUnit unit in units) {
+ AstNode node = new NodeLocator.con1(offset).searchWithin(unit);
+ Element element = ElementLocator.locateWithOffset(node, offset);
+ if (element != null) {
+ elements.add(element);
+ }
+ }
+ return elements;
+ }
+
+ /**
* Return the [CompilationUnit] of the Dart file with the given [path].
* Return `null` if the file is not a part of any context.
*/
« no previous file with comments | « no previous file | pkg/analysis_server/lib/src/computer/element.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698