-
Notifications
You must be signed in to change notification settings - Fork 105
/
Copy pathInitializationTests.cs
105 lines (91 loc) · 4.16 KB
/
InitializationTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
using System.Collections.Generic;
using System.Reactive.Linq;
using System.Reactive.Threading.Tasks;
using System.Threading;
using System.Threading.Tasks;
using FluentAssertions;
using Microsoft.Extensions.DependencyInjection;
using NSubstitute;
using OmniSharp.Extensions.JsonRpc.Testing;
using OmniSharp.Extensions.LanguageProtocol.Testing;
using OmniSharp.Extensions.LanguageServer.Client;
using OmniSharp.Extensions.LanguageServer.Protocol.Client;
using OmniSharp.Extensions.LanguageServer.Protocol.Document;
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
using OmniSharp.Extensions.LanguageServer.Protocol.Server;
using OmniSharp.Extensions.LanguageServer.Protocol.Window;
using OmniSharp.Extensions.LanguageServer.Server;
using Xunit;
using Xunit.Abstractions;
namespace Lsp.Tests.Integration
{
public class InitializationTests : LanguageProtocolTestBase
{
public InitializationTests(ITestOutputHelper outputHelper) : base(new JsonRpcTestOptions().ConfigureForXUnit(outputHelper))
{
}
[Fact]
public async Task Logs_should_be_allowed_during_startup()
{
var (client, server) = await Initialize(ConfigureClient, ConfigureServer);
_logs.Should().HaveCount(2);
_logs.Should().ContainInOrder("OnInitialize", "OnInitialized");
}
[Fact]
public async Task Facades_should_be_resolvable()
{
var (client, server) = await Initialize(ConfigureClient, ConfigureServer);
client.Services.GetService<ILanguageClientFacade>().Should().NotBeNull();
server.Services.GetService<ILanguageServerFacade>().Should().NotBeNull();
// This ensures that the facade made it.
var response = await client.RequestCodeLens(new CodeLensParams(), CancellationToken);
response.Should().NotBeNull();
}
[Fact]
public async Task Should_Be_Able_To_Register_Before_Initialize()
{
var (client, server) = Create(options => options.EnableDynamicRegistration().EnableAllCapabilities(), options => {});
server.Register(
r => {
r.AddHandler<CodeLensHandlerA>();
}
);
await Observable.FromAsync(client.Initialize)
.ForkJoin(Observable.FromAsync(server.Initialize), (a, b) => ( client, server ))
.ToTask(CancellationToken);
client.Services.GetService<ILanguageClientFacade>().Should().NotBeNull();
server.Services.GetService<ILanguageServerFacade>().Should().NotBeNull();
// This ensures that the facade made it.
var response = await client.RequestCodeLens(new CodeLensParams(), CancellationToken);
response.Should().NotBeNull();
}
class CodeLensHandlerA : CodeLensHandler
{
public CodeLensHandlerA(ILanguageServerFacade languageServerFacade) : base(new CodeLensRegistrationOptions() { })
{
languageServerFacade.Should().NotBeNull();
}
public override Task<CodeLensContainer> Handle(CodeLensParams request, CancellationToken cancellationToken) => Task.FromResult(new CodeLensContainer());
public override Task<CodeLens> Handle(CodeLens request, CancellationToken cancellationToken) => Task.FromResult(request);
}
private readonly List<string> _logs = new List<string>();
private void ConfigureClient(LanguageClientOptions options) =>
options.OnLogMessage(log => { _logs.Add(log.Message); });
private void ConfigureServer(LanguageServerOptions options)
{
options.OnInitialize(
(server, request, token) => {
server.Window.LogInfo("OnInitialize");
return Task.CompletedTask;
}
);
options.AddHandler<CodeLensHandlerA>();
options.OnInitialized(
(server, request, response, token) => {
server.Window.LogInfo("OnInitialized");
return Task.CompletedTask;
}
);
}
}
}