Skip to content

Commit

Permalink
Merge pull request #86 from OmniSharp/public-members
Browse files Browse the repository at this point in the history
[wip] export more public types
  • Loading branch information
david-driscoll authored Jun 26, 2018
2 parents d3468c2 + c069e5b commit 9fa60ff
Show file tree
Hide file tree
Showing 26 changed files with 101 additions and 64 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@ buildlog
# Build folder
tools/*/
/tools/packages.config.md5sum
/coverage

.idea
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ language: csharp
sudo: required
dist: trusty
mono: latest
dotnet: 2.0.0
dotnet: 2.1.301
os:
- linux
cache:
Expand Down
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"coverage-gutters.lcovname": "*.info"
}
15 changes: 9 additions & 6 deletions Common.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,19 @@
<Microsoft_Extensions_Logging_Version>2.0.0</Microsoft_Extensions_Logging_Version>
<Microsoft_Extensions_DependencyInjection_Version>2.0.0</Microsoft_Extensions_DependencyInjection_Version>
<Newtonsoft_Version>11.0.2</Newtonsoft_Version>
<SourceLink_Version>2.8.1</SourceLink_Version>
<System_Reactive_Version>3.1.1</System_Reactive_Version>
<MediatR_Version>4.1.0</MediatR_Version>
<Autofac_Version>4.8.0</Autofac_Version>
<SourceLink_Version>2.8.3</SourceLink_Version>
<System_Reactive_Version>4.0.0</System_Reactive_Version>
<MediatR_Version>5.0.1</MediatR_Version>
<MediatR_Extensions_DependencyInjection_Version>5.0.2</MediatR_Extensions_DependencyInjection_Version>
<Autofac_Version>4.8.1</Autofac_Version>
<Autofac_Extensions_DependencyInjection_Version>4.2.2</Autofac_Extensions_DependencyInjection_Version>
<Microsoft_NET_Test_Sdk_Version>15.7.0</Microsoft_NET_Test_Sdk_Version>
<Microsoft_NET_Test_Sdk_Version>15.7.2</Microsoft_NET_Test_Sdk_Version>
<xunit_Version>2.3.1</xunit_Version>
<FluentAssertions_Version>5.3.0</FluentAssertions_Version>
<FluentAssertions_Version>5.4.1</FluentAssertions_Version>
<NSubstitute_Version>3.1.0</NSubstitute_Version>
<Serilog_Extensions_Logging_Version>2.0.2</Serilog_Extensions_Logging_Version>
<Serilog_Sinks_XUnit_Version>1.0.5</Serilog_Sinks_XUnit_Version>
<XunitXml_TestLogger_Version>2.0.0</XunitXml_TestLogger_Version>
<coverlet_Version>2.0.1</coverlet_Version>
</PropertyGroup>
</Project>
33 changes: 19 additions & 14 deletions build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,8 @@ Task("TestSetup")
EnsureDirectoryExists(artifacts + "/coverage");
});

Task("Test (No Coverage)")
Task("Test (Unix)")
.WithCriteria(IsRunningOnUnix)
.WithCriteria(false) // TODO: Make work on travis
.IsDependentOn("TestSetup")
.IsDependentOn("Build")
.DoesForEach(GetFiles("test/*/*.csproj"), (testProject) =>
Expand All @@ -61,27 +60,33 @@ Task("Test (No Coverage)")
testProject.GetDirectory().FullPath,
new DotNetCoreTestSettings() {
NoBuild = true,
Framework = "netcoreapp2.0",
Configuration = configuration,
Framework = "netcoreapp2.1",
EnvironmentVariables = GitVersionEnvironmentVariables,
});
TestAdapterPath = ".",
Logger = $"\"xunit;LogFilePath={string.Format("{0}/tests/{1}.xml", artifacts, testProject.GetFilenameWithoutExtension())}\"",
ArgumentCustomization = args => args.Append("/p:CollectCoverage=true"),
}
);
});

Task("Test (Coverage)")
Task("Test (Windows)")
.WithCriteria(IsRunningOnWindows)
.IsDependentOn("TestSetup")
.IsDependentOn("Build")
.DoesForEach(GetFiles("test/*/*.csproj"), (testProject) =>
{
DotCoverCover(tool => {
tool.DotNetCoreTool(
tool.DotNetCoreTest(
testProject.GetDirectory().FullPath,
"xunit",
new ProcessArgumentBuilder()
.AppendSwitchQuoted("-xml", string.Format("{0}/tests/{1}.xml", artifacts, testProject.GetFilenameWithoutExtension()))
.AppendSwitch("-configuration", configuration)
.Append("-noshadow"),
new DotNetCoreToolSettings() {
new DotNetCoreTestSettings() {
NoBuild = true,
Configuration = configuration,
Framework = "netcoreapp2.1",
EnvironmentVariables = GitVersionEnvironmentVariables,
TestAdapterPath = ".",
Logger = $"\"xunit;LogFilePath={string.Format("{0}/tests/{1}.xml", artifacts, testProject.GetFilenameWithoutExtension())}\"",
// ArgumentCustomization = args => args.Append("/p:CollectCoverage=true"),
});
},
artifacts + "/coverage/coverage-"+ testProject.GetFilenameWithoutExtension() + ".dcvr",
Expand Down Expand Up @@ -120,8 +125,8 @@ Task("Test (Coverage)")
});

Task("Test")
.IsDependentOn("Test (Coverage)")
.IsDependentOn("Test (No Coverage)");
.IsDependentOn("Test (Unix)")
.IsDependentOn("Test (Windows)");

Task("Pack")
.WithCriteria(IsRunningOnWindows) // TODO: Make work on travis
Expand Down
16 changes: 9 additions & 7 deletions sample/SampleServer/TextDocumentHandler.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using MediatR;
using OmniSharp.Extensions.LanguageServer;
using OmniSharp.Extensions.LanguageServer.Protocol;
using OmniSharp.Extensions.LanguageServer.Protocol.Client.Capabilities;
Expand Down Expand Up @@ -32,14 +33,14 @@ public TextDocumentHandler(OmniSharp.Extensions.LanguageServer.Protocol.Server.I

public TextDocumentSyncKind Change { get; } = TextDocumentSyncKind.Full;

public Task Handle(DidChangeTextDocumentParams notification, CancellationToken token)
public Task<Unit> Handle(DidChangeTextDocumentParams notification, CancellationToken token)
{
_router.Window.LogMessage(new LogMessageParams()
{
Type = MessageType.Log,
Message = "Hello World!!!!"
});
return Task.CompletedTask;
return Unit.Task;
}

TextDocumentChangeRegistrationOptions IRegistration<TextDocumentChangeRegistrationOptions>.GetRegistrationOptions()
Expand All @@ -56,14 +57,15 @@ public void SetCapability(SynchronizationCapability capability)
_capability = capability;
}

public async Task Handle(DidOpenTextDocumentParams notification, CancellationToken token)
public async Task<Unit> Handle(DidOpenTextDocumentParams notification, CancellationToken token)
{
await Task.Yield();
_router.Window.LogMessage(new LogMessageParams()
{
Type = MessageType.Log,
Message = "Hello World!!!!"
});
return Unit.Value;
}

TextDocumentRegistrationOptions IRegistration<TextDocumentRegistrationOptions>.GetRegistrationOptions()
Expand All @@ -74,14 +76,14 @@ TextDocumentRegistrationOptions IRegistration<TextDocumentRegistrationOptions>.G
};
}

public Task Handle(DidCloseTextDocumentParams notification, CancellationToken token)
public Task<Unit> Handle(DidCloseTextDocumentParams notification, CancellationToken token)
{
return Task.CompletedTask;
return Unit.Task;
}

public Task Handle(DidSaveTextDocumentParams notification, CancellationToken token)
public Task<Unit> Handle(DidSaveTextDocumentParams notification, CancellationToken token)
{
return Task.CompletedTask;
return Unit.Task;
}

TextDocumentSaveRegistrationOptions IRegistration<TextDocumentSaveRegistrationOptions>.GetRegistrationOptions()
Expand Down
1 change: 1 addition & 0 deletions src/Client/LanguageClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using OmniSharp.Extensions.LanguageServer.Protocol.Serialization;
using OmniSharp.Extensions.LanguageServer.Protocol.Server.Capabilities;
using ISerializer = OmniSharp.Extensions.LanguageServer.Protocol.Serialization.ISerializer;
using Serializer = OmniSharp.Extensions.LanguageServer.Protocol.Serialization.Serializer;

namespace OmniSharp.Extensions.LanguageServer.Client
{
Expand Down
1 change: 1 addition & 0 deletions src/Client/Protocol/LspConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using OmniSharp.Extensions.LanguageServer.Protocol.Client.Capabilities;
using OmniSharp.Extensions.LanguageServer.Protocol.Serialization;
using JsonRpcMessages = OmniSharp.Extensions.JsonRpc.Server.Messages;
using Serializer = OmniSharp.Extensions.LanguageServer.Protocol.Serialization.Serializer;

namespace OmniSharp.Extensions.LanguageServer.Client.Protocol
{
Expand Down
4 changes: 3 additions & 1 deletion src/JsonRpc/HandlerCollection.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using MediatR;

namespace OmniSharp.Extensions.JsonRpc
{
class HandlerCollection : IEnumerable<IHandlerDescriptor>
[DebuggerDisplay("{Method}")]
public class HandlerCollection : IEnumerable<IHandlerDescriptor>
{
internal readonly List<HandlerInstance> _handlers = new List<HandlerInstance>();

Expand Down
4 changes: 2 additions & 2 deletions src/JsonRpc/JsonRpc.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<PlatformTarget>AnyCPU</PlatformTarget>
Expand All @@ -9,7 +9,7 @@
<PackageReference Include="MediatR" Version="$(MediatR_Version)" />
<PackageReference Include="Newtonsoft.Json" Version="$(Newtonsoft_Version)" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="$(Microsoft_Extensions_Logging_Version)" />
<PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="$(MediatR_Version)" />
<PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="$(MediatR_Extensions_DependencyInjection_Version)" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="$(Microsoft_Extensions_DependencyInjection_Version)" />
</ItemGroup>
</Project>
6 changes: 5 additions & 1 deletion src/JsonRpc/RequestRouter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace OmniSharp.Extensions.JsonRpc
{
class RequestRouter : IRequestRouter
public class RequestRouter : IRequestRouter
{
private readonly HandlerCollection _collection;
private readonly ISerializer _serializer;
Expand Down Expand Up @@ -88,6 +88,10 @@ protected virtual async Task<ErrorResponse> RouteRequest(IHandlerDescriptor hand
.GetProperty(nameof(Task<object>.Result), BindingFlags.Public | BindingFlags.Instance);

responseValue = property.GetValue(result);
if (responseValue?.GetType() == typeof(Unit))
{
responseValue = null;
}
}

return new Client.Response(request.Id, responseValue);
Expand Down
2 changes: 1 addition & 1 deletion src/JsonRpc/Serializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace OmniSharp.Extensions.JsonRpc
{
class Serializer : ISerializer
public class Serializer : ISerializer
{
public Serializer()
{
Expand Down
18 changes: 10 additions & 8 deletions src/JsonRpc/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,24 @@ public static IServiceCollection AddJsonRpcMediatR(this IServiceCollection servi
{
services.AddMediatR(assemblies);
services.AddScoped<IRequestContext, RequestContext>();
services.RemoveAll<SingleInstanceFactory>();
services.AddScoped<SingleInstanceFactory>(
services.RemoveAll<ServiceFactory>();
services.AddScoped<ServiceFactory>(
serviceProvider => {
return serviceType => {
return GetHandler(serviceProvider, serviceType);
};
return serviceType => GetHandler(serviceProvider, serviceType);
}
);
return services;
}

private static object GetHandler(IServiceProvider serviceProvider, Type serviceType)
{
var context = serviceProvider.GetService<IRequestContext>();
return context.Descriptor.Handler;
// return context?.Descriptor != null ? context.Descriptor.Handler : serviceProvider.GetService(serviceType);
if (serviceType.IsGenericType &&
typeof(IRequestHandler<,>).IsAssignableFrom(serviceType.GetGenericTypeDefinition()))
{
var context = serviceProvider.GetService<IRequestContext>();
return context.Descriptor != null ? context.Descriptor.Handler : serviceProvider.GetService(serviceType);
}
return serviceProvider.GetService(serviceType);
}
}
}
5 changes: 3 additions & 2 deletions src/Server/Handlers/CancelRequestHandler.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Threading;
using System.Threading.Tasks;
using MediatR;
using OmniSharp.Extensions.JsonRpc;
using OmniSharp.Extensions.LanguageServer.Protocol;
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
Expand All @@ -15,10 +16,10 @@ internal CancelRequestHandler(ILspRequestRouter requestRouter)
_requestRouter = requestRouter;
}

public Task Handle(CancelParams notification, CancellationToken token)
public Task<Unit> Handle(CancelParams notification, CancellationToken token)
{
_requestRouter.CancelRequest(notification.Id);
return Task.CompletedTask;
return Unit.Task;
}
}
}
3 changes: 2 additions & 1 deletion src/Server/Handlers/ExitHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@ public ExitHandler(ShutdownHandler shutdownHandler)
public IObservable<int> Exit { get; }


public async Task Handle(EmptyRequest request, CancellationToken token)
public async Task<Unit> Handle(EmptyRequest request, CancellationToken token)
{
await Task.Yield();

var result = _shutdownHandler.ShutdownRequested ? 0 : 1;
_exitSubject.OnNext(result);
_exitSubject.OnCompleted();
return Unit.Value;
}
}
}
3 changes: 2 additions & 1 deletion src/Server/Handlers/ShutdownHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public ShutdownHandler()
public bool ShutdownRequested { get; private set; }
public Task WasShutDown => Shutdown.ToTask();

public async Task Handle(EmptyRequest request, CancellationToken token)
public async Task<Unit> Handle(EmptyRequest request, CancellationToken token)
{
await Task.Yield(); // Ensure shutdown handler runs asynchronously.

Expand All @@ -38,6 +38,7 @@ public async Task Handle(EmptyRequest request, CancellationToken token)
{
_shutdownSubject.OnCompleted();
}
return Unit.Value;
}
}
}
3 changes: 2 additions & 1 deletion src/Server/LanguageServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ async Task<InitializeResult> IRequestHandler<InitializeParams, InitializeResult>
return result;
}

public async Task Handle(InitializedParams @params, CancellationToken token)
public async Task<Unit> Handle(InitializedParams @params, CancellationToken token)
{
if (_clientVersion == ClientVersion.Lsp3)
{
Expand All @@ -362,6 +362,7 @@ public async Task Handle(InitializedParams @params, CancellationToken token)
_initializeComplete.OnNext(ServerSettings);
_initializeComplete.OnCompleted();
}
return Unit.Value;
}

private async Task DynamicallyRegisterHandlers(Registration[] registrations)
Expand Down
4 changes: 2 additions & 2 deletions test/Client.Tests/Client.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<TargetFramework>netcoreapp2.1</TargetFramework>
<AssemblyName>OmniSharp.Extensions.LanguageClient.Tests</AssemblyName>
<RootNamespace>OmniSharp.Extensions.LanguageServerProtocol.Client.Tests</RootNamespace>
</PropertyGroup>
Expand Down
7 changes: 6 additions & 1 deletion test/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
<Project>
<Import Project="$([MSBuild]::GetPathOfFileAbove('Common.Build.props', '$(MSBuildThisFileDirectory)../'))" />
<PropertyGroup>
<RuntimeFrameworkVersion>2.0.6</RuntimeFrameworkVersion>
<IsPackable>false</IsPackable>
<PreserveCompilationContext>true</PreserveCompilationContext>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>

<!-- <CollectCoverage>true</CollectCoverage> -->
<CoverletOutputFormat>json,lcov,cobertura</CoverletOutputFormat>
<CoverletOutputDirectory>$([System.IO.Path]::GetDirectoryName($([MSBuild]::GetPathOfFileAbove('Common.Build.props', '$(MSBuildThisFileDirectory)../'))))/coverage/</CoverletOutputDirectory>
<CoverletOutputName>$(MSBuildProjectName)-$(TargetFramework)</CoverletOutputName>
</PropertyGroup>
</Project>
6 changes: 4 additions & 2 deletions test/Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
<Project>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="$(Newtonsoft_Version)" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(Microsoft_NET_Test_Sdk_Version)" />
<PackageReference Include="xunit.runner.visualstudio" Version="$(xunit_Version)" />
<PackageReference Include="xunit" Version="$(xunit_Version)" />
<PackageReference Include="FluentAssertions" Version="$(FluentAssertions_Version)" />
<PackageReference Include="NSubstitute" Version="$(NSubstitute_Version)" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="$(Microsoft_Extensions_DependencyInjection_Version)" />
<PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="$(MediatR_Version)" />
<PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="$(MediatR_Extensions_DependencyInjection_Version)" />
<PackageReference Include="Autofac" Version="$(Autofac_Version)" />
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="$(Autofac_Extensions_DependencyInjection_Version)" />
<PackageReference Include="Serilog.Extensions.Logging" Version="$(Serilog_Extensions_Logging_Version)" />
<PackageReference Include="Serilog.Sinks.XUnit" Version="$(Serilog_Sinks_XUnit_Version)" />
<DotNetCliToolReference Include="dotnet-xunit" Version="$(xunit_Version)" />
<PackageReference Include="XunitXml.TestLogger" Version="$(XunitXml_TestLogger_Version)" />
<PackageReference Include="coverlet.msbuild" Version="$(coverlet_Version)" />
</ItemGroup>
</Project>
Loading

0 comments on commit 9fa60ff

Please sign in to comment.