-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Merge all indentation related code into one service. #33989
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
Conversation
| public bool SupportsFormatOnPaste => true; | ||
| public bool SupportsFormatSelection => true; | ||
| public bool SupportsFormatOnReturn => true; | ||
| public bool SupportsFormatOnReturn => false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All the changes in this file come from #33983 that PR should be merged first.
| [Order(After = PredefinedCommandHandlerNames.Rename)] | ||
| [Order(Before = PredefinedCommandHandlerNames.Completion)] | ||
| internal class SmartTokenFormatterCommandHandler : | ||
| AbstractSmartTokenFormatterCommandHandler |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This type is completely unnecessary. I don't know why we had it. We already exposed the ISmartIndentProvider VS type to expose this functionality. So all this code was removed and integrated into IIndentationService.
| } | ||
| #endif | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All dead code.
| var newDocument = Document.WithSyntaxRoot(newRoot); | ||
|
|
||
| var indentationService = (IBlankLineIndentationService)newDocument.GetLanguageService<ISynchronousIndentationService>(); | ||
| var indentationService = newDocument.GetLanguageService<Indentation.IIndentationService>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is from the #33978 PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not just use IIndentationService?
src/EditorFeatures/CSharpTest/Formatting/Indentation/SmartIndenterTests.cs
Show resolved
Hide resolved
| namespace Microsoft.CodeAnalysis.Editor.Implementation.Formatting.Indentation | ||
| { | ||
| internal abstract class AbstractSmartTokenFormatterCommandHandler : | ||
| IChainedCommandHandler<ReturnKeyCommandArgs> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
completely uneeded. This just replicates the functionality that VS and the ISmartIndentProvider already take care of for us.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are you sure? I remember you and sam arguing that formatting and smart identation is so important and related to musle memory so unless we can prove it doesn't change behavior, we should try to change it. is that now changed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't prove a negative. But i can provide a lot of evidence this is safe. Specifically, the other class only handled hitting enter after typing using (...). We've already discussed and designed a new approach for handling that that hte IDE is fine with. Also, we have many tests covering indentation behavior, and we added more tests during the work to remov ethe need for AbstractSmartTokenFormatterCommandHandler. These help validate that the behavior we have is the one we want.
| { | ||
| internal static class WhitespaceExtensions | ||
| { | ||
| public static bool IsFirstTokenOnLine(this SyntaxToken token, ITextSnapshot snapshot) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
never used anywhere in the product.
| protected override ISmartTokenFormatter CreateSmartTokenFormatter(OptionSet optionSet, IEnumerable<AbstractFormattingRule> formattingRules, SyntaxNode root) | ||
| { | ||
| return new CSharpSmartTokenFormatter(optionSet, formattingRules, (CompilationUnitSyntax)root); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thse moved here from SmartTokenFormatCommandHandler.
|
@jinujoseph so, these seem to make subtle behavior changes on indentation. those subtle changes, I hard to imagine most of the people will ever notice but pretty sure there will be a person who cares in the world. with many formatting, indentation, auto brace completion options, I can't know all possible behavior changes it could have. but code clean up looks nice and behavior changes seems something I don't care much. I guess the biggest change is before when we don't care, we returned null or nothing to indicate someone else to take care, but now, we always return something which could break some random extension somewhere in the world. but again, seems so corner case... so I am +1 but, you probably need to aware so that if we get a bug from someone saying we broke their test or something, we can respond. |
|
@heejaechang Feel free to merge when you have a chance :) |
|
Also, @heejaechang, if you merge this, please do not squash. It will make further downstream PRs very difficult. Thanks! :) |
|
@heejaechang @jinujoseph woudl love if we could move forward and merge this. There are about 2-3 more followup PRs that depend on this that i'm blocked on. Thanks! |
|
@jinujoseph can you let me know when this will get through the review process? Thanks! |
|
@jinujoseph @jasonmalinowski can you advise on what's going with this PR? Thanks! |
|
Design meeting notes Overall feels like the right design to move towards a separate service. This could potentially break peoples existing tests, which we would suggest them to change there tests. There could be other unknown issues which we will have to address as they arise. This also needs another pair of review. @mavasani to review |
|
blocked so we don't merge this in 16.3.Preview1 branch |
|
@jinujoseph why is this blocked? |
|
@jinujoseph @jasonmalinowski Where can this be merged into? |
|
I think it was marked while we were juggling branches -- this is now fine to merge into master. @mavasani still waiting for a review I believe? |
|
I had a chat with Jinu offline and I think @sharwell might want to review this one given his work in this area. He should be back on Monday to review it. |
mavasani
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM based on my limited knowledge in this space.
|
Thanks! |
Followup to
#33978 and
#33983
This removes the strange and complex split we had between SmartIndent and SmartTokenCommandHandler. For some reason, we had two entirely different integration points into VS to handle where we should indent to when 'enter' is hit. This added a lot of complexity and made it very difficult to understand what was going on.
Furthermore, this split meant that no actual features could ask the simply question: "where should new code on this line be indented to?".
Now, all logic is handled by the IIndentationService. The internal implementation of IIndentationService is still a bit complex in that it has two separate codepaths for 'indentation' versus 'token indentation'. However, at least it's all in one place now instead of being scattered all over the place.