public void RemoveCircular() { var reachable = new HashSet <string>(); var roots = new HashSet <string>() { @"C:\dev\app\src\main.rs", @"C:\dev\app\src\foo.rs" }; var imports = new ModuleImport() { { new PathSegment("frob.rs", true), new ModuleImport() }, }; var frobImports = new ModuleImport() { { new PathSegment("in1", true), new ModuleImport() { { new PathSegment("in2.rs", true), new ModuleImport() } } } }; var in2Imports = new ModuleImport() { { new PathSegment("ext1.rs", true), new ModuleImport() }, { new PathSegment("ext2.rs", true), new ModuleImport() }, { new PathSegment(@"..\frob.rs", true), new ModuleImport() }, { new PathSegment(@"..\main.rs", true), new ModuleImport() }, { new PathSegment(@"..\foo.rs", true), new ModuleImport() }, }; var tracker = new ModuleTracker(@"C:\dev\app\src\main.rs"); foreach (string path in roots) { tracker.AddRootModule(path); } tracker.ExtractReachableAndMakeIncremental(); var orphanSet = tracker.DeleteModule(@"C:\dev\app\src\in1\in2.rs"); }
internal void IncludeFileNode(UntrackedFileNode node) { string path = node.Url; ModuleTracker.UpgradeModule(path); TreeOperations.Replace(this, node, () => CreateFileNode(path)); }
public void ExtractSimple() { // src\main.rs referenced nothing, we now scan src\foo.rs, which references two empty modules var reachable = new HashSet <string>(); var roots = new HashSet <string>() { @"C:\dev\app\src\main.rs", @"C:\dev\app\src\foo.rs" }; var importPath = @"C:\dev\app\src\foo.rs"; var imports = new ModuleImport() { { new PathSegment("bar.rs", true), new ModuleImport() }, { new PathSegment("baz.rs", true), new ModuleImport() } }; var tracker = new ModuleTracker(@"C:\dev\app\src\main.rs"); tracker.ExtractReachableModules(new Dictionary <string, HashSet <string> >(), reachable, key => roots.Contains(key), importPath, (s) => s.EndsWith("foo.rs") ? imports : new ModuleImport()); Assert.AreEqual(2, reachable.Count); Assert.True(reachable.Contains(@"C:\dev\app\src\bar.rs")); Assert.True(reachable.Contains(@"C:\dev\app\src\baz.rs")); Assert.AreEqual(1, tracker.moduleImportMap.Count); Assert.AreEqual(2, tracker.moduleImportMap[@"C:\dev\app\src\foo.rs"].Count); CollectionAssert.Contains(tracker.moduleImportMap[@"C:\dev\app\src\foo.rs"], @"C:\dev\app\src\bar.rs"); CollectionAssert.Contains(tracker.moduleImportMap[@"C:\dev\app\src\foo.rs"], @"C:\dev\app\src\baz.rs"); }
// It's formatted this way to make unit test failures more readable public bool IsEquivalnet(ModuleTracker other) { if (EntryPoint != other.EntryPoint) { return(false); } if (!AreEqual(this.fileRoots, other.fileRoots)) { return(false); } if (!AreEqual(this.blockingRoots, other.blockingRoots)) { return(false); } if (!AreEqual(this.moduleImportMap, other.moduleImportMap)) { return(false); } if (!AreEqual(this.reverseModuleImportMap, other.reverseModuleImportMap)) { return(false); } if (!AreEqual <string>(this.lastParseResult, other.lastParseResult)) { return(false); } return(true); }
internal void DisableAutoImport(BaseFileNode node) { var orphans = ModuleTracker.DisableTracking(node.Url); foreach (string mod in orphans) { TreeOperations.RemoveSubnodeFromHierarchy(this, mod, false); } }
internal void OnNodeIncluded(TrackedFileNode node) { HashSet <string> children = ModuleTracker.AddRootModuleIncremental(node.Url); foreach (string child in children) { HierarchyNode parent = this.CreateFolderNodes(Path.GetDirectoryName(child), false); parent.AddChild(CreateUntrackedNode(child)); } }
internal void EnableAutoImport(BaseFileNode node) { var newMods = ModuleTracker.EnableTracking(node.Url); foreach (string mod in newMods) { HierarchyNode parent = this.CreateFolderNodes(Path.GetDirectoryName(mod), false); parent.AddChild(CreateUntrackedNode(mod)); } }
internal void ReparseFileNode(BaseFileNode n) { var diff = ModuleTracker.Reparse(n.Url); foreach (string mod in diff.Removed) { TreeOperations.RemoveSubnodeFromHierarchy(this, mod, false); } foreach (string mod in diff.Added) { HierarchyNode parent = this.CreateFolderNodes(Path.GetDirectoryName(mod), false); parent.AddChild(CreateUntrackedNode(mod)); } }
internal void ExcludeFileNode(BaseFileNode srcNode) { // Ask mod tracker for a professional opinion string fullPath = srcNode.Url; ModuleRemovalResult downgradeResult = ModuleTracker.DowngradeModule(fullPath); if (downgradeResult.IsReferenced) { TreeOperations.Replace(this, srcNode, () => CreateUntrackedNode(fullPath)); } else { foreach (string path in downgradeResult.Orphans) { TreeOperations.RemoveSubnodeFromHierarchy(this, path, false); } } }
private TrackedFileNode CreateTrackedNode(ProjectElement elm) { var node = new TrackedFileNode(this, elm); if (!ModuleTracker.IsIncremental) { ModuleTracker.AddRootModule(node.Url); } else { HashSet <string> children = ModuleTracker.AddRootModuleIncremental(node.Url); foreach (string child in children) { HierarchyNode parent = this.CreateFolderNodes(Path.GetDirectoryName(child), false); parent.AddChild(CreateUntrackedNode(child)); } } return(node); }
protected void ReloadCore() { string outputType = GetProjectProperty(ProjectFileConstants.OutputType, true); string entryPoint = GetCrateFileNodePath(outputType); containsEntryPoint = GetCrateFileNode(outputType) != null; ModuleTracker = new ModuleTracker(entryPoint); base.Reload(); // This project for some reason doesn't include entrypoint node, add it if (!containsEntryPoint) { HierarchyNode parent = this.CreateFolderNodes(Path.GetDirectoryName(entryPoint), true); TrackedFileNode node = (TrackedFileNode)this.CreateFileNode(entryPoint); node.IsEntryPoint = true; parent.AddChild(node); } MarkEntryPointFolders(outputType); foreach (string file in ModuleTracker.ExtractReachableAndMakeIncremental()) { HierarchyNode parent = this.CreateFolderNodes(Path.GetDirectoryName(file), false); parent.AddChild(CreateUntrackedNode(file)); } }
protected override void Reload() { string outputType = GetProjectProperty(ProjectFileConstants.OutputType, false); string entryPoint = Path.Combine(Path.GetDirectoryName(this.FileName), outputType == "library" ? @"src\lib.rs" : @"src\main.rs"); containsEntryPoint = false; ModuleTracker = new ModuleTracker(entryPoint); base.Reload(); // This project for some reason doesn't include entrypoint node, add it if (!containsEntryPoint) { HierarchyNode parent = this.CreateFolderNodes(Path.GetDirectoryName(entryPoint), true); TrackedFileNode node = (TrackedFileNode)this.CreateFileNode(entryPoint); node.IsEntryPoint = true; parent.AddChild(node); } foreach (string file in ModuleTracker.ExtractReachableAndMakeIncremental()) { HierarchyNode parent = this.CreateFolderNodes(Path.GetDirectoryName(file), false); parent.AddChild(CreateUntrackedNode(file)); } this.BuildProject.Save(); }