Skip to content

Move registration options to the descriptor #156

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 3 commits into from
Jul 19, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 3 additions & 3 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 @@ -13,7 +13,7 @@
<PackageReference Include="Microsoft.Extensions.DependencyInjection" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" />
<PackageReference Include="Newtonsoft.Json" />
<Compile Include="../../submodules/MediatR/src/MediatR/**/*.cs" Exclude="**/AssemblyInfo.cs" Visible="false" />
<Compile Include="../../submodules/MediatR.Extensions.Microsoft.DependencyInjection/src/MediatR.Extensions.Microsoft.DependencyInjection/**/*.cs" Exclude="**/AssemblyInfo.cs" Visible="false" />
<Compile Include="../../submodules/MediatR/src/MediatR/**/*.cs" Exclude="**/*AssemblyInfo.cs" Visible="false" />
Copy link
Member Author

Choose a reason for hiding this comment

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

For some reason, when source including from OmniSharp-Roslyn, VS will go and restore the embedded MediatR, making it pickup a generated Assembly Info from obj folder. This fixes that.

<Compile Include="../../submodules/MediatR.Extensions.Microsoft.DependencyInjection/src/MediatR.Extensions.Microsoft.DependencyInjection/**/*.cs" Exclude="**/*AssemblyInfo.cs" Visible="false" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion src/Protocol/Models/Registration.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Newtonsoft.Json;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using OmniSharp.Extensions.LanguageServer.Protocol.Serialization;

Expand Down
1 change: 1 addition & 0 deletions src/Server/Abstractions/ILspHandlerDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public interface ILspHandlerDescriptor : IHandlerDescriptor
{
bool HasRegistration { get; }
Type RegistrationType { get; }
object RegisterOptions { get; }
Registration Registration { get; }

bool HasCapability { get; }
Expand Down
8 changes: 4 additions & 4 deletions src/Server/ClientCapabilityProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,29 +92,29 @@ public TOptions Get<TInterface, TOptions>(Func<TInterface, TOptions> action)
where TOptions : class
{
return _collection
.Select(x => x.Registration?.RegisterOptions is TInterface cl ? action(cl) : null)
.Select(x => x.RegisterOptions is TInterface cl ? action(cl) : null)
.FirstOrDefault(x => x != null);
}

public Supports<TOptions> Can<TInterface, TOptions>(Func<TInterface, TOptions> action)
where TOptions : class
{
var options = _collection
.Select(x => x.Registration?.RegisterOptions is TInterface cl ? action(cl) : null)
.Select(x => x.RegisterOptions is TInterface cl ? action(cl) : null)
.FirstOrDefault(x => x != null);
if (options == null)
return Supports.OfBoolean<TOptions>(false);

return _collection
.Select(x => x.Registration?.RegisterOptions is TInterface cl ? action(cl) : null)
.Select(x => x.RegisterOptions is TInterface cl ? action(cl) : null)
.FirstOrDefault(x => x != null);
}

public TOptions Reduce<TInterface, TOptions>(Func<IEnumerable<TInterface>, TOptions> action)
where TOptions : class
{
return action(_collection
.Select(x => x.Registration?.RegisterOptions is TInterface cl ? cl : default)
.Select(x => x.RegisterOptions is TInterface cl ? cl : default)
.Where(x => x != null));
}
}
Expand Down
1 change: 1 addition & 0 deletions src/Server/HandlerCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ private HandlerDescriptor GetDescriptor(string method, Type handlerType, IJsonRp
@interface,
@params,
registrationType,
registrationOptions,
registration,
capabilityType,
() => {
Expand Down
3 changes: 3 additions & 0 deletions src/Server/HandlerDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public HandlerDescriptor(
Type handlerType,
Type @params,
Type registrationType,
object registerOptions,
Registration registration,
Type capabilityType,
Action disposeAction)
Expand All @@ -35,6 +36,7 @@ public HandlerDescriptor(
Params = @params;
Response = Response;
RegistrationType = registrationType;
RegisterOptions = registerOptions;
Registration = registration;
CapabilityType = capabilityType;

Expand Down Expand Up @@ -65,6 +67,7 @@ public HandlerDescriptor(

public bool HasRegistration => RegistrationType != null;
public Type RegistrationType { get; }
public object RegisterOptions { get; }
public Registration Registration { get; }

public bool HasCapability => CapabilityType != null;
Expand Down
2 changes: 1 addition & 1 deletion src/Server/Matchers/ExecuteCommandMatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public IEnumerable<ILspHandlerDescriptor> FindHandler(object parameters, IEnumer
_logger.LogTrace("Registration options {OptionsName}", executeCommandParams.GetType().FullName);
foreach (var descriptor in descriptors)
{
if (descriptor.Registration?.RegisterOptions is ExecuteCommandRegistrationOptions registrationOptions && registrationOptions.Commands.Any(x => x == executeCommandParams.Command))
if (descriptor.RegisterOptions is ExecuteCommandRegistrationOptions registrationOptions && registrationOptions.Commands.Any(x => x == executeCommandParams.Command))
{
_logger.LogTrace("Checking handler {Method}:{Handler}",
executeCommandParams.Command,
Expand Down
2 changes: 1 addition & 1 deletion src/Server/Matchers/TextDocumentMatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ private IEnumerable<ILspHandlerDescriptor> GetHandler(IEnumerable<ILspHandlerDes
foreach (var descriptor in descriptors)
{
_logger.LogTrace("Checking handler {Method}:{Handler}", method, descriptor.ImplementationType.FullName);
var registrationOptions = descriptor.Registration?.RegisterOptions as ITextDocumentRegistrationOptions;
var registrationOptions = descriptor.RegisterOptions as ITextDocumentRegistrationOptions;

_logger.LogTrace("Registration options {OptionsName}", registrationOptions?.GetType().FullName);
_logger.LogTrace("Document Selector {DocumentSelector}", registrationOptions?.DocumentSelector.ToString());
Expand Down
8 changes: 5 additions & 3 deletions test/Lsp.Tests/Matchers/ExecuteCommandHandlerMatcherTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ public void Should_Return_Handler_Descriptor()
// Given
var handlerMatcher = AutoSubstitute.Resolve<ExecuteCommandMatcher>();
var executeCommandHandler = Substitute.For<IExecuteCommandHandler>().With(new Container<string>("Command"));
var registrationsOptions = new ExecuteCommandRegistrationOptions() {
Commands = new Container<string>("Command")
};

// When
var result = handlerMatcher.FindHandler(new ExecuteCommandParams { Command = "Command" },
Expand All @@ -68,10 +71,9 @@ public void Should_Return_Handler_Descriptor()
executeCommandHandler.GetType(),
typeof(ExecuteCommandParams),
typeof(ExecuteCommandRegistrationOptions),
registrationsOptions,
new Registration() {
RegisterOptions = new ExecuteCommandRegistrationOptions() {
Commands = new Container<string>("Command")
}
RegisterOptions = registrationsOptions
},
typeof(ExecuteCommandCapability),
() => { })
Expand Down
14 changes: 14 additions & 0 deletions test/Lsp.Tests/Matchers/ResolveCommandMatcherTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public void Should_Not_Throw_Given_Another_Descriptor()
null,
null,
null,
null,
() => { });
var handlerMatcher = new ResolveCommandPipeline<CodeLensParams, CodeLensContainer>(
new RequestContext() { Descriptor = handlerDescriptor },
Expand Down Expand Up @@ -101,6 +102,7 @@ public void Should_Return_CodeLensResolve_Descriptor()
null,
null,
null,
null,
() => { }),
new HandlerDescriptor(DocumentNames.CodeLensResolve,
"Key2",
Expand All @@ -110,6 +112,7 @@ public void Should_Return_CodeLensResolve_Descriptor()
null,
null,
null,
null,
() => { }),
})
.ToArray();
Expand Down Expand Up @@ -138,6 +141,7 @@ public void Should_Handle_Null_Data()
null,
null,
null,
null,
() => { }),
})
.ToArray();
Expand Down Expand Up @@ -168,6 +172,7 @@ public void Should_Handle_Simple_Json_Data()
null,
null,
null,
null,
() => { }),
})
.ToArray();
Expand Down Expand Up @@ -200,6 +205,7 @@ public void Should_Return_CompletionResolve_Descriptor()
null,
null,
null,
null,
() => { }),
new HandlerDescriptor(DocumentNames.CompletionResolve,
"Key2",
Expand All @@ -209,6 +215,7 @@ public void Should_Return_CompletionResolve_Descriptor()
null,
null,
null,
null,
() => { }),
})
.ToArray();
Expand Down Expand Up @@ -248,6 +255,7 @@ public void Should_Deal_WithHandlers_That_Not_Also_Resolvers()
null,
null,
null,
null,
() => { }),
new HandlerDescriptor(DocumentNames.CompletionResolve,
"Key2",
Expand All @@ -257,6 +265,7 @@ public void Should_Deal_WithHandlers_That_Not_Also_Resolvers()
null,
null,
null,
null,
() => { }),
})
.ToArray();
Expand Down Expand Up @@ -292,6 +301,7 @@ public void Should_Deal_WithHandlers_That_Not_Also_Resolvers2()
null,
null,
null,
null,
() => { }),
new HandlerDescriptor(DocumentNames.CompletionResolve,
"Key2",
Expand All @@ -301,6 +311,7 @@ public void Should_Deal_WithHandlers_That_Not_Also_Resolvers2()
null,
null,
null,
null,
() => { }),
})
.ToArray();
Expand Down Expand Up @@ -328,6 +339,7 @@ public async Task Should_Update_CompletionItems_With_HandlerType()
null,
null,
null,
null,
() => { });
var handlerMatcher = new ResolveCommandPipeline<CompletionParams, CompletionList>(
new RequestContext() { Descriptor = descriptor },
Expand Down Expand Up @@ -370,6 +382,7 @@ public async Task Should_Update_CodeLensContainer_With_HandlerType()
null,
null,
null,
null,
() => { });
var handlerMatcher = new ResolveCommandPipeline<CodeLensParams, CodeLensContainer>(
new RequestContext() { Descriptor = descriptor },
Expand Down Expand Up @@ -412,6 +425,7 @@ public async Task Should_Update_CodeLens_Removing_HandlerType()
null,
null,
null,
null,
() => { });
var handlerMatcher = new ResolveCommandPipeline<CodeLens, CodeLens>(
new RequestContext() { Descriptor = descriptor },
Expand Down
8 changes: 4 additions & 4 deletions vscode-testextension/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ export function activate(context: ExtensionContext) {

// The server is implemented in node
// let serverExe = 'dotnet';
let serverExe = 'D:\\development\\omnisharp\\omnisharp-roslyn\\bin\\Debug\\OmniSharp.Stdio.Driver\\net461\\OmniSharp.exe';
let serverExe = 'C:/Users/mb/src/gh/omnisharp-roslyn/artifacts/publish/OmniSharp.Stdio.Driver/win7-x64/OmniSharp.exe';
Copy link
Member Author

Choose a reason for hiding this comment

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

Oops, I'll remove these.

// let serverExe = context.asAbsolutePath('D:/Development/Omnisharp/omnisharp-roslyn/artifacts/publish/OmniSharp.Stdio/win7-x64/OmniSharp.exe');
// The debug options for the server
// let debugOptions = { execArgv: ['-lsp', '-d' };5
// let debugOptions = { execArgv: ['-lsp', '-d' };

// If the extension is launched in debug mode then the debug server options are used
// Otherwise the run options are used
let serverOptions: ServerOptions = {
run: { command: serverExe, args: ['-lsp', '-d'] },
debug: { command: serverExe, args: ['-lsp', '-d'] }
run: { command: serverExe, args: ['-lsp'] },
debug: { command: serverExe, args: ['-lsp'] }
}

// Options to control the language client
Expand Down