Fixing support for XML docs in OOP

The issue here is that the OOP host doesn't yet have support for
documentation, it will just return null. Fixing this code to look for the
documentation after we get the descriptors back into VS.

I tested this and confirmed that it works with TagHelpers in dlls + xml
file documenation as well as TagHelpers compiled in the project itself.
This commit is contained in:
Ryan Nowak 2017-02-22 13:45:57 -08:00
parent 539903c7cf
commit 94d21e03f5
3 changed files with 48 additions and 3 deletions

View File

@ -3,9 +3,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNetCore.Razor.Evolution;
using Microsoft.AspNetCore.Razor.Evolution.Legacy;
using System.Linq;
namespace Microsoft.CodeAnalysis.Razor
{

View File

@ -23,9 +23,8 @@ namespace Microsoft.CodeAnalysis.Razor
}
// the structure of the XML is defined by: https://msdn.microsoft.com/en-us/library/fsbx0t7x.aspx
// we expect the root node of the content we are passed to always be 'member'.
// we expect the root node of the content we are passed to always be 'member' or 'doc'.
_element = XElement.Parse(content);
Debug.Assert(_element.Name == "member");
}
/// <summary>

View File

@ -4,8 +4,10 @@
using System;
using System.Collections.Generic;
using System.Composition;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Razor.Evolution;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Razor;
@ -33,6 +35,12 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor
using (var session = await client.CreateSessionAsync(project.Solution))
{
var result = await session.InvokeAsync<TagHelperResolutionResult>("GetTagHelpersAsync", new object[] { project.Id.Id, "Foo", assemblyNameFilters, }).ConfigureAwait(false);
// Per https://github.com/dotnet/roslyn/issues/12770 - there's currently no support for documentation in the OOP host
// 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);
AddXmlDocumentation(compilation, result.Descriptors);
return result;
}
}
@ -44,5 +52,43 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor
exception);
}
}
private void AddXmlDocumentation(Compilation compilation, IReadOnlyList<TagHelperDescriptor> tagHelpers)
{
for (var i = 0; i < tagHelpers.Count; i++)
{
var tagHelper = tagHelpers[i];
tagHelper.DesignTimeDescriptor = tagHelper.DesignTimeDescriptor ?? new TagHelperDesignTimeDescriptor();
var symbol = compilation.GetTypeByMetadataName(tagHelper.TypeName);
if (symbol != null)
{
var xml = symbol.GetDocumentationCommentXml();
if (!string.IsNullOrEmpty(xml))
{
var documentation = new XmlMemberDocumentation(xml);
tagHelper.DesignTimeDescriptor.Summary = documentation.GetSummary();
tagHelper.DesignTimeDescriptor.Remarks = documentation.GetRemarks();
}
foreach (var attribute in tagHelper.Attributes)
{
attribute.DesignTimeDescriptor = attribute.DesignTimeDescriptor ?? new TagHelperAttributeDesignTimeDescriptor();
var attributeSymbol = symbol.GetMembers(attribute.PropertyName).FirstOrDefault();
if (attributeSymbol != null)
{
xml = attributeSymbol.GetDocumentationCommentXml();
if (!string.IsNullOrEmpty(xml))
{
var documentation = new XmlMemberDocumentation(xml);
tagHelper.DesignTimeDescriptor.Summary = documentation.GetSummary();
tagHelper.DesignTimeDescriptor.Remarks = documentation.GetRemarks();
}
}
}
}
}
}
}
}