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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | pkg/analysis_server/lib/src/computer/element.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 9
10 import 'package:analyzer/file_system/file_system.dart'; 10 import 'package:analyzer/file_system/file_system.dart';
(...skipping 10 matching lines...) Expand all
21 import 'package:analysis_server/src/protocol.dart'; 21 import 'package:analysis_server/src/protocol.dart';
22 import 'package:analyzer/src/generated/ast.dart'; 22 import 'package:analyzer/src/generated/ast.dart';
23 import 'package:analyzer/src/generated/engine.dart'; 23 import 'package:analyzer/src/generated/engine.dart';
24 import 'package:analyzer/src/generated/error.dart'; 24 import 'package:analyzer/src/generated/error.dart';
25 import 'package:analyzer/src/generated/source.dart'; 25 import 'package:analyzer/src/generated/source.dart';
26 import 'package:analyzer/src/generated/sdk.dart'; 26 import 'package:analyzer/src/generated/sdk.dart';
27 import 'package:analyzer/src/generated/sdk_io.dart'; 27 import 'package:analyzer/src/generated/sdk_io.dart';
28 import 'package:analyzer/src/generated/source_io.dart'; 28 import 'package:analyzer/src/generated/source_io.dart';
29 import 'package:analyzer/src/generated/java_engine.dart'; 29 import 'package:analyzer/src/generated/java_engine.dart';
30 import 'package:analysis_services/index/index.dart'; 30 import 'package:analysis_services/index/index.dart';
31 import 'package:analysis_services/search/search_engine.dart';
32 import 'package:analyzer/src/generated/element.dart';
31 33
32 34
33 /** 35 /**
34 * An instance of [DirectoryBasedDartSdk] that is shared between 36 * An instance of [DirectoryBasedDartSdk] that is shared between
35 * [AnalysisServer] instances to improve performance. 37 * [AnalysisServer] instances to improve performance.
36 */ 38 */
37 final DirectoryBasedDartSdk SHARED_SDK = DirectoryBasedDartSdk.defaultSdk; 39 final DirectoryBasedDartSdk SHARED_SDK = DirectoryBasedDartSdk.defaultSdk;
38 40
39 class AnalysisServerContextDirectoryManager extends ContextDirectoryManager { 41 class AnalysisServerContextDirectoryManager extends ContextDirectoryManager {
40 final AnalysisServer analysisServer; 42 final AnalysisServer analysisServer;
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 * be sent. 104 * be sent.
103 */ 105 */
104 final ServerCommunicationChannel channel; 106 final ServerCommunicationChannel channel;
105 107
106 /** 108 /**
107 * The [Index] for this server. 109 * The [Index] for this server.
108 */ 110 */
109 final Index index; 111 final Index index;
110 112
111 /** 113 /**
114 * The [SearchEngine] for this server.
115 */
116 SearchEngine searchEngine;
117
118 /**
112 * [ContextDirectoryManager] which handles the mapping from analysis roots 119 * [ContextDirectoryManager] which handles the mapping from analysis roots
113 * to context directories. 120 * to context directories.
114 */ 121 */
115 AnalysisServerContextDirectoryManager contextDirectoryManager; 122 AnalysisServerContextDirectoryManager contextDirectoryManager;
116 123
117 /** 124 /**
118 * A flag indicating whether the server is running. When false, contexts 125 * A flag indicating whether the server is running. When false, contexts
119 * will no longer be added to [contextWorkQueue], and [performOperation] will 126 * will no longer be added to [contextWorkQueue], and [performOperation] will
120 * discard any tasks it finds on [contextWorkQueue]. 127 * discard any tasks it finds on [contextWorkQueue].
121 */ 128 */
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 * responses to the given [channel]. 183 * responses to the given [channel].
177 * 184 *
178 * If [rethrowExceptions] is true, then any exceptions thrown by analysis are 185 * If [rethrowExceptions] is true, then any exceptions thrown by analysis are
179 * propagated up the call stack. The default is true to allow analysis 186 * propagated up the call stack. The default is true to allow analysis
180 * exceptions to show up in unit tests, but it should be set to false when 187 * exceptions to show up in unit tests, but it should be set to false when
181 * running a full analysis server. 188 * running a full analysis server.
182 */ 189 */
183 AnalysisServer(this.channel, ResourceProvider resourceProvider, 190 AnalysisServer(this.channel, ResourceProvider resourceProvider,
184 PackageMapProvider packageMapProvider, this.index, 191 PackageMapProvider packageMapProvider, this.index,
185 {this.rethrowExceptions: true}) { 192 {this.rethrowExceptions: true}) {
193 searchEngine = createSearchEngine(index);
186 operationQueue = new ServerOperationQueue(this); 194 operationQueue = new ServerOperationQueue(this);
187 contextDirectoryManager = new AnalysisServerContextDirectoryManager( 195 contextDirectoryManager = new AnalysisServerContextDirectoryManager(
188 this, resourceProvider, packageMapProvider); 196 this, resourceProvider, packageMapProvider);
189 AnalysisEngine.instance.logger = new AnalysisLogger(); 197 AnalysisEngine.instance.logger = new AnalysisLogger();
190 running = true; 198 running = true;
191 Notification notification = new Notification(SERVER_CONNECTED); 199 Notification notification = new Notification(SERVER_CONNECTED);
192 channel.sendNotification(notification); 200 channel.sendNotification(notification);
193 channel.listen(handleRequest, onDone: done, onError: error); 201 channel.listen(handleRequest, onDone: done, onError: error);
194 } 202 }
195 203
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 // if library has not been resolved yet, the unit will be resolved later 549 // if library has not been resolved yet, the unit will be resolved later
542 Source librarySource = librarySources[0]; 550 Source librarySource = librarySources[0];
543 if (context.getLibraryElement(librarySource) == null) { 551 if (context.getLibraryElement(librarySource) == null) {
544 return null; 552 return null;
545 } 553 }
546 // if library has been already resolved, resolve unit 554 // if library has been already resolved, resolve unit
547 return context.resolveCompilationUnit2(unitSource, librarySource); 555 return context.resolveCompilationUnit2(unitSource, librarySource);
548 } 556 }
549 557
550 /** 558 /**
559 * Returns resolved [CompilationUnit]s of the Dart file with the given [path].
560 *
561 * May be empty, but not `null`.
562 */
563 List<CompilationUnit> getResolvedCompilationUnits(String path) {
564 List<CompilationUnit> units = <CompilationUnit>[];
565 // prepare AnalysisContext
566 AnalysisContext context = getAnalysisContext(path);
567 if (context == null) {
568 return units;
569 }
570 // add a unit for each unit/library combination
571 Source unitSource = getSource(path);
572 List<Source> librarySources = context.getLibrariesContaining(unitSource);
573 for (Source librarySource in librarySources) {
574 CompilationUnit unit = context.getResolvedCompilationUnit2(unitSource, lib rarySource);
575 if (unit != null) {
576 units.add(unit);
577 }
578 }
579 // done
580 return units;
581 }
582
583 /**
584 * Returns [Element]s of the Dart file with the given [path], at the given
585 * offset.
586 *
587 * May be empty, but not `null`.
588 */
589 List<Element> getElementsAtOffset(String path, int offset) {
590 List<CompilationUnit> units = getResolvedCompilationUnits(path);
591 List<Element> elements = <Element>[];
592 for (CompilationUnit unit in units) {
593 AstNode node = new NodeLocator.con1(offset).searchWithin(unit);
594 Element element = ElementLocator.locateWithOffset(node, offset);
595 if (element != null) {
596 elements.add(element);
597 }
598 }
599 return elements;
600 }
601
602 /**
551 * Return the [CompilationUnit] of the Dart file with the given [path]. 603 * Return the [CompilationUnit] of the Dart file with the given [path].
552 * Return `null` if the file is not a part of any context. 604 * Return `null` if the file is not a part of any context.
553 */ 605 */
554 CompilationUnit test_getResolvedCompilationUnit(String path) { 606 CompilationUnit test_getResolvedCompilationUnit(String path) {
555 // prepare AnalysisContext 607 // prepare AnalysisContext
556 AnalysisContext context = getAnalysisContext(path); 608 AnalysisContext context = getAnalysisContext(path);
557 if (context == null) { 609 if (context == null) {
558 return null; 610 return null;
559 } 611 }
560 // prepare sources 612 // prepare sources
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
606 /** 658 /**
607 * An enumeration of the services provided by the server domain. 659 * An enumeration of the services provided by the server domain.
608 */ 660 */
609 class ServerService extends Enum2<ServerService> { 661 class ServerService extends Enum2<ServerService> {
610 static const ServerService STATUS = const ServerService('STATUS', 0); 662 static const ServerService STATUS = const ServerService('STATUS', 0);
611 663
612 static const List<ServerService> VALUES = const [STATUS]; 664 static const List<ServerService> VALUES = const [STATUS];
613 665
614 const ServerService(String name, int ordinal) : super(name, ordinal); 666 const ServerService(String name, int ordinal) : super(name, ordinal);
615 } 667 }
OLDNEW
« 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