Remove TagHelperDescriptor doc workaround.
- Roslyn now properly supports XML documentation retrieval OOP. #1032
This commit is contained in:
parent
a562480cd0
commit
82323456ee
|
|
@ -4,10 +4,8 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Composition;
|
using System.Composition;
|
||||||
using System.Linq;
|
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Razor.Language;
|
|
||||||
using Microsoft.CodeAnalysis;
|
using Microsoft.CodeAnalysis;
|
||||||
using Microsoft.CodeAnalysis.Razor;
|
using Microsoft.CodeAnalysis.Razor;
|
||||||
using Microsoft.VisualStudio.Shell;
|
using Microsoft.VisualStudio.Shell;
|
||||||
|
|
@ -51,13 +49,7 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor
|
||||||
|
|
||||||
if (result != null)
|
if (result != null)
|
||||||
{
|
{
|
||||||
// Per https://github.com/dotnet/roslyn/issues/12770 - there's currently no support for documentation in the OOP host
|
return result;
|
||||||
// until that's available we add the documentation on the VS side by looking up each symbol again.
|
|
||||||
var compilation = await project.GetCompilationAsync().ConfigureAwait(false);
|
|
||||||
var documentedTagHelpers = GetDocumentedTagHelpers(compilation, result.Descriptors);
|
|
||||||
var documentedResult = new TagHelperResolutionResult(documentedTagHelpers, result.Diagnostics);
|
|
||||||
|
|
||||||
return documentedResult;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -99,125 +91,6 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private IReadOnlyList<TagHelperDescriptor> GetDocumentedTagHelpers(Compilation compilation, IReadOnlyList<TagHelperDescriptor> tagHelpers)
|
|
||||||
{
|
|
||||||
var documentedTagHelpers = new List<TagHelperDescriptor>();
|
|
||||||
for (var i = 0; i < tagHelpers.Count; i++)
|
|
||||||
{
|
|
||||||
var tagHelper = tagHelpers[i];
|
|
||||||
|
|
||||||
if (tagHelper.Documentation != null)
|
|
||||||
{
|
|
||||||
documentedTagHelpers.Add(tagHelper);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
var typeName = tagHelper.Metadata[TagHelperDescriptorBuilder.TypeNameKey];
|
|
||||||
var symbol = compilation.GetTypeByMetadataName(typeName);
|
|
||||||
if (symbol != null)
|
|
||||||
{
|
|
||||||
var tagHelperBuilder = ShallowCopy(typeName, tagHelper);
|
|
||||||
var xml = symbol.GetDocumentationCommentXml();
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(xml))
|
|
||||||
{
|
|
||||||
tagHelperBuilder.Documentation(xml);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (var attribute in tagHelper.BoundAttributes)
|
|
||||||
{
|
|
||||||
var propertyName = attribute.Metadata[ITagHelperBoundAttributeDescriptorBuilder.PropertyNameKey];
|
|
||||||
|
|
||||||
var resolvedAttribute = attribute;
|
|
||||||
var attributeSymbol = symbol.GetMembers(propertyName).FirstOrDefault();
|
|
||||||
if (attributeSymbol != null)
|
|
||||||
{
|
|
||||||
xml = attributeSymbol.GetDocumentationCommentXml();
|
|
||||||
if (!string.IsNullOrEmpty(xml))
|
|
||||||
{
|
|
||||||
var attributeBuilder = ShallowCopy(typeName, resolvedAttribute);
|
|
||||||
attributeBuilder.Documentation(xml);
|
|
||||||
resolvedAttribute = attributeBuilder.Build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
tagHelperBuilder.BindAttribute(resolvedAttribute);
|
|
||||||
}
|
|
||||||
|
|
||||||
tagHelper = tagHelperBuilder.Build();
|
|
||||||
}
|
|
||||||
|
|
||||||
documentedTagHelpers.Add(tagHelper);
|
|
||||||
}
|
|
||||||
|
|
||||||
return documentedTagHelpers;
|
|
||||||
}
|
|
||||||
|
|
||||||
private ITagHelperBoundAttributeDescriptorBuilder ShallowCopy(string tagHelperTypeName, BoundAttributeDescriptor attribute)
|
|
||||||
{
|
|
||||||
var builder = ITagHelperBoundAttributeDescriptorBuilder.Create(tagHelperTypeName);
|
|
||||||
|
|
||||||
if (attribute.IsEnum)
|
|
||||||
{
|
|
||||||
builder.AsEnum();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (attribute.IndexerNamePrefix != null)
|
|
||||||
{
|
|
||||||
builder.AsDictionary(attribute.IndexerNamePrefix, attribute.IndexerTypeName);
|
|
||||||
}
|
|
||||||
|
|
||||||
builder.Name(attribute.Name);
|
|
||||||
builder.TypeName(attribute.TypeName);
|
|
||||||
|
|
||||||
var propertyName = attribute.Metadata[ITagHelperBoundAttributeDescriptorBuilder.PropertyNameKey];
|
|
||||||
builder.PropertyName(propertyName);
|
|
||||||
|
|
||||||
foreach (var metadata in attribute.Metadata)
|
|
||||||
{
|
|
||||||
builder.AddMetadata(metadata.Key, metadata.Value);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (var diagnostic in attribute.Diagnostics)
|
|
||||||
{
|
|
||||||
builder.AddDiagnostic(diagnostic);
|
|
||||||
}
|
|
||||||
|
|
||||||
return builder;
|
|
||||||
}
|
|
||||||
|
|
||||||
private TagHelperDescriptorBuilder ShallowCopy(string tagHelperTypeName, TagHelperDescriptor tagHelper)
|
|
||||||
{
|
|
||||||
var builder = TagHelperDescriptorBuilder.Create(tagHelperTypeName, tagHelper.AssemblyName);
|
|
||||||
|
|
||||||
foreach (var rule in tagHelper.TagMatchingRules)
|
|
||||||
{
|
|
||||||
builder.TagMatchingRule(rule);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tagHelper.AllowedChildTags != null)
|
|
||||||
{
|
|
||||||
foreach (var allowedChild in tagHelper.AllowedChildTags)
|
|
||||||
{
|
|
||||||
builder.AllowChildTag(allowedChild);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
builder.TagOutputHint(tagHelper.TagOutputHint);
|
|
||||||
|
|
||||||
foreach (var metadata in tagHelper.Metadata)
|
|
||||||
{
|
|
||||||
builder.AddMetadata(metadata.Key, metadata.Value);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (var diagnostic in tagHelper.Diagnostics)
|
|
||||||
{
|
|
||||||
builder.AddDiagnostic(diagnostic);
|
|
||||||
}
|
|
||||||
|
|
||||||
return builder;
|
|
||||||
}
|
|
||||||
|
|
||||||
private IVsActivityLog GetActivityLog()
|
private IVsActivityLog GetActivityLog()
|
||||||
{
|
{
|
||||||
var services = (IServiceProvider)Services;
|
var services = (IServiceProvider)Services;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue