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

Side by Side Diff: pkg/analysis_server/lib/src/analysis_server.dart

Issue 1455163005: Implement AnalysisServer.getContainingContext() using ContextManager. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 1 month 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
« no previous file with comments | « no previous file | pkg/analysis_server/lib/src/context_manager.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 import 'dart:core' hide Resource; 9 import 'dart:core' hide Resource;
10 import 'dart:math' show max; 10 import 'dart:math' show max;
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 // get element in the first library 466 // get element in the first library
467 List<Source> librarySources = context.getLibrariesContaining(unitSource); 467 List<Source> librarySources = context.getLibrariesContaining(unitSource);
468 if (!librarySources.isNotEmpty) { 468 if (!librarySources.isNotEmpty) {
469 return null; 469 return null;
470 } 470 }
471 Source librarySource = librarySources.first; 471 Source librarySource = librarySources.first;
472 return context.getCompilationUnitElement(unitSource, librarySource); 472 return context.getCompilationUnitElement(unitSource, librarySource);
473 } 473 }
474 474
475 /** 475 /**
476 * Return the [AnalysisContext] that contains the given [path]. 476 * Return the [AnalysisContext] for the "innermost" context whose associated
477 * Return `null` if no context contains the [path]. 477 * folder is or contains the given path. ("innermost" refers to the nesting
478 * of contexts, so if there is a context for path /foo and a context for
479 * path /foo/bar, then the innermost context containing /foo/bar/baz.dart is
480 * the context for /foo/bar.)
481 *
482 * If no context contains the given path, `null` is returned.
478 */ 483 */
479 AnalysisContext getContainingContext(String path) { 484 AnalysisContext getContainingContext(String path) {
480 Folder containingFolder = null; 485 return contextManager.getContextFor(path);
481 AnalysisContext containingContext = null;
482 folderMap.forEach((Folder folder, AnalysisContext context) {
483 if (folder.isOrContains(path)) {
484 if (containingFolder == null ||
485 containingFolder.path.length < folder.path.length) {
486 containingFolder = folder;
487 containingContext = context;
488 }
489 }
490 });
491 return containingContext;
492 } 486 }
493 487
494 /** 488 /**
495 * Return the primary [ContextSourcePair] representing the given [path]. 489 * Return the primary [ContextSourcePair] representing the given [path].
496 * 490 *
497 * The [AnalysisContext] of this pair will be the context that explicitly 491 * The [AnalysisContext] of this pair will be the context that explicitly
498 * contains the path, if any such context exists, otherwise it will be the 492 * contains the path, if any such context exists, otherwise it will be the
499 * first context that implicitly analyzes it. 493 * first context that implicitly analyzes it.
500 * 494 *
501 * If the [path] is not analyzed by any context, a [ContextSourcePair] with 495 * If the [path] is not analyzed by any context, a [ContextSourcePair] with
(...skipping 1030 matching lines...) Expand 10 before | Expand all | Expand 10 after
1532 } 1526 }
1533 1527
1534 void _computingPackageMap(bool computing) { 1528 void _computingPackageMap(bool computing) {
1535 if (analysisServer.serverServices.contains(ServerService.STATUS)) { 1529 if (analysisServer.serverServices.contains(ServerService.STATUS)) {
1536 PubStatus pubStatus = new PubStatus(computing); 1530 PubStatus pubStatus = new PubStatus(computing);
1537 ServerStatusParams params = new ServerStatusParams(pub: pubStatus); 1531 ServerStatusParams params = new ServerStatusParams(pub: pubStatus);
1538 analysisServer.sendNotification(params.toNotification()); 1532 analysisServer.sendNotification(params.toNotification());
1539 } 1533 }
1540 } 1534 }
1541 1535
1542 /// If [disposition] has a package map, attempt to locate `_embedder.yaml`
1543 /// files.
1544 void _locateEmbedderYamls(InternalAnalysisContext context,
1545 FolderDisposition disposition) {
1546 Map<String, List<Folder>> packageMap;
1547 if (disposition is PackageMapDisposition) {
1548 packageMap = disposition.packageMap;
1549 } else if (disposition is PackagesFileDisposition) {
1550 packageMap = disposition.buildPackageMap(resourceProvider);
1551 }
1552 context.embedderYamlLocator.refresh(packageMap);
1553 }
1554
1555 /** 1536 /**
1556 * Set up a [SourceFactory] that resolves packages as appropriate for the 1537 * Set up a [SourceFactory] that resolves packages as appropriate for the
1557 * given [disposition]. 1538 * given [disposition].
1558 */ 1539 */
1559 SourceFactory _createSourceFactory(InternalAnalysisContext context, 1540 SourceFactory _createSourceFactory(
1560 FolderDisposition disposition) { 1541 InternalAnalysisContext context, FolderDisposition disposition) {
1561 List<UriResolver> resolvers = []; 1542 List<UriResolver> resolvers = [];
1562 List<UriResolver> packageUriResolvers = 1543 List<UriResolver> packageUriResolvers =
1563 disposition.createPackageUriResolvers(resourceProvider); 1544 disposition.createPackageUriResolvers(resourceProvider);
1564 EmbedderUriResolver embedderUriResolver = 1545 EmbedderUriResolver embedderUriResolver =
1565 new EmbedderUriResolver(context.embedderYamlLocator.embedderYamls); 1546 new EmbedderUriResolver(context.embedderYamlLocator.embedderYamls);
1566 if (embedderUriResolver.length == 0) { 1547 if (embedderUriResolver.length == 0) {
1567 // The embedder uri resolver has no mappings. Use the default Dart SDK 1548 // The embedder uri resolver has no mappings. Use the default Dart SDK
1568 // uri resolver. 1549 // uri resolver.
1569 resolvers.add(new DartUriResolver(analysisServer.defaultSdk)); 1550 resolvers.add(new DartUriResolver(analysisServer.defaultSdk));
1570 } else { 1551 } else {
1571 // The embedder uri resolver has mappings, use it instead of the default 1552 // The embedder uri resolver has mappings, use it instead of the default
1572 // Dart SDK uri resolver. 1553 // Dart SDK uri resolver.
1573 resolvers.add(embedderUriResolver); 1554 resolvers.add(embedderUriResolver);
1574 } 1555 }
1575 resolvers.addAll(packageUriResolvers); 1556 resolvers.addAll(packageUriResolvers);
1576 resolvers.add(new ResourceUriResolver(resourceProvider)); 1557 resolvers.add(new ResourceUriResolver(resourceProvider));
1577 return new SourceFactory(resolvers, disposition.packages); 1558 return new SourceFactory(resolvers, disposition.packages);
1578 } 1559 }
1560
1561 /// If [disposition] has a package map, attempt to locate `_embedder.yaml`
1562 /// files.
1563 void _locateEmbedderYamls(
1564 InternalAnalysisContext context, FolderDisposition disposition) {
1565 Map<String, List<Folder>> packageMap;
1566 if (disposition is PackageMapDisposition) {
1567 packageMap = disposition.packageMap;
1568 } else if (disposition is PackagesFileDisposition) {
1569 packageMap = disposition.buildPackageMap(resourceProvider);
1570 }
1571 context.embedderYamlLocator.refresh(packageMap);
1572 }
1579 } 1573 }
1580 1574
1581 /** 1575 /**
1582 * A class used by [AnalysisServer] to record performance information 1576 * A class used by [AnalysisServer] to record performance information
1583 * such as request latency. 1577 * such as request latency.
1584 */ 1578 */
1585 class ServerPerformance { 1579 class ServerPerformance {
1586 /** 1580 /**
1587 * The creation time and the time when performance information 1581 * The creation time and the time when performance information
1588 * started to be recorded here. 1582 * started to be recorded here.
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
1672 /** 1666 /**
1673 * The [PerformanceTag] for time spent in server request handlers. 1667 * The [PerformanceTag] for time spent in server request handlers.
1674 */ 1668 */
1675 static PerformanceTag serverRequests = new PerformanceTag('serverRequests'); 1669 static PerformanceTag serverRequests = new PerformanceTag('serverRequests');
1676 1670
1677 /** 1671 /**
1678 * The [PerformanceTag] for time spent in split store microtasks. 1672 * The [PerformanceTag] for time spent in split store microtasks.
1679 */ 1673 */
1680 static PerformanceTag splitStore = new PerformanceTag('splitStore'); 1674 static PerformanceTag splitStore = new PerformanceTag('splitStore');
1681 } 1675 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analysis_server/lib/src/context_manager.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698