Skip to content

Fix IsExternalInit bug, re-enable tests, and update OmniSharp to v0.19.7 #1953

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

Merged
merged 4 commits into from
Dec 5, 2022
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
30 changes: 19 additions & 11 deletions PowerShellEditorServices.build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,36 @@ param(
[ValidateSet("Debug", "Release")]
[string]$Configuration = "Debug",

[switch]$LocalOmniSharp,

[string]$PsesSubmodulePath = "$PSScriptRoot/module",

[string]$ModulesJsonPath = "$PSScriptRoot/modules.json",

[string]$DefaultModuleRepository = "PSGallery",

[string[]]$VerbosityArgs = @("--verbosity", "quiet", "--nologo"),
[string]$Verbosity = "quiet",

# See: https://docs.microsoft.com/en-us/dotnet/core/testing/selective-unit-tests
[string]$TestFilter = '',

# See: https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-test
[string[]]$TestArgs = $VerbosityArgs + @("--logger", "console;verbosity=normal", "--logger", "trx")
[string[]]$TestArgs = @("--logger", "console;verbosity=normal", "--logger", "trx")
)

#Requires -Modules @{ModuleName="InvokeBuild"; ModuleVersion="5.0.0"}
#Requires -Modules @{ModuleName="platyPS"; ModuleVersion="0.14.0"}

$script:dotnetTestArgs = @(
"test"
$TestArgs
$script:dotnetBuildArgs = @(
"--verbosity"
$Verbosity
"--nologo"
"-c"
$Configuration
if ($LocalOmniSharp) { "-property:LocalOmniSharp=true" }
)

$script:dotnetTestArgs = @("test") + $script:dotnetBuildArgs + $TestArgs + @(
if ($TestFilter) { "--filter", $TestFilter }
"--framework"
)
Expand Down Expand Up @@ -80,7 +89,7 @@ Task BinClean {
}

Task Clean FindDotNet, BinClean, {
Invoke-BuildExec { & dotnet clean $VerbosityArgs }
Invoke-BuildExec { & dotnet clean --verbosity $Verbosity }
Get-ChildItem -Recurse $PSScriptRoot\src\*.nupkg | Remove-BuildItem
Get-ChildItem $PSScriptRoot\PowerShellEditorServices*.zip | Remove-BuildItem
Get-ChildItem $PSScriptRoot\module\PowerShellEditorServices\Commands\en-US\*-help.xml | Remove-BuildItem
Expand Down Expand Up @@ -162,15 +171,14 @@ Task SetupHelpForTests {
}

Task Build FindDotNet, CreateBuildInfo, {
Invoke-BuildExec { & dotnet restore $VerbosityArgs }
Invoke-BuildExec { & dotnet publish $VerbosityArgs -c $Configuration .\src\PowerShellEditorServices\PowerShellEditorServices.csproj -f $script:NetRuntime.Standard }
Invoke-BuildExec { & dotnet publish $VerbosityArgs -c $Configuration .\src\PowerShellEditorServices.Hosting\PowerShellEditorServices.Hosting.csproj -f $script:NetRuntime.PS7 }
Invoke-BuildExec { & dotnet publish $script:dotnetBuildArgs .\src\PowerShellEditorServices\PowerShellEditorServices.csproj -f $script:NetRuntime.Standard }
Invoke-BuildExec { & dotnet publish $script:dotnetBuildArgs .\src\PowerShellEditorServices.Hosting\PowerShellEditorServices.Hosting.csproj -f $script:NetRuntime.PS7 }
if (-not $script:IsNix) {
Invoke-BuildExec { & dotnet publish $VerbosityArgs -c $Configuration .\src\PowerShellEditorServices.Hosting\PowerShellEditorServices.Hosting.csproj -f $script:NetRuntime.Desktop }
Invoke-BuildExec { & dotnet publish $script:dotnetBuildArgs .\src\PowerShellEditorServices.Hosting\PowerShellEditorServices.Hosting.csproj -f $script:NetRuntime.Desktop }
}

# Build PowerShellEditorServices.VSCode module
Invoke-BuildExec { & dotnet publish $VerbosityArgs -c $Configuration .\src\PowerShellEditorServices.VSCode\PowerShellEditorServices.VSCode.csproj -f $script:NetRuntime.Standard }
Invoke-BuildExec { & dotnet publish $script:dotnetBuildArgs .\src\PowerShellEditorServices.VSCode\PowerShellEditorServices.VSCode.csproj -f $script:NetRuntime.Standard }
}

Task Test TestServer, TestE2E
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<ProjectReference Include="..\PowerShellEditorServices\PowerShellEditorServices.csproj" PrivateAssets="all" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)'=='net462'">
<ItemGroup Condition=" '$(TargetFramework)' == 'net462' ">
<PackageReference Include="System.ValueTuple" Version="4.5.0" />

<Compile Remove="Internal/PsesLoadContext.cs" />
Expand Down
19 changes: 19 additions & 0 deletions src/PowerShellEditorServices/IsExternalInit.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#pragma warning disable IDE0073
#if NET5_0_OR_GREATER
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Runtime.CompilerServices.IsExternalInit))]
#else

using System.ComponentModel;

namespace System.Runtime.CompilerServices
{
/// <summary>
/// Reserved to be used by the compiler for tracking metadata.
/// This class should not be used by developers in source code.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
internal static class IsExternalInit
{
}
}
#endif
22 changes: 18 additions & 4 deletions src/PowerShellEditorServices/PowerShellEditorServices.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,8 @@
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="Microsoft.Extensions.FileSystemGlobbing" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0" />
<!-- TODO: Manually pull in the updated version of Newtonsoft.Json after OmniSharp updates. -->
<!-- PackageReference Include="Newtonsoft.Json" Version="13.0.1" -->
<PackageReference Include="OmniSharp.Extensions.LanguageServer" Version="0.19.6" />
<PackageReference Include="OmniSharp.Extensions.DebugAdapter.Server" Version="0.19.6" />
<PackageReference Include="OmniSharp.Extensions.LanguageServer" Version="0.19.7" />
<PackageReference Include="OmniSharp.Extensions.DebugAdapter.Server" Version="0.19.7" />
<PackageReference Include="PowerShellStandard.Library" Version="5.1.1" />
<PackageReference Include="Serilog" Version="2.12.0" />
<PackageReference Include="Serilog.Extensions.Logging" Version="3.1.0" />
Expand All @@ -42,6 +40,22 @@
<PackageReference Include="System.Security.Principal.Windows" Version="5.0.0" />
</ItemGroup>

<Choose>
<When Condition=" '$(LocalOmniSharp)' == 'true' ">
<ItemGroup>
<ProjectReference Include="..\..\..\csharp-language-server-protocol\src\Server\Server.csproj" />
<ProjectReference Include="..\..\..\csharp-language-server-protocol\src\Dap.Server\Dap.Server.csproj" />
</ItemGroup>
</When>
<Otherwise>
<ItemGroup>
<PackageReference Include="OmniSharp.Extensions.LanguageServer" Version="0.19.7" />
<PackageReference Include="OmniSharp.Extensions.DebugAdapter.Server" Version="0.19.7" />
</ItemGroup>
</Otherwise>
</Choose>

<!-- TODO: Remove these entirely. -->
<ItemGroup>
<Compile Remove="Extensions\Api\DocumentSymbolService.cs" />
<Compile Remove="Services\Extension\Templating\**" />
Expand Down
15 changes: 0 additions & 15 deletions src/PowerShellEditorServices/Utility/IsExternalInit.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,26 @@
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="OmniSharp.Extensions.LanguageClient" Version="0.19.6" />
<PackageReference Include="OmniSharp.Extensions.DebugAdapter.Client" Version="0.19.6" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5" />
<PackageReference Include="Xunit.SkippableFact" Version="1.4.13" />
</ItemGroup>

<Choose>
<When Condition=" '$(LocalOmniSharp)' == 'true' ">
<ItemGroup>
<ProjectReference Include="..\..\..\csharp-language-server-protocol\src\Client\Client.csproj" />
<ProjectReference Include="..\..\..\csharp-language-server-protocol\src\Dap.Client\Dap.client.csproj" />
</ItemGroup>
</When>
<Otherwise>
<ItemGroup>
<PackageReference Include="OmniSharp.Extensions.LanguageClient" Version="0.19.7" />
<PackageReference Include="OmniSharp.Extensions.DebugAdapter.Client" Version="0.19.7" />
</ItemGroup>
</Otherwise>
</Choose>

<ItemGroup>
<ProjectReference Include="..\..\src\PowerShellEditorServices\PowerShellEditorServices.csproj" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,17 @@ private Task<CompletionResults> GetCompletionResultsAsync(ScriptRegion scriptReg
CancellationToken.None);
}

[SkippableFact]
[Fact]
public async Task CompletesCommandInFile()
{
Skip.If(VersionUtils.PSEdition == "Core", "OmniSharp records are broken!");
(_, IEnumerable<CompletionItem> results) = await GetCompletionResultsAsync(CompleteCommandInFile.SourceDetails).ConfigureAwait(true);
CompletionItem actual = Assert.Single(results);
Assert.Equal(CompleteCommandInFile.ExpectedCompletion, actual);
}

[SkippableFact]
[Fact]
public async Task CompletesCommandFromModule()
{
Skip.If(VersionUtils.PSEdition == "Core", "OmniSharp records are broken!");
(_, IEnumerable<CompletionItem> results) = await GetCompletionResultsAsync(CompleteCommandFromModule.SourceDetails).ConfigureAwait(true);
CompletionItem actual = Assert.Single(results);
// NOTE: The tooltip varies across PowerShell and OS versions, so we ignore it.
Expand All @@ -76,7 +74,6 @@ public async Task CompletesCommandFromModule()
[SkippableFact]
public async Task CompletesTypeName()
{
Skip.If(VersionUtils.PSEdition == "Core", "OmniSharp records are broken!");
Skip.If(VersionUtils.PSEdition == "Desktop", "Windows PowerShell has trouble with this test right now.");
(_, IEnumerable<CompletionItem> results) = await GetCompletionResultsAsync(CompleteTypeName.SourceDetails).ConfigureAwait(true);
CompletionItem actual = Assert.Single(results);
Expand All @@ -98,26 +95,23 @@ public async Task CompletesTypeName()
[SkippableFact]
public async Task CompletesNamespace()
{
Skip.If(VersionUtils.PSEdition == "Core", "OmniSharp records are broken!");
Skip.If(VersionUtils.PSEdition == "Desktop", "Windows PowerShell has trouble with this test right now.");
(_, IEnumerable<CompletionItem> results) = await GetCompletionResultsAsync(CompleteNamespace.SourceDetails).ConfigureAwait(true);
CompletionItem actual = Assert.Single(results);
Assert.Equal(CompleteNamespace.ExpectedCompletion, actual);
}

[SkippableFact]
[Fact]
public async Task CompletesVariableInFile()
{
Skip.If(VersionUtils.PSEdition == "Core", "OmniSharp records are broken!");
(_, IEnumerable<CompletionItem> results) = await GetCompletionResultsAsync(CompleteVariableInFile.SourceDetails).ConfigureAwait(true);
CompletionItem actual = Assert.Single(results);
Assert.Equal(CompleteVariableInFile.ExpectedCompletion, actual);
}

[SkippableFact]
[Fact]
public async Task CompletesAttributeValue()
{
Skip.If(VersionUtils.PSEdition == "Core", "OmniSharp records are broken!");
(_, IEnumerable<CompletionItem> results) = await GetCompletionResultsAsync(CompleteAttributeValue.SourceDetails).ConfigureAwait(true);
// NOTE: Since the completions come through un-ordered from PowerShell, their SortText
// (which has an index prepended from the original order) will mis-match our assumed
Expand All @@ -128,10 +122,9 @@ public async Task CompletesAttributeValue()
actual => Assert.Equal(actual with { Data = null, SortText = null }, CompleteAttributeValue.ExpectedCompletion3));
}

[SkippableFact]
[Fact]
public async Task CompletesFilePath()
{
Skip.If(VersionUtils.PSEdition == "Core", "OmniSharp records are broken!");
(_, IEnumerable<CompletionItem> results) = await GetCompletionResultsAsync(CompleteFilePath.SourceDetails).ConfigureAwait(true);
Assert.NotEmpty(results);
CompletionItem actual = results.First();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5" />
<PackageReference Include="Xunit.SkippableFact" Version="1.4.13" />
<PackageReference Include="OmniSharp.Extensions.LanguageServer" Version="0.19.6" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using Microsoft.PowerShell.EditorServices.Services;
using Microsoft.PowerShell.EditorServices.Services.TextDocument;
using Microsoft.PowerShell.EditorServices.Test;
using Microsoft.PowerShell.EditorServices.Utility;
using Xunit;

namespace PowerShellEditorServices.Test.Services.Symbols
Expand Down Expand Up @@ -66,10 +65,9 @@ public async Task CanLoadPSScriptAnalyzerAsync()
});
}

[SkippableFact]
[Fact]
public async Task DoesNotDuplicateScriptMarkersAsync()
{
Skip.If(VersionUtils.PSEdition == "Core", "OmniSharp records are broken!");
ScriptFile scriptFile = workspaceService.GetFileBuffer("untitled:Untitled-1", script);
ScriptFile[] scriptFiles = { scriptFile };

Expand All @@ -85,10 +83,9 @@ await analysisService
Assert.Single(scriptFile.DiagnosticMarkers);
}

[SkippableFact]
[Fact]
public async Task DoesNotClearParseErrorsAsync()
{
Skip.If(VersionUtils.PSEdition == "Core", "OmniSharp records are broken!");
// Causing a missing closing } parser error
ScriptFile scriptFile = workspaceService.GetFileBuffer("untitled:Untitled-2", script.TrimEnd('}'));
ScriptFile[] scriptFiles = { scriptFile };
Expand Down