diff --git a/EditorServicesCommandSuite.build.ps1 b/EditorServicesCommandSuite.build.ps1
index 03ba06c..f573b61 100644
--- a/EditorServicesCommandSuite.build.ps1
+++ b/EditorServicesCommandSuite.build.ps1
@@ -181,7 +181,7 @@ task DoTest {
InvokeWithPSModulePath {
& $dotnet test `
- --framework netcoreapp2.0 `
+ --framework netcoreapp3.1 `
--configuration Test `
--logger "trx;LogFileName=$PSScriptRoot/TestResults/results.trx" `
-nologo
diff --git a/module/EditorServicesCommandSuite.psd1 b/module/EditorServicesCommandSuite.psd1
index 036cf7d..9200699 100644
--- a/module/EditorServicesCommandSuite.psd1
+++ b/module/EditorServicesCommandSuite.psd1
@@ -92,7 +92,7 @@ PrivateData = @{
'@
# Prerelease string of this module
- Prerelease = 'beta3'
+ Prerelease = 'beta4'
} # End of PSData hashtable
diff --git a/nuget.config b/nuget.config
deleted file mode 100644
index 43acfbb..0000000
--- a/nuget.config
+++ /dev/null
@@ -1,9 +0,0 @@
-
-
-
-
-
-
-
-
-
diff --git a/src/EditorServicesCommandSuite.Common.props b/src/EditorServicesCommandSuite.Common.props
index 1e7966f..92595eb 100644
--- a/src/EditorServicesCommandSuite.Common.props
+++ b/src/EditorServicesCommandSuite.Common.props
@@ -6,19 +6,19 @@
Debug;Release;Test
true
preview
- netstandard2.0;netcoreapp2.0
+ netstandard2.0;netcoreapp3.1
1.0.0.0
-
+
-
+
-
-
+
+
TEST
diff --git a/src/EditorServicesCommandSuite.EditorServices/DocumentService.cs b/src/EditorServicesCommandSuite.EditorServices/DocumentService.cs
index 8448581..ef49e81 100644
--- a/src/EditorServicesCommandSuite.EditorServices/DocumentService.cs
+++ b/src/EditorServicesCommandSuite.EditorServices/DocumentService.cs
@@ -75,7 +75,7 @@ public async Task WriteDocumentEditsAsync(IEnumerable edits, Cance
textEdits.Add(textEdit);
}
- var versionedIdentifier = new VersionedTextDocumentIdentifier
+ var versionedIdentifier = new OptionalVersionedTextDocumentIdentifier
{
Uri = DocumentUri.From(editGroup.Key ?? context.Uri),
Version = default,
diff --git a/src/EditorServicesCommandSuite.EditorServices/EditorServicesCommandSuite.EditorServices.csproj b/src/EditorServicesCommandSuite.EditorServices/EditorServicesCommandSuite.EditorServices.csproj
index 8f3f733..2a208ed 100644
--- a/src/EditorServicesCommandSuite.EditorServices/EditorServicesCommandSuite.EditorServices.csproj
+++ b/src/EditorServicesCommandSuite.EditorServices/EditorServicesCommandSuite.EditorServices.csproj
@@ -1,13 +1,7 @@
-
-
- $(RestoreAdditionalProjectSources)
- https://www.myget.org/F/omnisharp/api/v3/index.json
-
-
-
+
..\..\lib\PowerShellEditorServices\bin\Microsoft.PowerShell.EditorServices.dll
diff --git a/src/EditorServicesCommandSuite/CodeGeneration/DocumentEditWriter.cs b/src/EditorServicesCommandSuite/CodeGeneration/DocumentEditWriter.cs
index b7c608a..d24fa2f 100644
--- a/src/EditorServicesCommandSuite/CodeGeneration/DocumentEditWriter.cs
+++ b/src/EditorServicesCommandSuite/CodeGeneration/DocumentEditWriter.cs
@@ -94,7 +94,7 @@ public virtual string TabString
}
}
- internal static Encoding DefaultEncoding { get; set; } = Encoding.ASCII;
+ internal static Encoding DefaultEncoding { get; set; } = Encoding.Unicode;
internal virtual IEnumerable Edits
{
diff --git a/src/EditorServicesCommandSuite/CodeGeneration/PowerShellScriptWriter.cs b/src/EditorServicesCommandSuite/CodeGeneration/PowerShellScriptWriter.cs
index 7a9749a..4558efb 100644
--- a/src/EditorServicesCommandSuite/CodeGeneration/PowerShellScriptWriter.cs
+++ b/src/EditorServicesCommandSuite/CodeGeneration/PowerShellScriptWriter.cs
@@ -699,6 +699,18 @@ internal void WriteAsExpressionValue(Parameter parameter, bool shouldNotWriteHin
if (parameter.Value.ConstantValue is bool boolean)
{
+ // Switch parameters lie sometimes, e.g. `-Verbose:$something.Value` will
+ // still report "ConstantValue: $true".
+ if (parameter.Value.Value is not null)
+ {
+ string astString = parameter.Value.Value.ToString();
+ if (!string.IsNullOrEmpty(astString))
+ {
+ Write(astString);
+ return;
+ }
+ }
+
Write(Dollar + boolean.ToString().ToLower());
return;
}
diff --git a/src/EditorServicesCommandSuite/CodeGeneration/Refactors/CommandSplatRefactor.cs b/src/EditorServicesCommandSuite/CodeGeneration/Refactors/CommandSplatRefactor.cs
index ac08af3..cd7f86d 100644
--- a/src/EditorServicesCommandSuite/CodeGeneration/Refactors/CommandSplatRefactor.cs
+++ b/src/EditorServicesCommandSuite/CodeGeneration/Refactors/CommandSplatRefactor.cs
@@ -186,16 +186,16 @@ await AddAdditionalParameters(
unresolvedBinding = StaticParameterBinder.BindCommand(args.Command, resolve: false);
}
- bool isBound = unresolvedBinding.BoundParameters.TryGetValue(
- bindingException.Key,
- out ParameterBindingResult unresolvedResult);
+ if (unresolvedBinding.BoundParameters.TryGetValue(bindingException.Key, out ParameterBindingResult unresolvedResult))
+ {
+ parameterList.Add(new Parameter(bindingException.Key, unresolvedResult));
+ continue;
+ }
- if (isBound)
+ if (bindingException.Value.BindingException is ParameterBindingException pbe
+ && unresolvedBinding.BoundParameters.TryGetValue(pbe.ParameterName, out unresolvedResult))
{
- parameterList.Add(
- new Parameter(
- bindingException.Key,
- unresolvedResult));
+ parameterList.Add(new Parameter(pbe.ParameterName, unresolvedResult));
}
}
diff --git a/src/EditorServicesCommandSuite/EditorServicesCommandSuite.csproj b/src/EditorServicesCommandSuite/EditorServicesCommandSuite.csproj
index 1f6a5b2..9a0863b 100644
--- a/src/EditorServicesCommandSuite/EditorServicesCommandSuite.csproj
+++ b/src/EditorServicesCommandSuite/EditorServicesCommandSuite.csproj
@@ -1,16 +1,10 @@
-
-
- $(RestoreAdditionalProjectSources)
- https://www.myget.org/F/omnisharp/api/v3/index.json
-
-
-
-
+
+
diff --git a/test/EditorServicesCommandSuite.Tests/CommandSplatTests.cs b/test/EditorServicesCommandSuite.Tests/CommandSplatTests.cs
index 3ed5a37..e37830d 100644
--- a/test/EditorServicesCommandSuite.Tests/CommandSplatTests.cs
+++ b/test/EditorServicesCommandSuite.Tests/CommandSplatTests.cs
@@ -12,6 +12,31 @@ public class CommandSplatTests
{
private readonly MockedRefactorService _refactorService = new MockedRefactorService(new CommandSplatRefactor(null));
+ [Fact]
+ public async void HandlesStrangeJoinStringParameterBindingException()
+ {
+ // See https://github.com/SeeminglyScience/EditorServicesCommandSuite/issues/62
+ Assert.Equal(
+ TestBuilder.Create()
+ .Lines("$splat = @{")
+ .Lines(" OutputPrefix = '-'")
+ .Lines("}")
+ .Texts("Join-String @splat"),
+ await GetRefactoredTextAsync("Join-String -OutputPrefix '-'"));
+ }
+
+ [Fact]
+ public async void PerservesExplicitSwitchValues()
+ {
+ Assert.Equal(
+ TestBuilder.Create()
+ .Lines("$splat = @{")
+ .Lines(" Verbose = $Test.IsPresent")
+ .Lines("}")
+ .Texts("Get-ChildItem @splat"),
+ await GetRefactoredTextAsync("Get-ChildItem -Verbose:$Test.IsPresent"));
+ }
+
[Fact]
public async void DoesNothingWithNoParameters()
{
@@ -91,7 +116,8 @@ public async void AllParameters_HandlesParameterSet_OneParamSet()
.Lines(" From = $mandatoryStringFrom")
.Lines(" SmtpServer = $stringSmtpServer")
.Lines(" Priority = $mailPriorityPriority")
- .Lines(" Subject = $mandatoryStringSubject")
+ .Lines(" ReplyTo = $stringArrayReplyTo")
+ .Lines(" Subject = $stringSubject")
.Lines(" To = $mandatoryStringArrayTo")
.Lines(" Credential = $pSCredentialCredential")
.Lines(" UseSsl = $switchParameterUseSsl")
@@ -119,7 +145,8 @@ public async void AllParameters_HandlesParameterSet_OneParamSet_OneParamGiven()
.Lines(" DeliveryNotificationOption = $deliveryNotificationOptionsDeliveryNotificationOption")
.Lines(" SmtpServer = $stringSmtpServer")
.Lines(" Priority = $mailPriorityPriority")
- .Lines(" Subject = $mandatoryStringSubject")
+ .Lines(" ReplyTo = $stringArrayReplyTo")
+ .Lines(" Subject = $stringSubject")
.Lines(" To = $mandatoryStringArrayTo")
.Lines(" Credential = $pSCredentialCredential")
.Lines(" UseSsl = $switchParameterUseSsl")
@@ -264,7 +291,6 @@ public async void MandatoryParameters_HandlesParameterSet_OneParamSet()
TestBuilder.Create()
.Lines("$splat = @{")
.Lines(" From = $mandatoryStringFrom")
- .Lines(" Subject = $mandatoryStringSubject")
.Lines(" To = $mandatoryStringArrayTo")
.Lines("}")
.Texts("Send-MailMessage @splat"),
@@ -280,7 +306,6 @@ public async void MandatoryParameters_HandlesParameterSet_OneParamSet_OneParamGi
TestBuilder.Create()
.Lines("$splat = @{")
.Lines(" From = 'someone@someplace.com'")
- .Lines(" Subject = $mandatoryStringSubject")
.Lines(" To = $mandatoryStringArrayTo")
.Lines("}")
.Texts("Send-MailMessage @splat"),
@@ -383,7 +408,6 @@ public async void NoHints_HandlesParameterSet_OneParamSet()
TestBuilder.Create()
.Lines("$splat = @{")
.Lines(" From = $from")
- .Lines(" Subject = $subject")
.Lines(" To = $to")
.Lines("}")
.Texts("Send-MailMessage @splat"),
@@ -419,7 +443,7 @@ private async Task GetRefactoredTextAsync(
testString,
context => CommandSplatRefactor.SplatCommandAsync(
context,
- context.Ast.FindParent(),
+ context.Ast.FindParent(maxDepth: 10),
includedTypes,
null),
cancellationToken: cancellationToken,
diff --git a/test/EditorServicesCommandSuite.Tests/EditorServicesCommandSuite.Tests.csproj b/test/EditorServicesCommandSuite.Tests/EditorServicesCommandSuite.Tests.csproj
index 0f54dac..466f6ac 100644
--- a/test/EditorServicesCommandSuite.Tests/EditorServicesCommandSuite.Tests.csproj
+++ b/test/EditorServicesCommandSuite.Tests/EditorServicesCommandSuite.Tests.csproj
@@ -1,7 +1,7 @@
- netcoreapp2.0
+ netcoreapp3.1
preview
true
@@ -10,7 +10,7 @@
-
+
diff --git a/tools/AssertPSES.ps1 b/tools/AssertPSES.ps1
index 4485c05..213235b 100644
--- a/tools/AssertPSES.ps1
+++ b/tools/AssertPSES.ps1
@@ -1,7 +1,7 @@
[CmdletBinding()]
param(
[ValidateNotNull()]
- [string] $RequiredVersion = '2.2.0'
+ [string] $RequiredVersion = '2.4.5'
)
begin {
Add-Type -AssemblyName System.IO.Compression