Skip to content

Commit 851ac06

Browse files
Fixed logging so it works correctly! (#341)
* Fixed logging so it works correctly! * timing * bump * tests are still stalling on windows * buffer work done test * Update client tests to skip windows too * minor fix
1 parent c7716ce commit 851ac06

18 files changed

+186
-40
lines changed

.build/Build.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ public partial class Solution : NukeBuild,
5757

5858
public Target Clean => _ => _.Inherit<ICanClean>(x => x.Clean);
5959
public Target Restore => _ => _.Inherit<ICanRestoreWithDotNetCore>(x => x.CoreRestore);
60+
6061
public Target Test => _ => _.Inherit<ICanTestWithDotNetCore>(x => x.CoreTest);
6162

6263
public Target BuildVersion => _ => _.Inherit<IHaveBuildVersion>(x => x.BuildVersion)

src/Dap.Testing/DebugAdapterProtocolTestBase.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ Action<DebugAdapterServerOptions> serverOptionsAction
4747
.ConfigureLogging(
4848
x => {
4949
x.SetMinimumLevel(LogLevel.Trace);
50-
x.Services.AddSingleton(TestOptions.ClientLoggerFactory);
5150
}
5251
)
5352
.Services
@@ -65,7 +64,6 @@ Action<DebugAdapterServerOptions> serverOptionsAction
6564
.ConfigureLogging(
6665
x => {
6766
x.SetMinimumLevel(LogLevel.Trace);
68-
x.Services.AddSingleton(TestOptions.ServerLoggerFactory);
6967
}
7068
)
7169
.Services

src/Dap.Testing/DebugAdapterServerTestBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ protected virtual async Task<IDebugAdapterClient> InitializeClient(Action<DebugA
3131
options
3232
.WithInput(reader)
3333
.WithOutput(writer)
34+
.WithLoggerFactory(TestOptions.ClientLoggerFactory)
3435
.ConfigureLogging(
3536
x => {
3637
x.SetMinimumLevel(LogLevel.Trace);
37-
x.Services.AddSingleton(TestOptions.ClientLoggerFactory);
3838
}
3939
)
4040
.Services

src/JsonRpc.Testing/JsonRpcServerTestBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ Action<JsonRpcServerOptions> serverOptionsAction
3636
var clientTask = JsonRpcServer.From(
3737
options => {
3838
options
39+
.WithLoggerFactory(TestOptions.ClientLoggerFactory)
3940
.WithServices(
4041
services => services
4142
.AddTransient(typeof(IPipelineBehavior<,>), typeof(SettlePipeline<,>))
4243
.AddSingleton(ClientEvents as IRequestSettler)
4344
.AddLogging(
4445
x => {
4546
x.SetMinimumLevel(LogLevel.Trace);
46-
x.Services.AddSingleton(TestOptions.ClientLoggerFactory);
4747
}
4848
)
4949
);

src/JsonRpc/JsonRpcServerOptionsBase.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using Microsoft.Extensions.DependencyInjection;
99
using Microsoft.Extensions.DependencyInjection.Extensions;
1010
using Microsoft.Extensions.Logging;
11+
using Microsoft.Extensions.Logging.Abstractions;
1112
using Nerdbank.Streams;
1213

1314
namespace OmniSharp.Extensions.JsonRpc
@@ -86,6 +87,7 @@ public T WithPipe(Pipe pipe)
8687

8788
public T WithLoggerFactory(ILoggerFactory loggerFactory)
8889
{
90+
if (loggerFactory == NullLoggerFactory.Instance) return (T) (object) this;
8991
Services.RemoveAll(typeof(ILoggerFactory));
9092
Services.AddSingleton(loggerFactory);
9193
return (T) (object) this;

src/JsonRpc/ResponseRouter.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,31 @@
99

1010
namespace OmniSharp.Extensions.JsonRpc
1111
{
12-
public class ResponseRouter : IResponseRouter
12+
internal class ResponseRouter : IResponseRouter
1313
{
14-
internal readonly IOutputHandler OutputHandler;
14+
internal readonly Lazy<IOutputHandler> OutputHandler;
1515
internal readonly ISerializer Serializer;
1616
private readonly IHandlerTypeDescriptorProvider<IHandlerTypeDescriptor> _handlerTypeDescriptorProvider;
1717

1818
internal readonly ConcurrentDictionary<long, (string method, TaskCompletionSource<JToken> pendingTask)> Requests =
1919
new ConcurrentDictionary<long, (string method, TaskCompletionSource<JToken> pendingTask)>();
2020

21-
public ResponseRouter(IOutputHandler outputHandler, ISerializer serializer, IHandlerTypeDescriptorProvider<IHandlerTypeDescriptor> handlerTypeDescriptorProvider)
21+
public ResponseRouter(Lazy<IOutputHandler> outputHandler, ISerializer serializer, IHandlerTypeDescriptorProvider<IHandlerTypeDescriptor> handlerTypeDescriptorProvider)
2222
{
2323
OutputHandler = outputHandler;
2424
Serializer = serializer;
2525
_handlerTypeDescriptorProvider = handlerTypeDescriptorProvider;
2626
}
2727

2828
public void SendNotification(string method) =>
29-
OutputHandler.Send(
29+
OutputHandler.Value.Send(
3030
new OutgoingNotification {
3131
Method = method
3232
}
3333
);
3434

3535
public void SendNotification<T>(string method, T @params) =>
36-
OutputHandler.Send(
36+
OutputHandler.Value.Send(
3737
new OutgoingNotification {
3838
Method = method,
3939
Params = @params
@@ -81,7 +81,7 @@ public async Task<TResponse> Returning<TResponse>(CancellationToken cancellation
8181

8282
cancellationToken.ThrowIfCancellationRequested();
8383

84-
_router.OutputHandler.Send(
84+
_router.OutputHandler.Value.Send(
8585
new OutgoingRequest {
8686
Method = _method,
8787
Params = _params,

src/Protocol/LanguageProtocolRpcOptionsBase.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ public abstract class LanguageProtocolRpcOptionsBase<T> : JsonRpcServerOptionsBa
1414
{
1515
public LanguageProtocolRpcOptionsBase()
1616
{
17-
Services.AddLogging(builder => LoggingBuilderAction?.Invoke(builder));
1817
WithAssemblies(typeof(LanguageProtocolRpcOptionsBase<>).Assembly);
1918
}
2019

src/Server/Logging/LanguageServerLogger.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ namespace OmniSharp.Extensions.LanguageServer.Server
1212
{
1313
internal class LanguageServerLogger : ILogger
1414
{
15-
private readonly ILanguageServer _responseRouter;
15+
private readonly ILanguageServerFacade _responseRouter;
1616
private readonly string _categoryName;
1717
private readonly Func<LogLevel> _logLevelGetter;
1818

19-
public LanguageServerLogger(ILanguageServer responseRouter, string categoryName, Func<LogLevel> logLevelGetter)
19+
public LanguageServerLogger(ILanguageServerFacade responseRouter, string categoryName, Func<LogLevel> logLevelGetter)
2020
{
2121
_logLevelGetter = logLevelGetter;
2222
_responseRouter = responseRouter;
@@ -68,7 +68,8 @@ private bool TryGetMessageType(LogLevel logLevel, out MessageType messageType)
6868
return true;
6969
case LogLevel.Debug:
7070
case LogLevel.Trace:
71-
messageType = MessageType.Info;
71+
// TODO: Integrate with set trace?
72+
messageType = MessageType.Log;
7273
return true;
7374
}
7475

src/Server/Logging/LanguageServerLoggerProvider.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ namespace OmniSharp.Extensions.LanguageServer.Server
55
{
66
internal class LanguageServerLoggerProvider : ILoggerProvider
77
{
8-
private readonly ILanguageServer _languageServer;
8+
private readonly ILanguageServerFacade _languageServer;
99
private readonly LanguageServerLoggerSettings _settings;
1010

11-
public LanguageServerLoggerProvider(ILanguageServer languageServer, LanguageServerLoggerSettings settings)
11+
public LanguageServerLoggerProvider(ILanguageServerFacade languageServer, LanguageServerLoggerSettings settings)
1212
{
1313
_languageServer = languageServer;
1414
_settings = settings;

src/Shared/LanguageProtocolServiceCollectionExtensions.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ internal static IContainer AddLanguageProtocolInternals<T>(this IContainer conta
2525
throw new ArgumentException("Serializer is missing!", nameof(options));
2626
}
2727

28+
options.Services.AddLogging(builder => options.LoggingBuilderAction?.Invoke(builder));
29+
2830
container = container.AddJsonRpcServerCore(options);
2931
container.RegisterInstanceMany(new LspHandlerTypeDescriptorProvider(options.Assemblies), nonPublicServiceTypes: true);
3032

0 commit comments

Comments
 (0)