diff --git a/pkg/analysis_server/lib/src/context_manager.dart b/pkg/analysis_server/lib/src/context_manager.dart index 8d22758b77f..723c9c7d069 100644 --- a/pkg/analysis_server/lib/src/context_manager.dart +++ b/pkg/analysis_server/lib/src/context_manager.dart @@ -844,9 +844,13 @@ class ContextManagerImpl implements ContextManager { packageSpec = folder.getChild(PUBSPEC_NAME); } - bool parentCreated = false; - if (packageSpec.exists || !withPackageSpecOnly) { - parentCreated = true; + bool createContext = packageSpec.exists || !withPackageSpecOnly; + if (withPackageSpecOnly && packageSpec.exists && + (parent != null) && parent.ignored(packageSpec.path)) { + // Don't create a context if the package spec is required and ignored. + createContext = false; + } + if (createContext) { parent = _createContext(parent, folder, packageSpec); } @@ -854,7 +858,9 @@ class ContextManagerImpl implements ContextManager { try { for (Resource child in folder.getChildren()) { if (child is Folder) { - _createContexts(parent, child, true); + if (!parent.ignored(child.path)) { + _createContexts(parent, child, true); + } } } } on FileSystemException { @@ -862,7 +868,7 @@ class ContextManagerImpl implements ContextManager { // are no subfolders that need to be added. } - if (parentCreated) { + if (createContext) { // Now that the child contexts have been created, add the sources that // don't belong to the children. ChangeSet changeSet = new ChangeSet(); diff --git a/pkg/analysis_server/test/context_manager_test.dart b/pkg/analysis_server/test/context_manager_test.dart index b8f2b6c6455..d81f338c4cb 100644 --- a/pkg/analysis_server/test/context_manager_test.dart +++ b/pkg/analysis_server/test/context_manager_test.dart @@ -231,6 +231,96 @@ analyzer: expect(files[0], equals('/my/proj/lib/main.dart')); } + test_path_filter_child_contexts_option() async { + // Create files. + String libPath = newFolder([projPath, LIB_NAME]); + newFile([libPath, 'main.dart']); + newFile([libPath, 'pubspec.yaml'], r''' +name: foobar +'''); + String otherLibPath = newFolder([projPath, 'other_lib']); + newFile([otherLibPath, 'entry.dart']); + newFile([otherLibPath, 'pubspec.yaml'], r''' +name: other_lib +'''); + // Setup analysis options file with ignore list that ignores the 'other_lib' + // directory by name. + newFile([projPath, '.analysis_options'], r''' +analyzer: + exclude: + - 'other_lib' +'''); + // Setup context. + manager.setRoots([projPath], [], {}); + // Verify that the context in other_lib wasn't created and that the + // context in lib was created. + var contexts = manager.contextsInAnalysisRoot( + resourceProvider.newFolder(projPath)); + expect(contexts.length, 2); + expect(contexts[0].name, equals('/my/proj')); + expect(contexts[1].name, equals('/my/proj/lib')); + } + + test_path_filter_wildcard_child_contexts_option() async { + // Create files. + String libPath = newFolder([projPath, LIB_NAME]); + newFile([libPath, 'main.dart']); + newFile([libPath, 'pubspec.yaml'], r''' +name: foobar +'''); + String otherLibPath = newFolder([projPath, 'other_lib']); + newFile([otherLibPath, 'entry.dart']); + newFile([otherLibPath, 'pubspec.yaml'], r''' +name: other_lib +'''); + // Setup analysis options file with ignore list that ignores 'other_lib' + // and all immediate children. + newFile([projPath, '.analysis_options'], r''' +analyzer: + exclude: + - 'other_lib/*' +'''); + // Setup context. + manager.setRoots([projPath], [], {}); + // Verify that the context in other_lib wasn't created and that the + // context in lib was created. + var contexts = manager.contextsInAnalysisRoot( + resourceProvider.newFolder(projPath)); + expect(contexts.length, 2); + expect(contexts[0].name, equals('/my/proj')); + expect(contexts[1].name, equals('/my/proj/lib')); + } + + test_path_filter_recursive_wildcard_child_contexts_option() async { + // Create files. + String libPath = newFolder([projPath, LIB_NAME]); + newFile([libPath, 'main.dart']); + newFile([libPath, 'pubspec.yaml'], r''' + name: foobar + '''); + String otherLibPath = newFolder([projPath, 'other_lib']); + newFile([otherLibPath, 'entry.dart']); + newFile([otherLibPath, 'pubspec.yaml'], r''' + name: other_lib + '''); + // Setup analysis options file with ignore list that ignores 'other_lib' + // and all descendants. + newFile([projPath, '.analysis_options'], r''' +analyzer: + exclude: + - 'other_lib/**' + '''); + // Setup context. + manager.setRoots([projPath], [], {}); + // Verify that the context in other_lib wasn't created and that the + // context in lib was created. + var contexts = manager.contextsInAnalysisRoot( + resourceProvider.newFolder(projPath)); + expect(contexts.length, 2); + expect(contexts[0].name, equals('/my/proj')); + expect(contexts[1].name, equals('/my/proj/lib')); + } + test_refresh_folder_with_packagespec() { // create a context with a .packages file String packagespecFile = posix.join(projPath, '.packages'); diff --git a/pkg/analyzer/lib/source/path_filter.dart b/pkg/analyzer/lib/source/path_filter.dart index 6e54ac6549d..f4123f88321 100644 --- a/pkg/analyzer/lib/source/path_filter.dart +++ b/pkg/analyzer/lib/source/path_filter.dart @@ -62,4 +62,13 @@ class PathFilter { /// Returns the relative portion of [path] from [root]. String _relative(String path) => pathContext.relative(path, from: root); + + String toString() { + StringBuffer sb = new StringBuffer(); + for (var pattern in _ignorePatterns) { + sb.write('$pattern '); + } + sb.writeln(''); + return sb.toString(); + } }