diff --git a/src/PowerShellEditorServices/Workspace/ScriptFile.cs b/src/PowerShellEditorServices/Workspace/ScriptFile.cs index dab2918ccc..d36fb2669e 100644 --- a/src/PowerShellEditorServices/Workspace/ScriptFile.cs +++ b/src/PowerShellEditorServices/Workspace/ScriptFile.cs @@ -26,7 +26,6 @@ public class ScriptFile "\n" }; - private Token[] scriptTokens; private Version powerShellVersion; #endregion @@ -116,7 +115,8 @@ public ScriptBlockAst ScriptAst /// public Token[] ScriptTokens { - get { return this.scriptTokens; } + get; + private set; } /// @@ -146,11 +146,16 @@ public ScriptFile( TextReader textReader, Version powerShellVersion) { + this.powerShellVersion = powerShellVersion; + this.FilePath = filePath; this.ClientFilePath = clientFilePath; this.IsAnalysisEnabled = true; this.IsInMemory = Workspace.IsPathInMemory(filePath); - this.powerShellVersion = powerShellVersion; + this.ReferencedFiles = new string[0]; + this.SyntaxMarkers = new ScriptFileMarker[0]; + this.FileLines = new List(); + this.ScriptTokens = new Token[0]; this.SetFileContents(textReader.ReadToEnd()); } @@ -600,6 +605,8 @@ private void ParseFileContents() try { #if PowerShellv5r2 + Token[] scriptTokens; + // This overload appeared with Windows 10 Update 1 if (this.powerShellVersion.Major >= 5 && this.powerShellVersion.Build >= 10586) @@ -610,7 +617,7 @@ private void ParseFileContents() Parser.ParseInput( this.Contents, this.FilePath, - out this.scriptTokens, + out scriptTokens, out parseErrors); } else @@ -618,9 +625,11 @@ private void ParseFileContents() this.ScriptAst = Parser.ParseInput( this.Contents, - out this.scriptTokens, + out scriptTokens, out parseErrors); } + + this.ScriptTokens = scriptTokens; #else this.ScriptAst = Parser.ParseInput( @@ -638,7 +647,7 @@ private void ParseFileContents() ex.Message); parseErrors = new[] { parseError }; - this.scriptTokens = new Token[0]; + this.ScriptTokens = new Token[0]; this.ScriptAst = null; }