Skip to content
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

Merged
merged 14 commits into from
Jan 29, 2018

Conversation

akshita31
Copy link
Contributor

@akshita31 akshita31 commented Jan 12, 2018

Changes:

  1. Added StructuredDocumentation field to SignatureHelpResponse to display signature help documentation properly.
  2. Added code for returning documentation for parameters, typeparameters and alias types, by adding a class DocumentationHelper and the corresponding methods.
  3. Modified DocumentationComment to return empty object instead of null if the xmlDocumentation is empty.
  4. Modified the GetStructuredDocumentation - to be used by both TypeLookUp and SignatureHelp to check for the type of symbol and return the DocumentationComment object accordingly.
  5. Modified SignatureHelp to use the StructuredDocumentation for the signature and get the correct documentation for the parameter.
  6. Modified TypeLookUp according to the changes.
  7. Added test cases for the SignatureHelp and TypeLookUp.

Please review : @DustinCampbell @rchande @TheRealPiotrP @david-driscoll @filipw

@akshita31 akshita31 changed the title Using StructuredDocumentation for Signature Help and Documentation for Parameter symbols Using StructuredDocumentation for Signature Help and appropriate documentation for Parameter symbols Jan 12, 2018
@akshita31
Copy link
Contributor Author

With this change the Hover in VSCode will show documentation for parameters :
hover_param_doc_showing

@akshita31
Copy link
Contributor Author

Omnisharp-vscode side : dotnet/vscode-csharp#1958

@@ -168,19 +169,19 @@ private static SignatureHelpItem BuildSignature(IMethodSymbol symbol)
signature.Documentation = symbol.GetDocumentationCommentXml();
Copy link
Contributor Author

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()
Copy link

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; }
Copy link

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;
Copy link

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);
Copy link

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();
Copy link

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));
Copy link

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.

Copy link

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")
Copy link

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?

Copy link

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);
Copy link

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?

Copy link
Contributor Author

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);
Copy link

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?

Copy link

@rchande rchande left a 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
Copy link

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 = "",
Copy link

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];
Copy link

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);
Copy link

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)
Copy link

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?

Copy link

@rchande rchande left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@rchande rchande merged commit ab289f5 into OmniSharp:master Jan 29, 2018
@akshita31 akshita31 deleted the sig_help_doc branch January 29, 2018 23:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants