Make TagHelperDescriptor public for tooling

This commit is contained in:
Ryan Nowak 2017-01-10 09:06:05 -08:00
parent 6c7d121ce8
commit 59b24fb724
19 changed files with 50 additions and 42 deletions

View File

@ -4,12 +4,12 @@
using System; using System;
using System.Reflection; using System.Reflection;
namespace Microsoft.AspNetCore.Razor.Evolution.Legacy namespace Microsoft.AspNetCore.Razor.Evolution
{ {
/// <summary> /// <summary>
/// A metadata class describing a tag helper attribute. /// A metadata class describing a tag helper attribute.
/// </summary> /// </summary>
internal class TagHelperAttributeDescriptor public class TagHelperAttributeDescriptor
{ {
private string _typeName; private string _typeName;
private string _name; private string _name;

View File

@ -1,12 +1,12 @@
// Copyright (c) .NET Foundation. All rights reserved. // 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. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
namespace Microsoft.AspNetCore.Razor.Evolution.Legacy namespace Microsoft.AspNetCore.Razor.Evolution
{ {
/// <summary> /// <summary>
/// A metadata class containing information about tag helper use. /// A metadata class containing information about tag helper use.
/// </summary> /// </summary>
internal class TagHelperAttributeDesignTimeDescriptor public class TagHelperAttributeDesignTimeDescriptor
{ {
/// <summary> /// <summary>
/// A summary of how to use a tag helper. /// A summary of how to use a tag helper.

View File

@ -5,12 +5,12 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
namespace Microsoft.AspNetCore.Razor.Evolution.Legacy namespace Microsoft.AspNetCore.Razor.Evolution
{ {
/// <summary> /// <summary>
/// A metadata class describing a tag helper. /// A metadata class describing a tag helper.
/// </summary> /// </summary>
internal class TagHelperDescriptor public class TagHelperDescriptor
{ {
private string _prefix = string.Empty; private string _prefix = string.Empty;
private string _tagName; private string _tagName;

View File

@ -1,12 +1,12 @@
// Copyright (c) .NET Foundation. All rights reserved. // 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. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
namespace Microsoft.AspNetCore.Razor.Evolution.Legacy namespace Microsoft.AspNetCore.Razor.Evolution
{ {
/// <summary> /// <summary>
/// A metadata class containing design time information about a tag helper. /// A metadata class containing design time information about a tag helper.
/// </summary> /// </summary>
internal class TagHelperDesignTimeDescriptor public class TagHelperDesignTimeDescriptor
{ {
/// <summary> /// <summary>
/// A summary of how to use a tag helper. /// A summary of how to use a tag helper.

View File

@ -5,12 +5,12 @@ using System;
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;
namespace Microsoft.AspNetCore.Razor.Evolution.Legacy namespace Microsoft.AspNetCore.Razor.Evolution
{ {
/// <summary> /// <summary>
/// A metadata class describing a required tag helper attribute. /// A metadata class describing a required tag helper attribute.
/// </summary> /// </summary>
internal class TagHelperRequiredAttributeDescriptor public class TagHelperRequiredAttributeDescriptor
{ {
/// <summary> /// <summary>
/// The HTML attribute name. /// The HTML attribute name.

View File

@ -1,12 +1,12 @@
// Copyright (c) .NET Foundation. All rights reserved. // 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. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
namespace Microsoft.AspNetCore.Razor.Evolution.Legacy namespace Microsoft.AspNetCore.Razor.Evolution
{ {
/// <summary> /// <summary>
/// Acceptable <see cref="TagHelperRequiredAttributeDescriptor.Name"/> comparison modes. /// Acceptable <see cref="TagHelperRequiredAttributeDescriptor.Name"/> comparison modes.
/// </summary> /// </summary>
internal enum TagHelperRequiredAttributeNameComparison public enum TagHelperRequiredAttributeNameComparison
{ {
/// <summary> /// <summary>
/// HTML attribute name case insensitively matches <see cref="TagHelperRequiredAttributeDescriptor.Name"/>. /// HTML attribute name case insensitively matches <see cref="TagHelperRequiredAttributeDescriptor.Name"/>.

View File

@ -1,12 +1,12 @@
// Copyright (c) .NET Foundation. All rights reserved. // 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. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
namespace Microsoft.AspNetCore.Razor.Evolution.Legacy namespace Microsoft.AspNetCore.Razor.Evolution
{ {
/// <summary> /// <summary>
/// Acceptable <see cref="TagHelperRequiredAttributeDescriptor.Value"/> comparison modes. /// Acceptable <see cref="TagHelperRequiredAttributeDescriptor.Value"/> comparison modes.
/// </summary> /// </summary>
internal enum TagHelperRequiredAttributeValueComparison public enum TagHelperRequiredAttributeValueComparison
{ {
/// <summary> /// <summary>
/// HTML attribute value always matches <see cref="TagHelperRequiredAttributeDescriptor.Value"/>. /// HTML attribute value always matches <see cref="TagHelperRequiredAttributeDescriptor.Value"/>.

View File

@ -1,12 +1,12 @@
// Copyright (c) .NET Foundation. All rights reserved. // 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. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
namespace Microsoft.AspNetCore.Razor.Evolution.Legacy namespace Microsoft.AspNetCore.Razor.Evolution
{ {
/// <summary> /// <summary>
/// The mode in which an element should render. /// The mode in which an element should render.
/// </summary> /// </summary>
internal enum TagMode public enum TagMode
{ {
/// <summary> /// <summary>
/// Include both start and end tags. /// Include both start and end tags.

View File

@ -1,12 +1,12 @@
// Copyright (c) .NET Foundation. All rights reserved. // 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. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
namespace Microsoft.AspNetCore.Razor.Evolution.Legacy namespace Microsoft.AspNetCore.Razor.Evolution
{ {
/// <summary> /// <summary>
/// The structure the element should be written in. /// The structure the element should be written in.
/// </summary> /// </summary>
internal enum TagStructure public enum TagStructure
{ {
/// <summary> /// <summary>
/// If no other tag helper applies to the same element and specifies a <see cref="TagStructure"/>, /// If no other tag helper applies to the same element and specifies a <see cref="TagStructure"/>,

View File

@ -1,10 +1,11 @@
// Copyright (c) .NET Foundation. All rights reserved. // 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. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNetCore.Razor.Evolution.Legacy;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Razor.Evolution;
using Microsoft.AspNetCore.Razor.Evolution.Legacy;
namespace Microsoft.CodeAnalysis.Razor namespace Microsoft.CodeAnalysis.Razor
{ {
@ -30,8 +31,7 @@ namespace Microsoft.CodeAnalysis.Razor
foreach (var reference in compilation.References) foreach (var reference in compilation.References)
{ {
var assembly = compilation.GetAssemblyOrModuleSymbol(reference) as IAssemblySymbol; if (compilation.GetAssemblyOrModuleSymbol(reference) is IAssemblySymbol assembly)
if (assembly != null)
{ {
visitor.Visit(assembly.GlobalNamespace); visitor.Visit(assembly.GlobalNamespace);
} }

View File

@ -5,7 +5,7 @@ using System.Collections.Generic;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Host; using Microsoft.CodeAnalysis.Host;
using Microsoft.AspNetCore.Razor.Evolution.Legacy; using Microsoft.AspNetCore.Razor.Evolution;
namespace Microsoft.CodeAnalysis.Razor namespace Microsoft.CodeAnalysis.Razor
{ {

View File

@ -3,10 +3,11 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.AspNetCore.Razor.Evolution.Legacy;
using Newtonsoft.Json; using Newtonsoft.Json;
using Xunit; using Xunit;
namespace Microsoft.AspNetCore.Razor.Evolution.Legacy namespace Microsoft.AspNetCore.Razor.Evolution
{ {
public class TagHelperDescriptorTest public class TagHelperDescriptorTest
{ {

View File

@ -1,6 +1,6 @@
using Xunit; using Xunit;
namespace Microsoft.AspNetCore.Razor.Evolution.Legacy namespace Microsoft.AspNetCore.Razor.Evolution
{ {
public class TagHelperRequiredAttributeDescriptorTest public class TagHelperRequiredAttributeDescriptorTest
{ {

View File

@ -1,24 +1,30 @@
// Copyright (c) .NET Foundation. All rights reserved. // 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. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Composition;
using System.Text;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Razor.Evolution.Legacy; using Microsoft.AspNetCore.Razor.Evolution;
using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis;
using System.Composition;
namespace Microsoft.VisualStudio.LanguageServices.Razor namespace Microsoft.VisualStudio.LanguageServices.Razor
{ {
[Export(typeof(IRazorEngineTagHelperResolver))] [Export(typeof(ITagHelperResolver))]
internal class DefaultRazorEngineTagHelperResolver : IRazorEngineTagHelperResolver internal class DefaultTagHelperResolver : ITagHelperResolver
{ {
public async Task<IEnumerable<TagHelperDescriptor>> GetRazorEngineTagHelpersAsync(Workspace workspace, Project project) [Import]
public VisualStudioWorkspace Workspace { get; set; }
public async Task<IEnumerable<TagHelperDescriptor>> GetTagHelpersAsync(Project project)
{ {
var client = await RazorLanguageServiceClientFactory.CreateAsync(workspace, CancellationToken.None); var client = await RazorLanguageServiceClientFactory.CreateAsync(Workspace, CancellationToken.None);
if (client == null)
{
// The OOP host is turned off, so let's do this in process.
var resolver = new CodeAnalysis.Razor.DefaultTagHelperResolver();
return await resolver.GetTagHelpersAsync(project, CancellationToken.None).ConfigureAwait(false);
}
using (var session = await client.CreateSessionAsync(project.Solution)) using (var session = await client.CreateSessionAsync(project.Solution))
{ {

View File

@ -3,13 +3,13 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Razor.Evolution.Legacy; using Microsoft.AspNetCore.Razor.Evolution;
using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis;
namespace Microsoft.VisualStudio.LanguageServices.Razor namespace Microsoft.VisualStudio.LanguageServices.Razor
{ {
internal interface IRazorEngineTagHelperResolver public interface ITagHelperResolver
{ {
Task<IEnumerable<TagHelperDescriptor>> GetRazorEngineTagHelpersAsync(Workspace workspace, Project project); Task<IEnumerable<TagHelperDescriptor>> GetTagHelpersAsync(Project project);
} }
} }

View File

@ -21,6 +21,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.Workspaces.Common" Version="2.0.0-rc3-61306-01" /> <PackageReference Include="Microsoft.CodeAnalysis.Workspaces.Common" Version="2.0.0-rc3-61306-01" />
<PackageReference Include="Microsoft.VisualStudio.LanguageServices" Version="2.0.0-rc3-61306-01" />
<PackageReference Include="Microsoft.VisualStudio.LanguageServices.Razor.RemoteClient" Version="2.0.0-rc3-61306-01" /> <PackageReference Include="Microsoft.VisualStudio.LanguageServices.Razor.RemoteClient" Version="2.0.0-rc3-61306-01" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@ -17,7 +17,7 @@ namespace Microsoft.VisualStudio.RazorExtension.RazorInfo
private IRazorEngineAssemblyResolver _assemblyResolver; private IRazorEngineAssemblyResolver _assemblyResolver;
private IRazorEngineDocumentGenerator _documentGenerator; private IRazorEngineDocumentGenerator _documentGenerator;
private IRazorEngineDirectiveResolver _directiveResolver; private IRazorEngineDirectiveResolver _directiveResolver;
private IRazorEngineTagHelperResolver _tagHelperResolver; private ITagHelperResolver _tagHelperResolver;
private VisualStudioWorkspace _workspace; private VisualStudioWorkspace _workspace;
public RazorInfoToolWindow() : base(null) public RazorInfoToolWindow() : base(null)
@ -35,7 +35,7 @@ namespace Microsoft.VisualStudio.RazorExtension.RazorInfo
_assemblyResolver = componentModel.GetService<IRazorEngineAssemblyResolver>(); _assemblyResolver = componentModel.GetService<IRazorEngineAssemblyResolver>();
_documentGenerator = componentModel.GetService<IRazorEngineDocumentGenerator>(); _documentGenerator = componentModel.GetService<IRazorEngineDocumentGenerator>();
_directiveResolver = componentModel.GetService<IRazorEngineDirectiveResolver>(); _directiveResolver = componentModel.GetService<IRazorEngineDirectiveResolver>();
_tagHelperResolver = componentModel.GetService<IRazorEngineTagHelperResolver>(); _tagHelperResolver = componentModel.GetService<ITagHelperResolver>();
_workspace = componentModel.GetService<VisualStudioWorkspace>(); _workspace = componentModel.GetService<VisualStudioWorkspace>();
_workspace.WorkspaceChanged += Workspace_WorkspaceChanged; _workspace.WorkspaceChanged += Workspace_WorkspaceChanged;

View File

@ -22,7 +22,7 @@ namespace Microsoft.VisualStudio.RazorExtension.RazorInfo
private readonly IRazorEngineAssemblyResolver _assemblyResolver; private readonly IRazorEngineAssemblyResolver _assemblyResolver;
private readonly IRazorEngineDirectiveResolver _directiveResolver; private readonly IRazorEngineDirectiveResolver _directiveResolver;
private readonly IRazorEngineDocumentGenerator _documentGenerator; private readonly IRazorEngineDocumentGenerator _documentGenerator;
private readonly IRazorEngineTagHelperResolver _tagHelperResolver; private readonly ITagHelperResolver _tagHelperResolver;
private readonly IServiceProvider _services; private readonly IServiceProvider _services;
private readonly Workspace _workspace; private readonly Workspace _workspace;
@ -39,7 +39,7 @@ namespace Microsoft.VisualStudio.RazorExtension.RazorInfo
Workspace workspace, Workspace workspace,
IRazorEngineAssemblyResolver assemblyResolver, IRazorEngineAssemblyResolver assemblyResolver,
IRazorEngineDirectiveResolver directiveResolver, IRazorEngineDirectiveResolver directiveResolver,
IRazorEngineTagHelperResolver tagHelperResolver, ITagHelperResolver tagHelperResolver,
IRazorEngineDocumentGenerator documentGenerator) IRazorEngineDocumentGenerator documentGenerator)
{ {
_services = services; _services = services;
@ -166,7 +166,7 @@ namespace Microsoft.VisualStudio.RazorExtension.RazorInfo
var assemblies = await _assemblyResolver.GetRazorEngineAssembliesAsync(project); var assemblies = await _assemblyResolver.GetRazorEngineAssembliesAsync(project);
var directives = await _directiveResolver.GetRazorEngineDirectivesAsync(_workspace, project); var directives = await _directiveResolver.GetRazorEngineDirectivesAsync(_workspace, project);
var tagHelpers = await _tagHelperResolver.GetRazorEngineTagHelpersAsync(_workspace, project); var tagHelpers = await _tagHelperResolver.GetTagHelpersAsync(project);
var files = GetCshtmlDocuments(project); var files = GetCshtmlDocuments(project);

View File

@ -1,7 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved. // 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. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNetCore.Razor.Evolution.Legacy; using Microsoft.AspNetCore.Razor.Evolution;
namespace Microsoft.VisualStudio.RazorExtension.RazorInfo namespace Microsoft.VisualStudio.RazorExtension.RazorInfo
{ {