Make DefaultTagHelperResolver use the correct GetTagHelpersAsync.

- Prior to this we weren't overriding the `GetTagHelpersAsync` method resulting in our TagHelper discovery being executed in-process.
- Removed legacy `ITagHelperResolver` legacy types.
This commit is contained in:
N. Taylor Mullen 2017-12-12 15:22:55 -08:00
parent 7654f73c54
commit 1e1630068f
7 changed files with 18 additions and 62 deletions

View File

@ -48,7 +48,7 @@ namespace Microsoft.CodeAnalysis.Razor.ProjectSystem
// Don't block the main thread
if (_foregroundDispatcher.IsForegroundThread)
{
return Task.Factory.StartNew(ProjectUpdatesCoreAsync, update, CancellationToken.None, TaskCreationOptions.None, _foregroundDispatcher.BackgroundScheduler);
return Task.Factory.StartNew(ProjectUpdatesCoreAsync, update, cancellationToken, TaskCreationOptions.None, _foregroundDispatcher.BackgroundScheduler);
}
return ProjectUpdatesCoreAsync(update);
@ -63,7 +63,7 @@ namespace Microsoft.CodeAnalysis.Razor.ProjectSystem
var configuration = await _configurationFactory.GetConfigurationAsync(update.UnderlyingProject);
update.Configuration = configuration;
var result = await _tagHelperResolver.GetTagHelpersAsync(update.UnderlyingProject);
var result = await _tagHelperResolver.GetTagHelpersAsync(update.UnderlyingProject, CancellationToken.None);
update.TagHelpers = result.Descriptors;
}
}

View File

@ -11,12 +11,6 @@ namespace Microsoft.CodeAnalysis.Razor
{
public abstract TagHelperResolutionResult GetTagHelpers(Compilation compilation);
public virtual async Task<TagHelperResolutionResult> GetTagHelpersAsync(
Project project,
CancellationToken cancellationToken = default(CancellationToken))
{
var compilation = await project.GetCompilationAsync(cancellationToken).ConfigureAwait(false);
return GetTagHelpers(compilation);
}
public abstract Task<TagHelperResolutionResult> GetTagHelpersAsync(Project project, CancellationToken cancellationToken);
}
}

View File

@ -2,6 +2,8 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc.Razor.Extensions;
using Microsoft.AspNetCore.Razor.Language;
using Microsoft.CodeAnalysis.Razor;
@ -42,5 +44,11 @@ namespace Microsoft.CodeAnalysis.Remote.Razor
return resolutionResult;
}
public override async Task<TagHelperResolutionResult> GetTagHelpersAsync(Project project, CancellationToken cancellationToken)
{
var compilation = await project.GetCompilationAsync(cancellationToken).ConfigureAwait(false);
return GetTagHelpers(compilation);
}
}
}

View File

@ -3,15 +3,12 @@
using System;
using System.Collections.Generic;
using System.Composition;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc.Razor.Extensions;
using Microsoft.AspNetCore.Razor.Language;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Razor;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
@ -28,7 +25,7 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor
_workspace = workspace;
}
public async Task<TagHelperResolutionResult> GetTagHelpersAsync(Project project)
public override async Task<TagHelperResolutionResult> GetTagHelpersAsync(Project project, CancellationToken cancellationToken)
{
if (project == null)
{
@ -39,11 +36,9 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor
{
TagHelperResolutionResult result;
// We're being overly defensive here because the OOP host can return null for the client/session/operation
// We're being defensive here because the OOP host can return null for the client/session/operation
// when it's disconnected (user stops the process).
//
// This will change in the future to an easier to consume API but for VS RTM this is what we have.
var client = await RazorLanguageServiceClientFactory.CreateAsync(_workspace, CancellationToken.None);
var client = await RazorLanguageServiceClientFactory.CreateAsync(_workspace, cancellationToken);
if (client != null)
{
using (var session = await client.CreateSessionAsync(project.Solution))
@ -53,7 +48,7 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor
var jsonObject = await session.InvokeAsync<JObject>(
"GetTagHelpersAsync",
new object[] { project.Id.Id, "Foo", },
CancellationToken.None).ConfigureAwait(false);
cancellationToken).ConfigureAwait(false);
result = GetTagHelperResolutionResult(jsonObject);
@ -66,7 +61,7 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor
}
// The OOP host is turned off, so let's do this in process.
var compilation = await project.GetCompilationAsync(CancellationToken.None).ConfigureAwait(false);
var compilation = await project.GetCompilationAsync(cancellationToken).ConfigureAwait(false);
result = GetTagHelpers(compilation);
return result;
}

View File

@ -1,18 +0,0 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Razor;
namespace Microsoft.VisualStudio.LanguageServices.Razor
{
// ----------------------------------------------------------------------------------------------------
// NOTE: This is only here for VisualStudio binary compatibility. This type should not be used; instead
// use the Microsoft.CodeAnalysis.Razor variant from Microsoft.CodeAnalysis.Razor.Workspaces
// ----------------------------------------------------------------------------------------------------
public interface ITagHelperResolver
{
Task<TagHelperResolutionResult> GetTagHelpersAsync(Project project);
}
}

View File

@ -1,24 +0,0 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.ComponentModel.Composition;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Razor;
namespace Microsoft.VisualStudio.LanguageServices.Razor
{
// ----------------------------------------------------------------------------------------------------
// NOTE: This is only here for VisualStudio binary compatibility. This type should not be used; instead
// use TagHelperResolver.
// ----------------------------------------------------------------------------------------------------
[Export(typeof(ITagHelperResolver))]
internal class LegacyTagHelperResolver : DefaultTagHelperResolver, ITagHelperResolver
{
[ImportingConstructor]
public LegacyTagHelperResolver(
[Import(typeof(VisualStudioWorkspace))] Workspace workspace)
: base(workspace.Services.GetRequiredService<ErrorReporter>(), workspace)
{
}
}
}

View File

@ -18,6 +18,7 @@ using Microsoft.VisualStudio.Shell.Interop;
using Microsoft.VisualStudio.TextManager.Interop;
using System.IO;
using Microsoft.CodeAnalysis.Razor;
using System.Threading;
namespace Microsoft.VisualStudio.RazorExtension.RazorInfo
{
@ -177,7 +178,7 @@ namespace Microsoft.VisualStudio.RazorExtension.RazorInfo
.Select(reference => reference.Display)
.Select(filter => Path.GetFileNameWithoutExtension(filter));
var projectFilters = project.AllProjectReferences.Select(filter => solution.GetProject(filter.ProjectId).AssemblyName);
var resolutionResult = await _tagHelperResolver.GetTagHelpersAsync(project);
var resolutionResult = await _tagHelperResolver.GetTagHelpersAsync(project, CancellationToken.None);
var files = GetCshtmlDocuments(project);