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

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

Issue 303413003: Don't add files inside "packages" subdir to context. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 6 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/resource.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 context.directory.manager; 5 library context.directory.manager;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:analysis_server/src/resource.dart'; 9 import 'package:analysis_server/src/resource.dart';
10 import 'package:analyzer/src/generated/engine.dart'; 10 import 'package:analyzer/src/generated/engine.dart';
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 addContext(folder, pubspecFile.exists ? pubspecFile : null); 93 addContext(folder, pubspecFile.exists ? pubspecFile : null);
94 ChangeSet changeSet = new ChangeSet(); 94 ChangeSet changeSet = new ChangeSet();
95 _addSourceFiles(changeSet, folder, info); 95 _addSourceFiles(changeSet, folder, info);
96 applyChangesToContext(folder, changeSet); 96 applyChangesToContext(folder, changeSet);
97 } 97 }
98 } 98 }
99 99
100 void _handleWatchEvent(Folder folder, _ContextDirectoryInfo info, WatchEvent e vent) { 100 void _handleWatchEvent(Folder folder, _ContextDirectoryInfo info, WatchEvent e vent) {
101 switch (event.type) { 101 switch (event.type) {
102 case ChangeType.ADD: 102 case ChangeType.ADD:
103 if (_isInPackagesDir(event.path, folder)) {
104 // TODO(paulberry): perhaps we should only skip packages dirs if
105 // there is a pubspec.yaml?
106 break;
107 }
103 // TODO(paulberry): handle adding pubspec.yaml 108 // TODO(paulberry): handle adding pubspec.yaml
104 if (_shouldFileBeAnalyzed(event.path)) { 109 if (_shouldFileBeAnalyzed(event.path)) {
105 ChangeSet changeSet = new ChangeSet(); 110 ChangeSet changeSet = new ChangeSet();
106 Resource resource = resourceProvider.getResource(event.path); 111 Resource resource = resourceProvider.getResource(event.path);
107 // If the file went away and was replaced by a folder before we 112 // If the file went away and was replaced by a folder before we
108 // had a chance to process the event, resource might be a Folder. In 113 // had a chance to process the event, resource might be a Folder. In
109 // that case don't add it. 114 // that case don't add it.
110 if (resource is File) { 115 if (resource is File) {
111 File file = resource; 116 File file = resource;
112 Source source = file.createSource(UriKind.FILE_URI); 117 Source source = file.createSource(UriKind.FILE_URI);
(...skipping 13 matching lines...) Expand all
126 info.sources.remove(event.path); 131 info.sources.remove(event.path);
127 } 132 }
128 break; 133 break;
129 case ChangeType.MODIFY: 134 case ChangeType.MODIFY:
130 // TODO(paulberry): handle modification events 135 // TODO(paulberry): handle modification events
131 break; 136 break;
132 } 137 }
133 } 138 }
134 139
135 /** 140 /**
141 * Determine if the path from [folder] to [path] contains a 'packages'
142 * directory.
143 */
144 bool _isInPackagesDir(String path, Folder folder) {
145 String relativePath = resourceProvider.pathContext.relative(path, from: fold er.path);
146 List<String> pathParts = resourceProvider.pathContext.split(relativePath);
147 for (int i = 0; i < pathParts.length - 1; i++) {
148 if (pathParts[i] == 'packages') {
149 return true;
150 }
151 }
152 return false;
153 }
154
155 /**
136 * Resursively adds all Dart and HTML files to the [changeSet]. 156 * Resursively adds all Dart and HTML files to the [changeSet].
137 */ 157 */
138 static void _addSourceFiles(ChangeSet changeSet, Folder folder, _ContextDirect oryInfo info) { 158 static void _addSourceFiles(ChangeSet changeSet, Folder folder, _ContextDirect oryInfo info) {
139 List<Resource> children = folder.getChildren(); 159 List<Resource> children = folder.getChildren();
140 for (Resource child in children) { 160 for (Resource child in children) {
141 if (child is File) { 161 if (child is File) {
142 if (_shouldFileBeAnalyzed(child.path)) { 162 if (_shouldFileBeAnalyzed(child.path)) {
143 Source source = child.createSource(UriKind.FILE_URI); 163 Source source = child.createSource(UriKind.FILE_URI);
144 changeSet.addedSource(source); 164 changeSet.addedSource(source);
145 info.sources[child.path] = source; 165 info.sources[child.path] = source;
146 } 166 }
147 } else if (child is Folder) { 167 } else if (child is Folder) {
168 if (child.shortName == 'packages') {
169 // TODO(paulberry): perhaps we should only skip packages dirs if
170 // there is a pubspec.yaml?
171 continue;
172 }
148 _addSourceFiles(changeSet, child, info); 173 _addSourceFiles(changeSet, child, info);
149 } 174 }
150 } 175 }
151 } 176 }
152 177
153 static bool _shouldFileBeAnalyzed(String path) { 178 static bool _shouldFileBeAnalyzed(String path) {
154 return AnalysisEngine.isDartFileName(path) 179 return AnalysisEngine.isDartFileName(path)
155 || AnalysisEngine.isHtmlFileName(path); 180 || AnalysisEngine.isHtmlFileName(path);
156 } 181 }
157 182
158 /** 183 /**
159 * Called when a new context needs to be created. If the context is 184 * Called when a new context needs to be created. If the context is
160 * associated with a pubspec file, that file is passed in [pubspecFile]; 185 * associated with a pubspec file, that file is passed in [pubspecFile];
161 * otherwise it is null. 186 * otherwise it is null.
162 */ 187 */
163 void addContext(Folder folder, File pubspecFile); 188 void addContext(Folder folder, File pubspecFile);
164 189
165 /** 190 /**
166 * Called when the set of files associated with a context have changed (or 191 * Called when the set of files associated with a context have changed (or
167 * some of those files have been modified). [changeSet] is the set of 192 * some of those files have been modified). [changeSet] is the set of
168 * changes that need to be applied to the context. 193 * changes that need to be applied to the context.
169 */ 194 */
170 void applyChangesToContext(Folder contextFolder, ChangeSet changeSet); 195 void applyChangesToContext(Folder contextFolder, ChangeSet changeSet);
171 } 196 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analysis_server/lib/src/resource.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698