Skip to content

Simplify handling of 'enter' in formatting.#33983

Merged
sharwell merged 15 commits intodotnet:masterfrom
CyrusNajmabadi:simplifyEnterHandling
Apr 5, 2019
Merged

Simplify handling of 'enter' in formatting.#33983
sharwell merged 15 commits intodotnet:masterfrom
CyrusNajmabadi:simplifyEnterHandling

Conversation

@CyrusNajmabadi
Copy link
Copy Markdown
Contributor

@CyrusNajmabadi CyrusNajmabadi commented Mar 9, 2019

We had a bunch of logic to handle processing "enter" after writing using (...). The purpose of this was to ensure that if you started with

using (a)
    using (b)$$

And you pressed enter, you'd get:

using (a)
using (b)
    $$

However, this code seems unnecessary and inconsistent. First, if you type the close-paren manually, you automatically get the expected code format. Second, we don't do this sort of fixup on enter for anything else. For example, if you have:

case x:
    case y:$$

We don't align these when you press enter. Instead, we align when you hit :. So this just makes using operate just like our other alignment-on-typing rules.

@CyrusNajmabadi CyrusNajmabadi requested a review from a team as a code owner March 9, 2019 00:52
@CyrusNajmabadi
Copy link
Copy Markdown
Contributor Author

Tagging @dotnet/roslyn-ide @dpoeschl

@CyrusNajmabadi
Copy link
Copy Markdown
Contributor Author

Tagging @jasonmalinowski as well.

@CyrusNajmabadi
Copy link
Copy Markdown
Contributor Author

@jasonmalinowski @dotnet/roslyn-infrastructure @jaredpar Do you know what is causing:

Publishing build artifacts failed with an error: Not found PathtoPublish: F:\vsagent\1\s\artifacts\bin\Microsoft.VisualStudio.LanguageServices.IntegrationTests\Release\net472\xUnitResults

?


private static bool TokenShouldNotFormatOnReturn(SyntaxToken token)
{
return !token.IsKind(SyntaxKind.CloseParenToken) || !token.Parent.IsKind(SyntaxKind.UsingStatement);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

this truly was an entire IEditorFormattingService that was created solely for hitting enter after the ) in using (a). Very very strange!

@sharwell
Copy link
Copy Markdown
Contributor

sharwell commented Mar 9, 2019

@CyrusNajmabadi Once the test(s) are updated as described above, I have no objection to this change. However, I need to review the original linked bug http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/912965 to see if it contains any information that would block this behavior change.

@sharwell sharwell added Area-IDE Community The pull request was submitted by a contributor who is not a Microsoft employee. labels Mar 9, 2019
@sharwell sharwell self-assigned this Mar 9, 2019
@sharwell
Copy link
Copy Markdown
Contributor

sharwell commented Mar 9, 2019

@CyrusNajmabadi I reviewed the bug and it seems like the following tests need to be present. Some of them may already exist in the code but we should search for them to ensure coverage. If you believe an existing test covers one or more scenarios from below, please point out the test and mention the scenarios covered.

Typing tests

Sample code:

class TestClass
{
  void TestMethod(IDisposable obj)
  {
    using (obj)
    using (obj)
    using (obj)
    using (obj)
    {
    }
  }
}

Test cases:

  1. Typing the code top-to-bottom without manual indentation changes should result in vertical alignment of all using keywords
  2. Typing the code top-to-bottom without manual indentation changes should result in vertical alignment of { and } with the using keywords
  3. Pressing Enter after any ) of a using statement in the sample should place the caret one indent more than the using keyword
  4. Typing { after any variant of step 3 should vertically align the brace with the using keyword

Format document test

Input:

class TestClass
{
  void TestMethod(IDisposable obj)
  {
    using (obj)
      using (obj)
      using (obj)
      using (obj)
    {
    }
  }
}

Expected result:

class TestClass
{
  void TestMethod(IDisposable obj)
  {
    using (obj)
    using (obj)
    using (obj)
    using (obj)
    {
    }
  }
}

@CyrusNajmabadi
Copy link
Copy Markdown
Contributor Author

@CyrusNajmabadi I reviewed the bug and it seems like the following tests need to be present. Some of them may already exist in the code but we should search for them to ensure coverage.

Sure. I will add those today.

@CyrusNajmabadi
Copy link
Copy Markdown
Contributor Author

@sharwell tests added that validate behavior for both typing and for format-doc

@sharwell
Copy link
Copy Markdown
Contributor

sharwell commented Mar 9, 2019

@CyrusNajmabadi LGTM but I'm going to wait until Monday to ensure people have a chance to review the behavior change.

@sharwell sharwell added the Need Design Review The end user experience design needs to be reviewed and approved. label Mar 9, 2019
@CyrusNajmabadi
Copy link
Copy Markdown
Contributor Author

@sharwell could you get the relevant eyes on this?

@sharwell
Copy link
Copy Markdown
Contributor

@CyrusNajmabadi it was on schedule for last Monday but we ran out of time so it's moved to 18 March.

@CyrusNajmabadi
Copy link
Copy Markdown
Contributor Author

closing

@sharwell
Copy link
Copy Markdown
Contributor

Design review conclusion: overall, this seems like a reasonable change. I will file follow-up issues for two specific things:

  1. Caused by this change: users who have automatic brace completion enabled and use Tab to complete the closing parentheses could end up in a state where the indentation of the using (true) line is incorrect. We don't believe this will cause problems, but if it does we could end up needing to address it in the future.
  2. Not caused by this change, but observed when looking through the test sequences: we may have a test gap covering the formatting at the end of a line, when multiple spaces appear between ) and {, and the user presses enter somewhere in the middle of this. We should verify tests are present for these cases both for using statements and other types of statements that allow braces.

@sharwell sharwell reopened this Mar 21, 2019
@sharwell sharwell removed the Need Design Review The end user experience design needs to be reviewed and approved. label Mar 21, 2019
@sharwell sharwell added this to the 16.1.P1 milestone Mar 21, 2019
@sharwell
Copy link
Copy Markdown
Contributor

@CyrusNajmabadi there were some compilation errors here. I'm happy to correct them if you want, or you can update it yourself. Please let me know your preference. 😄

@CyrusNajmabadi
Copy link
Copy Markdown
Contributor Author

Feel free to take it on. Thanks!

@jinujoseph jinujoseph closed this Apr 1, 2019
@jinujoseph jinujoseph reopened this Apr 1, 2019
@CyrusNajmabadi
Copy link
Copy Markdown
Contributor Author

@sharwell @jasonmalinowski not sure what's up with the determinism build. I'm not sure how i could have broken that. Error seems to be:

F:\workspace\_work\1\s\.tools\msbuild\16.0.0-alpha\tools\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2114,5): error MSB3277: Found conflicts between different versions of "Newtonsoft.Json" that could not be resolved.  These reference conflicts are listed in the build log when log verbosity is set to detailed. [F:\workspace\_work\1\s\src\Tools\ExternalAccess\Xamarin.Remote\Microsoft.CodeAnalysis.ExternalAccess.Xamarin.Remote.csproj]
    0 Warning(s)
    1 Error(s)

@sharwell
Copy link
Copy Markdown
Contributor

sharwell commented Apr 3, 2019

@CyrusNajmabadi I just merged a fix for that and will restart this build

@CyrusNajmabadi
Copy link
Copy Markdown
Contributor Author

Oh, that's appreciated. Thanks!

@CyrusNajmabadi
Copy link
Copy Markdown
Contributor Author

@sharwell Integration tests are failing, but i don't think it's me. The test is:

            SetUpEditor(@"
class Class1
{
    void Main(string[] args)
    {
        $$
    }
}");

            VisualStudio.Editor.SetUseSuggestionMode(false);

            VisualStudio.Editor.SendKeys(
                'M',
                Shift(VirtualKey.Enter));

            VisualStudio.Editor.Verify.TextContains(@"
class Class1
{
    void Main(string[] args)
    {
        Main$$
    }
}",
assertCaretPosition: true);

However, when i manually test this without my change, shift-enter takes the caret positoin and puts it here:

class Class1
{
    void Main(string[] args)
    {
        Main
            $$
    }
}

Do you know what's up here?

@CyrusNajmabadi
Copy link
Copy Markdown
Contributor Author

Oh, i see this failing for other people as well. For example: #34718

So it looks like this PR is ok. Feel free to merge when convenient @sharwell . Thanks!

         -- Cyrus

@CyrusNajmabadi
Copy link
Copy Markdown
Contributor Author

@sharwell This has all passed. can you merge in? thanks!

@sharwell sharwell merged commit ead4884 into dotnet:master Apr 5, 2019
@CyrusNajmabadi
Copy link
Copy Markdown
Contributor Author

thanks!

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.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants