Fix shutdown issues from CLaSP

This commit is contained in:
Ryan Brandenburg 2022-10-19 17:08:24 -07:00
Родитель 5f9c65ace3
Коммит 3d76feadff
8 изменённых файлов: 98 добавлений и 103 удалений

Просмотреть файл

@ -81,7 +81,7 @@
<RoslynPackageVersion>4.4.0-2.22424.2</RoslynPackageVersion>
<VisualStudioLanguageServerProtocolVersion>17.4.1008-preview</VisualStudioLanguageServerProtocolVersion>
<MicrosoftNetCompilersToolsetVersion>4.4.0-1.final</MicrosoftNetCompilersToolsetVersion>
<MicrosoftCommonLanguageServerProtocolFrameworkPackageVersion>4.5.0-1.22513.3</MicrosoftCommonLanguageServerProtocolFrameworkPackageVersion>
<MicrosoftCommonLanguageServerProtocolFrameworkPackageVersion>4.5.0-1.22519.14</MicrosoftCommonLanguageServerProtocolFrameworkPackageVersion>
</PropertyGroup>
<PropertyGroup Label="Manual">
<!-- dotnet/runtime packages -->

Просмотреть файл

@ -127,11 +127,11 @@ namespace Microsoft.AspNetCore.Razor.Microbenchmarks.LanguageServer
}
[GlobalCleanup]
public async Task CleanupServerAsync()
public Task CleanupServerAsync()
{
File.Delete(_filePath);
await RazorLanguageServer.DisposeAsync();
return Task.CompletedTask;
}
private void EnsureServicesInitialized()

Просмотреть файл

@ -101,9 +101,9 @@ namespace Microsoft.AspNetCore.Razor.Microbenchmarks.LanguageServer
}
[GlobalCleanup]
public async Task CleanupServerAsync()
public Task CleanupServerAsync()
{
await RazorLanguageServer.DisposeAsync();
return Task.CompletedTask;
}
protected internal override void Builder(IServiceCollection collection)

Просмотреть файл

@ -18,117 +18,117 @@ using static Microsoft.AspNetCore.Razor.Microbenchmarks.LanguageServer.RazorSema
namespace Microsoft.AspNetCore.Razor.Microbenchmarks.LanguageServer
{
public class RazorSemanticTokensScrollingBenchmark : RazorLanguageServerBenchmarkBase
{
private DefaultRazorSemanticTokensInfoService RazorSemanticTokenService { get; set; }
public class RazorSemanticTokensScrollingBenchmark : RazorLanguageServerBenchmarkBase
{
private DefaultRazorSemanticTokensInfoService RazorSemanticTokenService { get; set; }
private DocumentVersionCache VersionCache { get; set; }
private DocumentVersionCache VersionCache { get; set; }
private DocumentContext DocumentContext { get; set; }
private DocumentContext DocumentContext { get; set; }
private Uri DocumentUri => DocumentContext.Uri;
private Uri DocumentUri => DocumentContext.Uri;
private DocumentSnapshot DocumentSnapshot => DocumentContext.Snapshot;
private DocumentSnapshot DocumentSnapshot => DocumentContext.Snapshot;
private Range Range { get; set; }
private Range Range { get; set; }
private ProjectSnapshotManagerDispatcher ProjectSnapshotManagerDispatcher { get; set; }
private ProjectSnapshotManagerDispatcher ProjectSnapshotManagerDispatcher { get; set; }
private string PagesDirectory { get; set; }
private string PagesDirectory { get; set; }
private string ProjectFilePath { get; set; }
private string ProjectFilePath { get; set; }
private string TargetPath { get; set; }
private string TargetPath { get; set; }
[GlobalSetup(Target = nameof(RazorSemanticTokensRangeScrollingAsync))]
public async Task InitializeRazorSemanticAsync()
{
EnsureServicesInitialized();
[GlobalSetup(Target = nameof(RazorSemanticTokensRangeScrollingAsync))]
public async Task InitializeRazorSemanticAsync()
{
EnsureServicesInitialized();
var projectRoot = Path.Combine(RepoRoot, "src", "Razor", "test", "testapps", "ComponentApp");
ProjectFilePath = Path.Combine(projectRoot, "ComponentApp.csproj");
PagesDirectory = Path.Combine(projectRoot, "Components", "Pages");
var filePath = Path.Combine(PagesDirectory, $"FormattingTest.razor");
TargetPath = "/Components/Pages/FormattingTest.razor";
var projectRoot = Path.Combine(RepoRoot, "src", "Razor", "test", "testapps", "ComponentApp");
ProjectFilePath = Path.Combine(projectRoot, "ComponentApp.csproj");
PagesDirectory = Path.Combine(projectRoot, "Components", "Pages");
var filePath = Path.Combine(PagesDirectory, $"FormattingTest.razor");
TargetPath = "/Components/Pages/FormattingTest.razor";
var documentUri = new Uri(filePath);
var documentSnapshot = GetDocumentSnapshot(ProjectFilePath, filePath, TargetPath);
DocumentContext = new DocumentContext(documentUri, documentSnapshot, version: 1);
var documentUri = new Uri(filePath);
var documentSnapshot = GetDocumentSnapshot(ProjectFilePath, filePath, TargetPath);
DocumentContext = new DocumentContext(documentUri, documentSnapshot, version: 1);
var text = await DocumentSnapshot.GetTextAsync().ConfigureAwait(false);
Range = new Range
{
Start = new Position
{
Line = 0,
Character = 0
},
End = new Position
{
Line = text.Lines.Count - 1,
Character = 0
}
};
}
var text = await DocumentSnapshot.GetTextAsync().ConfigureAwait(false);
Range = new Range
{
Start = new Position
{
Line = 0,
Character = 0
},
End = new Position
{
Line = text.Lines.Count - 1,
Character = 0
}
};
}
private const int WindowSize = 10;
private const int WindowSize = 10;
[Benchmark(Description = "Razor Semantic Tokens Range Scrolling")]
public async Task RazorSemanticTokensRangeScrollingAsync()
{
var textDocumentIdentifier = new TextDocumentIdentifier()
{
Uri = DocumentUri
};
var cancellationToken = CancellationToken.None;
var documentVersion = 1;
[Benchmark(Description = "Razor Semantic Tokens Range Scrolling")]
public async Task RazorSemanticTokensRangeScrollingAsync()
{
var textDocumentIdentifier = new TextDocumentIdentifier()
{
Uri = DocumentUri
};
var cancellationToken = CancellationToken.None;
var documentVersion = 1;
await UpdateDocumentAsync(documentVersion, DocumentSnapshot).ConfigureAwait(false);
await UpdateDocumentAsync(documentVersion, DocumentSnapshot).ConfigureAwait(false);
var documentLineCount = Range.End.Line;
var documentLineCount = Range.End.Line;
var lineCount = 0;
while (lineCount != documentLineCount)
{
var newLineCount = Math.Min(lineCount + WindowSize, documentLineCount);
var range = new Range
{
Start = new Position(lineCount, 0),
End = new Position(newLineCount, 0)
};
await RazorSemanticTokenService!.GetSemanticTokensAsync(
textDocumentIdentifier,
range,
DocumentContext,
cancellationToken);
var lineCount = 0;
while (lineCount != documentLineCount)
{
var newLineCount = Math.Min(lineCount + WindowSize, documentLineCount);
var range = new Range
{
Start = new Position(lineCount, 0),
End = new Position(newLineCount, 0)
};
await RazorSemanticTokenService!.GetSemanticTokensAsync(
textDocumentIdentifier,
range,
DocumentContext,
cancellationToken);
lineCount = newLineCount;
}
}
lineCount = newLineCount;
}
}
private async Task UpdateDocumentAsync(int newVersion, DocumentSnapshot documentSnapshot)
{
await ProjectSnapshotManagerDispatcher!.RunOnDispatcherThreadAsync(
() => VersionCache!.TrackDocumentVersion(documentSnapshot, newVersion), CancellationToken.None).ConfigureAwait(false);
}
private async Task UpdateDocumentAsync(int newVersion, DocumentSnapshot documentSnapshot)
{
await ProjectSnapshotManagerDispatcher!.RunOnDispatcherThreadAsync(
() => VersionCache!.TrackDocumentVersion(documentSnapshot, newVersion), CancellationToken.None).ConfigureAwait(false);
}
[GlobalCleanup]
public async Task CleanupServerAsync()
{
await RazorLanguageServer.DisposeAsync();
}
[GlobalCleanup]
public Task CleanupServerAsync()
{
return Task.CompletedTask;
}
protected internal override void Builder(IServiceCollection collection)
{
protected internal override void Builder(IServiceCollection collection)
{
collection.AddSingleton<RazorSemanticTokensInfoService, TestRazorSemanticTokensInfoService>();
}
}
private void EnsureServicesInitialized()
{
var languageServer = RazorLanguageServer.GetInnerLanguageServerForTesting();
RazorSemanticTokenService = (languageServer.GetRequiredService<RazorSemanticTokensInfoService>() as TestRazorSemanticTokensInfoService)!;
VersionCache = languageServer.GetRequiredService<DocumentVersionCache>();
ProjectSnapshotManagerDispatcher = languageServer.GetRequiredService<ProjectSnapshotManagerDispatcher>();
}
}
private void EnsureServicesInitialized()
{
var languageServer = RazorLanguageServer.GetInnerLanguageServerForTesting();
RazorSemanticTokenService = (languageServer.GetRequiredService<RazorSemanticTokensInfoService>() as TestRazorSemanticTokensInfoService)!;
VersionCache = languageServer.GetRequiredService<DocumentVersionCache>();
ProjectSnapshotManagerDispatcher = languageServer.GetRequiredService<ProjectSnapshotManagerDispatcher>();
}
}
}

Просмотреть файл

@ -32,7 +32,6 @@ internal static class IServiceCollectionExtensions
{
services.AddHandler<RazorInitializeEndpoint>();
services.AddHandler<RazorInitializedEndpoint>();
services.AddHandler<ShutdownHandler<RazorRequestContext>>();
var razorLifeCycleManager = new RazorLifeCycleManager(razorLanguageServer);
services.AddSingleton<ILifeCycleManager>(razorLifeCycleManager);

Просмотреть файл

@ -14,7 +14,7 @@ using StreamJsonRpc;
namespace Microsoft.AspNetCore.Razor.LanguageServer;
internal sealed class RazorLanguageServerWrapper : IAsyncDisposable
internal sealed class RazorLanguageServerWrapper : IDisposable
{
private readonly RazorLanguageServer _innerServer;
private readonly object _disposeLock;
@ -78,10 +78,8 @@ internal sealed class RazorLanguageServerWrapper : IAsyncDisposable
return _innerServer.GetRequiredService<T>();
}
public async ValueTask DisposeAsync()
public void Dispose()
{
await _innerServer.DisposeAsync();
lock (_disposeLock)
{
if (!_disposed)

Просмотреть файл

@ -196,8 +196,6 @@ namespace Microsoft.VisualStudio.LanguageServerClient.Razor
if (_server is not null)
{
// Server still hasn't shutdown, attempt an ungraceful shutdown.
await _server.DisposeAsync();
ServerShutdown();
}
}

Просмотреть файл

@ -21,10 +21,10 @@ public class RazorLanguageServerTest : TestBase
}
[Fact]
public async Task AllHandlersRegisteredAsync()
public void AllHandlersRegisteredAsync()
{
var (clientStream, serverStream) = FullDuplexStream.CreatePair();
await using var server = RazorLanguageServerWrapper.Create(serverStream, serverStream, Logger);
using var server = RazorLanguageServerWrapper.Create(serverStream, serverStream, Logger);
var innerServer = server.GetInnerLanguageServerForTesting();
var handlerProvider = innerServer.GetTestAccessor().GetHandlerProvider();