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

A code fix for a set of Documentation Comment diagnostics returned by the compiler #12902

Merged
merged 9 commits into from
Aug 6, 2016

Conversation

Hosch250
Copy link
Contributor

@Hosch250 Hosch250 commented Aug 3, 2016

Reference #7070

@Pilchie Pilchie added Area-IDE Community The pull request was submitted by a contributor who is not a Microsoft employee. labels Aug 3, 2016
@Pilchie
Copy link
Member

Pilchie commented Aug 3, 2016

Thanks for the submission - tagging @dotnet/roslyn-ide for review

@jmarolf
Copy link
Contributor

jmarolf commented Aug 3, 2016

test vsi please

<Document>
class Program1
{
/// &lt;summary&gt;
Copy link
Member

Choose a reason for hiding this comment

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

Minor note: if you wrap the body in <![CDATA[ and ]]> tags you don't need &lt; and &gt which might make this easier to read. E.g.,

var initial = @"
<Workspace>
    <Project ...>
        <Document>
<![CDATA[
class Program 1
{
    /// <summary>
...
]]>
...
";

@brettfo
Copy link
Member

brettfo commented Aug 3, 2016

Aside from my minor comments, looks good to me. :shipit:

public void Fizz(int value) {}
}
";
var parseOptions = Options.Regular.WithDocumentationMode(DocumentationMode.Diagnose);
Copy link
Member

Choose a reason for hiding this comment

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

so the pattern i prefer in cases like this is that you have your own TestAsync function in this class which creates theese parse options and calls the original TestAsync. Then all the functions in this class call that Test function. Test code follows hte same rules as normal code and we shoudl apply DRY.

(yes, i know there are TONS of cases where we violate this. but no reason to continue bad habits when we can avoid them). Thanks!

Copy link
Member

@CyrusNajmabadi CyrusNajmabadi Aug 3, 2016

Choose a reason for hiding this comment

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

Also, the core test method you call must pass in:

, compareTokens: false

The reason for this is that if you don't pass this in, then our test code will explicitly ignore trivia. That's obviously bad because this entire feature is precisely about changing trivia. :)

This is also the benefit of having a single test method. You change one and everything else picks it up.

@CyrusNajmabadi
Copy link
Member

As usual @Hosch250 your commitment to testing is phenomenal. Your contributions are very appreciated by the entire team.

@jmarolf
Copy link
Contributor

jmarolf commented Aug 3, 2016

Looks like test failure is due to: #11032

retest windows_vsi_p1_open_prtest please
retest windows_vsi_p3_open_prtest please

@@ -14,351 +14,373 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.DocumentationComme
Nothing,
New VisualBasicRemoveDocCommentNodeCodeFixProvider())
End Function

Private Overloads Async Function TestAsync(ByVal initial As String, ByVal expected As String) As Task

Copy link
Member

Choose a reason for hiding this comment

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

remove newline.

@CyrusNajmabadi
Copy link
Member

LGTM. @Pilchie Any concerns here?

@Hosch250
Copy link
Contributor Author

Hosch250 commented Aug 4, 2016

If you hold off a bit on merging this, I'll add the fix for CS1572 also. The others all involve removing the entire block, or adding elements (I think).

@jmarolf
Copy link
Contributor

jmarolf commented Aug 4, 2016

@Hosch250 alright, thanks, I'll hold off on merging until I hear from you.

@Hosch250
Copy link
Contributor Author

Hosch250 commented Aug 4, 2016

Just running my tests right now, so it shouldn't be long :)

{
var root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);
var commentParent = root.FindNode(span);
var triviaNode = commentParent.GetLeadingTrivia().Single(s => s.GetLocation().SourceSpan.Contains(span));
Copy link
Member

Choose a reason for hiding this comment

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

s => s.Span.Contains(span)

@Hosch250
Copy link
Contributor Author

Hosch250 commented Aug 4, 2016

I will fix these and add fixes for BC42313 and BC42315 as well (I just need to add them to the list of fixable diagnostics and add tests).


var triviaNodeStructure = triviaNode.GetStructure();

var paramNode = triviaNodeStructure.ChildNodes().Single(s => s.Span.Contains(span));
Copy link
Member

Choose a reason for hiding this comment

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

single is dangerous here. What if you had something like:

/// <summary>
/// <param ... >
/// </summary>

Couldn't both the summary node and the param node contain the span in question?

I'd far prefer something like SingleOrDefault just to be resilient to strange parse tree structures. (same applies to the higher use of Single).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will change this, but, IIRC, SingleOrDefault still throws if there is more than one matching node. I'll have to add tests for this possibility.

Copy link
Member

Choose a reason for hiding this comment

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

You are correct. 'FirstOrDefault' then. :)

Copy link
Member

Choose a reason for hiding this comment

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

Or, somethgin that actually tries to get the right node but won't crash :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I will have to redesign this.

Copy link
Contributor Author

@Hosch250 Hosch250 Aug 4, 2016

Choose a reason for hiding this comment

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

Actually, no, that situation you show will not cause a crash. I only retrieve the child nodes, which is the first level under the given element. This would crash if I had retrieved the descendant nodes, but the only way it could crash under the child nodes would be if the span covered two elements. I will change it to SingleOrDefault and return an unchanged document if I can't find a matching node, however, unless you think this isn't safe enough.

Copy link
Member

Choose a reason for hiding this comment

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

Ah good point. Can you still do FirstOrDefault then, and just bail in the default case. I don't want us to introduce a crash with Single late in the process that only happens in rare cases, but we don't run into until some customer hits it :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that would be good--I wouldn't want to cause a crash either.

@CyrusNajmabadi
Copy link
Member

A few more comments. If @Pilchie is cool with this, and the comments are addressed, then 👍

Thanks!

@Hosch250
Copy link
Contributor Author

Hosch250 commented Aug 4, 2016

I may not be able to get this in tonight. Working on addressing the comments and adding tests right now.

@Hosch250
Copy link
Contributor Author

Hosch250 commented Aug 4, 2016

I just caught a bug:

/// <summary>
/// <param name="args"></param>
/// <param name="args"></param>
/// </summary>

That fires the diagnostic off, and running my quick fix will kill the whole summary tag. Now, no diagnostic comment should ever be like that, but I'll address this bug tomorrow anyway (especially since I've seen some that are like that).

@Hosch250
Copy link
Contributor Author

Hosch250 commented Aug 4, 2016

@CyrusNajmabadi Bug fixed and ready for review again.

@Pilchie
Copy link
Member

Pilchie commented Aug 4, 2016

I won't have a chance to review until Saturday, but this can be merged before then if @CyrusNajmabadi and @jmarolf are happy with it.

@Hosch250
Copy link
Contributor Author

Hosch250 commented Aug 5, 2016

test vsi please

@Hosch250
Copy link
Contributor Author

Hosch250 commented Aug 5, 2016

Is the reason for failure #11032 again?


// There *should* always be one node here if the diagnostic fires,
// but we will use `FirstOrDefault` just to safeguard against a sly bug
var triviaNode = commentParent.GetLeadingTrivia().FirstOrDefault(s => s.Span.Contains(span));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can use the flag to search in trivia as well as non-trivia nodes here to simplify this.

@Hosch250
Copy link
Contributor Author

Hosch250 commented Aug 5, 2016

test vsi please

@Hosch250
Copy link
Contributor Author

Hosch250 commented Aug 5, 2016

@CyrusNajmabadi I'm ready for this to be reviewed again whenever you are ready. I made a few slight changes to use the pre-written node-finding API, and fixed the bug I mentioned on Wednesday night.

@Hosch250
Copy link
Contributor Author

Hosch250 commented Aug 6, 2016

Thank you for the information.

paramNode = paramNode.Parent;
}

if (paramNode == null)
Copy link
Member

Choose a reason for hiding this comment

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

This whole check should happen prior to calling "RegisterCodeFix". Because if we can't transform the document then we shouldn't offer a fix.

@CyrusNajmabadi
Copy link
Member

@Hosch250 If you extract that code into a helper you can then call it both before and after the 'RegisterXXX' call.

Make that change and i'll happily merge this. If you want, i'm also ok making that change myself. Your call!

@Hosch250
Copy link
Contributor Author

Hosch250 commented Aug 6, 2016

I will do it.

@Hosch250
Copy link
Contributor Author

Hosch250 commented Aug 6, 2016

Done, sorry it took so long. I will be back in about an hour in case you have more questions.

@CyrusNajmabadi CyrusNajmabadi merged commit 811ddd1 into dotnet:master Aug 6, 2016
@CyrusNajmabadi
Copy link
Member

Merged in. Thanks a ton!

@jmarolf
Copy link
Contributor

jmarolf commented Aug 6, 2016

Thanks for merging @CyrusNajmabadi. and thanks for the awesome contribution @Hosch250!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE cla-already-signed Community The pull request was submitted by a contributor who is not a Microsoft employee.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants