Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Nodejs/Product/Analysis/Analysis/Analyzer/AnalysisUnit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ namespace Microsoft.NodejsTools.Analysis {
/// Our dependency tracking scheme works by tracking analysis units - when we add a dependency it is the current
/// AnalysisUnit which is dependent upon the variable. If the value of a variable changes then all of the dependent
/// AnalysisUnit's will be re-enqueued. This proceeds until we reach a fixed point.
///
/// Note that AnalysisUnit contructors / methods are not threadsafe because we expect there to be many AnalysisUnits,
/// and we want to keep things as performant as possible (which means minimizing locking behavior and whatnot.)
/// </summary>
[Serializable]
internal class AnalysisUnit : ISet<AnalysisUnit> {
Expand Down
32 changes: 20 additions & 12 deletions Nodejs/Product/Analysis/Analysis/JsAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,12 @@ public IAnalyzable AddPackageJson(string filePath, string entryPoint, List<strin

tree.DefaultPackage = entryPoint;

var requireAnalysisUnits = new List<RequireAnalysisUnit>();
ProjectEntry projectEntry = null;
if (dependencies != null) {
var projectEntry = new ProjectEntry(this, filePath, null);
requireAnalysisUnits.AddRange(dependencies.Select(
dependency => { return new RequireAnalysisUnit(tree, Modules, projectEntry, dependency);
}));
projectEntry = new ProjectEntry(this, filePath, null);
}

return new TreeUpdateAnalysis(tree, requireAnalysisUnits);
return new TreeUpdateAnalysis(tree, dependencies, projectEntry, Modules);
}

/// <summary>
Expand All @@ -162,22 +159,33 @@ public IAnalyzable AddPackageJson(string filePath, string entryPoint, List<strin
[Serializable]
internal class TreeUpdateAnalysis : IAnalyzable {
private readonly ModuleTree _tree;
private readonly IEnumerable<RequireAnalysisUnit> _requireAnalysisUnits;
private readonly IEnumerable<string> _dependencies;
private readonly ProjectEntry _projectEntry;
private readonly ModuleTable _modules;

public TreeUpdateAnalysis(ModuleTree tree, IEnumerable<RequireAnalysisUnit> requireAnalysisUnits = null) {
public TreeUpdateAnalysis(ModuleTree tree, IEnumerable<string> dependencies = null, ProjectEntry projectEntry = null, ModuleTable modules = null) {
_tree = tree;
_requireAnalysisUnits = requireAnalysisUnits;
_dependencies = dependencies;
_projectEntry = projectEntry;
_modules = modules;
}

public void Analyze(CancellationToken cancel) {
if (_tree != null) {
_tree.EnqueueDependents();
}
if (_requireAnalysisUnits != null) {
foreach (var unit in _requireAnalysisUnits) {

if (_dependencies != null) {
var requireAnalysisUnits = new List<RequireAnalysisUnit>();
requireAnalysisUnits.AddRange(_dependencies.Select(
dependency => {
return new RequireAnalysisUnit(_tree, _modules, _projectEntry, dependency);
}));

foreach (var unit in requireAnalysisUnits) {
unit.AnalyzeWorker(null, cancel);
}
}
}
}
}

Expand Down