Skip to content

Fix #138 Add medium level of IntelliSense / limit to the analysis depth (Related to #88). #146

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jun 26, 2015
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
73 changes: 70 additions & 3 deletions Nodejs/Product/Analysis/Analysis/AnalysisLimits.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,43 @@ public AnalysisLimits() {
MaxObjectLiteralProperties = 50;
MaxObjectKeysTypes = 5;
MaxMergeTypes = 5;

// There no practical reasons to go deeper in dependencies analysis.
// Number 4 is very practical. Here the examples which hightlight idea.
//
// Example 1
//
// Level 0 - Large system. Some code should use properties of the object on level 4 here.
// Level 1 - Subsystem - pass data from level 4
// Level 2 - Internal dependency for company - Do some work and pass data to level 1
// Level 3 - Framework on top of which created Internal dependency.
// Level 4 - Dependency of the framework. Objects from here still should be available.
// Level 5 - Dependency of the framework provide some usefull primitive which would be used very often on the level of whole system. Hmmm.
//
// Example 2 (reason why I could increase to 5)
//
// Level 0 - Large system. Some code should use properties of the object on level 4 here.
// Level 1 - Subsystem - pass data from level 4
// Level 2 - Internal dependency for company - Wrap access to internal library and perform business logic. Do some work and pass data to level 1
// Level 3 - Internal library which wrap access to API.
// Level 4 - Http library.
// Level 5 - Promise Polyfill.
//
// All these examples are highly speculative and I specifically try to create such deep level.
// If you develop on windows with such deep level you already close to your limit, your maximum is probably 10.
NestedModulesLimit = 4;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really want to mess with the high analysis limits here? How did you decide on 4?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reason for 4 following - I try to be very practical about numbers.

For small applications this number more then enough, and they don't have any issues dealing with some potential errors in Intellisense.

But if we have large application with Full setting, then VS Tools for Node.JS as a product immediately became unusable for that users.

I try to imagine dependency tree which exceed this 4 depth limit. Here the examples of trees about which I thought:

Example 1

Level 0 - Large system. Some code should use properties of the object on level 4 here.
Level 1 - Subsystem - pass data from level 4
Level 2 - Internal dependency for company - Do some work and pass data to level 1
Level 3 - Framework on top of which created Internal dependency.
Level 4 - Dependency of the framework. Objects from here still should be available.
Level 5 - Dependency of the framework provide some usefull primitive which would be used very often on the level of whole system. Hmmm.

Example 2 (reason why I could increase to 5)

Level 0 - Large system. Some code should use properties of the object on level 4 here.
Level 1 - Subsystem - pass data from level 4
Level 2 - Internal dependency for company - Wrap access to internal library and perform business logic. Do some work and pass data to level 1
Level 3 - Internal library which wrap access to API.
Level 4 - Http library.
Level 5 - Promise Polyfill.

All these examples are highly speculative and I specifically try to create such deep level. If you develop on windows with such deep level you already close to your limit, your maximum is probably 10.
If you have such deep structure already, chances that you have more then one such deep dependency is very high, and thus we just increase time for loading solution, loading analysis file and increase memory consumption without any practical benefits.

From my point of view practical benefits much better, and better have good and usable product with 90% working intellisense.
Or we just have 2 options: Medium and None without Full being usable by anyone on the large projects.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thanks for the detailed explanation. Logically it makes sense to me, though Dino has the most familiarity on this and what the edge cases might be, so it'll be great if he can chime in here too.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not seeing the change that actually limits this in the product? AnalysisTests\AnalysisFile will limit it when we run the tests, but won't do anything when running inside of VS.

Personally I would suggest not putting this in AnalysisLimits, and not having the analyzer actually be aware of this at all. The AnalysisLimits class is really used for limits on things when we're analyzing. But in this case we actually just don't want to analyze these files at all. Which means we also want to avoid parsing them entirely too.

Therefore I think the correct spot to put this limit in would be in NodejsFileNode.ShouldAnalyze. If you return false from there then we won't even bother parsing the file which should give the best performance gain.

}

/// <summary>
/// Creates instance of the <see cref="AnalysisLimits"/> for medium level of Intellisense support.
/// </summary>
/// <returns>An <see cref="AnalysisLimits"/> object representing medium level Initellisense settings.</returns>
public static AnalysisLimits MakeMediumAnalysisLimits() {
return new AnalysisLimits() {

// Maximum practical limit for the dependencies analysis oriented on producing faster results.
NestedModulesLimit = 2
};
}

public static AnalysisLimits MakeLowAnalysisLimits() {
Expand All @@ -43,7 +80,8 @@ public static AnalysisLimits MakeLowAnalysisLimits() {
DictKeyTypes = 1,
DictValueTypes = 1,
IndexTypes = 1,
InstanceMembers = 1
InstanceMembers = 1,
NestedModulesLimit = 1
};
}

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

/// <summary>
/// Gets the maximum level of dependency modules which could be analyzed.
/// </summary>
public int NestedModulesLimit { get; set; }

/// <summary>
/// Checks whether relative path exceed the nested module limit.
/// </summary>
/// <param name="path">Path to module file which has to be checked for depth limit.</param>
/// <returns>True if path too deep in nesting tree; false overwise.</returns>
public bool IsPathExceedNestingLimit(string path) {
int nestedModulesCount = 0;
int startIndex = 0;
int index = path.IndexOf(AnalysisConstants.NodeModulesFolder, startIndex, StringComparison.OrdinalIgnoreCase);
while (index != -1) {
nestedModulesCount++;
if (nestedModulesCount > this.NestedModulesLimit){
return true;
}

startIndex = index + AnalysisConstants.NodeModulesFolder.Length;
index = path.IndexOf(AnalysisConstants.NodeModulesFolder, startIndex, StringComparison.OrdinalIgnoreCase);
}

return false;
}

public override bool Equals(object obj) {
AnalysisLimits other = obj as AnalysisLimits;
if (other != null) {
Expand All @@ -125,7 +190,8 @@ public override bool Equals(object obj) {
other.MaxArrayLiterals == MaxArrayLiterals &&
other.MaxObjectLiteralProperties == MaxObjectLiteralProperties &&
other.MaxObjectKeysTypes == MaxObjectKeysTypes &&
other.MaxMergeTypes == MaxMergeTypes;
other.MaxMergeTypes == MaxMergeTypes &&
other.NestedModulesLimit == NestedModulesLimit;
}
return false;
}
Expand All @@ -142,7 +208,8 @@ public override int GetHashCode() {
MaxArrayLiterals +
MaxObjectLiteralProperties +
MaxObjectKeysTypes +
MaxMergeTypes;
MaxMergeTypes +
NestedModulesLimit;
}
}
}
5 changes: 5 additions & 0 deletions Nodejs/Product/Nodejs/Intellisense/VsProjectAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1459,6 +1459,9 @@ private AnalysisLimits LoadLimits() {

if (NodejsPackage.Instance != null) {
switch (_analysisLevel) {
case Options.AnalysisLevel.Medium:
defaults = AnalysisLimits.MakeMediumAnalysisLimits();
break;
case Options.AnalysisLevel.Low:
defaults = _lowLimits;
break;
Expand Down Expand Up @@ -1500,6 +1503,7 @@ private static AnalysisLimits LoadLimitsFromStorage(RegistryKey key, AnalysisLim
limits.DictValueTypes = GetSetting(key, DictValueTypesId) ?? defaults.DictValueTypes;
limits.IndexTypes = GetSetting(key, IndexTypesId) ?? defaults.IndexTypes;
limits.AssignedTypes = GetSetting(key, AssignedTypesId) ?? defaults.AssignedTypes;
limits.NestedModulesLimit = GetSetting(key, NestedModulesLimitId) ?? defaults.NestedModulesLimit;

return limits;
}
Expand All @@ -1518,6 +1522,7 @@ private static AnalysisLimits LoadLimitsFromStorage(RegistryKey key, AnalysisLim
private const string DictValueTypesId = "DictValueTypes";
private const string IndexTypesId = "IndexTypes";
private const string AssignedTypesId = "AssignedTypes";
private const string NestedModulesLimitId = "NestedModulesLimit";

#endregion
}
Expand Down
1 change: 1 addition & 0 deletions Nodejs/Product/Nodejs/Options/AnalysisLevel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ namespace Microsoft.NodejsTools.Options {
enum AnalysisLevel {
None,
Low,
Medium,
High
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ internal AnalysisLevel AnalysisLevel {
get {
if (_fullIntelliSenseRadioButton.Checked) {
return AnalysisLevel.High;
} else if (_mediumIntelliSenseRadioButton.Checked) {
return AnalysisLevel.Medium;
} else {
return AnalysisLevel.None;
}
Expand All @@ -51,6 +53,9 @@ internal AnalysisLevel AnalysisLevel {
case AnalysisLevel.High:
_fullIntelliSenseRadioButton.Checked = true;
break;
case AnalysisLevel.Medium:
_mediumIntelliSenseRadioButton.Checked = true;
break;
case AnalysisLevel.None:
_noIntelliSenseRadioButton.Checked = true;
break;
Expand Down
Loading