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

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

Issue 2834673002: Revert "Update PluginWatcher to be more efficient" (TBR) (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 | no next file » | 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.fsState.knownFilesSetChanges.listen((KnownFilesSetChange change) { 55 driver.results.listen((AnalysisResult result) {
56 List<String> addedPluginPaths = _checkPluginsFor(driver, change); 56 List<String> addedPluginPaths = _checkPluginsFor(driver);
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( 81 List<String> _checkPluginsFor(AnalysisDriver driver) {
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;
91 AbsolutePathContext context = resourceProvider.absolutePathContext; 82 AbsolutePathContext context = resourceProvider.absolutePathContext;
83 List<String> packageRoots = _driverInfo[driver].packageRoots;
92 84
93 bool isInRoot(String path) { 85 bool isInRoot(String path) {
94 for (String root in packageRoots) { 86 for (String root in packageRoots) {
95 if (context.isWithin(root, path)) { 87 if (context.isWithin(root, path)) {
96 return true; 88 return true;
97 } 89 }
98 } 90 }
99 return false; 91 return false;
100 } 92 }
101 93
102 String getPackageRoot(String path, Uri uri) { 94 String getPackageRoot(String path, Uri uri) {
103 List<String> segments = uri.pathSegments.toList(); 95 List<String> segments = uri.pathSegments.toList();
104 segments[0] = 'lib'; 96 segments[0] = 'lib';
105 String suffix = resourceProvider.pathContext.joinAll(segments); 97 String suffix = resourceProvider.pathContext.joinAll(segments);
106 return path.substring(0, path.length - suffix.length - 1); 98 return path.substring(0, path.length - suffix.length - 1);
107 } 99 }
108 100
109 List<String> addedPluginPaths = <String>[]; 101 List<String> addedPluginPaths = <String>[];
110 for (String path in change.added) { 102 for (FileState state in driver.fsState.knownFiles) {
111 FileState state = fileSystemState.getFileForPath(path); 103 String path = state.path;
112 if (!isInRoot(path)) { 104 if (!isInRoot(path)) {
113 // Found a file not in a previously known package. 105 // Found a file not in a previously known package.
114 Uri uri = state.uri; 106 Uri uri = state.uri;
115 if (PackageMapUriResolver.isPackageUri(uri)) { 107 if (PackageMapUriResolver.isPackageUri(uri)) {
116 String packageRoot = getPackageRoot(path, uri); 108 String packageRoot = getPackageRoot(path, uri);
117 packageRoots.add(packageRoot); 109 packageRoots.add(packageRoot);
118 String pluginPath = _locator.findPlugin(packageRoot); 110 String pluginPath = _locator.findPlugin(packageRoot);
119 if (pluginPath != null) { 111 if (pluginPath != null) {
120 addedPluginPaths.add(pluginPath); 112 addedPluginPaths.add(pluginPath);
121 } 113 }
(...skipping 30 matching lines...) Expand all
152 * A list of the absolute paths of directories inside of which we have already 144 * A list of the absolute paths of directories inside of which we have already
153 * searched for a plugin. 145 * searched for a plugin.
154 */ 146 */
155 final List<String> packageRoots; 147 final List<String> packageRoots;
156 148
157 /** 149 /**
158 * Initialize a newly created information holder. 150 * Initialize a newly created information holder.
159 */ 151 */
160 _DriverInfo(this.contextRoot, this.packageRoots); 152 _DriverInfo(this.contextRoot, this.packageRoots);
161 } 153 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698