Skip to content

Commit

Permalink
Update OmniSharp and some fixes (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
SeeminglyScience authored Jul 4, 2021
1 parent 52d079f commit 57cfb7d
Show file tree
Hide file tree
Showing 13 changed files with 65 additions and 50 deletions.
2 changes: 1 addition & 1 deletion EditorServicesCommandSuite.build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion module/EditorServicesCommandSuite.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ PrivateData = @{
'@

# Prerelease string of this module
Prerelease = 'beta3'
Prerelease = 'beta4'

} # End of PSData hashtable

Expand Down
9 changes: 0 additions & 9 deletions nuget.config

This file was deleted.

10 changes: 5 additions & 5 deletions src/EditorServicesCommandSuite.Common.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@
<Configurations>Debug;Release;Test</Configurations>
<RunCodeAnalysis>true</RunCodeAnalysis>
<LangVersion>preview</LangVersion>
<TargetFrameworks>netstandard2.0;netcoreapp2.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0;netcoreapp3.1</TargetFrameworks>
<Version>1.0.0.0</Version>
</PropertyGroup>
<ItemGroup>
<AdditionalFiles Include="..\EditorServicesCommandSuite\stylecop.json" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118" PrivateAssets="All" />
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.354" PrivateAssets="All" />
<PackageReference Include="System.Collections.Immutable" Version="1.7.1" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
<PackageReference Include="PowerShellStandard.Library" Version="5.1.0-preview-04" PrivateAssets="All" />
<PackageReference Include="PowerShellStandard.Library" Version="5.1.0" PrivateAssets="All" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp2.0' ">
<PackageReference Include="Microsoft.PowerShell.SDK" Version="6.0.2" PrivateAssets="All" />
<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp3.1' ">
<PackageReference Include="Microsoft.PowerShell.SDK" Version="7.0.6" PrivateAssets="All" />
</ItemGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Test' ">
<DefineConstants>TEST</DefineConstants>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public async Task WriteDocumentEditsAsync(IEnumerable<DocumentEdit> edits, Cance
textEdits.Add(textEdit);
}

var versionedIdentifier = new VersionedTextDocumentIdentifier
var versionedIdentifier = new OptionalVersionedTextDocumentIdentifier
{
Uri = DocumentUri.From(editGroup.Key ?? context.Uri),
Version = default,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\EditorServicesCommandSuite.Common.props" />
<PropertyGroup>
<RestoreAdditionalProjectSources>
$(RestoreAdditionalProjectSources)
https://www.myget.org/F/omnisharp/api/v3/index.json
</RestoreAdditionalProjectSources>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="OmniSharp.Extensions.LanguageServer" Version="0.17.0-*" PrivateAssets="all" />
<PackageReference Include="OmniSharp.Extensions.LanguageServer" Version="0.19.2" PrivateAssets="all" />
<ProjectReference Include="..\EditorServicesCommandSuite\EditorServicesCommandSuite.csproj" />
<Reference Include="Microsoft.PowerShell.EditorServices">
<HintPath>..\..\lib\PowerShellEditorServices\bin\Microsoft.PowerShell.EditorServices.dll</HintPath>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<DocumentEdit> Edits
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

Expand Down
10 changes: 2 additions & 8 deletions src/EditorServicesCommandSuite/EditorServicesCommandSuite.csproj
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\EditorServicesCommandSuite.Common.props" />
<PropertyGroup>
<RestoreAdditionalProjectSources>
$(RestoreAdditionalProjectSources)
https://www.myget.org/F/omnisharp/api/v3/index.json
</RestoreAdditionalProjectSources>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CSharp" Version="4.5.0" />
<PackageReference Include="System.Buffers" Version="4.5.1" />
<PackageReference Include="System.Memory" Version="4.5.4" />
<PackageReference Include="OmniSharp.Extensions.LanguageServer" Version="0.17.0-*" PrivateAssets="all" />
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="4.7.0" />
<PackageReference Include="OmniSharp.Extensions.LanguageServer" Version="0.19.2" PrivateAssets="all" />
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="4.7.1" />
</ItemGroup>
</Project>
36 changes: 30 additions & 6 deletions test/EditorServicesCommandSuite.Tests/CommandSplatTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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"),
Expand All @@ -280,7 +306,6 @@ public async void MandatoryParameters_HandlesParameterSet_OneParamSet_OneParamGi
TestBuilder.Create()
.Lines("$splat = @{")
.Lines(" From = '[email protected]'")
.Lines(" Subject = $mandatoryStringSubject")
.Lines(" To = $mandatoryStringArrayTo")
.Lines("}")
.Texts("Send-MailMessage @splat"),
Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -419,7 +443,7 @@ private async Task<string> GetRefactoredTextAsync(
testString,
context => CommandSplatRefactor.SplatCommandAsync(
context,
context.Ast.FindParent<CommandAst>(),
context.Ast.FindParent<CommandAst>(maxDepth: 10),
includedTypes,
null),
cancellationToken: cancellationToken,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netcoreapp2.0</TargetFrameworks>
<TargetFrameworks>netcoreapp3.1</TargetFrameworks>
<LangVersion>preview</LangVersion>
<IsTestProject>true</IsTestProject>
</PropertyGroup>
Expand All @@ -10,7 +10,7 @@
<PackageReference Include="Moq" Version="4.8.3" />
<PackageReference Include="xunit" Version="2.3.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
<PackageReference Include="Microsoft.PowerShell.SDK" Version="6.0.2" />
<PackageReference Include="Microsoft.PowerShell.SDK" Version="7.0.6" />
<ProjectReference Include="..\..\src\EditorServicesCommandSuite\EditorServicesCommandSuite.csproj" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.2" />
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
Expand Down
2 changes: 1 addition & 1 deletion tools/AssertPSES.ps1
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[CmdletBinding()]
param(
[ValidateNotNull()]
[string] $RequiredVersion = '2.2.0'
[string] $RequiredVersion = '2.4.5'
)
begin {
Add-Type -AssemblyName System.IO.Compression
Expand Down

0 comments on commit 57cfb7d

Please sign in to comment.