-
Notifications
You must be signed in to change notification settings - Fork 418
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
Using StructuredDocumentation for Signature Help and appropriate documentation for Parameter symbols #1085
Conversation
Omnisharp-vscode side : dotnet/vscode-csharp#1958 |
@@ -168,19 +169,19 @@ private static SignatureHelpItem BuildSignature(IMethodSymbol symbol) | |||
signature.Documentation = symbol.GetDocumentationCommentXml(); |
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.
@rchande @DustinCampbell Do we want to return the Parsed xml for other editors as well. Currently GetDocumentationCommentXml() gives the xml with the tags.
@@ -30,8 +30,22 @@ private DocumentationComment(string summaryText, DocumentationItem[] typeParamEl | |||
Exception = exception; | |||
} | |||
|
|||
private DocumentationComment() |
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.
You could make a this()
constructor call and call your existing constructor with the default values (to avoid having to write the assignments over and over again).
Alternatively, you could remove this constructor and make all the parameters optional in the one above this.
public DocumentationItem[] Exception { get; } | ||
|
||
private DocumentationComment(string summaryText, DocumentationItem[] typeParamElements, DocumentationItem[] paramElements, string returnsText, string remarksText, string exampleText, string valueText, DocumentationItem[ ] exception) | ||
public string SummaryText { get; private set; } |
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.
Why setters? You should be able to set get-only in the constructor.
public static DocumentationComment From(string xmlDocumentation, string lineEnding) | ||
{ | ||
if (string.IsNullOrEmpty(xmlDocumentation)) | ||
return Empty; |
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.
Newline.
//Gets the parameter documentation from this object | ||
public string GetParameterText(string name) | ||
{ | ||
var requiredParam = Array.Find(ParamElements, parameter => parameter.Name == name); |
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.
You could do an expression body here:
`GetParameterText() => Array.Find(...)?.Documentation ?? string.Empty.
|
||
public static DocumentationComment WithSummaryText(string summaryText) | ||
{ | ||
var docComment = new DocumentationComment(); |
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.
Yeah, let's just make the arguments to the first constructor optional.
{ | ||
switch (symbol) | ||
{ | ||
case IParameterSymbol parameter: return DocumentationComment.WithSummaryText(DocumentationHelper.GetParameterDocumentation(parameter, lineEnding)); |
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.
Typically the case code goes on the line after the case label.
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.
Wouldn't this be nicer if it was New DocumentationComment(summaryText = DocumentationHelper.GetParameterer(...
?
|
||
public static class DocumentationHelper | ||
{ | ||
public static string GetParameterDocumentation(IParameterSymbol parameter, string lineEnding = "\n") |
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.
What's the advantage of putting these in another class versus inside DocumentationConverter? Do you imagine other code using these methods?
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.
NVM, used below. Can you move this class to its own file?
var signature = actual.Signatures.ElementAt(0); | ||
Assert.Equal(2, signature.Parameters.Count()); | ||
Assert.Equal("gameObject", signature.Parameters.ElementAt(0).Name); | ||
Assert.Equal("The game object.", signature.Parameters.ElementAt(0).Documentation); |
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.
What happens if there are additional tags inside the parameter documentation?
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.
The StructuredDocumentation removes all the tags and appends the text to the appropriate section hence any additional tags inside the parameter documentation will be processed accordingly.
Added a test to check for the same.
@@ -168,19 +169,19 @@ private static SignatureHelpItem BuildSignature(IMethodSymbol symbol) | |||
signature.Documentation = symbol.GetDocumentationCommentXml(); | |||
signature.Name = symbol.MethodKind == MethodKind.Constructor ? symbol.ContainingType.Name : symbol.Name; | |||
signature.Label = symbol.ToDisplayString(SymbolDisplayFormat.MinimallyQualifiedFormat); | |||
signature.StructuredDocumentation = DocumentationConverter.GetStructuredDocumentation(symbol); |
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.
It looks like this code is calling symbol.GetDocumentationCommentXml once for the method itself and once for every parameter in the method. Is there a way we can just parse the XML once?
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.
Very close, just a couple more things.
@@ -175,6 +186,15 @@ private static string TrimStartRetainingSingleLeadingSpace(string input) | |||
return input; | |||
return $" {input.TrimStart()}"; | |||
} | |||
|
|||
//Gets the parameter documentation from this object |
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.
Make this a doc comment or remove?
@@ -18,20 +18,31 @@ public class DocumentationComment | |||
public string ValueText { get; } | |||
public DocumentationItem[] Exception { get; } | |||
|
|||
private DocumentationComment(string summaryText, DocumentationItem[] typeParamElements, DocumentationItem[] paramElements, string returnsText, string remarksText, string exampleText, string valueText, DocumentationItem[ ] exception) | |||
public DocumentationComment | |||
(string summaryText = "", |
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.
Nit: paren should be on the same line as DocumentationComment
{ | ||
SummaryText = summaryText; | ||
TypeParamElements = typeParamElements; | ||
ParamElements = paramElements; | ||
TypeParamElements = typeParamElements ?? new DocumentationItem[0]; |
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.
Array.Empty
public static string GetParameterDocumentation(IParameterSymbol parameter, string lineEnding = "\n") | ||
{ | ||
var contaningSymbolDef = parameter.ContainingSymbol.OriginalDefinition; | ||
return DocumentationConverter.GetStructuredDocumentation(contaningSymbolDef.GetDocumentationCommentXml(), lineEnding).GetParameterText(parameter.Name); |
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 would wrap a line of this length.
|
||
signature.Parameters = symbol.Parameters.Select(parameter => | ||
{ | ||
return new SignatureHelpParameter() | ||
{ | ||
Name = parameter.Name, | ||
Label = parameter.ToDisplayString(SymbolDisplayFormat.MinimallyQualifiedFormat), | ||
Documentation = parameter.GetDocumentationCommentXml() | ||
Documentation = signature.StructuredDocumentation.GetParameterText(parameter.Name) |
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.
Ah, now there's only one caller for each of those methods in DocumentationHelper. Can they move inside StructuredDocumentation?
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.
Thanks!
Changes:
StructuredDocumentation
field to SignatureHelpResponse to display signature help documentation properly.DocumentationHelper
and the corresponding methods.GetStructuredDocumentation
- to be used by both TypeLookUp and SignatureHelp to check for the type of symbol and return theDocumentationComment
object accordingly.StructuredDocumentation
for the signature and get the correct documentation for the parameter.Please review : @DustinCampbell @rchande @TheRealPiotrP @david-driscoll @filipw