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

Further refactoring of Razor tooling project system #11320

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
fcfd3ce
ProjectState: Replace LanguageServerFeatureOptions with enum
DustinCampbell Dec 12, 2024
eb5d916
Improve ProjectState.Create(...) factory methods and constructors
DustinCampbell Dec 12, 2024
ea3fd03
Clean up TestProjectEngineFactoryProvider a bit
DustinCampbell Dec 12, 2024
9042ae4
Seal DocumentState and ProjectState and make effectively immutable
DustinCampbell Dec 12, 2024
ee0e239
Rework ProjectState.ImportsToRelatedDocuments map
DustinCampbell Dec 13, 2024
3ba0eda
Simplify DocumentState.Version tracking
DustinCampbell Dec 16, 2024
fdf9486
Remove unused DocumentState property
DustinCampbell Dec 16, 2024
5b0bfb6
Clean up DocumentState With* methods
DustinCampbell Dec 16, 2024
8d376cc
Move DocumentState helper methods for computing imports
DustinCampbell Dec 16, 2024
4601b2d
Clean up EmptyTextLoader (currently only used by tests)
DustinCampbell Dec 16, 2024
e3a9a86
Replace DocumentState.EmptyLoader with EmptyTextLoader.Instance
DustinCampbell Dec 16, 2024
4d18137
Replace CreateEmptyTextLoader with EmptyTextLoader.Instance
DustinCampbell Dec 16, 2024
4c9becf
Clean up TestMocks.CreateTextLoader calls
DustinCampbell Dec 16, 2024
a3b25f8
Clean up calls to ProjectState.AddDocument with empty loaders
DustinCampbell Dec 16, 2024
18ad48f
Augment Assumed class with new helpers and message parameters
DustinCampbell Dec 16, 2024
ae4e86c
Introduce AsyncLazy<T> variation from Roslyn
DustinCampbell Dec 16, 2024
813e448
Introduce ITextAndVersionSource to manage text loading in DocumentState
DustinCampbell Dec 16, 2024
b508614
Don't update ProjectState when DocumentState doesn't
DustinCampbell Dec 16, 2024
1f9144f
Move DocumentState helper methods for compilation
DustinCampbell Dec 17, 2024
df3e21c
Remove DocumentState.ComputedStateTracker
DustinCampbell Dec 17, 2024
1e045ea
Introduce legacy snapshot interfaces to support legacy editor
DustinCampbell Dec 17, 2024
0049ac0
Remove IProjectSnapshot.Version
DustinCampbell Dec 17, 2024
b5acc30
Remove ProjectState.DocumentCollectionVersion
DustinCampbell Dec 17, 2024
f26bd81
Remove remaining version logic from ProjectState
DustinCampbell Dec 17, 2024
b341603
Make IProjectSnapshot.GetProjectEngine() async
DustinCampbell Dec 17, 2024
aafea13
Remove IProjectSnapshotManager interface
DustinCampbell Dec 18, 2024
c838a75
Remove IProjectSnapshot.GetProjectEngineAsync
DustinCampbell Dec 18, 2024
49a973c
Remove IProjectSnapshot.ProjectWorkspaceState
DustinCampbell Dec 18, 2024
04bf4bf
Move IDocumentSnapshot and IProjectSnapshot to lower tooling layer
DustinCampbell Dec 18, 2024
f27d768
Remove IProjectSnapshot.Configuration
DustinCampbell Dec 18, 2024
67e3227
Don't use LINQ Count() method
DustinCampbell Dec 18, 2024
295d482
Compute test span correctly
DustinCampbell Dec 18, 2024
74167ba
Double-checked lock
DustinCampbell Dec 18, 2024
670eae2
Fix comment
DustinCampbell Dec 18, 2024
f28f239
Remove unused method
DustinCampbell Dec 18, 2024
284c7d7
Rename method to ProjectState.UpdateRelatedDocumentsIfNecessary
DustinCampbell Dec 18, 2024
f952c9b
Delete unused ExtractToComponentResolverDocumentContextFactory
DustinCampbell Dec 18, 2024
1deb4a0
Remove all but one ProjectState.Create(...) factory method
DustinCampbell Dec 18, 2024
d35e121
RazorProjectService: Use TryGetDocument rather than pattern matching
DustinCampbell Dec 18, 2024
b51fabc
RazorProjectService: Rename for consistency throughout
DustinCampbell Dec 18, 2024
f3fed12
ProjectState: Don't perform string replacements unless necessary
DustinCampbell Dec 18, 2024
80709ba
Merge branch 'main' into cleanup-project-and-documentstate
DustinCampbell Jan 6, 2025
f9096fe
Move FORMAT_FUSE constant to Directory.Build.props
DustinCampbell Jan 6, 2025
4d299ee
Merge branch 'main' into cleanup-project-and-documentstate
DustinCampbell Jan 6, 2025
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
3 changes: 3 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
<ExcludeFromSourceOnlyBuild>true</ExcludeFromSourceOnlyBuild>

<DefaultNetFxTargetFramework>net472</DefaultNetFxTargetFramework>

<!-- Uncomment this line to run formatting on runtime code-gen if FUSE is turned on -->
<!-- <DefineConstants>$(DefineConstants);FORMAT_FUSE</DefineConstants> -->
</PropertyGroup>

<!--
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Threading;
using System.Threading.Tasks;
using BenchmarkDotNet.Attributes;
using Microsoft.AspNetCore.Razor.ProjectSystem;
using Microsoft.CodeAnalysis.Razor.Formatting;
using Microsoft.CodeAnalysis.Razor.ProjectSystem;
using Microsoft.CodeAnalysis.Text;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Microsoft.AspNetCore.Razor.LanguageServer.CodeActions;
using Microsoft.AspNetCore.Razor.LanguageServer.EndpointContracts;
using Microsoft.AspNetCore.Razor.LanguageServer.Hosting;
using Microsoft.AspNetCore.Razor.ProjectSystem;
using Microsoft.AspNetCore.Razor.Telemetry;
using Microsoft.CodeAnalysis.Razor.CodeActions;
using Microsoft.CodeAnalysis.Razor.ProjectSystem;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using Microsoft.AspNetCore.Razor.LanguageServer.Completion.Delegation;
using Microsoft.AspNetCore.Razor.LanguageServer.EndpointContracts;
using Microsoft.AspNetCore.Razor.LanguageServer.Hosting;
using Microsoft.AspNetCore.Razor.ProjectSystem;
using Microsoft.CodeAnalysis.Razor.Completion;
using Microsoft.CodeAnalysis.Razor.DocumentMapping;
using Microsoft.CodeAnalysis.Razor.Logging;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using Microsoft.AspNetCore.Razor.LanguageServer.Diagnostics;
using Microsoft.AspNetCore.Razor.LanguageServer.EndpointContracts;
using Microsoft.AspNetCore.Razor.LanguageServer.Hosting;
using Microsoft.AspNetCore.Razor.ProjectSystem;
using Microsoft.CodeAnalysis.Razor.Diagnostics;
using Microsoft.CodeAnalysis.Razor.DocumentMapping;
using Microsoft.CodeAnalysis.Razor.Logging;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
using System.Threading.Tasks;
using BenchmarkDotNet.Attributes;
using Microsoft.AspNetCore.Razor.Language;
using Microsoft.AspNetCore.Razor.ProjectSystem;
using Microsoft.CodeAnalysis.Razor.DocumentMapping;
using Microsoft.CodeAnalysis.Razor.ProjectSystem;
using Microsoft.CodeAnalysis.Text;

namespace Microsoft.AspNetCore.Razor.Microbenchmarks.LanguageServer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using BenchmarkDotNet.Attributes;
using Microsoft.AspNetCore.Razor.Language;
using Microsoft.AspNetCore.Razor.LanguageServer.Semantic;
using Microsoft.AspNetCore.Razor.ProjectSystem;
using Microsoft.CodeAnalysis.Razor.DocumentMapping;
using Microsoft.CodeAnalysis.Razor.Logging;
using Microsoft.CodeAnalysis.Razor.ProjectSystem;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Threading;
using System.Threading.Tasks;
using BenchmarkDotNet.Attributes;
using Microsoft.AspNetCore.Razor.ProjectSystem;
using Microsoft.CodeAnalysis.Razor.ProjectSystem;
using Microsoft.CodeAnalysis.Razor.SemanticTokens;
using Microsoft.CodeAnalysis.Text;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.Collections.Immutable;
using System.IO;
using Microsoft.AspNetCore.Razor.Language;
using Microsoft.AspNetCore.Razor.LanguageServer;
using Microsoft.AspNetCore.Razor.PooledObjects;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Razor.Logging;
Expand Down Expand Up @@ -50,11 +49,9 @@ protected ProjectSnapshotManagerBenchmarkBase(int documentCount = 100)
Documents = documents.ToImmutable();
}

internal ProjectSnapshotManager CreateProjectSnapshotManager()
{
return new ProjectSnapshotManager(
internal static ProjectSnapshotManager CreateProjectSnapshotManager()
=> new(
projectEngineFactoryProvider: StaticProjectEngineFactoryProvider.Instance,
languageServerFeatureOptions: new DefaultLanguageServerFeatureOptions(),
compilerOptions: RazorCompilerOptions.None,
loggerFactory: EmptyLoggerFactory.Instance);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ internal sealed class CapabilitiesManager : IInitializeManager<InitializeParams,
{
private readonly ILspServices _lspServices;
private readonly TaskCompletionSource<InitializeParams> _initializeParamsTaskSource;
private readonly AsyncLazy<string> _lazyRootPath;
private readonly VisualStudio.Threading.AsyncLazy<string> _lazyRootPath;

public bool HasInitialized => _initializeParamsTaskSource.Task.IsCompleted;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
using Microsoft.AspNetCore.Razor.Language;
using Microsoft.AspNetCore.Razor.LanguageServer.EndpointContracts;
using Microsoft.AspNetCore.Razor.LanguageServer.Hosting;
using Microsoft.AspNetCore.Razor.ProjectSystem;
using Microsoft.AspNetCore.Razor.Telemetry;
using Microsoft.CodeAnalysis.Razor.CodeActions;
using Microsoft.CodeAnalysis.Razor.CodeActions.Models;
using Microsoft.CodeAnalysis.Razor.ProjectSystem;
using Microsoft.CodeAnalysis.Razor.Protocol;
using Microsoft.CodeAnalysis.Razor.Protocol.CodeActions;
using Microsoft.CodeAnalysis.Razor.Workspaces.Telemetry;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using Microsoft.CodeAnalysis.Razor.Protocol.CodeActions;
using Microsoft.VisualStudio.LanguageServer.Protocol;
using Microsoft.CodeAnalysis.Formatting;
using Microsoft.AspNetCore.Razor.ProjectSystem;

namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions;

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ internal class RazorCompletionResolveEndpoint
{
private readonly AggregateCompletionItemResolver _completionItemResolver;
private readonly CompletionListCache _completionListCache;
private readonly IProjectSnapshotManager _projectSnapshotManager;
private readonly ProjectSnapshotManager _projectSnapshotManager;
private VSInternalClientCapabilities? _clientCapabilities;

public RazorCompletionResolveEndpoint(
AggregateCompletionItemResolver completionItemResolver,
CompletionListCache completionListCache,
IProjectSnapshotManager projectSnapshotManager)
ProjectSnapshotManager projectSnapshotManager)
{
_completionItemResolver = completionItemResolver;
_completionListCache = completionListCache;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Definition;
internal sealed class DefinitionEndpoint(
IRazorComponentDefinitionService componentDefinitionService,
IDocumentMappingService documentMappingService,
IProjectSnapshotManager projectManager,
ProjectSnapshotManager projectManager,
LanguageServerFeatureOptions languageServerFeatureOptions,
IClientConnection clientConnection,
ILoggerFactory loggerFactory)
Expand All @@ -37,7 +37,7 @@ internal sealed class DefinitionEndpoint(
{
private readonly IRazorComponentDefinitionService _componentDefinitionService = componentDefinitionService;
private readonly IDocumentMappingService _documentMappingService = documentMappingService;
private readonly IProjectSnapshotManager _projectManager = projectManager;
private readonly ProjectSnapshotManager _projectManager = projectManager;

protected override bool PreferCSharpOverHtmlIfPossible => true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ private async ValueTask ReportRZ10012TelemetryAsync(DocumentContext documentCont
}

var tagHelpers = await documentContext.Project.GetTagHelpersAsync(cancellationToken).ConfigureAwait(false);
var tagHelperCount = tagHelpers.Count();
var tagHelperCount = tagHelpers.Length;
var shouldReport = false;

ImmutableInterlocked.AddOrUpdate(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Licensed under the MIT license. See License.txt in the project root for license information.

using System.Collections.Generic;
using Microsoft.AspNetCore.Razor.ProjectSystem;
using Microsoft.CodeAnalysis.Razor;
using Microsoft.CodeAnalysis.Razor.ProjectSystem;

namespace Microsoft.AspNetCore.Razor.LanguageServer.Diagnostics;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void ClearClosedDocuments()
instance.ClearClosedDocuments();
}

public Task PublishDiagnosticsAsync(IDocumentSnapshot document, CancellationToken cancellationToken)
public Task PublishDiagnosticsAsync(DocumentSnapshot document, CancellationToken cancellationToken)
{
return instance.PublishDiagnosticsAsync(document, cancellationToken);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Microsoft.AspNetCore.Razor.Language;
using Microsoft.AspNetCore.Razor.LanguageServer.Hosting;
using Microsoft.AspNetCore.Razor.PooledObjects;
using Microsoft.AspNetCore.Razor.ProjectSystem;
using Microsoft.AspNetCore.Razor.Utilities;
using Microsoft.CodeAnalysis.Razor;
using Microsoft.CodeAnalysis.Razor.Diagnostics;
Expand All @@ -33,21 +34,21 @@ private readonly record struct PublishedDiagnostics(IReadOnlyList<RazorDiagnosti
private static readonly TimeSpan s_publishDelay = TimeSpan.FromSeconds(2);
private static readonly TimeSpan s_clearClosedDocumentsDelay = TimeSpan.FromSeconds(5);

private readonly IProjectSnapshotManager _projectManager;
private readonly ProjectSnapshotManager _projectManager;
private readonly IClientConnection _clientConnection;
private readonly ILogger _logger;
private readonly LanguageServerFeatureOptions _options;
private readonly Lazy<RazorTranslateDiagnosticsService> _translateDiagnosticsService;
private readonly Lazy<IDocumentContextFactory> _documentContextFactory;

private readonly CancellationTokenSource _disposeTokenSource;
private readonly AsyncBatchingWorkQueue<IDocumentSnapshot> _workQueue;
private readonly AsyncBatchingWorkQueue<DocumentSnapshot> _workQueue;
private readonly Dictionary<string, PublishedDiagnostics> _publishedDiagnostics;

private Task _clearClosedDocumentsTask = Task.CompletedTask;

public RazorDiagnosticsPublisher(
IProjectSnapshotManager projectManager,
ProjectSnapshotManager projectManager,
IClientConnection clientConnection,
LanguageServerFeatureOptions options,
Lazy<RazorTranslateDiagnosticsService> translateDiagnosticsService,
Expand All @@ -61,7 +62,7 @@ public RazorDiagnosticsPublisher(

// Present for test to specify publish delay
protected RazorDiagnosticsPublisher(
IProjectSnapshotManager projectManager,
ProjectSnapshotManager projectManager,
IClientConnection clientConnection,
LanguageServerFeatureOptions options,
Lazy<RazorTranslateDiagnosticsService> translateDiagnosticsService,
Expand All @@ -76,7 +77,7 @@ protected RazorDiagnosticsPublisher(
_documentContextFactory = documentContextFactory;

_disposeTokenSource = new();
_workQueue = new AsyncBatchingWorkQueue<IDocumentSnapshot>(publishDelay, ProcessBatchAsync, _disposeTokenSource.Token);
_workQueue = new AsyncBatchingWorkQueue<DocumentSnapshot>(publishDelay, ProcessBatchAsync, _disposeTokenSource.Token);

_publishedDiagnostics = new Dictionary<string, PublishedDiagnostics>(FilePathComparer.Instance);
_logger = loggerFactory.GetOrCreateLogger<RazorDiagnosticsPublisher>();
Expand All @@ -93,14 +94,14 @@ public void Dispose()
_disposeTokenSource.Dispose();
}

public void DocumentProcessed(RazorCodeDocument codeDocument, IDocumentSnapshot document)
public void DocumentProcessed(RazorCodeDocument codeDocument, DocumentSnapshot document)
{
_workQueue.AddWork(document);

StartDelayToClearDocuments();
}

private async ValueTask ProcessBatchAsync(ImmutableArray<IDocumentSnapshot> items, CancellationToken token)
private async ValueTask ProcessBatchAsync(ImmutableArray<DocumentSnapshot> items, CancellationToken token)
{
foreach (var document in items.GetMostRecentUniqueItems(Comparer.Instance))
{
Expand All @@ -113,7 +114,7 @@ private async ValueTask ProcessBatchAsync(ImmutableArray<IDocumentSnapshot> item
}
}

private async Task PublishDiagnosticsAsync(IDocumentSnapshot document, CancellationToken cancellationToken)
private async Task PublishDiagnosticsAsync(DocumentSnapshot document, CancellationToken cancellationToken)
{
var result = await document.GetGeneratedOutputAsync(cancellationToken).ConfigureAwait(false);
var csharpDiagnostics = await GetCSharpDiagnosticsAsync(document, cancellationToken).ConfigureAwait(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
namespace Microsoft.AspNetCore.Razor.LanguageServer;

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

public bool TryCreate(
Expand All @@ -41,7 +41,7 @@ public bool TryCreate(
private bool TryResolveDocument(
string filePath,
VSProjectContext? projectContext,
[NotNullWhen(true)] out IDocumentSnapshot? documentSnapshot)
[NotNullWhen(true)] out DocumentSnapshot? documentSnapshot)
{
if (projectContext is null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
using Microsoft.AspNetCore.Razor.LanguageServer.EndpointContracts;
using Microsoft.AspNetCore.Razor.LanguageServer.Hosting;
using Microsoft.AspNetCore.Razor.PooledObjects;
using Microsoft.AspNetCore.Razor.ProjectSystem;
using Microsoft.CodeAnalysis.Razor.DocumentMapping;
using Microsoft.CodeAnalysis.Razor.Logging;
using Microsoft.CodeAnalysis.Razor.ProjectSystem;
using Microsoft.CodeAnalysis.Razor.Protocol;
using Microsoft.CodeAnalysis.Razor.Protocol.DocumentPresentation;
using Microsoft.CodeAnalysis.Razor.Workspaces;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Razor.ProjectSystem;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Razor.ProjectSystem;

namespace Microsoft.AspNetCore.Razor.LanguageServer;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,9 @@ public static void AddDocumentManagementServices(this IServiceCollection service
}

services.AddSingleton<IDocumentProcessedListener, GeneratedDocumentSynchronizer>();
services.AddSingleton<IDocumentProcessedListener, CodeDocumentReferenceHolder>();

// Add project snapshot manager
services.AddSingleton<IProjectEngineFactoryProvider, LspProjectEngineFactoryProvider>();
services.AddSingleton<IProjectSnapshotManager, LspProjectSnapshotManager>();
services.AddSingleton<ProjectSnapshotManager, LspProjectSnapshotManager>();
}
}
Loading
Loading