-
Notifications
You must be signed in to change notification settings - Fork 217
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
Add regression test for untitled scripts in Windows PowerShell #1830
Changes from all commits
1818bf7
0d77907
7e94697
07d8577
95c9afe
bc123b4
bb9cdfe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,17 +2,17 @@ | |
// Licensed under the MIT License. | ||
|
||
using System; | ||
using System.Collections.Concurrent; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Security; | ||
using System.Text; | ||
using Microsoft.Extensions.FileSystemGlobbing; | ||
using Microsoft.Extensions.Logging; | ||
using Microsoft.PowerShell.EditorServices.Utility; | ||
using Microsoft.PowerShell.EditorServices.Services.Workspace; | ||
using Microsoft.PowerShell.EditorServices.Services.TextDocument; | ||
using System.Collections.Concurrent; | ||
using Microsoft.PowerShell.EditorServices.Services.Workspace; | ||
using Microsoft.PowerShell.EditorServices.Utility; | ||
using OmniSharp.Extensions.LanguageServer.Protocol; | ||
|
||
namespace Microsoft.PowerShell.EditorServices.Services | ||
|
@@ -152,8 +152,19 @@ public ScriptFile GetFile(DocumentUri documentUri) | |
/// </summary> | ||
/// <param name="filePath">The file path at which the script resides.</param> | ||
/// <param name="scriptFile">The out parameter that will contain the ScriptFile object.</param> | ||
public bool TryGetFile(string filePath, out ScriptFile scriptFile) => | ||
TryGetFile(new Uri(filePath), out scriptFile); | ||
public bool TryGetFile(string filePath, out ScriptFile scriptFile) | ||
{ | ||
// This might not have been given a file path, in which case the Uri constructor barfs. | ||
try | ||
{ | ||
return TryGetFile(new Uri(filePath), out scriptFile); | ||
} | ||
catch (UriFormatException) | ||
{ | ||
scriptFile = null; | ||
return false; | ||
} | ||
} | ||
Comment on lines
+155
to
+167
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had to change this one to catch the exception instead of using |
||
|
||
/// <summary> | ||
/// Tries to get an open file in the workspace. Returns true if it succeeds, false otherwise. | ||
|
@@ -301,7 +312,7 @@ public ScriptFile[] ExpandScriptReferences(ScriptFile scriptFile) | |
referencedScriptFiles.Add(scriptFile.Id, scriptFile); | ||
RecursivelyFindReferences(scriptFile, referencedScriptFiles); | ||
|
||
// remove original file from referened file and add it as the first element of the | ||
// remove original file from referenced file and add it as the first element of the | ||
// expanded referenced list to maintain order so the original file is always first in the list | ||
referencedScriptFiles.Remove(scriptFile.Id); | ||
expandedReferences.Add(scriptFile); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -651,6 +651,7 @@ public void DocumentUriReturnsCorrectStringForAbsolutePath() | |
[InlineData("vscode-notebook-cell:/Users/me/Documents/test.ps1#0001", true)] | ||
[InlineData("https://microsoft.com", true)] | ||
[InlineData("Untitled:Untitled-1", true)] | ||
[InlineData("'a log statement' > 'c:\\Users\\me\\Documents\\test.txt'\r\n", false)] | ||
public void IsUntitledFileIsCorrect(string path, bool expected) => Assert.Equal(expected, ScriptFile.IsUntitledPath(path)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See, this test implies that the function is asking "is this path a URI that indicates we're untitled?" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps we should expect this case to be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, doesn't work, since |
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Double-check me here please. As far as I can tell, this is expecting a URI?