Skip to content

Fixed how partial items are scheduled #565

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 34 commits into from
Apr 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
28f6068
wip scheduler fix
david-driscoll Apr 9, 2021
93ead30
Fixed issues with scheduling around partial items and results. This …
david-driscoll Apr 10, 2021
6f58efc
rollback changes from wip commit
david-driscoll Apr 10, 2021
a5fc237
Updated sample project
david-driscoll Apr 10, 2021
6004faa
Merge remote-tracking branch 'origin/master' into scheduler/fix
david-driscoll Apr 16, 2021
edc2ac0
Remove retry facts!
david-driscoll Apr 10, 2021
9bbe918
Updated tests to run generation tests on all platforms
david-driscoll Apr 10, 2021
0dae323
Updated replay subject
david-driscoll Apr 10, 2021
74660a7
Fixed schedulers for replay subjects
david-driscoll Apr 16, 2021
81b402f
Merge remote-tracking branch 'origin/master' into temp/remove-retry-f…
david-driscoll Apr 22, 2021
9003a11
Ensure that progress observable task is created before the handler me…
david-driscoll Apr 22, 2021
fc347ef
so very very close
david-driscoll Apr 22, 2021
c63f4a4
register UnregisterCapability disposable earlier in the process
david-driscoll Apr 22, 2021
5011832
mirror partial item observable
david-driscoll Apr 22, 2021
2ad833d
more minor changes
david-driscoll Apr 22, 2021
f8502d3
change how completion works
david-driscoll Apr 22, 2021
b1ef462
replay scheduling maybe?
david-driscoll Apr 22, 2021
845a4fe
add output logging
david-driscoll Apr 22, 2021
2d09c8c
make logging output records for better details
david-driscoll Apr 22, 2021
0adadfb
Output handler is annoying at times
david-driscoll Apr 22, 2021
f470660
was the success a fluke???
david-driscoll Apr 23, 2021
0a1d0a6
place facts back
david-driscoll Apr 23, 2021
b94e7a1
does this break the world?
david-driscoll Apr 23, 2021
a689d93
does this break the world?
david-driscoll Apr 23, 2021
fde9d1c
retry facts for a few things
david-driscoll Apr 23, 2021
08e4ab1
retry facts for a few things
david-driscoll Apr 23, 2021
49cb9a0
retry facts for a few things
david-driscoll Apr 23, 2021
5cdb228
retry facts for a few things
david-driscoll Apr 23, 2021
1a10461
retry facts for a few things
david-driscoll Apr 23, 2021
314eba8
Revert "retry facts for a few things"
david-driscoll Apr 23, 2021
2eae994
overhaul the outputhandler
david-driscoll Apr 23, 2021
a599e48
Make progress events serial
david-driscoll Apr 23, 2021
e4b04cb
more serial changes
david-driscoll Apr 23, 2021
42cafff
remove retry fact comments
david-driscoll Apr 23, 2021
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
105 changes: 53 additions & 52 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -1,52 +1,53 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>
<PropertyGroup>
<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GeneratedFiles</CompilerGeneratedFilesOutputPath>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
<PackageReference Include="Rocket.Surgery.MSBuild.CI" Version="1.1.0" PrivateAssets="All" />
<PackageReference Include="Rocket.Surgery.MSBuild.Metadata" Version="1.1.0" PrivateAssets="All" />
<PackageReference Include="Rocket.Surgery.MSBuild.SourceLink" Version="1.1.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.0" PrivateAssets="All" />
</ItemGroup>
<ItemGroup>
<PackageReference Update="GitVersion.Tool" Version="5.6.6" />
<PackageReference Update="JetBrains.ReSharper.CommandLineTools" Version="2020.3.3" />
<PackageReference Update="ReportGenerator" Version="4.8.6" />
<PackageReference Update="Rocket.Surgery.Nuke" Version="0.14.3" />
</ItemGroup>
<ItemGroup>
<PackageReference Update="Microsoft.Extensions.Logging" Version="2.0.0" />
<PackageReference Update="Microsoft.Extensions.Logging.Debug" Version="2.0.0" />
<PackageReference Update="Microsoft.Extensions.Configuration" Version="2.0.0" />
<PackageReference Update="Microsoft.Extensions.Configuration.Binder" Version="2.0.0" />
<PackageReference Update="Microsoft.Extensions.Options" Version="2.0.0" />
<PackageReference Update="Microsoft.Extensions.Options.ConfigurationExtensions" Version="2.0.0" />
<PackageReference Update="Microsoft.Extensions.DependencyInjection" Version="2.0.0" />
<PackageReference Update="Newtonsoft.Json" Version="11.0.2" />
<PackageReference Update="Microsoft.NET.Test.Sdk" Version="16.9.1" />
<PackageReference Update="xunit.runner.visualstudio" Version="2.4.3" />
<PackageReference Update="xunit" Version="2.4.1" />
<PackageReference Update="FluentAssertions" Version="5.10.3" />
<PackageReference Update="NSubstitute" Version="4.2.2" />
<PackageReference Update="Serilog.Extensions.Logging" Version="2.0.2" />
<PackageReference Update="Serilog.Sinks.Observable" Version="2.0.2" />
<PackageReference Update="Serilog.Sinks.XUnit" Version="2.0.4" />
<PackageReference Update="XunitXml.TestLogger" Version="3.0.62" />
<PackageReference Update="coverlet.collector" Version="3.0.3" />
<PackageReference Update="coverlet.msbuild" Version="3.0.3" />
<PackageReference Update="System.Reactive" Version="4.4.1" />
<PackageReference Update="System.Collections.Immutable" Version="1.7.1" />
<PackageReference Update="Microsoft.Reactive.Testing" Version="4.4.1" />
<PackageReference Update="MediatR" Version="8.1.0" />
<PackageReference Update="Bogus" Version="33.0.2" />
<PackageReference Update="Snapper" Version="2.3.0" />
<PackageReference Update="Xunit.SkippableFact" Version="1.4.13" />
<PackageReference Update="System.IO.Pipelines" Version="4.7.3" />
<PackageReference Update="Nerdbank.Streams" Version="2.6.81" />
<PackageReference Update="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="3.8.0" />
<PackageReference Update="Microsoft.CodeAnalysis.Analyzers" Version="3.3.2" />
<PackageReference Update="DryIoc.Internal" Version="4.7.3" />
</ItemGroup>
</Project>
<?xml version="1.0" encoding="utf-8"?>
<Project>
<PropertyGroup>
<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GeneratedFiles</CompilerGeneratedFilesOutputPath>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All"/>
<PackageReference Include="Rocket.Surgery.MSBuild.CI" Version="1.1.0" PrivateAssets="All"/>
<PackageReference Include="Rocket.Surgery.MSBuild.Metadata" Version="1.1.0" PrivateAssets="All"/>
<PackageReference Include="Rocket.Surgery.MSBuild.SourceLink" Version="1.1.0" PrivateAssets="All"/>
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.0" PrivateAssets="All"/>
</ItemGroup>
<ItemGroup>
<PackageReference Update="GitVersion.Tool" Version="5.6.6"/>
<PackageReference Update="JetBrains.ReSharper.CommandLineTools" Version="2020.3.3"/>
<PackageReference Update="ReportGenerator" Version="4.8.6"/>
<PackageReference Update="Rocket.Surgery.Nuke" Version="0.14.3"/>
</ItemGroup>
<ItemGroup>
<PackageReference Update="Microsoft.Extensions.Logging" Version="2.0.0"/>
<PackageReference Update="Microsoft.Extensions.Logging.Debug" Version="2.0.0"/>
<PackageReference Update="Microsoft.Extensions.Configuration" Version="2.0.0"/>
<PackageReference Update="Microsoft.Extensions.Configuration.Binder" Version="2.0.0"/>
<PackageReference Update="Microsoft.Extensions.Options" Version="2.0.0"/>
<PackageReference Update="Microsoft.Extensions.Options.ConfigurationExtensions" Version="2.0.0"/>
<PackageReference Update="Microsoft.Extensions.DependencyInjection" Version="2.0.0"/>
<PackageReference Update="Newtonsoft.Json" Version="11.0.2"/>
<PackageReference Update="Microsoft.NET.Test.Sdk" Version="16.9.1"/>
<PackageReference Update="xunit.runner.visualstudio" Version="2.4.3"/>
<PackageReference Update="xunit" Version="2.4.1"/>
<PackageReference Update="FluentAssertions" Version="5.10.3"/>
<PackageReference Update="NSubstitute" Version="4.2.2"/>
<PackageReference Update="Serilog.Extensions.Logging" Version="2.0.2"/>
<PackageReference Update="Serilog.Sinks.Observable" Version="2.0.2"/>
<PackageReference Update="Serilog.Sinks.XUnit" Version="2.0.4"/>
<PackageReference Update="XunitXml.TestLogger" Version="3.0.62"/>
<PackageReference Update="coverlet.collector" Version="3.0.3"/>
<PackageReference Update="coverlet.msbuild" Version="3.0.3"/>
<PackageReference Update="System.Reactive" Version="4.4.1"/>
<PackageReference Update="System.Collections.Immutable" Version="1.7.1"/>
<PackageReference Update="System.Threading.Channels" Version="4.7.1"/>
<PackageReference Update="Microsoft.Reactive.Testing" Version="4.4.1"/>
<PackageReference Update="MediatR" Version="8.1.0"/>
<PackageReference Update="Bogus" Version="33.0.2"/>
<PackageReference Update="Snapper" Version="2.3.0"/>
<PackageReference Update="Xunit.SkippableFact" Version="1.4.13"/>
<PackageReference Update="System.IO.Pipelines" Version="4.7.3"/>
<PackageReference Update="Nerdbank.Streams" Version="2.6.81"/>
<PackageReference Update="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="3.8.0"/>
<PackageReference Update="Microsoft.CodeAnalysis.Analyzers" Version="3.3.2"/>
<PackageReference Update="DryIoc.Internal" Version="4.7.3"/>
</ItemGroup>
</Project>
11 changes: 9 additions & 2 deletions src/Client/LanguageClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Reactive.Concurrency;
using System.Reactive.Disposables;
using System.Reactive.Linq;
using System.Reactive.Subjects;
Expand Down Expand Up @@ -48,6 +49,7 @@ public class LanguageClient : JsonRpcServerBase, ILanguageClient
private readonly IEnumerable<IOnLanguageClientInitialized> _initializedHandlers;
private readonly LspSerializer _serializer;
private readonly InstanceHasStarted _instanceHasStarted;
private readonly IScheduler _scheduler;
private readonly IResponseRouter _responseRouter;
private readonly ISubject<InitializeResult> _initializeComplete = new AsyncSubject<InitializeResult>();
private readonly CompositeDisposable _disposable = new CompositeDisposable();
Expand Down Expand Up @@ -150,7 +152,8 @@ internal LanguageClient(
IEnumerable<OnLanguageClientInitializedDelegate> initializedDelegates,
IEnumerable<IOnLanguageClientInitialized> initializedHandlers,
LspSerializer serializer,
InstanceHasStarted instanceHasStarted
InstanceHasStarted instanceHasStarted,
IScheduler scheduler
) : base(handlerCollection, responseRouter)
{
_connection = connection;
Expand Down Expand Up @@ -179,6 +182,7 @@ InstanceHasStarted instanceHasStarted
_initializedHandlers = initializedHandlers;
_serializer = serializer;
_instanceHasStarted = instanceHasStarted;
_scheduler = scheduler;
_concurrency = options.Value.Concurrency;

// We need to at least create Window here in case any handler does loggin in their constructor
Expand Down Expand Up @@ -262,6 +266,7 @@ await LanguageProtocolEventingHelper.Run(
_initializeHandlers.Union(_collection.Select(z => z.Handler).OfType<IOnLanguageClientInitialize>()),
(handler, ct) => handler.OnInitialize(this, @params, ct),
_concurrency,
_scheduler,
token
).ConfigureAwait(false);

Expand All @@ -281,6 +286,7 @@ await LanguageProtocolEventingHelper.Run(
_initializedHandlers.Union(_collection.Select(z => z.Handler).OfType<IOnLanguageClientInitialized>()),
(handler, ct) => handler.OnInitialized(this, @params, serverParams, ct),
_concurrency,
_scheduler,
token
).ConfigureAwait(false);

Expand All @@ -299,6 +305,7 @@ await LanguageProtocolEventingHelper.Run(
_startedHandlers.Union(_collection.Select(z => z.Handler).OfType<IOnLanguageClientStarted>()),
(handler, ct) => handler.OnStarted(this, ct),
_concurrency,
_scheduler,
token
).ConfigureAwait(false);

Expand Down Expand Up @@ -395,7 +402,7 @@ private Supports<T> UseOrTryAndFindCapability<T>(Supports<T> supports) where T :
bool IResponseRouter.TryGetRequest(long id, [NotNullWhen(true)] out string method, [NotNullWhen(true)] out TaskCompletionSource<JToken> pendingTask) =>
_responseRouter.TryGetRequest(id, out method, out pendingTask);

public Task<InitializeResult> WasStarted => _initializeComplete.ToTask();
public Task<InitializeResult> WasStarted => _initializeComplete.ToTask(_scheduler);

public void Dispose()
{
Expand Down
49 changes: 49 additions & 0 deletions src/Client/LanguageClientOptionsExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Reactive.Concurrency;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
Expand Down Expand Up @@ -87,6 +88,54 @@ public static LanguageClientOptions WithClientCapabilities(this LanguageClientOp
return options;
}

/// <summary>
/// Sets both input and output schedulers to the same scheduler
/// </summary>
/// <param name="options"></param>
/// <param name="inputScheduler"></param>
/// <returns></returns>
public static LanguageClientOptions WithScheduler(this LanguageClientOptions options, IScheduler inputScheduler)
{
options.InputScheduler = options.OutputScheduler = options.DefaultScheduler = inputScheduler;
return options;
}

/// <summary>
/// Sets the scheduler used during reading input
/// </summary>
/// <param name="options"></param>
/// <param name="inputScheduler"></param>
/// <returns></returns>
public static LanguageClientOptions WithInputScheduler(this LanguageClientOptions options, IScheduler inputScheduler)
{
options.InputScheduler = inputScheduler;
return options;
}

/// <summary>
/// Sets the default scheduler to be used when scheduling other tasks
/// </summary>
/// <param name="options"></param>
/// <param name="defaultScheduler"></param>
/// <returns></returns>
public static LanguageClientOptions WithDefaultScheduler(this LanguageClientOptions options, IScheduler defaultScheduler)
{
options.DefaultScheduler = defaultScheduler;
return options;
}

/// <summary>
/// Sets the scheduler use during writing output
/// </summary>
/// <param name="options"></param>
/// <param name="outputScheduler"></param>
/// <returns></returns>
public static LanguageClientOptions WithOutputScheduler(this LanguageClientOptions options, IScheduler outputScheduler)
{
options.OutputScheduler = outputScheduler;
return options;
}

public static LanguageClientOptions OnInitialize(this LanguageClientOptions options, OnLanguageClientInitializeDelegate @delegate)
{
options.Services.AddSingleton(@delegate);
Expand Down
3 changes: 2 additions & 1 deletion src/Client/LanguageClientRegistrationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Reactive.Concurrency;
using System.Reactive.Linq;
using System.Reactive.Subjects;
using System.Threading;
Expand All @@ -26,7 +27,7 @@ internal class LanguageClientRegistrationManager : IRegisterCapabilityHandler, I
private readonly ILspHandlerTypeDescriptorProvider _handlerTypeDescriptorProvider;
private readonly ILogger<LanguageClientRegistrationManager> _logger;
private readonly ConcurrentDictionary<string, Registration> _registrations;
private readonly ReplaySubject<IEnumerable<Registration>> _registrationSubject = new ReplaySubject<IEnumerable<Registration>>(1);
private readonly ReplaySubject<IEnumerable<Registration>> _registrationSubject = new ReplaySubject<IEnumerable<Registration>>(1, Scheduler.Immediate);

public LanguageClientRegistrationManager(
ISerializer serializer,
Expand Down
3 changes: 2 additions & 1 deletion src/Client/LanguageClientWorkspaceFoldersManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Reactive.Concurrency;
using System.Reactive.Linq;
using System.Reactive.Subjects;
using System.Threading;
Expand All @@ -25,7 +26,7 @@ public LanguageClientWorkspaceFoldersManager(IWorkspaceLanguageClient client, IE
{
_client = client;
_workspaceFolders = new ConcurrentDictionary<DocumentUri, WorkspaceFolder>(DocumentUri.Comparer);
_workspaceFoldersSubject = new ReplaySubject<IEnumerable<WorkspaceFolder>>(1);
_workspaceFoldersSubject = new ReplaySubject<IEnumerable<WorkspaceFolder>>(1, Scheduler.Immediate);

foreach (var folder in workspaceFolders)
{
Expand Down
11 changes: 9 additions & 2 deletions src/Dap.Client/DebugAdapterClient.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reactive.Concurrency;
using System.Reactive.Disposables;
using System.Reactive.Subjects;
using System.Reactive.Threading.Tasks;
Expand Down Expand Up @@ -30,6 +31,7 @@ public class DebugAdapterClient : JsonRpcServerBase, IDebugAdapterClient, IDebug
private readonly IEnumerable<OnDebugAdapterClientStartedDelegate> _startedDelegates;
private readonly IEnumerable<IOnDebugAdapterClientStarted> _startedHandlers;
private readonly InstanceHasStarted _instanceHasStarted;
private readonly IScheduler _scheduler;
private readonly CompositeDisposable _disposable = new CompositeDisposable();
private readonly Connection _connection;
private readonly DapReceiver _receiver;
Expand Down Expand Up @@ -97,7 +99,8 @@ internal DebugAdapterClient(
IEnumerable<OnDebugAdapterClientInitializedDelegate> initializedDelegates,
IEnumerable<IOnDebugAdapterClientInitialized> initializedHandlers,
IEnumerable<IOnDebugAdapterClientStarted> startedHandlers,
InstanceHasStarted instanceHasStarted
InstanceHasStarted instanceHasStarted,
IScheduler scheduler
) : base(collection, responseRouter)
{
_settingsBag = settingsBag;
Expand All @@ -114,6 +117,7 @@ InstanceHasStarted instanceHasStarted
_initializedHandlers = initializedHandlers;
_startedHandlers = startedHandlers;
_instanceHasStarted = instanceHasStarted;
_scheduler = scheduler;
_concurrency = options.Value.Concurrency;

_disposable.Add(collection.Add(this));
Expand All @@ -127,6 +131,7 @@ await DebugAdapterEventingHelper.Run(
_initializeHandlers.Union(_collection.Select(z => z.Handler).OfType<IOnDebugAdapterClientInitialize>()),
(handler, ct) => handler.OnInitialize(this, ClientSettings, ct),
_concurrency,
_scheduler,
token
).ConfigureAwait(false);

Expand All @@ -145,17 +150,19 @@ await DebugAdapterEventingHelper.Run(
_initializedHandlers.Union(_collection.Select(z => z.Handler).OfType<IOnDebugAdapterClientInitialized>()),
(handler, ct) => handler.OnInitialized(this, ClientSettings, ServerSettings, ct),
_concurrency,
_scheduler,
token
).ConfigureAwait(false);

await _initializedComplete.ToTask(token);
await _initializedComplete.ToTask(token, _scheduler);

await DebugAdapterEventingHelper.Run(
_startedDelegates,
(handler, ct) => handler(this, ct),
_startedHandlers.Union(_collection.Select(z => z.Handler).OfType<IOnDebugAdapterClientStarted>()),
(handler, ct) => handler.OnStarted(this, ct),
_concurrency,
_scheduler,
token
).ConfigureAwait(false);

Expand Down
Loading