Skip to content

Needs Design Review: First pass at fixing the formatting of VB Line Continuation Formatting#38072

Closed
paul1956 wants to merge 6 commits intodotnet:masterfrom
paul1956:LineCOnfinuationFormatting
Closed

Needs Design Review: First pass at fixing the formatting of VB Line Continuation Formatting#38072
paul1956 wants to merge 6 commits intodotnet:masterfrom
paul1956:LineCOnfinuationFormatting

Conversation

@paul1956
Copy link
Contributor

This addresses _ on line without code, with or without comment. This uses existing Formatting Rules which don't understand VB Line Continuation on blank lines or followed by comment. The results need a design review. I temporarily renamed the effected tests by added 3 _, they could be removed but it would be harder to see the effects of any changes, these are the only tests that I found that hit the code I changed. One area that needs review is the alignment of lines under lines with _ comment.

…ent. This addresses _ on line without code with out without comment. This uses existing Formatting Rules which don't understand VB Line Continuation on blank lines or followed by comment.
@paul1956 paul1956 requested a review from a team as a code owner August 17, 2019 06:34
@jinujoseph jinujoseph added Area-IDE Community The pull request was submitted by a contributor who is not a Microsoft employee. labels Aug 17, 2019
2 + _
3
2 + _
3
Copy link
Contributor

Choose a reason for hiding this comment

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

this formatting doesn't seem desirable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is not desirable and I would love to fix it but I don't see a rule that would format it correctly and doesn't undo all the newer formatting. I have experimented with the available rules and you either get this behavior or the "2" is left aligned sometimes and correctly aligned others depending on what the line looks like before the formatting.

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 code that does the indenting based on the rules needs to understand " _ ' Optional Comment' and I have not found it yet or I need to use a different rule.

Copy link
Contributor

Choose a reason for hiding this comment

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

I would love to fix it but I don't see a rule that would format it correctly and doesn't undo all the newer formatting

What do you mean by 'newer formatting'?

The code that does the indenting based on the rules needs to understand " _ ' Optional Comment' and I have not found it yet or I need to use a different rule.

Can you write a set of tests that show the behavior you want roslyn to have, but doesn't have? That way we can then have a code change that makes those tests pass, while not regressing these other scenarios?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That is my goal, I restored all the original tests, some fail is expected other fail because my code incorrectly breaks them. Is there a way to expect the old test to fail and have it pass?

@CyrusNajmabadi
Copy link
Contributor

they could be removed but it would be harder to see the effects of any changes,

Please don't do this. It appears as if your code changes are regressing these scenarios. Removing tests will simply hide that and allow regressions in areas we have tests explicitly there to ensure the behavior of.

these are the only tests that I found that hit the code I changed. One area that needs review is the alignment of lines under lines with _ comment.

I think you need to update your change so that it can give you the behavior you want without regressing these cases.

@CyrusNajmabadi
Copy link
Contributor

I don't see any tests actually showing cases you think should be fixed/improved by your product code change. Can you write tests that at least show what positive behavior you think the changes so far have?

If trivia2.Kind = SyntaxKind.LineContinuationTrivia Then
Return LineColumnRule.ForceSpacesOrUseAbsoluteIndentation(spacesOrIndentation:=1)
If trivia1.Kind = SyntaxKind.None Then
Return LineColumnRule.ForceSpacesOrUseAbsoluteIndentation(spacesOrIndentation:=1)
Copy link
Contributor

Choose a reason for hiding this comment

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

what code example causes this case to be hit?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A file with only _

Copy link
Contributor

Choose a reason for hiding this comment

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

please document this code to make those cases clear.

ElseIf trivia1.Kind = SyntaxKind.commenttrivia Then
Return LineColumnRule.ForceSpacesOrUseDefaultIndentation(spaces:=-1)
Else
Return LineColumnRule.PreserveLinesWithFollowingPrecedingIndentation()
Copy link
Contributor

@CyrusNajmabadi CyrusNajmabadi Aug 19, 2019

Choose a reason for hiding this comment

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

can you provide comments in this code giving examples of what each of these if-blocks would correspond to and why the LineColumnRules you are returning are desirable? For example, i have no idea why you are returning spacesOrIndentation:=1 for trivia1.Kind = SyntaxKind.None or why you return spaces:=-1 for trivia1.Kind = SyntaxKind.commenttrivia. etc. etc.

Copy link
Contributor Author

@paul1956 paul1956 Aug 19, 2019

Choose a reason for hiding this comment

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

Done in newest commit

Dim aa = 1 + _
_
_
_' Comment 1
Copy link
Contributor

Choose a reason for hiding this comment

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

please don't change the inputs of existing tests. Instead, add a new test with the different input. By doing this, i can't see what the impact of your code change is on hte original input of the original test.

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 realized I needed to do that. Some of the old tests will fail but I think for now that is OK.

Copy link
Contributor

Choose a reason for hiding this comment

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

thanks!

<Fact, Trait(Traits.Feature, Traits.Features.Formatting)>
<WorkItem(529899, "DevDiv_Projects/Roslyn")>
Public Async Function IndentContinuedLineOfSingleLineLambdaToFunctionKeyword() As Task
Public Async Function IndentContinuedLineOfSingleLineLambdaToFunctionKeyword___() As Task
Copy link
Contributor

Choose a reason for hiding this comment

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

why did you add ___ to all the tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So I could identify all the tests that are effected by my changes, as I said it was temporary. I will put the old tests back (which was always my intent) and put my changes next to them with ___.

Copy link
Contributor Author

@paul1956 paul1956 Aug 19, 2019

Choose a reason for hiding this comment

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

I have restored all the old test, there are 3 possibilities, New ___ tests passes and old test fails this is expected, the new test is what I think the code should look like. Both tests fail, here the old test is expected to fail but my changes did not produce desired result as shown in new test. Old test fails and there is no new test, my changes broke the old code.

…e results should be. When an old test fails and new test passes this is the correct new behaviour. If the old test fails and there is no new test I broke the old test and need guidance, if both fail the desited result is the new test. VisualBasicTriviaFormatter only fixed case error no logic changes.
@paul1956
Copy link
Contributor Author

The main thing I am trying to change is what happens when a _ with optional Comment is on a line by itself and what happens on the code line following after that line(s). Today lines after, align left with 1 space. This is similer to how in VB aligns Directives Vs. C#. All of my attempts to date have broken the code followed by _ ' Comment on a single line case or caused the newly indented lines to drift right by two space when a comment is present.

ElseIf trivia1.Kind = SyntaxKind.CommentTrivia Then
' _ ' Comment aligns with the ' instead of the _ causing each line to move right
' 2 space
Return LineColumnRule.ForceSpacesOrUseDefaultIndentation(spaces:=-1)
Copy link
Contributor

Choose a reason for hiding this comment

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

so, in terms of a comment, this isn't really helpful. What i'd like is both an example of waht the original VB code looks like that this case is trying to handle, what we want the final code to look like, and why this particular method/arguent is the right thing to do that. i.e. why do we use ForceSpacesOrUseDefaultIndentation? why do we pass spaces:=-1 to it?

I honestly don't know the answers, and reviewing the PR isn't informative enough. As such, the code needs effective comments to make it clear.

@CyrusNajmabadi
Copy link
Contributor

Tagging @heejaechang . @heejaechang can you help @paul1956 here?

@paul1956
Copy link
Contributor Author

paul1956 commented Jan 4, 2020

Ping @sharwell, I started looking at this again and if I can't get some help I should close. It seems that since I started working on this new code fixes and tests have been added that depend on the current behavior of _ and they break with my PR and it is unclear to me if I need to fix their tests (becuase my new formatting is better) or my code (because the current formatting is better/desired) and as has been said the behavior of my code is sometimes better but sometimes odd or undesirable.

@sharwell sharwell added the Need Design Review The end user experience design needs to be reviewed and approved. label Jan 10, 2020
… tests that break with changes or don't do the desired thing with 3 _, if there is a newer test I added use 4 _. All the _ renaming is temporary to make it easy to identify affected tests.
@sharwell
Copy link
Contributor

I added several tests for the current state of line continuation support in #44267. I'm not sure we need to implement handling beyond this, but I at least wanted to capture the test cases. 👍

@sharwell sharwell closed this May 14, 2020
@sharwell sharwell added Resolution-Expired The request is closed due to inactivity under our contribution review policy. and removed Need Design Review The end user experience design needs to be reviewed and approved. labels May 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-IDE Community The pull request was submitted by a contributor who is not a Microsoft employee. Resolution-Expired The request is closed due to inactivity under our contribution review policy.

Projects

Status: Complete

Development

Successfully merging this pull request may close these issues.

4 participants