Skip to content

Commit 2392283

Browse files
Additional changes so that notifications get picked up properly
1 parent 3392ca5 commit 2392283

File tree

7 files changed

+33
-19
lines changed

7 files changed

+33
-19
lines changed

sample/SampleServer/TextDocumentHandler.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ class TextDocumentHandler : ITextDocumentSyncHandler
1919
private readonly DocumentSelector _documentSelector = new DocumentSelector(
2020
new DocumentFilter()
2121
{
22-
Pattern = "**/*.csproj",
23-
Language = "xml"
22+
Pattern = "**/*.cs"
2423
}
2524
);
2625

src/JsonRpc/InputHandler.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,8 @@ private void HandleRequest(string request)
175175
_scheduler.Add(
176176
type,
177177
item.Request.Method,
178-
async () => {
178+
async () =>
179+
{
179180
try
180181
{
181182
var result = await _requestRouter.RouteRequest(descriptor, item.Request);
@@ -191,15 +192,17 @@ private void HandleRequest(string request)
191192
}
192193
);
193194
}
194-
else if (item.IsNotification)
195+
196+
if (item.IsNotification)
195197
{
196198
var descriptor = _requestRouter.GetDescriptor(item.Notification);
197199
if (descriptor is null) continue;
198200
var type = _requestProcessIdentifier.Identify(descriptor);
199201
_scheduler.Add(
200202
type,
201203
item.Notification.Method,
202-
async () => {
204+
async () =>
205+
{
203206
try
204207
{
205208
await _requestRouter.RouteNotification(descriptor, item.Notification);
@@ -214,7 +217,8 @@ private void HandleRequest(string request)
214217
}
215218
);
216219
}
217-
else if (item.IsError)
220+
221+
if (item.IsError)
218222
{
219223
// TODO:
220224
_outputHandler.Send(item.Error);

src/JsonRpc/ProcessScheduler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ private void ProcessRequestQueue()
9797
{
9898
// TODO: Should we rethrow or swallow?
9999
// If an exception happens... the whole system could be in a bad state, hence this throwing currently.
100-
_logger.LogCritical(Events.UnhandledException, e, "Unhandled exception executing request {Name}", name);
100+
_logger.LogCritical(Events.UnhandledException, e, "Unhandled exception executing {Name}", name);
101101
throw;
102102
}
103103
}

src/Server/LanguageServer.cs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,16 @@ async Task<InitializeResult> IRequestHandler<InitializeParams, InitializeResult>
232232
{
233233
ClientSettings = request;
234234

235+
if (request.Trace == InitializeTrace.Verbose && MinimumLogLevel >= LogLevel.Information)
236+
{
237+
MinimumLogLevel = LogLevel.Trace;
238+
}
239+
240+
await Task.WhenAll(_initializeDelegates.Select(c => c(request)));
241+
242+
_clientVersion = request.Capabilities.GetClientVersion();
243+
_serializer.SetClientCapabilities(_clientVersion.Value, request.Capabilities);
244+
235245
var supportedCapabilites = new List<ISupports>();
236246
if (_clientVersion == ClientVersion.Lsp3)
237247
{
@@ -252,13 +262,8 @@ async Task<InitializeResult> IRequestHandler<InitializeParams, InitializeResult>
252262

253263
_supportedCapabilities.Add(supportedCapabilites);
254264

255-
await Task.WhenAll(_initializeDelegates.Select(c => c(request)));
256-
257265
AddHandlers(_serviceProvider.GetServices<IJsonRpcHandler>().ToArray());
258266

259-
_clientVersion = request.Capabilities.GetClientVersion();
260-
_serializer.SetClientCapabilities(_clientVersion.Value, request.Capabilities);
261-
262267
var textDocumentCapabilities = ClientSettings.Capabilities.TextDocument;
263268
var workspaceCapabilities = ClientSettings.Capabilities.Workspace;
264269

@@ -334,7 +339,6 @@ async Task<InitializeResult> IRequestHandler<InitializeParams, InitializeResult>
334339

335340
await Task.WhenAll(_initializedDelegates.Select(c => c(request, result)));
336341

337-
338342
// TODO:
339343
if (_clientVersion == ClientVersion.Lsp2)
340344
{
@@ -367,9 +371,8 @@ private async Task DynamicallyRegisterHandlers(Registration[] registrations)
367371

368372
var @params = new RegistrationParams() { Registrations = registrations };
369373

370-
await _initializeComplete
371-
.Select(x => System.Reactive.Unit.Default)
372-
.Concat(Observable.Defer(() => Client.RegisterCapability(@params).ToObservable()));
374+
await _initializeComplete;
375+
await Client.RegisterCapability(@params);
373376
}
374377

375378
public IObservable<bool> Shutdown => _shutdownHandler.Shutdown;
@@ -452,7 +455,8 @@ public void Add(IEnumerable<ISupports> supports)
452455
{
453456
foreach (var item in supports)
454457
{
455-
_supports.Add(item.ValueType, item.Value);
458+
if (!_supports.TryGetValue(item.ValueType, out _))
459+
_supports.Add(item.ValueType, item.Value);
456460
}
457461
}
458462

src/Server/LanguageServerLogger.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Except
3535
_responseRouter.Window.Log(new LogMessageParams()
3636
{
3737
Type = messageType,
38-
Message = formatter(state, exception)
38+
Message = formatter(state, exception) + (exception != null ? " - " + exception.ToString() : "")
3939
});
4040
}
4141
}

src/Server/LspReciever.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public override (IEnumerable<Renor> results, bool hasResponse) GetRequests(JToke
3434
{
3535
newResults.Add(item);
3636
}
37-
else if (item.IsNotification && item.Notification.Method == GeneralNames.Exit)
37+
else if (item.IsNotification)
3838
{
3939
newResults.Add(item);
4040
}

test/JsonRpc.Tests/Server/SpecifictionRecieverTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,13 @@ public override IEnumerable<ValueTuple<string, Renor[]>> GetValues()
101101
new Notification("foobar", new JObject())
102102
});
103103

104+
yield return (
105+
@"{""jsonrpc"":""2.0"",""method"":""initialized"",""params"":{}}",
106+
new Renor[] {
107+
new Notification("initialized", new JObject()),
108+
}
109+
);
110+
104111
yield return (
105112
@"{""jsonrpc"": ""2.0"", ""method"": 1, ""params"": ""bar""}",
106113
new Renor[]

0 commit comments

Comments
 (0)