Simplify handling of 'enter' in formatting.#33983
Conversation
|
Tagging @dotnet/roslyn-ide @dpoeschl |
|
Tagging @jasonmalinowski as well. |
|
@jasonmalinowski @dotnet/roslyn-infrastructure @jaredpar Do you know what is causing: ? |
|
|
||
| private static bool TokenShouldNotFormatOnReturn(SyntaxToken token) | ||
| { | ||
| return !token.IsKind(SyntaxKind.CloseParenToken) || !token.Parent.IsKind(SyntaxKind.UsingStatement); |
There was a problem hiding this comment.
this truly was an entire IEditorFormattingService that was created solely for hitting enter after the ) in using (a). Very very strange!
src/EditorFeatures/CSharp/Formatting/CSharpEditorFormattingService.cs
Outdated
Show resolved
Hide resolved
|
@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. |
|
@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 testsSample code: class TestClass
{
void TestMethod(IDisposable obj)
{
using (obj)
using (obj)
using (obj)
using (obj)
{
}
}
}Test cases:
Format document testInput: 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)
{
}
}
} |
Sure. I will add those today. |
…vice.cs Co-Authored-By: CyrusNajmabadi <cyrus.najmabadi@gmail.com>
|
@sharwell tests added that validate behavior for both typing and for format-doc |
|
@CyrusNajmabadi LGTM but I'm going to wait until Monday to ensure people have a chance to review the behavior change. |
|
@sharwell could you get the relevant eyes on this? |
|
@CyrusNajmabadi it was on schedule for last Monday but we ran out of time so it's moved to 18 March. |
|
closing |
|
Design review conclusion: overall, this seems like a reasonable change. I will file follow-up issues for two specific things:
|
|
@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. 😄 |
|
Feel free to take it on. Thanks! |
|
@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: |
|
@CyrusNajmabadi I just merged a fix for that and will restart this build |
|
Oh, that's appreciated. Thanks! |
|
@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? |
|
@sharwell This has all passed. can you merge in? thanks! |
|
thanks! |
We had a bunch of logic to handle processing "enter" after writing
using (...). The purpose of this was to ensure that if you started withAnd you pressed enter, you'd get:
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:
We don't align these when you press enter. Instead, we align when you hit
:. So this just makesusingoperate just like our other alignment-on-typing rules.