Skip to content
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

Self-versioned documents #10747

Merged
merged 18 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
using System.Threading.Tasks;
using BenchmarkDotNet.Attributes;
using Microsoft.AspNetCore.Razor.Language;
using Microsoft.AspNetCore.Razor.LanguageServer;
using Microsoft.AspNetCore.Razor.LanguageServer.Semantic;
using Microsoft.CodeAnalysis.Razor.DocumentMapping;
using Microsoft.CodeAnalysis.Razor.Logging;
Expand All @@ -28,8 +27,6 @@ public class RazorSemanticTokensBenchmark : RazorLanguageServerBenchmarkBase
{
private IRazorSemanticTokensInfoService RazorSemanticTokenService { get; set; }

private IDocumentVersionCache VersionCache { get; set; }

private Uri DocumentUri => DocumentContext.Uri;

private IDocumentSnapshot DocumentSnapshot => DocumentContext.Snapshot;
Expand Down Expand Up @@ -75,9 +72,6 @@ public async Task InitializeRazorSemanticAsync()
public async Task RazorSemanticTokensRangeAsync()
{
var cancellationToken = CancellationToken.None;
var documentVersion = 1;

VersionCache.TrackDocumentVersion(DocumentSnapshot, documentVersion);

await RazorSemanticTokenService.GetSemanticTokensAsync(DocumentContext, Range.ToLinePositionSpan(), colorBackground: false, Guid.Empty, cancellationToken: cancellationToken).ConfigureAwait(false);
}
Expand All @@ -98,10 +92,7 @@ protected internal override void Builder(IServiceCollection collection)

private void EnsureServicesInitialized()
{
var capabilitiesService = new BenchmarkClientCapabilitiesService(new VSInternalClientCapabilities { SupportsVisualStudioExtensions = true });
var legend = new RazorSemanticTokensLegendService(capabilitiesService);
RazorSemanticTokenService = RazorLanguageServerHost.GetRequiredService<IRazorSemanticTokensInfoService>();
VersionCache = RazorLanguageServerHost.GetRequiredService<IDocumentVersionCache>();
}

internal class TestRazorSemanticTokensInfoService : RazorSemanticTokensInfoService
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,8 @@ public class RazorSemanticTokensRangeEndpointBenchmark : RazorLanguageServerBenc

private SemanticTokensRangeEndpoint SemanticTokensRangeEndpoint { get; set; }

private IDocumentVersionCache VersionCache { get; set; }

private Uri DocumentUri => DocumentContext.Uri;

private IDocumentSnapshot DocumentSnapshot => DocumentContext.Snapshot;

private VersionedDocumentContext DocumentContext { get; set; }

private Range Range { get; set; }
Expand Down Expand Up @@ -83,9 +79,6 @@ public async Task InitializeRazorSemanticAsync()
start: (0, 0),
end: (text.Lines.Count - 1, text.Lines[^1].Span.Length - 1));

var documentVersion = 1;
VersionCache.TrackDocumentVersion(DocumentSnapshot, documentVersion);

RequestContext = new RazorRequestContext(DocumentContext, RazorLanguageServerHost.GetRequiredService<ILspServices>(), "lsp/method", uri: null);

var random = new Random();
Expand Down Expand Up @@ -133,7 +126,6 @@ protected internal override void Builder(IServiceCollection collection)
private void EnsureServicesInitialized()
{
RazorSemanticTokenService = RazorLanguageServerHost.GetRequiredService<IRazorSemanticTokensInfoService>();
VersionCache = RazorLanguageServerHost.GetRequiredService<IDocumentVersionCache>();
}

internal class TestCustomizableRazorSemanticTokensInfoService : RazorSemanticTokensInfoService
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using System.Threading;
using System.Threading.Tasks;
using BenchmarkDotNet.Attributes;
using Microsoft.AspNetCore.Razor.LanguageServer;
using Microsoft.CodeAnalysis.Razor.ProjectSystem;
using Microsoft.CodeAnalysis.Razor.SemanticTokens;
using Microsoft.CodeAnalysis.Text;
Expand All @@ -23,8 +22,6 @@ public class RazorSemanticTokensScrollingBenchmark : RazorLanguageServerBenchmar
{
private IRazorSemanticTokensInfoService RazorSemanticTokenService { get; set; }

private IDocumentVersionCache VersionCache { get; set; }

private VersionedDocumentContext DocumentContext { get; set; }

private Uri DocumentUri => DocumentContext.Uri;
Expand Down Expand Up @@ -66,9 +63,6 @@ public async Task InitializeRazorSemanticAsync()
public async Task RazorSemanticTokensRangeScrollingAsync()
{
var cancellationToken = CancellationToken.None;
var documentVersion = 1;

VersionCache!.TrackDocumentVersion(DocumentSnapshot, documentVersion);

var documentLineCount = Range.End.Line;

Expand Down Expand Up @@ -105,6 +99,5 @@ protected internal override void Builder(IServiceCollection collection)
private void EnsureServicesInitialized()
{
RazorSemanticTokenService = RazorLanguageServerHost.GetRequiredService<IRazorSemanticTokensInfoService>();
VersionCache = RazorLanguageServerHost.GetRequiredService<IDocumentVersionCache>();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer;

internal sealed class DocumentContextFactory(
IProjectSnapshotManager projectManager,
IDocumentVersionCache documentVersionCache,
ILoggerFactory loggerFactory)
: IDocumentContextFactory
{
private readonly IProjectSnapshotManager _projectManager = projectManager;
private readonly IDocumentVersionCache _documentVersionCache = documentVersionCache;
private readonly ILogger _logger = loggerFactory.GetOrCreateLogger<DocumentContextFactory>();

public bool TryCreate(
Expand Down Expand Up @@ -80,13 +78,8 @@ private bool TryGetDocumentAndVersion(
return true;
}

if (_documentVersionCache.TryGetDocumentVersion(documentSnapshot, out var version))
{
documentAndVersion = new DocumentSnapshotAndVersion(documentSnapshot, version.Value);
return true;
}

_logger.LogWarning($"Tried to create context for document {filePath} and project {projectContext?.Id} and a document was found, but version didn't match.");
documentAndVersion = new DocumentSnapshotAndVersion(documentSnapshot, documentSnapshot.Version);
return true;
}

// This is super rare, if we get here it could mean many things. Some of which:
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,6 @@ public static void AddDocumentManagementServices(this IServiceCollection service
services.AddSingleton<IDocumentContextFactory, DocumentContextFactory>();
services.AddSingleton(sp => new Lazy<IDocumentContextFactory>(sp.GetRequiredService<IDocumentContextFactory>));

services.AddSingleton<IDocumentVersionCache, DocumentVersionCache>();
services.AddSingleton((services) => (IRazorStartupService)services.GetRequiredService<IDocumentVersionCache>());

services.AddSingleton<RemoteTextLoaderFactory, DefaultRemoteTextLoaderFactory>();
services.AddSingleton<IRazorProjectService, RazorProjectService>();
services.AddSingleton<IRazorStartupService>((services) => (RazorProjectService)services.GetRequiredService<IRazorProjectService>());
Expand Down
Loading