Skip to content

Commit 6919dd4

Browse files
Updated how handlers are resolved, and when they are resolved.
Changed how capabilities are made available. Added additional callbacks
2 parents 507173c + af67c0d commit 6919dd4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+788
-574
lines changed

sample/SampleServer/Program.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,14 @@ static async Task MainAsync(string[] args)
2121
// await Task.Delay(100);
2222
//}
2323

24-
var server = LanguageServer.From(options =>
24+
var server = await LanguageServer.From(options =>
2525
options
2626
.WithInput(Console.OpenStandardInput())
2727
.WithOutput(Console.OpenStandardOutput())
2828
.WithLoggerFactory(new LoggerFactory()));
2929

30-
server.AddHandler(new TextDocumentHandler(server));
30+
server.AddHandlers(new TextDocumentHandler(server));
3131

32-
await server.Initialize();
3332
await server.WaitForExit;
3433
}
3534
}

sample/SampleServer/TextDocumentHandler.cs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,7 @@ public TextDocumentHandler(ILanguageServer router)
2929
_router = router;
3030
}
3131

32-
public TextDocumentSyncOptions Options { get; } = new TextDocumentSyncOptions()
33-
{
34-
WillSaveWaitUntil = false,
35-
WillSave = true,
36-
Change = TextDocumentSyncKind.Full,
37-
Save = new SaveOptions()
38-
{
39-
IncludeText = true
40-
},
41-
OpenClose = true
42-
};
32+
public TextDocumentSyncKind Change { get; } = TextDocumentSyncKind.Full;
4333

4434
public Task Handle(DidChangeTextDocumentParams notification, CancellationToken token)
4535
{
@@ -56,7 +46,7 @@ TextDocumentChangeRegistrationOptions IRegistration<TextDocumentChangeRegistrati
5646
return new TextDocumentChangeRegistrationOptions()
5747
{
5848
DocumentSelector = _documentSelector,
59-
SyncKind = Options.Change
49+
SyncKind = Change
6050
};
6151
}
6252

@@ -98,7 +88,7 @@ TextDocumentSaveRegistrationOptions IRegistration<TextDocumentSaveRegistrationOp
9888
return new TextDocumentSaveRegistrationOptions()
9989
{
10090
DocumentSelector = _documentSelector,
101-
IncludeText = Options.Save.IncludeText
91+
IncludeText = true
10292
};
10393
}
10494
public TextDocumentAttributes GetTextDocumentAttributes(Uri uri)

src/Client/LanguageClient.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public LanguageClient(ILoggerFactory loggerFactory, ServerProcess process)
9292
throw new ArgumentNullException(nameof(process));
9393

9494
_process = process;
95-
_process.Exited += ServerProcess_Exit;
95+
_process.Exited.Subscribe(x => ServerProcess_Exit());
9696
}
9797

9898
/// <summary>
@@ -452,7 +452,7 @@ async Task Start()
452452
/// <param name="args">
453453
/// The event arguments.
454454
/// </param>
455-
async void ServerProcess_Exit(object sender, EventArgs args)
455+
async void ServerProcess_Exit()
456456
{
457457
Log.LogDebug("Server process has exited; language client is shutting down...");
458458

src/Client/Processes/ServerProcess.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
using System;
1+
using System;
22
using System.IO;
3+
using System.Reactive.Linq;
4+
using System.Reactive.Subjects;
35
using System.Threading.Tasks;
46
using Microsoft.Extensions.Logging;
57

@@ -11,6 +13,7 @@ namespace OmniSharp.Extensions.LanguageServer.Client.Processes
1113
public abstract class ServerProcess
1214
: IDisposable
1315
{
16+
private readonly ISubject<System.Reactive.Unit> _exitedSubject;
1417
/// <summary>
1518
/// Create a new <see cref="ServerProcess"/>.
1619
/// </summary>
@@ -31,6 +34,8 @@ protected ServerProcess(ILoggerFactory loggerFactory)
3134

3235
ServerExitCompletion = new TaskCompletionSource<object>();
3336
ServerExitCompletion.SetResult(null); // Start out as if the server has already exited.
37+
38+
Exited = _exitedSubject = new AsyncSubject<System.Reactive.Unit>();
3439
}
3540

3641
/// <summary>
@@ -82,7 +87,7 @@ protected virtual void Dispose(bool disposing)
8287
/// <summary>
8388
/// Event raised when the server has exited.
8489
/// </summary>
85-
public event EventHandler<EventArgs> Exited;
90+
public IObservable<System.Reactive.Unit> Exited { get; }
8691

8792
/// <summary>
8893
/// Is the server running?
@@ -130,7 +135,8 @@ protected virtual void Dispose(bool disposing)
130135
/// </summary>
131136
protected virtual void OnExited()
132137
{
133-
Exited?.Invoke(this, EventArgs.Empty);
138+
_exitedSubject.OnNext(System.Reactive.Unit.Default);
139+
_exitedSubject.OnCompleted();
134140
}
135141
}
136142
}

src/JsonRpc/HandlerCollection.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public HandlerInstance(string method, IJsonRpcHandler handler, Type handlerInter
1919
{
2020
_disposeAction = disposeAction;
2121
Handler = handler;
22+
ImplementationType = handler.GetType();
2223
Method = method;
2324
HandlerType = handlerInterface;
2425
Params = @params;
@@ -27,6 +28,7 @@ public HandlerInstance(string method, IJsonRpcHandler handler, Type handlerInter
2728

2829
public IJsonRpcHandler Handler { get; }
2930
public Type HandlerType { get; }
31+
public Type ImplementationType { get; }
3032
public string Method { get; }
3133
public Type Params { get; }
3234
public Type Response { get; }

src/JsonRpc/IHandlerDescriptor.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ namespace OmniSharp.Extensions.JsonRpc
55
public interface IHandlerDescriptor
66
{
77
string Method { get; }
8-
IJsonRpcHandler Handler { get; }
98
Type HandlerType { get; }
9+
Type ImplementationType { get; }
1010
Type Params { get; }
1111
Type Response { get; }
12+
IJsonRpcHandler Handler { get; }
1213
}
1314
}

src/Protocol/Client/Capabilities/SynchronizationCapability.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace OmniSharp.Extensions.LanguageServer.Protocol.Client.Capabilities
66
{
7-
public class SynchronizationCapability : DynamicCapability, ConnectedCapability<ITextDocumentSyncHandler>
7+
public class SynchronizationCapability : DynamicCapability
88
{
99
/// <summary>
1010
/// The client supports sending will save notifications.

src/Protocol/Document/IDidChangeTextDocumentHandler.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using OmniSharp.Extensions.JsonRpc;
22
using OmniSharp.Extensions.LanguageServer.Protocol.Client.Capabilities;
33
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
4+
using OmniSharp.Extensions.LanguageServer.Protocol.Server.Capabilities;
45

56
// ReSharper disable CheckNamespace
67

@@ -13,5 +14,9 @@ public static partial class DocumentNames
1314
}
1415

1516
[Serial, Method(DidChange)]
16-
public interface IDidChangeTextDocumentHandler : IJsonRpcNotificationHandler<DidChangeTextDocumentParams>, IRegistration<TextDocumentChangeRegistrationOptions>, ICapability<SynchronizationCapability> { }
17+
public interface IDidChangeTextDocumentHandler : IJsonRpcNotificationHandler<DidChangeTextDocumentParams>,
18+
IRegistration<TextDocumentChangeRegistrationOptions>, ICapability<SynchronizationCapability>
19+
{
20+
TextDocumentSyncKind Change { get; }
21+
}
1722
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System;
2+
3+
namespace OmniSharp.Extensions.LanguageServer.Protocol
4+
{
5+
public interface ITextDocumentIdentifier
6+
{
7+
/// <summary>
8+
/// Returns the attributes for the document at the given URI. This can return null.
9+
/// </summary>
10+
/// <param name="uri"></param>
11+
/// <returns></returns>
12+
TextDocumentAttributes GetTextDocumentAttributes(Uri uri);
13+
}
14+
}
Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,10 @@
1-
using System;
21
using OmniSharp.Extensions.LanguageServer.Protocol.Server.Capabilities;
32

43
// ReSharper disable CheckNamespace
54

65
namespace OmniSharp.Extensions.LanguageServer.Protocol
76
{
8-
public interface ITextDocumentSyncHandler : IDidChangeTextDocumentHandler, IDidOpenTextDocumentHandler, IDidCloseTextDocumentHandler, IDidSaveTextDocumentHandler
7+
public interface ITextDocumentSyncHandler : IDidChangeTextDocumentHandler, IDidOpenTextDocumentHandler, IDidCloseTextDocumentHandler, IDidSaveTextDocumentHandler, ITextDocumentIdentifier
98
{
10-
TextDocumentSyncOptions Options { get; }
11-
/// <summary>
12-
/// Returns the attributes for the document at the given URI. This can return null.
13-
/// </summary>
14-
/// <param name="uri"></param>
15-
/// <returns></returns>
16-
TextDocumentAttributes GetTextDocumentAttributes(Uri uri);
179
}
1810
}

0 commit comments

Comments
 (0)