diff --git a/Engine/Formatter.cs b/Engine/Formatter.cs index d2b7e0776..76557856d 100644 --- a/Engine/Formatter.cs +++ b/Engine/Formatter.cs @@ -59,7 +59,7 @@ public static string Format( Range updatedRange; bool fixesWereApplied; - text = ScriptAnalyzer.Instance.Fix(text, range, out updatedRange, out fixesWereApplied); + text = ScriptAnalyzer.Instance.Fix(text, range, out updatedRange, out fixesWereApplied, skipVariableAnalysis: true); range = updatedRange; } diff --git a/Engine/ScriptAnalyzer.cs b/Engine/ScriptAnalyzer.cs index 18fc06bf8..811c265fd 100644 --- a/Engine/ScriptAnalyzer.cs +++ b/Engine/ScriptAnalyzer.cs @@ -1499,7 +1499,7 @@ public IEnumerable AnalyzeAndFixPath(string path, Func /// The script to be analyzed /// - public IEnumerable AnalyzeScriptDefinition(string scriptDefinition) + public IEnumerable AnalyzeScriptDefinition(string scriptDefinition, bool skipVariableAnalysis = false) { ScriptBlockAst scriptAst = null; Token[] scriptTokens = null; @@ -1539,7 +1539,7 @@ public IEnumerable AnalyzeScriptDefinition(string scriptDefini } // now, analyze the script definition - return diagnosticRecords.Concat(this.AnalyzeSyntaxTree(scriptAst, scriptTokens, String.Empty)); + return diagnosticRecords.Concat(this.AnalyzeSyntaxTree(scriptAst, scriptTokens, String.Empty, skipVariableAnalysis)); } /// @@ -1566,8 +1566,9 @@ public string Fix(string scriptDefinition, out bool fixesWereApplied) /// The range in which the fixes are allowed. /// The updated range after the fixes have been applied. /// Whether any warnings were fixed. + /// Whether to skip variable analysis. /// The same instance of `EditableText` that was passed to the method, but the instance encapsulates the fixed script text. This helps in chaining the Fix method. - public EditableText Fix(EditableText text, Range range, out Range updatedRange, out bool fixesWereApplied) + public EditableText Fix(EditableText text, Range range, out Range updatedRange, out bool fixesWereApplied, bool skipVariableAnalysis = false) { if (text == null) { @@ -1589,7 +1590,7 @@ public EditableText Fix(EditableText text, Range range, out Range updatedRange, var previousUnusedCorrections = 0; do { - var records = AnalyzeScriptDefinition(text.ToString()); + var records = AnalyzeScriptDefinition(text.ToString(), skipVariableAnalysis); var corrections = records .Select(r => r.SuggestedCorrections) .Where(sc => sc != null && sc.Any()) @@ -2016,13 +2017,15 @@ DiagnosticRecord ruleDiagnosticRecord /// The ScriptBlockAst from the parsed script. /// The tokens found in the script. /// The path to the file that was parsed. + /// Whether to skip variable analysis. /// If AnalyzeSyntaxTree is called from an ast that we get from ParseInput, then this field will be String.Empty /// /// An enumeration of DiagnosticRecords that were found by rules. public IEnumerable AnalyzeSyntaxTree( ScriptBlockAst scriptAst, Token[] scriptTokens, - string filePath) + string filePath, + bool skipVariableAnalysis = false) { Dictionary> ruleSuppressions = new Dictionary>(); ConcurrentBag diagnostics = new ConcurrentBag(); @@ -2053,13 +2056,16 @@ public IEnumerable AnalyzeSyntaxTree( } } -#region Run VariableAnalysis - try + if (!skipVariableAnalysis) { - Helper.Instance.InitializeVariableAnalysis(scriptAst); - } - catch { } +#region Run VariableAnalysis + try + { + Helper.Instance.InitializeVariableAnalysis(scriptAst); + } + catch { } #endregion + } Helper.Instance.Tokens = scriptTokens; }