зеркало из https://github.com/dotnet/razor.git
Fix shutdown issues from CLaSP
This commit is contained in:
Родитель
5f9c65ace3
Коммит
3d76feadff
|
@ -81,7 +81,7 @@
|
||||||
<RoslynPackageVersion>4.4.0-2.22424.2</RoslynPackageVersion>
|
<RoslynPackageVersion>4.4.0-2.22424.2</RoslynPackageVersion>
|
||||||
<VisualStudioLanguageServerProtocolVersion>17.4.1008-preview</VisualStudioLanguageServerProtocolVersion>
|
<VisualStudioLanguageServerProtocolVersion>17.4.1008-preview</VisualStudioLanguageServerProtocolVersion>
|
||||||
<MicrosoftNetCompilersToolsetVersion>4.4.0-1.final</MicrosoftNetCompilersToolsetVersion>
|
<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>
|
||||||
<PropertyGroup Label="Manual">
|
<PropertyGroup Label="Manual">
|
||||||
<!-- dotnet/runtime packages -->
|
<!-- dotnet/runtime packages -->
|
||||||
|
|
|
@ -127,11 +127,11 @@ namespace Microsoft.AspNetCore.Razor.Microbenchmarks.LanguageServer
|
||||||
}
|
}
|
||||||
|
|
||||||
[GlobalCleanup]
|
[GlobalCleanup]
|
||||||
public async Task CleanupServerAsync()
|
public Task CleanupServerAsync()
|
||||||
{
|
{
|
||||||
File.Delete(_filePath);
|
File.Delete(_filePath);
|
||||||
|
|
||||||
await RazorLanguageServer.DisposeAsync();
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void EnsureServicesInitialized()
|
private void EnsureServicesInitialized()
|
||||||
|
|
|
@ -101,9 +101,9 @@ namespace Microsoft.AspNetCore.Razor.Microbenchmarks.LanguageServer
|
||||||
}
|
}
|
||||||
|
|
||||||
[GlobalCleanup]
|
[GlobalCleanup]
|
||||||
public async Task CleanupServerAsync()
|
public Task CleanupServerAsync()
|
||||||
{
|
{
|
||||||
await RazorLanguageServer.DisposeAsync();
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected internal override void Builder(IServiceCollection collection)
|
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
|
namespace Microsoft.AspNetCore.Razor.Microbenchmarks.LanguageServer
|
||||||
{
|
{
|
||||||
public class RazorSemanticTokensScrollingBenchmark : RazorLanguageServerBenchmarkBase
|
public class RazorSemanticTokensScrollingBenchmark : RazorLanguageServerBenchmarkBase
|
||||||
{
|
{
|
||||||
private DefaultRazorSemanticTokensInfoService RazorSemanticTokenService { get; set; }
|
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))]
|
[GlobalSetup(Target = nameof(RazorSemanticTokensRangeScrollingAsync))]
|
||||||
public async Task InitializeRazorSemanticAsync()
|
public async Task InitializeRazorSemanticAsync()
|
||||||
{
|
{
|
||||||
EnsureServicesInitialized();
|
EnsureServicesInitialized();
|
||||||
|
|
||||||
var projectRoot = Path.Combine(RepoRoot, "src", "Razor", "test", "testapps", "ComponentApp");
|
var projectRoot = Path.Combine(RepoRoot, "src", "Razor", "test", "testapps", "ComponentApp");
|
||||||
ProjectFilePath = Path.Combine(projectRoot, "ComponentApp.csproj");
|
ProjectFilePath = Path.Combine(projectRoot, "ComponentApp.csproj");
|
||||||
PagesDirectory = Path.Combine(projectRoot, "Components", "Pages");
|
PagesDirectory = Path.Combine(projectRoot, "Components", "Pages");
|
||||||
var filePath = Path.Combine(PagesDirectory, $"FormattingTest.razor");
|
var filePath = Path.Combine(PagesDirectory, $"FormattingTest.razor");
|
||||||
TargetPath = "/Components/Pages/FormattingTest.razor";
|
TargetPath = "/Components/Pages/FormattingTest.razor";
|
||||||
|
|
||||||
var documentUri = new Uri(filePath);
|
var documentUri = new Uri(filePath);
|
||||||
var documentSnapshot = GetDocumentSnapshot(ProjectFilePath, filePath, TargetPath);
|
var documentSnapshot = GetDocumentSnapshot(ProjectFilePath, filePath, TargetPath);
|
||||||
DocumentContext = new DocumentContext(documentUri, documentSnapshot, version: 1);
|
DocumentContext = new DocumentContext(documentUri, documentSnapshot, version: 1);
|
||||||
|
|
||||||
var text = await DocumentSnapshot.GetTextAsync().ConfigureAwait(false);
|
var text = await DocumentSnapshot.GetTextAsync().ConfigureAwait(false);
|
||||||
Range = new Range
|
Range = new Range
|
||||||
{
|
{
|
||||||
Start = new Position
|
Start = new Position
|
||||||
{
|
{
|
||||||
Line = 0,
|
Line = 0,
|
||||||
Character = 0
|
Character = 0
|
||||||
},
|
},
|
||||||
End = new Position
|
End = new Position
|
||||||
{
|
{
|
||||||
Line = text.Lines.Count - 1,
|
Line = text.Lines.Count - 1,
|
||||||
Character = 0
|
Character = 0
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private const int WindowSize = 10;
|
private const int WindowSize = 10;
|
||||||
|
|
||||||
[Benchmark(Description = "Razor Semantic Tokens Range Scrolling")]
|
[Benchmark(Description = "Razor Semantic Tokens Range Scrolling")]
|
||||||
public async Task RazorSemanticTokensRangeScrollingAsync()
|
public async Task RazorSemanticTokensRangeScrollingAsync()
|
||||||
{
|
{
|
||||||
var textDocumentIdentifier = new TextDocumentIdentifier()
|
var textDocumentIdentifier = new TextDocumentIdentifier()
|
||||||
{
|
{
|
||||||
Uri = DocumentUri
|
Uri = DocumentUri
|
||||||
};
|
};
|
||||||
var cancellationToken = CancellationToken.None;
|
var cancellationToken = CancellationToken.None;
|
||||||
var documentVersion = 1;
|
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;
|
var lineCount = 0;
|
||||||
while (lineCount != documentLineCount)
|
while (lineCount != documentLineCount)
|
||||||
{
|
{
|
||||||
var newLineCount = Math.Min(lineCount + WindowSize, documentLineCount);
|
var newLineCount = Math.Min(lineCount + WindowSize, documentLineCount);
|
||||||
var range = new Range
|
var range = new Range
|
||||||
{
|
{
|
||||||
Start = new Position(lineCount, 0),
|
Start = new Position(lineCount, 0),
|
||||||
End = new Position(newLineCount, 0)
|
End = new Position(newLineCount, 0)
|
||||||
};
|
};
|
||||||
await RazorSemanticTokenService!.GetSemanticTokensAsync(
|
await RazorSemanticTokenService!.GetSemanticTokensAsync(
|
||||||
textDocumentIdentifier,
|
textDocumentIdentifier,
|
||||||
range,
|
range,
|
||||||
DocumentContext,
|
DocumentContext,
|
||||||
cancellationToken);
|
cancellationToken);
|
||||||
|
|
||||||
lineCount = newLineCount;
|
lineCount = newLineCount;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task UpdateDocumentAsync(int newVersion, DocumentSnapshot documentSnapshot)
|
private async Task UpdateDocumentAsync(int newVersion, DocumentSnapshot documentSnapshot)
|
||||||
{
|
{
|
||||||
await ProjectSnapshotManagerDispatcher!.RunOnDispatcherThreadAsync(
|
await ProjectSnapshotManagerDispatcher!.RunOnDispatcherThreadAsync(
|
||||||
() => VersionCache!.TrackDocumentVersion(documentSnapshot, newVersion), CancellationToken.None).ConfigureAwait(false);
|
() => VersionCache!.TrackDocumentVersion(documentSnapshot, newVersion), CancellationToken.None).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
[GlobalCleanup]
|
[GlobalCleanup]
|
||||||
public async Task CleanupServerAsync()
|
public Task CleanupServerAsync()
|
||||||
{
|
{
|
||||||
await RazorLanguageServer.DisposeAsync();
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected internal override void Builder(IServiceCollection collection)
|
protected internal override void Builder(IServiceCollection collection)
|
||||||
{
|
{
|
||||||
collection.AddSingleton<RazorSemanticTokensInfoService, TestRazorSemanticTokensInfoService>();
|
collection.AddSingleton<RazorSemanticTokensInfoService, TestRazorSemanticTokensInfoService>();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void EnsureServicesInitialized()
|
private void EnsureServicesInitialized()
|
||||||
{
|
{
|
||||||
var languageServer = RazorLanguageServer.GetInnerLanguageServerForTesting();
|
var languageServer = RazorLanguageServer.GetInnerLanguageServerForTesting();
|
||||||
RazorSemanticTokenService = (languageServer.GetRequiredService<RazorSemanticTokensInfoService>() as TestRazorSemanticTokensInfoService)!;
|
RazorSemanticTokenService = (languageServer.GetRequiredService<RazorSemanticTokensInfoService>() as TestRazorSemanticTokensInfoService)!;
|
||||||
VersionCache = languageServer.GetRequiredService<DocumentVersionCache>();
|
VersionCache = languageServer.GetRequiredService<DocumentVersionCache>();
|
||||||
ProjectSnapshotManagerDispatcher = languageServer.GetRequiredService<ProjectSnapshotManagerDispatcher>();
|
ProjectSnapshotManagerDispatcher = languageServer.GetRequiredService<ProjectSnapshotManagerDispatcher>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,6 @@ internal static class IServiceCollectionExtensions
|
||||||
{
|
{
|
||||||
services.AddHandler<RazorInitializeEndpoint>();
|
services.AddHandler<RazorInitializeEndpoint>();
|
||||||
services.AddHandler<RazorInitializedEndpoint>();
|
services.AddHandler<RazorInitializedEndpoint>();
|
||||||
services.AddHandler<ShutdownHandler<RazorRequestContext>>();
|
|
||||||
|
|
||||||
var razorLifeCycleManager = new RazorLifeCycleManager(razorLanguageServer);
|
var razorLifeCycleManager = new RazorLifeCycleManager(razorLanguageServer);
|
||||||
services.AddSingleton<ILifeCycleManager>(razorLifeCycleManager);
|
services.AddSingleton<ILifeCycleManager>(razorLifeCycleManager);
|
||||||
|
|
|
@ -14,7 +14,7 @@ using StreamJsonRpc;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Razor.LanguageServer;
|
namespace Microsoft.AspNetCore.Razor.LanguageServer;
|
||||||
|
|
||||||
internal sealed class RazorLanguageServerWrapper : IAsyncDisposable
|
internal sealed class RazorLanguageServerWrapper : IDisposable
|
||||||
{
|
{
|
||||||
private readonly RazorLanguageServer _innerServer;
|
private readonly RazorLanguageServer _innerServer;
|
||||||
private readonly object _disposeLock;
|
private readonly object _disposeLock;
|
||||||
|
@ -78,10 +78,8 @@ internal sealed class RazorLanguageServerWrapper : IAsyncDisposable
|
||||||
return _innerServer.GetRequiredService<T>();
|
return _innerServer.GetRequiredService<T>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async ValueTask DisposeAsync()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
await _innerServer.DisposeAsync();
|
|
||||||
|
|
||||||
lock (_disposeLock)
|
lock (_disposeLock)
|
||||||
{
|
{
|
||||||
if (!_disposed)
|
if (!_disposed)
|
||||||
|
|
|
@ -196,8 +196,6 @@ namespace Microsoft.VisualStudio.LanguageServerClient.Razor
|
||||||
if (_server is not null)
|
if (_server is not null)
|
||||||
{
|
{
|
||||||
// Server still hasn't shutdown, attempt an ungraceful shutdown.
|
// Server still hasn't shutdown, attempt an ungraceful shutdown.
|
||||||
await _server.DisposeAsync();
|
|
||||||
|
|
||||||
ServerShutdown();
|
ServerShutdown();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,10 +21,10 @@ public class RazorLanguageServerTest : TestBase
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task AllHandlersRegisteredAsync()
|
public void AllHandlersRegisteredAsync()
|
||||||
{
|
{
|
||||||
var (clientStream, serverStream) = FullDuplexStream.CreatePair();
|
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 innerServer = server.GetInnerLanguageServerForTesting();
|
||||||
var handlerProvider = innerServer.GetTestAccessor().GetHandlerProvider();
|
var handlerProvider = innerServer.GetTestAccessor().GetHandlerProvider();
|
||||||
|
|
Загрузка…
Ссылка в новой задаче