Skip to content
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

Rework completion resolution #2126

Merged
merged 8 commits into from
Apr 8, 2021
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
23 changes: 19 additions & 4 deletions OmniSharp.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27004.2005
# Visual Studio Version 16
VisualStudioVersion = 16.0.31129.286
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{2C348365-A9D8-459E-9276-56FC46AAEE31}"
EndProject
Expand Down Expand Up @@ -67,9 +67,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OmniSharp.Stdio.Driver", "s
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OmniSharp.Script.Tests", "tests\OmniSharp.Script.Tests\OmniSharp.Script.Tests.csproj", "{9E4BA68C-7F4B-429A-A0C7-8CE7D41D610F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OmniSharp.Shared", "src\OmniSharp.Shared\OmniSharp.Shared.csproj", "{9571E3FE-E742-44AC-9E1F-64156815B8E1}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OmniSharp.Shared", "src\OmniSharp.Shared\OmniSharp.Shared.csproj", "{9571E3FE-E742-44AC-9E1F-64156815B8E1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OmniSharp.Lsp.Tests", "tests\OmniSharp.Lsp.Tests\OmniSharp.Lsp.Tests.csproj", "{D67AA10B-8DB6-408D-A4C5-0B1DDCF5B3CC}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OmniSharp.Lsp.Tests", "tests\OmniSharp.Lsp.Tests\OmniSharp.Lsp.Tests.csproj", "{D67AA10B-8DB6-408D-A4C5-0B1DDCF5B3CC}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OmniSharp.Benchmarks", "src\OmniSharp.Benchmarks\OmniSharp.Benchmarks.csproj", "{6F5B209E-8DD3-4E90-A1F3-D85E7AF56588}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you for adding this... It has been long long long overdue ✨

EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -369,6 +371,18 @@ Global
{D67AA10B-8DB6-408D-A4C5-0B1DDCF5B3CC}.Release|x64.Build.0 = Release|Any CPU
{D67AA10B-8DB6-408D-A4C5-0B1DDCF5B3CC}.Release|x86.ActiveCfg = Release|Any CPU
{D67AA10B-8DB6-408D-A4C5-0B1DDCF5B3CC}.Release|x86.Build.0 = Release|Any CPU
{6F5B209E-8DD3-4E90-A1F3-D85E7AF56588}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6F5B209E-8DD3-4E90-A1F3-D85E7AF56588}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6F5B209E-8DD3-4E90-A1F3-D85E7AF56588}.Debug|x64.ActiveCfg = Debug|Any CPU
{6F5B209E-8DD3-4E90-A1F3-D85E7AF56588}.Debug|x64.Build.0 = Debug|Any CPU
{6F5B209E-8DD3-4E90-A1F3-D85E7AF56588}.Debug|x86.ActiveCfg = Debug|Any CPU
{6F5B209E-8DD3-4E90-A1F3-D85E7AF56588}.Debug|x86.Build.0 = Debug|Any CPU
{6F5B209E-8DD3-4E90-A1F3-D85E7AF56588}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6F5B209E-8DD3-4E90-A1F3-D85E7AF56588}.Release|Any CPU.Build.0 = Release|Any CPU
{6F5B209E-8DD3-4E90-A1F3-D85E7AF56588}.Release|x64.ActiveCfg = Release|Any CPU
{6F5B209E-8DD3-4E90-A1F3-D85E7AF56588}.Release|x64.Build.0 = Release|Any CPU
{6F5B209E-8DD3-4E90-A1F3-D85E7AF56588}.Release|x86.ActiveCfg = Release|Any CPU
{6F5B209E-8DD3-4E90-A1F3-D85E7AF56588}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -398,6 +412,7 @@ Global
{9E4BA68C-7F4B-429A-A0C7-8CE7D41D610F} = {35E025BF-BBB2-4FAC-9F4B-37CBA083EE47}
{9571E3FE-E742-44AC-9E1F-64156815B8E1} = {2C348365-A9D8-459E-9276-56FC46AAEE31}
{D67AA10B-8DB6-408D-A4C5-0B1DDCF5B3CC} = {35E025BF-BBB2-4FAC-9F4B-37CBA083EE47}
{6F5B209E-8DD3-4E90-A1F3-D85E7AF56588} = {2C348365-A9D8-459E-9276-56FC46AAEE31}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {4DD725CE-B49A-4151-8B77-BB33FE88E46E}
Expand Down
1 change: 1 addition & 0 deletions src/OmniSharp.Benchmarks/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
BenchmarkDotNet.Artifacts/*
63 changes: 63 additions & 0 deletions src/OmniSharp.Benchmarks/ImportCompletionBenchmarks.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Diagnostics.Windows.Configs;
using OmniSharp.Models.v1.Completion;
using OmniSharp.Roslyn.CSharp.Services.Completion;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TestUtility;

namespace OmniSharp.Benchmarks
{
[EtwProfiler]
public class ImportCompletionBenchmarks : HostBase
{
public CompletionRequest Request { get; set; } = null!;

[GlobalSetup]
public async Task SetupAsync()
{
Setup(new KeyValuePair<string, string>("RoslynExtensionsOptions:EnableImportCompletion", "true"));

var builder = new StringBuilder();

builder.AppendLine("class Base");
builder.AppendLine("{");
builder.AppendLine(" void M()");
builder.AppendLine(" {");
builder.AppendLine(" $$");
builder.AppendLine(" }");
builder.AppendLine("}");

const string FileName = "ImportCompletionTest.cs";
var file = new TestFile(FileName, builder.ToString());
OmniSharpTestHost.AddFilesToWorkspace(file);

var point = file.Content.GetPointFromPosition();

Request = new()
{
CompletionTrigger = CompletionTriggerKind.Invoked,
Line = point.Line,
Column = point.Offset,
FileName = FileName
};

// Trigger completion once to ensure that all the runs have a warmed-up server, with full completions loaded
CompletionResponse completions;
do
{
completions = await ImportCompletionListAsync();
} while (!completions.Items.Any(i => i.Label == "Console"));

}

[Benchmark]
public async Task<CompletionResponse> ImportCompletionListAsync()
{
var handler = OmniSharpTestHost.GetRequestHandler<CompletionService>(OmniSharpEndpoints.Completion);
return await handler.Handle(Request);
}
}
}
22 changes: 22 additions & 0 deletions src/OmniSharp.Benchmarks/OmniSharp.Benchmarks.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net472</TargetFramework>
<Nullable>enable</Nullable>
<LangVersion>9.0</LangVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.12.1" />
<PackageReference Include="BenchmarkDotNet.Diagnostics.Windows" Version="0.12.1" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.abstractions" Version="2.0.3" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\OmniSharp.Roslyn.CSharp\OmniSharp.Roslyn.CSharp.csproj" />
<ProjectReference Include="..\..\tests\TestUtility\TestUtility.csproj" />
</ItemGroup>

</Project>
71 changes: 71 additions & 0 deletions src/OmniSharp.Benchmarks/OverrideCompletionBenchmarks.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Diagnostics.Windows.Configs;
using OmniSharp.Models.v1.Completion;
using OmniSharp.Roslyn.CSharp.Services.Completion;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using TestUtility;

namespace OmniSharp.Benchmarks
{
[EtwProfiler]
public class OverrideCompletionBenchmarks : HostBase
{
[Params(10, 100, 250, 500)]
public int NumOverrides { get; set; }

public CompletionRequest Request { get; set; } = null!;

[GlobalSetup]
public async Task SetupAsync()
{
Setup(new KeyValuePair<string, string>( "RoslynExtensionsOptions:EnableImportCompletion", "true" ));

var builder = new StringBuilder();

builder.AppendLine("namespace N1");
builder.AppendLine("{");
builder.AppendLine(" using System.Collections.Generic;");
builder.AppendLine(" class Base");
builder.AppendLine(" {");
for (int i = 0; i < NumOverrides; i++)
{
builder.AppendLine($" public virtual Dictionary<string, string> M{i}(List<string> s) {{ return null; }}");
}
builder.AppendLine(" }");
builder.AppendLine("}");
builder.AppendLine("namespace N2 : N1.Base");
builder.AppendLine("{");
builder.AppendLine(" class Derived");
builder.AppendLine(" {");
builder.AppendLine(" override $$");
builder.AppendLine(" }");
builder.AppendLine("}");

const string FileName = "OverrideTest.cs";
var file = new TestFile(FileName, builder.ToString());
OmniSharpTestHost.AddFilesToWorkspace(file);

var point = file.Content.GetPointFromPosition();

Request = new()
{
CompletionTrigger = OmniSharp.Models.v1.Completion.CompletionTriggerKind.Invoked,
Line = point.Line,
Column = point.Offset,
FileName = FileName
};

// Trigger completion once to ensure that all the runs have a warmed-up server
await OverrideCompletionAsync();
}

[Benchmark]
public async Task<CompletionResponse> OverrideCompletionAsync()
{
var handler = OmniSharpTestHost.GetRequestHandler<CompletionService>(OmniSharpEndpoints.Completion);
return await handler.Handle(Request);
}
}
}
27 changes: 27 additions & 0 deletions src/OmniSharp.Benchmarks/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using BenchmarkDotNet.Running;
using Microsoft.Extensions.Configuration;
using OmniSharp.Benchmarks;
using OmniSharp.Utilities;
using System.Collections.Generic;
using TestUtility;

BenchmarkRunner.Run(typeof(OverrideCompletionBenchmarks).Assembly);

namespace OmniSharp.Benchmarks
{
public abstract class HostBase : DisposableObject
{
protected OmniSharpTestHost OmniSharpTestHost { get; set; } = null!;

protected override void DisposeCore(bool disposing)
{
OmniSharpTestHost.Dispose();
}

public void Setup(params KeyValuePair<string, string>[]? configuration)
{
var builder = new Microsoft.Extensions.Configuration.ConfigurationBuilder().AddInMemoryCollection(configuration);
OmniSharpTestHost = OmniSharpTestHost.Create(configurationData: builder.Build());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ private static void VerifyEnumsInSync(Type enum1, Type enum2)
Debug.Assert(lspValues.Length == modelValues.Length);
for (int i = 0; i < lspValues.Length; i++)
{
Debug.Assert((int?)lspValues.GetValue(i) == (int?)modelValues.GetValue(i));
Debug.Assert((int)lspValues.GetValue(i) == (int)modelValues.GetValue(i));
Copy link
Member

@filipw filipw Apr 6, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed this to int? because I noticed on the .NET 5.0 branch that it reports CS8605 "Unboxing possibly null value" there - and since we have TreatWarningsAsErrors enabled, it wouldn't build

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, if it's int? the assert fails because these are ints, not nullable ints :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh 😅

}
}

Expand Down
Loading