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

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

Issue 2830933005: Update PluginWatcher to be more efficient (Closed)
Patch Set: Created 3 years, 8 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
« no previous file with comments | « no previous file | pkg/analysis_server/test/src/plugin/plugin_watcher_test.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) 2017, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2017, 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 import 'package:analysis_server/src/plugin/plugin_locator.dart'; 5 import 'package:analysis_server/src/plugin/plugin_locator.dart';
6 import 'package:analysis_server/src/plugin/plugin_manager.dart'; 6 import 'package:analysis_server/src/plugin/plugin_manager.dart';
7 import 'package:analyzer/context/context_root.dart'; 7 import 'package:analyzer/context/context_root.dart';
8 import 'package:analyzer/file_system/file_system.dart'; 8 import 'package:analyzer/file_system/file_system.dart';
9 import 'package:analyzer/source/package_map_resolver.dart'; 9 import 'package:analyzer/source/package_map_resolver.dart';
10 import 'package:analyzer/src/dart/analysis/driver.dart'; 10 import 'package:analyzer/src/dart/analysis/driver.dart';
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 PluginWatcher(this.resourceProvider, this.manager) 45 PluginWatcher(this.resourceProvider, this.manager)
46 : _locator = new PluginLocator(resourceProvider); 46 : _locator = new PluginLocator(resourceProvider);
47 47
48 /** 48 /**
49 * The context manager has just added the given analysis [driver]. This method 49 * The context manager has just added the given analysis [driver]. This method
50 * must be called before the driver has been allowed to perform any analysis. 50 * must be called before the driver has been allowed to perform any analysis.
51 */ 51 */
52 void addedDriver(AnalysisDriver driver, ContextRoot contextRoot) { 52 void addedDriver(AnalysisDriver driver, ContextRoot contextRoot) {
53 _driverInfo[driver] = new _DriverInfo( 53 _driverInfo[driver] = new _DriverInfo(
54 contextRoot, <String>[contextRoot.root, _getSdkPath(driver)]); 54 contextRoot, <String>[contextRoot.root, _getSdkPath(driver)]);
55 driver.results.listen((AnalysisResult result) { 55 driver.fsState.knownFilesSetChanges.listen((KnownFilesSetChange change) {
56 List<String> addedPluginPaths = _checkPluginsFor(driver); 56 List<String> addedPluginPaths = _checkPluginsFor(driver, change);
57 for (String pluginPath in addedPluginPaths) { 57 for (String pluginPath in addedPluginPaths) {
58 manager.addPluginToContextRoot(contextRoot, pluginPath); 58 manager.addPluginToContextRoot(contextRoot, pluginPath);
59 } 59 }
60 }); 60 });
61 } 61 }
62 62
63 /** 63 /**
64 * The context manager has just removed the given analysis [driver]. 64 * The context manager has just removed the given analysis [driver].
65 */ 65 */
66 void removedDriver(AnalysisDriver driver) { 66 void removedDriver(AnalysisDriver driver) {
67 _DriverInfo info = _driverInfo[driver]; 67 _DriverInfo info = _driverInfo[driver];
68 if (info == null) { 68 if (info == null) {
69 throw new StateError('Cannot remove a driver that was not added'); 69 throw new StateError('Cannot remove a driver that was not added');
70 } 70 }
71 manager.removedContextRoot(info.contextRoot); 71 manager.removedContextRoot(info.contextRoot);
72 _driverInfo.remove(driver); 72 _driverInfo.remove(driver);
73 } 73 }
74 74
75 /** 75 /**
76 * Check all of the files that have been analyzed so far by the given [driver] 76 * Check all of the files that have been analyzed so far by the given [driver]
77 * to see whether any of them are in a package that had not previously been 77 * to see whether any of them are in a package that had not previously been
78 * seen that defines a plugin. Return a list of the roots of all such plugins 78 * seen that defines a plugin. Return a list of the roots of all such plugins
79 * that are found. 79 * that are found.
80 */ 80 */
81 List<String> _checkPluginsFor(AnalysisDriver driver) { 81 List<String> _checkPluginsFor(
82 AnalysisDriver driver, KnownFilesSetChange change) {
83 _DriverInfo info = _driverInfo[driver];
84 if (info == null) {
85 // The driver must have been removed prior to getting the notification of
86 // newly analyzed files.
87 return const <String>[];
88 }
89 List<String> packageRoots = info.packageRoots;
90 FileSystemState fileSystemState = driver.fsState;
82 AbsolutePathContext context = resourceProvider.absolutePathContext; 91 AbsolutePathContext context = resourceProvider.absolutePathContext;
83 List<String> packageRoots = _driverInfo[driver].packageRoots;
84 92
85 bool isInRoot(String path) { 93 bool isInRoot(String path) {
86 for (String root in packageRoots) { 94 for (String root in packageRoots) {
87 if (context.isWithin(root, path)) { 95 if (context.isWithin(root, path)) {
88 return true; 96 return true;
89 } 97 }
90 } 98 }
91 return false; 99 return false;
92 } 100 }
93 101
94 String getPackageRoot(String path, Uri uri) { 102 String getPackageRoot(String path, Uri uri) {
95 List<String> segments = uri.pathSegments.toList(); 103 List<String> segments = uri.pathSegments.toList();
96 segments[0] = 'lib'; 104 segments[0] = 'lib';
97 String suffix = resourceProvider.pathContext.joinAll(segments); 105 String suffix = resourceProvider.pathContext.joinAll(segments);
98 return path.substring(0, path.length - suffix.length - 1); 106 return path.substring(0, path.length - suffix.length - 1);
99 } 107 }
100 108
101 List<String> addedPluginPaths = <String>[]; 109 List<String> addedPluginPaths = <String>[];
102 for (FileState state in driver.fsState.knownFiles) { 110 for (String path in change.added) {
103 String path = state.path; 111 FileState state = fileSystemState.getFileForPath(path);
104 if (!isInRoot(path)) { 112 if (!isInRoot(path)) {
105 // Found a file not in a previously known package. 113 // Found a file not in a previously known package.
106 Uri uri = state.uri; 114 Uri uri = state.uri;
107 if (PackageMapUriResolver.isPackageUri(uri)) { 115 if (PackageMapUriResolver.isPackageUri(uri)) {
108 String packageRoot = getPackageRoot(path, uri); 116 String packageRoot = getPackageRoot(path, uri);
109 packageRoots.add(packageRoot); 117 packageRoots.add(packageRoot);
110 String pluginPath = _locator.findPlugin(packageRoot); 118 String pluginPath = _locator.findPlugin(packageRoot);
111 if (pluginPath != null) { 119 if (pluginPath != null) {
112 addedPluginPaths.add(pluginPath); 120 addedPluginPaths.add(pluginPath);
113 } 121 }
(...skipping 30 matching lines...) Expand all
144 * A list of the absolute paths of directories inside of which we have already 152 * A list of the absolute paths of directories inside of which we have already
145 * searched for a plugin. 153 * searched for a plugin.
146 */ 154 */
147 final List<String> packageRoots; 155 final List<String> packageRoots;
148 156
149 /** 157 /**
150 * Initialize a newly created information holder. 158 * Initialize a newly created information holder.
151 */ 159 */
152 _DriverInfo(this.contextRoot, this.packageRoots); 160 _DriverInfo(this.contextRoot, this.packageRoots);
153 } 161 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analysis_server/test/src/plugin/plugin_watcher_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698