Skip to content
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

Fixed TextReader disposal #2137

Merged
merged 1 commit into from
Feb 15, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,14 @@ internal ScriptFile(
/// <param name="fileUri">The System.Uri of the file.</param>
/// <param name="initialBuffer">The initial contents of the script file.</param>
/// <param name="powerShellVersion">The version of PowerShell for which the script is being parsed.</param>
internal ScriptFile(
internal static ScriptFile Create(
DocumentUri fileUri,
string initialBuffer,
Version powerShellVersion)
: this(
fileUri,
new StringReader(initialBuffer),
powerShellVersion)

{
using TextReader textReader = new StringReader(initialBuffer);
return new ScriptFile(fileUri, textReader, powerShellVersion);
}

#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ public ScriptFile GetFileBuffer(DocumentUri documentUri, string initialBuffer)
if (!workspaceFiles.TryGetValue(keyName, out ScriptFile scriptFile) && initialBuffer != null)
{
scriptFile =
new ScriptFile(
ScriptFile.Create(
documentUri,
initialBuffer,
powerShellVersion);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void Dispose()
public async Task CanRegisterAndInvokeCommandWithCmdletName()
{
string filePath = TestUtilities.NormalizePath(@"C:\Temp\Test.ps1");
ScriptFile currentFile = new(new Uri(filePath), "This is a test file", new Version("7.0"));
ScriptFile currentFile = ScriptFile.Create(new Uri(filePath), "This is a test file", new Version("7.0"));
EditorContext editorContext = new(
editorOperations: null,
currentFile,
Expand Down Expand Up @@ -88,7 +88,7 @@ await psesHost.ExecutePSCommandAsync(
public async Task CanRegisterAndInvokeCommandWithScriptBlock()
{
string filePath = TestUtilities.NormalizePath(@"C:\Temp\Test.ps1");
ScriptFile currentFile = new(new Uri(filePath), "This is a test file", new Version("7.0"));
ScriptFile currentFile = ScriptFile.Create(new Uri(filePath), "This is a test file", new Version("7.0"));
EditorContext editorContext = new(
editorOperations: null,
currentFile,
Expand Down Expand Up @@ -150,7 +150,7 @@ await psesHost.ExecutePSCommandAsync(
public async Task CanUnregisterCommand()
{
string filePath = TestUtilities.NormalizePath(@"C:\Temp\Test.ps1");
ScriptFile currentFile = new(new Uri(filePath), "This is a test file", new Version("7.0"));
ScriptFile currentFile = ScriptFile.Create(new Uri(filePath), "This is a test file", new Version("7.0"));
EditorContext editorContext = new(
editorOperations: null,
currentFile,
Expand Down
12 changes: 6 additions & 6 deletions test/PowerShellEditorServices.Test/Language/SemanticTokenTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function Get-Sum {
return $a + $b
}
";
ScriptFile scriptFile = new(
ScriptFile scriptFile = ScriptFile.Create(
// Use any absolute path. Even if it doesn't exist.
DocumentUri.FromFileSystemPath(Path.Combine(Path.GetTempPath(), "TestFile.ps1")),
text,
Expand Down Expand Up @@ -61,7 +61,7 @@ function Get-Sum {
public void TokenizesStringExpansion()
{
const string text = "Write-Host \"$(Test-Property Get-Whatever) $(Get-Whatever)\"";
ScriptFile scriptFile = new(
ScriptFile scriptFile = ScriptFile.Create(
// Use any absolute path. Even if it doesn't exist.
DocumentUri.FromFileSystemPath(Path.Combine(Path.GetTempPath(), "TestFile.ps1")),
text,
Expand All @@ -88,7 +88,7 @@ function Get-A*A {
}
Get-A*A
";
ScriptFile scriptFile = new(
ScriptFile scriptFile = ScriptFile.Create(
// Use any absolute path. Even if it doesn't exist.
DocumentUri.FromFileSystemPath(Path.Combine(Path.GetTempPath(), "TestFile.ps1")),
text,
Expand All @@ -113,7 +113,7 @@ function Get-A*A {
public void RecognizesArrayPropertyInExpandableString()
{
const string text = "\"$(@($Array).Count) OtherText\"";
ScriptFile scriptFile = new(
ScriptFile scriptFile = ScriptFile.Create(
// Use any absolute path. Even if it doesn't exist.
DocumentUri.FromFileSystemPath(Path.Combine(Path.GetTempPath(), "TestFile.ps1")),
text,
Expand All @@ -138,7 +138,7 @@ public void RecognizesArrayPropertyInExpandableString()
public void RecognizesCurlyQuotedString()
{
const string text = "“^[-'a-z]*”";
ScriptFile scriptFile = new(
ScriptFile scriptFile = ScriptFile.Create(
// Use any absolute path. Even if it doesn't exist.
DocumentUri.FromFileSystemPath(Path.Combine(Path.GetTempPath(), "TestFile.ps1")),
text,
Expand All @@ -158,7 +158,7 @@ enum MyEnum{
three
}
";
ScriptFile scriptFile = new(
ScriptFile scriptFile = ScriptFile.Create(
// Use any absolute path. Even if it doesn't exist.
DocumentUri.FromFileSystemPath(Path.Combine(Path.GetTempPath(), "TestFile.ps1")),
text,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class TokenOperationsTests
/// </summary>
private static FoldingReference[] GetRegions(string text)
{
ScriptFile scriptFile = new(
ScriptFile scriptFile = ScriptFile.Create(
// Use any absolute path. Even if it doesn't exist.
DocumentUri.FromFileSystemPath(Path.Combine(Path.GetTempPath(), "TestFile.ps1")),
text,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class WorkspaceTests
? s_lazyDriveLetter.Value
: string.Empty;

internal static ScriptFile CreateScriptFile(string path) => new(path, "", VersionUtils.PSVersion);
internal static ScriptFile CreateScriptFile(string path) => ScriptFile.Create(path, "", VersionUtils.PSVersion);

// Remember that LSP does weird stuff to the drive letter, so we have to convert it to a URI
// and back to ensure that drive letter gets lower cased and everything matches up.
Expand Down
Loading