From bda584dd5049541a7506701d33077056930f2738 Mon Sep 17 00:00:00 2001 From: Dustin Campbell Date: Wed, 13 Nov 2024 08:31:15 -0800 Subject: [PATCH] Remove GetTagHelpersSynchronously extension method It turns out that this extension method isn't necessary. It's only used by the legacy editor, which can just access `IProjectSnaphshot.ProjectWorkspaceState.TagHelpers`. That property is always implemented by any project snapshot that the legacy editor encounters, namely `ProjectSnapshot` or `EphemeralProjectSnapshot`. --- .../ProjectSystem/IProjectSnapshotExtensions.cs | 17 ----------------- .../VisualStudioDocumentTracker.cs | 16 ++++------------ 2 files changed, 4 insertions(+), 29 deletions(-) diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/IProjectSnapshotExtensions.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/IProjectSnapshotExtensions.cs index 693b7d6265a..5e83e9f48ec 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/IProjectSnapshotExtensions.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/IProjectSnapshotExtensions.cs @@ -3,9 +3,6 @@ using System; using System.Collections.Immutable; -using System.Diagnostics; -using System.Threading; -using Microsoft.AspNetCore.Razor.Language; using Microsoft.AspNetCore.Razor.PooledObjects; using Microsoft.AspNetCore.Razor.ProjectSystem; using Microsoft.AspNetCore.Razor.Serialization; @@ -38,20 +35,6 @@ public static RazorProjectInfo ToRazorProjectInfo(this IProjectSnapshot project) documents: documents.DrainToImmutable()); } - public static ImmutableArray GetTagHelpersSynchronously(this IProjectSnapshot projectSnapshot) - { - var canResolveTagHelpersSynchronously = projectSnapshot is ProjectSnapshot || - projectSnapshot.GetType().FullName == "Microsoft.VisualStudio.LegacyEditor.Razor.EphemeralProjectSnapshot"; - - Debug.Assert(canResolveTagHelpersSynchronously, "The ProjectSnapshot in the VisualStudioDocumentTracker should not be a cohosted project."); - var tagHelperTask = projectSnapshot.GetTagHelpersAsync(CancellationToken.None); - Debug.Assert(tagHelperTask.IsCompleted, "GetTagHelpersAsync should be synchronous for non-cohosted projects."); - -#pragma warning disable VSTHRD002 // Avoid problematic synchronous waits - return tagHelperTask.Result; -#pragma warning restore VSTHRD002 // Avoid problematic synchronous waits - } - public static ImmutableArray GetRelatedDocuments(this IProjectSnapshot projectSnapshot, IDocumentSnapshot document) { if (projectSnapshot is not ProjectSnapshot project) diff --git a/src/Razor/src/Microsoft.VisualStudio.LegacyEditor.Razor/VisualStudioDocumentTracker.cs b/src/Razor/src/Microsoft.VisualStudio.LegacyEditor.Razor/VisualStudioDocumentTracker.cs index 1147805e2b2..30886307274 100644 --- a/src/Razor/src/Microsoft.VisualStudio.LegacyEditor.Razor/VisualStudioDocumentTracker.cs +++ b/src/Razor/src/Microsoft.VisualStudio.LegacyEditor.Razor/VisualStudioDocumentTracker.cs @@ -70,17 +70,9 @@ public VisualStudioDocumentTracker( public ClientSpaceSettings EditorSettings => _workspaceEditorSettings.Current.ClientSpaceSettings; public ImmutableArray TagHelpers - { - get - { - if (ProjectSnapshot is null) - { - return ImmutableArray.Empty; - } - - return ProjectSnapshot.GetTagHelpersSynchronously(); - } - } + => _projectSnapshot is { ProjectWorkspaceState.TagHelpers: var tagHelpers } + ? tagHelpers + : []; public bool IsSupportedProject => _isSupportedProject; @@ -231,7 +223,7 @@ internal void ProjectManager_Changed(object sender, ProjectChangeEventArgs e) _ = OnContextChangedAsync(ContextChangeKind.ProjectChanged); if (e.Older is null || - !e.Older.GetTagHelpersSynchronously().SequenceEqual(e.Newer!.GetTagHelpersSynchronously())) + !e.Older.ProjectWorkspaceState.TagHelpers.SequenceEqual(e.Newer!.ProjectWorkspaceState.TagHelpers)) { _ = OnContextChangedAsync(ContextChangeKind.TagHelpersChanged); }