-
Notifications
You must be signed in to change notification settings - Fork 416
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeLookUp Structured Documentation Feature to be used by VS Code #1038
Merged
Merged
Changes from 12 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
0de6d84
Added Basic Structure
akshita31 a6933f2
Text Fields for Doc Convertor running
akshita31 02e7a35
see and seeref working
akshita31 4b50e4e
All Test Cases Running
akshita31 b35485d
Cleaned the code
akshita31 9ca970f
Removed ParamRef
akshita31 056aed5
Added test
akshita31 5013278
Converted from stringBuilder to string
akshita31 eb79ac8
Added array for exceptions
akshita31 c3d1faf
Unncessary Lines Removed and Tests Modified
akshita31 93b3846
Added tests for tags appearing together
akshita31 a6b1a97
Added property to V1
akshita31 90a236f
Added the code for forming the comment object into the documentation …
akshita31 d3de7c2
Merge remote-tracking branch 'upstream/master' into typelookup_v2
akshita31 18fe9c5
Changed order of the members in DocumentationComment object
akshita31 5494fb9
Merge branch 'master' into typelookup_v2
DustinCampbell File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
src/OmniSharp.Abstractions/Models/v1/TypeLookup/DocumentationComment.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
namespace OmniSharp.Models.TypeLookup | ||
{ | ||
public class DocumentationComment | ||
{ | ||
public string RemarksText { get; set; } | ||
public string ExampleText { get; set; } | ||
public string ReturnsText { get; set; } | ||
public string SummaryText { get; set; } | ||
public string ValueText { get; set; } | ||
public string[ ] ParamElements { get; set; } | ||
public string[ ] TypeParamElements { get; set; } | ||
public string[ ] Exception { get; set; } | ||
|
||
public DocumentationComment() | ||
{ | ||
RemarksText = ""; | ||
ExampleText = ""; | ||
ReturnsText = ""; | ||
SummaryText = ""; | ||
ValueText = ""; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Xml; | ||
using OmniSharp.Models.TypeLookup; | ||
|
||
namespace OmniSharp.Roslyn.CSharp.Services.Documentation | ||
{ | ||
|
@@ -126,5 +128,131 @@ private static string GetCref(string cref) | |
} | ||
return cref + " "; | ||
} | ||
|
||
public static DocumentationComment GetStructuredDocumentation(string xmlDocumentation, string lineEnding) | ||
{ | ||
if (string.IsNullOrEmpty(xmlDocumentation)) | ||
return null; | ||
var docComment = new DocumentationComment(); | ||
var reader = new StringReader("<docroot>" + xmlDocumentation + "</docroot>"); | ||
StringBuilder remarksText = new StringBuilder(); | ||
StringBuilder exampleText = new StringBuilder(); | ||
StringBuilder returnsText = new StringBuilder(); | ||
StringBuilder summaryText = new StringBuilder(); | ||
StringBuilder valueText = new StringBuilder(); | ||
List<StringBuilder> paramElements = new List<StringBuilder>(); | ||
List<StringBuilder> typeParamElements = new List<StringBuilder>(); | ||
List<StringBuilder> exception = new List<StringBuilder>(); | ||
|
||
using (var xml = XmlReader.Create(reader)) | ||
{ | ||
try | ||
{ | ||
xml.Read(); | ||
string elementName = null; | ||
StringBuilder currentSectionBuilder = null; | ||
do | ||
{ | ||
if (xml.NodeType == XmlNodeType.Element) | ||
{ | ||
elementName = xml.Name.ToLowerInvariant(); | ||
switch (elementName) | ||
{ | ||
case "filterpriority": | ||
xml.Skip(); | ||
break; | ||
case "remarks": | ||
remarksText.Append("Remarks: "); | ||
currentSectionBuilder = remarksText; | ||
break; | ||
case "example": | ||
exampleText.Append("Example: "); | ||
currentSectionBuilder = exampleText; | ||
break; | ||
case "exception": | ||
StringBuilder ExceptionInstance = new StringBuilder(); | ||
ExceptionInstance.Append(GetCref(xml["cref"]).TrimEnd()); | ||
ExceptionInstance.Append(": "); | ||
currentSectionBuilder = ExceptionInstance; | ||
exception.Add(ExceptionInstance); | ||
break; | ||
case "returns": | ||
returnsText.Append("Returns: "); | ||
currentSectionBuilder = returnsText; | ||
break; | ||
case "summary": | ||
summaryText.Append("Summary: "); | ||
currentSectionBuilder = summaryText; | ||
break; | ||
case "see": | ||
currentSectionBuilder.Append(GetCref(xml["cref"])); | ||
currentSectionBuilder.Append(xml["langword"]); | ||
break; | ||
case "seealso": | ||
currentSectionBuilder.Append("See also: "); | ||
currentSectionBuilder.Append(GetCref(xml["cref"])); | ||
break; | ||
case "paramref": | ||
currentSectionBuilder.Append(xml["name"]); | ||
currentSectionBuilder.Append(" "); | ||
break; | ||
case "param": | ||
StringBuilder paramInstance = new StringBuilder(); | ||
paramInstance.Append(TrimMultiLineString(xml["name"], lineEnding)); | ||
paramInstance.Append(": "); | ||
currentSectionBuilder = paramInstance; | ||
paramElements.Add(paramInstance); | ||
break; | ||
case "typeparamref": | ||
currentSectionBuilder.Append(xml["name"]); | ||
currentSectionBuilder.Append(" "); | ||
break; | ||
case "typeparam": | ||
StringBuilder typeParamInstance = new StringBuilder(); | ||
typeParamInstance.Append(TrimMultiLineString(xml["name"], lineEnding)); | ||
typeParamInstance.Append(": "); | ||
currentSectionBuilder = typeParamInstance; | ||
typeParamElements.Add(typeParamInstance); | ||
break; | ||
case "value": | ||
valueText.Append("Value: "); | ||
currentSectionBuilder = valueText; | ||
break; | ||
case "br": | ||
case "para": | ||
currentSectionBuilder.Append(lineEnding); | ||
break; | ||
} | ||
} | ||
else if (xml.NodeType == XmlNodeType.Text && currentSectionBuilder != null) | ||
{ | ||
if (elementName == "code") | ||
{ | ||
currentSectionBuilder.Append(xml.Value); | ||
} | ||
else | ||
{ | ||
currentSectionBuilder.Append(TrimMultiLineString(xml.Value, lineEnding)); | ||
} | ||
} | ||
} while (xml.Read()); | ||
} | ||
catch (Exception) | ||
{ | ||
return null; | ||
} | ||
|
||
docComment.RemarksText = remarksText.ToString(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How do you feel about adding a constructor to docComment that takes all of these, rather than having to remember to set all of the properties? (Maybe makes it easier to not forget a section if we refactor). |
||
docComment.ExampleText = exampleText.ToString(); | ||
docComment.ReturnsText = returnsText.ToString(); | ||
docComment.SummaryText = summaryText.ToString(); | ||
docComment.ValueText = valueText.ToString(); | ||
docComment.ParamElements = paramElements.Select(s => s.ToString()).ToArray(); | ||
docComment.TypeParamElements = typeParamElements.Select(s => s.ToString()).ToArray(); | ||
docComment.Exception = exception.Select(s => s.ToString()).ToArray(); | ||
return docComment; | ||
} | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lowerCase.