Skip to content

Commit 1366e22

Browse files
committed
Merge pull request microsoft#146 from kant2002/high_mem
Fix microsoft#138 Add medium level of IntelliSense / limit to the analysis depth (Related to microsoft#88). Limit depth analysys to relative paths which contains only 2 node_modules. This should be sufficient enough to capture a) Capture API of the root package b) Capture API of the dependencies. This is obiviously the must to analyze (1 node_modules) c) Capture API of subdependencies (2 node_modules). This is also the must, since a lot of packages are wrapper/glue for another library. For example using gulp-typescript require that gulp-typescript should be parsed (level b) and typescript should be parsed (level c) since typescritp provide some config options for gulp-typescript. Related to microsoft#88 microsoft#138 Added Medium level of Intellisense. This level now same as Full level, but limit analysis depth to the 2 nested modules depth. Full mode is now has limit to 4 modules depth which I almost sure practical enough, but could be increased if needed. Low level is analyse 1 level depth.
2 parents f18a3f4 + 74dffd6 commit 1366e22

File tree

8 files changed

+356
-153
lines changed

8 files changed

+356
-153
lines changed

Nodejs/Product/Analysis/Analysis/AnalysisLimits.cs

Lines changed: 70 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,43 @@ public AnalysisLimits() {
3434
MaxObjectLiteralProperties = 50;
3535
MaxObjectKeysTypes = 5;
3636
MaxMergeTypes = 5;
37+
38+
// There no practical reasons to go deeper in dependencies analysis.
39+
// Number 4 is very practical. Here the examples which hightlight idea.
40+
//
41+
// Example 1
42+
//
43+
// Level 0 - Large system. Some code should use properties of the object on level 4 here.
44+
// Level 1 - Subsystem - pass data from level 4
45+
// Level 2 - Internal dependency for company - Do some work and pass data to level 1
46+
// Level 3 - Framework on top of which created Internal dependency.
47+
// Level 4 - Dependency of the framework. Objects from here still should be available.
48+
// Level 5 - Dependency of the framework provide some usefull primitive which would be used very often on the level of whole system. Hmmm.
49+
//
50+
// Example 2 (reason why I could increase to 5)
51+
//
52+
// Level 0 - Large system. Some code should use properties of the object on level 4 here.
53+
// Level 1 - Subsystem - pass data from level 4
54+
// Level 2 - Internal dependency for company - Wrap access to internal library and perform business logic. Do some work and pass data to level 1
55+
// Level 3 - Internal library which wrap access to API.
56+
// Level 4 - Http library.
57+
// Level 5 - Promise Polyfill.
58+
//
59+
// All these examples are highly speculative and I specifically try to create such deep level.
60+
// If you develop on windows with such deep level you already close to your limit, your maximum is probably 10.
61+
NestedModulesLimit = 4;
62+
}
63+
64+
/// <summary>
65+
/// Creates instance of the <see cref="AnalysisLimits"/> for medium level of Intellisense support.
66+
/// </summary>
67+
/// <returns>An <see cref="AnalysisLimits"/> object representing medium level Initellisense settings.</returns>
68+
public static AnalysisLimits MakeMediumAnalysisLimits() {
69+
return new AnalysisLimits() {
70+
71+
// Maximum practical limit for the dependencies analysis oriented on producing faster results.
72+
NestedModulesLimit = 2
73+
};
3774
}
3875

3976
public static AnalysisLimits MakeLowAnalysisLimits() {
@@ -43,7 +80,8 @@ public static AnalysisLimits MakeLowAnalysisLimits() {
4380
DictKeyTypes = 1,
4481
DictValueTypes = 1,
4582
IndexTypes = 1,
46-
InstanceMembers = 1
83+
InstanceMembers = 1,
84+
NestedModulesLimit = 1
4785
};
4886
}
4987

@@ -111,6 +149,33 @@ public static AnalysisLimits MakeLowAnalysisLimits() {
111149
/// </summary>
112150
public int MaxMergeTypes { get; set; }
113151

152+
/// <summary>
153+
/// Gets the maximum level of dependency modules which could be analyzed.
154+
/// </summary>
155+
public int NestedModulesLimit { get; set; }
156+
157+
/// <summary>
158+
/// Checks whether relative path exceed the nested module limit.
159+
/// </summary>
160+
/// <param name="path">Path to module file which has to be checked for depth limit.</param>
161+
/// <returns>True if path too deep in nesting tree; false overwise.</returns>
162+
public bool IsPathExceedNestingLimit(string path) {
163+
int nestedModulesCount = 0;
164+
int startIndex = 0;
165+
int index = path.IndexOf(AnalysisConstants.NodeModulesFolder, startIndex, StringComparison.OrdinalIgnoreCase);
166+
while (index != -1) {
167+
nestedModulesCount++;
168+
if (nestedModulesCount > this.NestedModulesLimit){
169+
return true;
170+
}
171+
172+
startIndex = index + AnalysisConstants.NodeModulesFolder.Length;
173+
index = path.IndexOf(AnalysisConstants.NodeModulesFolder, startIndex, StringComparison.OrdinalIgnoreCase);
174+
}
175+
176+
return false;
177+
}
178+
114179
public override bool Equals(object obj) {
115180
AnalysisLimits other = obj as AnalysisLimits;
116181
if (other != null) {
@@ -125,7 +190,8 @@ public override bool Equals(object obj) {
125190
other.MaxArrayLiterals == MaxArrayLiterals &&
126191
other.MaxObjectLiteralProperties == MaxObjectLiteralProperties &&
127192
other.MaxObjectKeysTypes == MaxObjectKeysTypes &&
128-
other.MaxMergeTypes == MaxMergeTypes;
193+
other.MaxMergeTypes == MaxMergeTypes &&
194+
other.NestedModulesLimit == NestedModulesLimit;
129195
}
130196
return false;
131197
}
@@ -142,7 +208,8 @@ public override int GetHashCode() {
142208
MaxArrayLiterals +
143209
MaxObjectLiteralProperties +
144210
MaxObjectKeysTypes +
145-
MaxMergeTypes;
211+
MaxMergeTypes +
212+
NestedModulesLimit;
146213
}
147214
}
148215
}

Nodejs/Product/Nodejs/Intellisense/VsProjectAnalyzer.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1459,6 +1459,9 @@ private AnalysisLimits LoadLimits() {
14591459

14601460
if (NodejsPackage.Instance != null) {
14611461
switch (_analysisLevel) {
1462+
case Options.AnalysisLevel.Medium:
1463+
defaults = AnalysisLimits.MakeMediumAnalysisLimits();
1464+
break;
14621465
case Options.AnalysisLevel.Low:
14631466
defaults = _lowLimits;
14641467
break;
@@ -1500,6 +1503,7 @@ private static AnalysisLimits LoadLimitsFromStorage(RegistryKey key, AnalysisLim
15001503
limits.DictValueTypes = GetSetting(key, DictValueTypesId) ?? defaults.DictValueTypes;
15011504
limits.IndexTypes = GetSetting(key, IndexTypesId) ?? defaults.IndexTypes;
15021505
limits.AssignedTypes = GetSetting(key, AssignedTypesId) ?? defaults.AssignedTypes;
1506+
limits.NestedModulesLimit = GetSetting(key, NestedModulesLimitId) ?? defaults.NestedModulesLimit;
15031507

15041508
return limits;
15051509
}
@@ -1518,6 +1522,7 @@ private static AnalysisLimits LoadLimitsFromStorage(RegistryKey key, AnalysisLim
15181522
private const string DictValueTypesId = "DictValueTypes";
15191523
private const string IndexTypesId = "IndexTypes";
15201524
private const string AssignedTypesId = "AssignedTypes";
1525+
private const string NestedModulesLimitId = "NestedModulesLimit";
15211526

15221527
#endregion
15231528
}

Nodejs/Product/Nodejs/Options/AnalysisLevel.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ namespace Microsoft.NodejsTools.Options {
1818
enum AnalysisLevel {
1919
None,
2020
Low,
21+
Medium,
2122
High
2223
}
2324
}

Nodejs/Product/Nodejs/Options/NodejsIntellisenseOptionsControl.Designer.cs

Lines changed: 14 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Nodejs/Product/Nodejs/Options/NodejsIntellisenseOptionsControl.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ internal AnalysisLevel AnalysisLevel {
4242
get {
4343
if (_fullIntelliSenseRadioButton.Checked) {
4444
return AnalysisLevel.High;
45+
} else if (_mediumIntelliSenseRadioButton.Checked) {
46+
return AnalysisLevel.Medium;
4547
} else {
4648
return AnalysisLevel.None;
4749
}
@@ -51,6 +53,9 @@ internal AnalysisLevel AnalysisLevel {
5153
case AnalysisLevel.High:
5254
_fullIntelliSenseRadioButton.Checked = true;
5355
break;
56+
case AnalysisLevel.Medium:
57+
_mediumIntelliSenseRadioButton.Checked = true;
58+
break;
5459
case AnalysisLevel.None:
5560
_noIntelliSenseRadioButton.Checked = true;
5661
break;

0 commit comments

Comments
 (0)