-
Notifications
You must be signed in to change notification settings - Fork 419
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 clean up and add objects for parameters and similar symbols #1062
Changes from 6 commits
941e653
734b475
c52d1b0
c843e42
f12ecb3
81cf69b
35cca90
6ca471d
516971f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,15 +10,15 @@ namespace OmniSharp.Models.TypeLookup | |
public class DocumentationComment | ||
{ | ||
public string SummaryText { get; } | ||
public string[] TypeParamElements { get; } | ||
public string[] ParamElements { get; } | ||
public DocumentedObject[] TypeParamElements { get; } | ||
public DocumentedObject[] ParamElements { get; } | ||
public string ReturnsText { get; } | ||
public string RemarksText { get; } | ||
public string ExampleText { get; } | ||
public string ValueText { get; } | ||
public string[ ] Exception { get; } | ||
public DocumentedObject[ ] Exception { get; } | ||
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. Extra space |
||
|
||
private DocumentationComment(string summaryText, string[] typeParamElements, string[] paramElements, string returnsText, string remarksText, string exampleText, string valueText, string [ ] exception) | ||
private DocumentationComment(string summaryText, DocumentedObject[] typeParamElements, DocumentedObject[] paramElements, string returnsText, string remarksText, string exampleText, string valueText, DocumentedObject[ ] exception) | ||
{ | ||
SummaryText = summaryText; | ||
TypeParamElements = typeParamElements; | ||
|
@@ -34,13 +34,13 @@ public static DocumentationComment From(string xmlDocumentation, string lineEndi | |
{ | ||
var reader = new StringReader("<docroot>" + xmlDocumentation + "</docroot>"); | ||
StringBuilder summaryText = new StringBuilder(); | ||
List<StringBuilder> typeParamElements = new List<StringBuilder>(); | ||
List<StringBuilder> paramElements = new List<StringBuilder>(); | ||
List<DocumentedObjectHelper> typeParamElements = new List<DocumentedObjectHelper>(); | ||
List<DocumentedObjectHelper> paramElements = new List<DocumentedObjectHelper>(); | ||
StringBuilder returnsText = new StringBuilder(); | ||
StringBuilder remarksText = new StringBuilder(); | ||
StringBuilder exampleText = new StringBuilder(); | ||
StringBuilder valueText = new StringBuilder(); | ||
List<StringBuilder> exception = new List<StringBuilder>(); | ||
List<DocumentedObjectHelper> exception = new List<DocumentedObjectHelper>(); | ||
|
||
using (var xml = XmlReader.Create(reader)) | ||
{ | ||
|
@@ -60,26 +60,21 @@ public static DocumentationComment From(string xmlDocumentation, string lineEndi | |
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); | ||
DocumentedObjectHelper exceptionInstance = new DocumentedObjectHelper(); | ||
exceptionInstance.Name = GetCref(xml["cref"]).TrimEnd(); | ||
currentSectionBuilder = exceptionInstance.Documentation; | ||
exception.Add(exceptionInstance); | ||
break; | ||
case "returns": | ||
returnsText.Append("Returns: "); | ||
currentSectionBuilder = returnsText; | ||
break; | ||
case "summary": | ||
summaryText.Append("Summary: "); | ||
currentSectionBuilder = summaryText; | ||
break; | ||
case "see": | ||
|
@@ -95,25 +90,22 @@ public static DocumentationComment From(string xmlDocumentation, string lineEndi | |
currentSectionBuilder.Append(" "); | ||
break; | ||
case "param": | ||
StringBuilder paramInstance = new StringBuilder(); | ||
paramInstance.Append(TrimMultiLineString(xml["name"], lineEnding)); | ||
paramInstance.Append(": "); | ||
currentSectionBuilder = paramInstance; | ||
DocumentedObjectHelper paramInstance = new DocumentedObjectHelper(); | ||
paramInstance.Name = TrimMultiLineString(xml["name"], lineEnding); | ||
currentSectionBuilder = paramInstance.Documentation; | ||
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; | ||
DocumentedObjectHelper typeParamInstance = new DocumentedObjectHelper(); | ||
typeParamInstance.Name = TrimMultiLineString(xml["name"], lineEnding); | ||
currentSectionBuilder = typeParamInstance.Documentation; | ||
typeParamElements.Add(typeParamInstance); | ||
break; | ||
case "value": | ||
valueText.Append("Value: "); | ||
currentSectionBuilder = valueText; | ||
break; | ||
case "br": | ||
|
@@ -140,7 +132,8 @@ public static DocumentationComment From(string xmlDocumentation, string lineEndi | |
return null; | ||
} | ||
} | ||
return new DocumentationComment(summaryText.ToString(), typeParamElements.Select(s => s.ToString()).ToArray(), paramElements.Select(s => s.ToString()).ToArray(), returnsText.ToString(), remarksText.ToString(), exampleText.ToString(), valueText.ToString(), exception.Select(s => s.ToString()).ToArray()); | ||
|
||
return new DocumentationComment(summaryText.ToString(), typeParamElements.Select(s => s.ConvertToDocumentedObject()).ToArray(), paramElements.Select(s => s.ConvertToDocumentedObject()).ToArray(), returnsText.ToString(), remarksText.ToString(), exampleText.ToString(), valueText.ToString(), exception.Select(s => s.ConvertToDocumentedObject()).ToArray()); | ||
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. Put each argument on its own line. |
||
} | ||
|
||
private static string TrimMultiLineString(string input, string lineEnding) | ||
|
@@ -166,4 +159,25 @@ private static string GetCref(string cref) | |
return cref + " "; | ||
} | ||
} | ||
|
||
class DocumentedObjectHelper | ||
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. DocumentedObjectBuilder? |
||
{ | ||
public string Name { get; set; } | ||
public StringBuilder Documentation { get; set; } | ||
|
||
public DocumentedObjectHelper() | ||
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. extra spaces |
||
{ | ||
Documentation = new StringBuilder(); | ||
} | ||
|
||
public DocumentedObject ConvertToDocumentedObject() | ||
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. extra spaces |
||
{ | ||
var documentedObject = new DocumentedObject | ||
{ | ||
Name = Name, | ||
Documentation = Documentation.ToString() | ||
}; | ||
return documentedObject; | ||
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. Newline after close brace of block when followed by non-brace. |
||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace OmniSharp.Models.TypeLookup | ||
{ | ||
public class DocumentedObject | ||
{ | ||
public string Name { get; set; } | ||
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. Can we get rid of the public setters? This type should be immutable. |
||
public string Documentation { get; set; } | ||
public DocumentedObject() { } | ||
} | ||
} |
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.
This could just be Array<KeyValuePair<string, string>> or Array<Tuple<string, string>>
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.
Thoughts @DustinCampbell ?
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.
I'm not sure what Newtownsoft.Json supports here. If we go with a custom type, I might call it
DocumentationItem
.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.
@akshita31 : Note that Array is not a thing in C#. @rchande meant
KeyValuePair<string, string>>[]
andTuple<string, string>[]
. I would lean away from tuple because it would mean that the protocol would have weird names likeItem1
andItem2
in it, which isn't what we want.