Skip to content

Commit 57cfb7d

Browse files
Update OmniSharp and some fixes (#67)
1 parent 52d079f commit 57cfb7d

13 files changed

+65
-50
lines changed

EditorServicesCommandSuite.build.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ task DoTest {
181181

182182
InvokeWithPSModulePath {
183183
& $dotnet test `
184-
--framework netcoreapp2.0 `
184+
--framework netcoreapp3.1 `
185185
--configuration Test `
186186
--logger "trx;LogFileName=$PSScriptRoot/TestResults/results.trx" `
187187
-nologo

module/EditorServicesCommandSuite.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ PrivateData = @{
9292
'@
9393

9494
# Prerelease string of this module
95-
Prerelease = 'beta3'
95+
Prerelease = 'beta4'
9696

9797
} # End of PSData hashtable
9898

nuget.config

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/EditorServicesCommandSuite.Common.props

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@
66
<Configurations>Debug;Release;Test</Configurations>
77
<RunCodeAnalysis>true</RunCodeAnalysis>
88
<LangVersion>preview</LangVersion>
9-
<TargetFrameworks>netstandard2.0;netcoreapp2.0</TargetFrameworks>
9+
<TargetFrameworks>netstandard2.0;netcoreapp3.1</TargetFrameworks>
1010
<Version>1.0.0.0</Version>
1111
</PropertyGroup>
1212
<ItemGroup>
1313
<AdditionalFiles Include="..\EditorServicesCommandSuite\stylecop.json" />
14-
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118" PrivateAssets="All" />
14+
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.354" PrivateAssets="All" />
1515
<PackageReference Include="System.Collections.Immutable" Version="1.7.1" />
1616
</ItemGroup>
1717
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
18-
<PackageReference Include="PowerShellStandard.Library" Version="5.1.0-preview-04" PrivateAssets="All" />
18+
<PackageReference Include="PowerShellStandard.Library" Version="5.1.0" PrivateAssets="All" />
1919
</ItemGroup>
20-
<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp2.0' ">
21-
<PackageReference Include="Microsoft.PowerShell.SDK" Version="6.0.2" PrivateAssets="All" />
20+
<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp3.1' ">
21+
<PackageReference Include="Microsoft.PowerShell.SDK" Version="7.0.6" PrivateAssets="All" />
2222
</ItemGroup>
2323
<PropertyGroup Condition=" '$(Configuration)' == 'Test' ">
2424
<DefineConstants>TEST</DefineConstants>

src/EditorServicesCommandSuite.EditorServices/DocumentService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public async Task WriteDocumentEditsAsync(IEnumerable<DocumentEdit> edits, Cance
7575
textEdits.Add(textEdit);
7676
}
7777

78-
var versionedIdentifier = new VersionedTextDocumentIdentifier
78+
var versionedIdentifier = new OptionalVersionedTextDocumentIdentifier
7979
{
8080
Uri = DocumentUri.From(editGroup.Key ?? context.Uri),
8181
Version = default,

src/EditorServicesCommandSuite.EditorServices/EditorServicesCommandSuite.EditorServices.csproj

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<Import Project="..\EditorServicesCommandSuite.Common.props" />
3-
<PropertyGroup>
4-
<RestoreAdditionalProjectSources>
5-
$(RestoreAdditionalProjectSources)
6-
https://www.myget.org/F/omnisharp/api/v3/index.json
7-
</RestoreAdditionalProjectSources>
8-
</PropertyGroup>
93
<ItemGroup>
10-
<PackageReference Include="OmniSharp.Extensions.LanguageServer" Version="0.17.0-*" PrivateAssets="all" />
4+
<PackageReference Include="OmniSharp.Extensions.LanguageServer" Version="0.19.2" PrivateAssets="all" />
115
<ProjectReference Include="..\EditorServicesCommandSuite\EditorServicesCommandSuite.csproj" />
126
<Reference Include="Microsoft.PowerShell.EditorServices">
137
<HintPath>..\..\lib\PowerShellEditorServices\bin\Microsoft.PowerShell.EditorServices.dll</HintPath>

src/EditorServicesCommandSuite/CodeGeneration/DocumentEditWriter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public virtual string TabString
9494
}
9595
}
9696

97-
internal static Encoding DefaultEncoding { get; set; } = Encoding.ASCII;
97+
internal static Encoding DefaultEncoding { get; set; } = Encoding.Unicode;
9898

9999
internal virtual IEnumerable<DocumentEdit> Edits
100100
{

src/EditorServicesCommandSuite/CodeGeneration/PowerShellScriptWriter.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,18 @@ internal void WriteAsExpressionValue(Parameter parameter, bool shouldNotWriteHin
699699

700700
if (parameter.Value.ConstantValue is bool boolean)
701701
{
702+
// Switch parameters lie sometimes, e.g. `-Verbose:$something.Value` will
703+
// still report "ConstantValue: $true".
704+
if (parameter.Value.Value is not null)
705+
{
706+
string astString = parameter.Value.Value.ToString();
707+
if (!string.IsNullOrEmpty(astString))
708+
{
709+
Write(astString);
710+
return;
711+
}
712+
}
713+
702714
Write(Dollar + boolean.ToString().ToLower());
703715
return;
704716
}

src/EditorServicesCommandSuite/CodeGeneration/Refactors/CommandSplatRefactor.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -186,16 +186,16 @@ await AddAdditionalParameters(
186186
unresolvedBinding = StaticParameterBinder.BindCommand(args.Command, resolve: false);
187187
}
188188

189-
bool isBound = unresolvedBinding.BoundParameters.TryGetValue(
190-
bindingException.Key,
191-
out ParameterBindingResult unresolvedResult);
189+
if (unresolvedBinding.BoundParameters.TryGetValue(bindingException.Key, out ParameterBindingResult unresolvedResult))
190+
{
191+
parameterList.Add(new Parameter(bindingException.Key, unresolvedResult));
192+
continue;
193+
}
192194

193-
if (isBound)
195+
if (bindingException.Value.BindingException is ParameterBindingException pbe
196+
&& unresolvedBinding.BoundParameters.TryGetValue(pbe.ParameterName, out unresolvedResult))
194197
{
195-
parameterList.Add(
196-
new Parameter(
197-
bindingException.Key,
198-
unresolvedResult));
198+
parameterList.Add(new Parameter(pbe.ParameterName, unresolvedResult));
199199
}
200200
}
201201

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<Import Project="..\EditorServicesCommandSuite.Common.props" />
3-
<PropertyGroup>
4-
<RestoreAdditionalProjectSources>
5-
$(RestoreAdditionalProjectSources)
6-
https://www.myget.org/F/omnisharp/api/v3/index.json
7-
</RestoreAdditionalProjectSources>
8-
</PropertyGroup>
93
<ItemGroup>
104
<PackageReference Include="Microsoft.CSharp" Version="4.5.0" />
115
<PackageReference Include="System.Buffers" Version="4.5.1" />
126
<PackageReference Include="System.Memory" Version="4.5.4" />
13-
<PackageReference Include="OmniSharp.Extensions.LanguageServer" Version="0.17.0-*" PrivateAssets="all" />
14-
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="4.7.0" />
7+
<PackageReference Include="OmniSharp.Extensions.LanguageServer" Version="0.19.2" PrivateAssets="all" />
8+
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="4.7.1" />
159
</ItemGroup>
1610
</Project>

test/EditorServicesCommandSuite.Tests/CommandSplatTests.cs

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,31 @@ public class CommandSplatTests
1212
{
1313
private readonly MockedRefactorService _refactorService = new MockedRefactorService(new CommandSplatRefactor(null));
1414

15+
[Fact]
16+
public async void HandlesStrangeJoinStringParameterBindingException()
17+
{
18+
// See https://github.com/SeeminglyScience/EditorServicesCommandSuite/issues/62
19+
Assert.Equal(
20+
TestBuilder.Create()
21+
.Lines("$splat = @{")
22+
.Lines(" OutputPrefix = '-'")
23+
.Lines("}")
24+
.Texts("Join-String @splat"),
25+
await GetRefactoredTextAsync("Join-String -OutputPrefix '-'"));
26+
}
27+
28+
[Fact]
29+
public async void PerservesExplicitSwitchValues()
30+
{
31+
Assert.Equal(
32+
TestBuilder.Create()
33+
.Lines("$splat = @{")
34+
.Lines(" Verbose = $Test.IsPresent")
35+
.Lines("}")
36+
.Texts("Get-ChildItem @splat"),
37+
await GetRefactoredTextAsync("Get-ChildItem -Verbose:$Test.IsPresent"));
38+
}
39+
1540
[Fact]
1641
public async void DoesNothingWithNoParameters()
1742
{
@@ -91,7 +116,8 @@ public async void AllParameters_HandlesParameterSet_OneParamSet()
91116
.Lines(" From = $mandatoryStringFrom")
92117
.Lines(" SmtpServer = $stringSmtpServer")
93118
.Lines(" Priority = $mailPriorityPriority")
94-
.Lines(" Subject = $mandatoryStringSubject")
119+
.Lines(" ReplyTo = $stringArrayReplyTo")
120+
.Lines(" Subject = $stringSubject")
95121
.Lines(" To = $mandatoryStringArrayTo")
96122
.Lines(" Credential = $pSCredentialCredential")
97123
.Lines(" UseSsl = $switchParameterUseSsl")
@@ -119,7 +145,8 @@ public async void AllParameters_HandlesParameterSet_OneParamSet_OneParamGiven()
119145
.Lines(" DeliveryNotificationOption = $deliveryNotificationOptionsDeliveryNotificationOption")
120146
.Lines(" SmtpServer = $stringSmtpServer")
121147
.Lines(" Priority = $mailPriorityPriority")
122-
.Lines(" Subject = $mandatoryStringSubject")
148+
.Lines(" ReplyTo = $stringArrayReplyTo")
149+
.Lines(" Subject = $stringSubject")
123150
.Lines(" To = $mandatoryStringArrayTo")
124151
.Lines(" Credential = $pSCredentialCredential")
125152
.Lines(" UseSsl = $switchParameterUseSsl")
@@ -264,7 +291,6 @@ public async void MandatoryParameters_HandlesParameterSet_OneParamSet()
264291
TestBuilder.Create()
265292
.Lines("$splat = @{")
266293
.Lines(" From = $mandatoryStringFrom")
267-
.Lines(" Subject = $mandatoryStringSubject")
268294
.Lines(" To = $mandatoryStringArrayTo")
269295
.Lines("}")
270296
.Texts("Send-MailMessage @splat"),
@@ -280,7 +306,6 @@ public async void MandatoryParameters_HandlesParameterSet_OneParamSet_OneParamGi
280306
TestBuilder.Create()
281307
.Lines("$splat = @{")
282308
.Lines(" From = '[email protected]'")
283-
.Lines(" Subject = $mandatoryStringSubject")
284309
.Lines(" To = $mandatoryStringArrayTo")
285310
.Lines("}")
286311
.Texts("Send-MailMessage @splat"),
@@ -383,7 +408,6 @@ public async void NoHints_HandlesParameterSet_OneParamSet()
383408
TestBuilder.Create()
384409
.Lines("$splat = @{")
385410
.Lines(" From = $from")
386-
.Lines(" Subject = $subject")
387411
.Lines(" To = $to")
388412
.Lines("}")
389413
.Texts("Send-MailMessage @splat"),
@@ -419,7 +443,7 @@ private async Task<string> GetRefactoredTextAsync(
419443
testString,
420444
context => CommandSplatRefactor.SplatCommandAsync(
421445
context,
422-
context.Ast.FindParent<CommandAst>(),
446+
context.Ast.FindParent<CommandAst>(maxDepth: 10),
423447
includedTypes,
424448
null),
425449
cancellationToken: cancellationToken,

test/EditorServicesCommandSuite.Tests/EditorServicesCommandSuite.Tests.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>netcoreapp2.0</TargetFrameworks>
4+
<TargetFrameworks>netcoreapp3.1</TargetFrameworks>
55
<LangVersion>preview</LangVersion>
66
<IsTestProject>true</IsTestProject>
77
</PropertyGroup>
@@ -10,7 +10,7 @@
1010
<PackageReference Include="Moq" Version="4.8.3" />
1111
<PackageReference Include="xunit" Version="2.3.1" />
1212
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
13-
<PackageReference Include="Microsoft.PowerShell.SDK" Version="6.0.2" />
13+
<PackageReference Include="Microsoft.PowerShell.SDK" Version="7.0.6" />
1414
<ProjectReference Include="..\..\src\EditorServicesCommandSuite\EditorServicesCommandSuite.csproj" />
1515
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.2" />
1616
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />

tools/AssertPSES.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[CmdletBinding()]
22
param(
33
[ValidateNotNull()]
4-
[string] $RequiredVersion = '2.2.0'
4+
[string] $RequiredVersion = '2.4.5'
55
)
66
begin {
77
Add-Type -AssemblyName System.IO.Compression

0 commit comments

Comments
 (0)