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

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

Issue 1152013002: Add support for specifying files needing analysis (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 7 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
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 import 'dart:collection'; 8 import 'dart:collection';
9 9
10 import 'package:analysis_server/src/analysis_server.dart'; 10 import 'package:analysis_server/src/analysis_server.dart';
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 }); 288 });
289 // add previously excluded sources 289 // add previously excluded sources
290 _contexts.forEach((folder, info) { 290 _contexts.forEach((folder, info) {
291 ChangeSet changeSet = new ChangeSet(); 291 ChangeSet changeSet = new ChangeSet();
292 _addPreviouslyExcludedSources(info, changeSet, folder, oldExcludedPaths); 292 _addPreviouslyExcludedSources(info, changeSet, folder, oldExcludedPaths);
293 applyChangesToContext(folder, changeSet); 293 applyChangesToContext(folder, changeSet);
294 }); 294 });
295 } 295 }
296 296
297 /** 297 /**
298 * Return `true` if the given [file] should be analyzed.
299 */
300 bool shouldFileBeAnalyzed(File file);
301
302 /**
298 * Called when the package map for a context has changed. 303 * Called when the package map for a context has changed.
299 */ 304 */
300 void updateContextPackageUriResolver( 305 void updateContextPackageUriResolver(
301 Folder contextFolder, UriResolver packageUriResolver); 306 Folder contextFolder, UriResolver packageUriResolver);
302 307
303 /** 308 /**
304 * Resursively adds all Dart and HTML files to the [changeSet]. 309 * Resursively adds all Dart and HTML files to the [changeSet].
305 */ 310 */
306 void _addPreviouslyExcludedSources(_ContextInfo info, ChangeSet changeSet, 311 void _addPreviouslyExcludedSources(_ContextInfo info, ChangeSet changeSet,
307 Folder folder, List<String> oldExcludedPaths) { 312 Folder folder, List<String> oldExcludedPaths) {
308 if (info.excludesResource(folder)) { 313 if (info.excludesResource(folder)) {
309 return; 314 return;
310 } 315 }
311 List<Resource> children; 316 List<Resource> children;
312 try { 317 try {
313 children = folder.getChildren(); 318 children = folder.getChildren();
314 } on FileSystemException { 319 } on FileSystemException {
315 // The folder no longer exists, or cannot be read, to there's nothing to 320 // The folder no longer exists, or cannot be read, to there's nothing to
316 // do. 321 // do.
317 return; 322 return;
318 } 323 }
319 for (Resource child in children) { 324 for (Resource child in children) {
320 String path = child.path; 325 String path = child.path;
321 // add files, recurse into folders 326 // add files, recurse into folders
322 if (child is File) { 327 if (child is File) {
323 // ignore if should not be analyzed at all 328 // ignore if should not be analyzed at all
324 if (!_shouldFileBeAnalyzed(child)) { 329 if (!shouldFileBeAnalyzed(child)) {
325 continue; 330 continue;
326 } 331 }
327 // ignore if was not excluded 332 // ignore if was not excluded
328 bool wasExcluded = _isExcludedBy(oldExcludedPaths, path) && 333 bool wasExcluded = _isExcludedBy(oldExcludedPaths, path) &&
329 !_isExcludedBy(excludedPaths, path); 334 !_isExcludedBy(excludedPaths, path);
330 if (!wasExcluded) { 335 if (!wasExcluded) {
331 continue; 336 continue;
332 } 337 }
333 // do add the file 338 // do add the file
334 Source source = createSourceInContext(info.context, child); 339 Source source = createSourceInContext(info.context, child);
(...skipping 24 matching lines...) Expand all
359 return; 364 return;
360 } 365 }
361 for (Resource child in children) { 366 for (Resource child in children) {
362 String path = child.path; 367 String path = child.path;
363 // ignore excluded files or folders 368 // ignore excluded files or folders
364 if (_isExcluded(path) || info.excludes(path)) { 369 if (_isExcluded(path) || info.excludes(path)) {
365 continue; 370 continue;
366 } 371 }
367 // add files, recurse into folders 372 // add files, recurse into folders
368 if (child is File) { 373 if (child is File) {
369 if (_shouldFileBeAnalyzed(child)) { 374 if (shouldFileBeAnalyzed(child)) {
370 Source source = createSourceInContext(info.context, child); 375 Source source = createSourceInContext(info.context, child);
371 changeSet.addedSource(source); 376 changeSet.addedSource(source);
372 info.sources[path] = source; 377 info.sources[path] = source;
373 } 378 }
374 } else if (child is Folder) { 379 } else if (child is Folder) {
375 String shortName = child.shortName; 380 String shortName = child.shortName;
376 if (shortName == PACKAGES_NAME) { 381 if (shortName == PACKAGES_NAME) {
377 continue; 382 continue;
378 } 383 }
379 _addSourceFiles(changeSet, child, info); 384 _addSourceFiles(changeSet, child, info);
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 // pubspec was added in a sub-folder, extract a new context 578 // pubspec was added in a sub-folder, extract a new context
574 if (_isPubspec(path) && info.isRoot && !info.isPubspec(path)) { 579 if (_isPubspec(path) && info.isRoot && !info.isPubspec(path)) {
575 _extractContext(info, resource); 580 _extractContext(info, resource);
576 return; 581 return;
577 } 582 }
578 // If the file went away and was replaced by a folder before we 583 // If the file went away and was replaced by a folder before we
579 // had a chance to process the event, resource might be a Folder. In 584 // had a chance to process the event, resource might be a Folder. In
580 // that case don't add it. 585 // that case don't add it.
581 if (resource is File) { 586 if (resource is File) {
582 File file = resource; 587 File file = resource;
583 if (_shouldFileBeAnalyzed(file)) { 588 if (shouldFileBeAnalyzed(file)) {
584 ChangeSet changeSet = new ChangeSet(); 589 ChangeSet changeSet = new ChangeSet();
585 Source source = createSourceInContext(info.context, file); 590 Source source = createSourceInContext(info.context, file);
586 changeSet.addedSource(source); 591 changeSet.addedSource(source);
587 applyChangesToContext(folder, changeSet); 592 applyChangesToContext(folder, changeSet);
588 info.sources[path] = source; 593 info.sources[path] = source;
589 } 594 }
590 } 595 }
591 break; 596 break;
592 case ChangeType.REMOVE: 597 case ChangeType.REMOVE:
593 // pubspec was removed, merge the context into its parent 598 // pubspec was removed, merge the context into its parent
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
699 static Source createSourceInContext(AnalysisContext context, File file) { 704 static Source createSourceInContext(AnalysisContext context, File file) {
700 // TODO(brianwilkerson) Optimize this, by allowing support for source 705 // TODO(brianwilkerson) Optimize this, by allowing support for source
701 // factories to restore URI's from a file path rather than a source. 706 // factories to restore URI's from a file path rather than a source.
702 Source source = file.createSource(); 707 Source source = file.createSource();
703 if (context == null) { 708 if (context == null) {
704 return source; 709 return source;
705 } 710 }
706 Uri uri = context.sourceFactory.restoreUri(source); 711 Uri uri = context.sourceFactory.restoreUri(source);
707 return file.createSource(uri); 712 return file.createSource(uri);
708 } 713 }
709
710 static bool _shouldFileBeAnalyzed(File file) {
711 if (!(AnalysisEngine.isDartFileName(file.path) ||
712 AnalysisEngine.isHtmlFileName(file.path))) {
713 return false;
714 }
715 // Emacs creates dummy links to track the fact that a file is open for
716 // editing and has unsaved changes (e.g. having unsaved changes to
717 // 'foo.dart' causes a link '.#foo.dart' to be created, which points to the
718 // non-existent file 'username@hostname.pid'. To avoid these dummy links
719 // causing the analyzer to thrash, just ignore links to non-existent files.
720 return file.exists;
721 }
722 } 714 }
723 715
724 /** 716 /**
725 * Information tracked by the [ContextManager] for each context. 717 * Information tracked by the [ContextManager] for each context.
726 */ 718 */
727 class _ContextInfo { 719 class _ContextInfo {
728 /** 720 /**
729 * The [Folder] for which this information object is created. 721 * The [Folder] for which this information object is created.
730 */ 722 */
731 final Folder folder; 723 final Folder folder;
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
802 return excludes(resource.path); 794 return excludes(resource.path);
803 } 795 }
804 796
805 /** 797 /**
806 * Returns `true` if [path] is the pubspec file of this context. 798 * Returns `true` if [path] is the pubspec file of this context.
807 */ 799 */
808 bool isPubspec(String path) { 800 bool isPubspec(String path) {
809 return path == pubspecPath; 801 return path == pubspecPath;
810 } 802 }
811 } 803 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/analysis_server.dart ('k') | pkg/analysis_server/lib/src/edit/edit_domain.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698