Skip to content

Conversation

@CyrusNajmabadi
Copy link
Member

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.

@CyrusNajmabadi CyrusNajmabadi requested a review from a team as a code owner March 9, 2019 04:31
public bool SupportsFormatOnPaste => true;
public bool SupportsFormatSelection => true;
public bool SupportsFormatOnReturn => true;
public bool SupportsFormatOnReturn => false;
Copy link
Member Author

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
Copy link
Member Author

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
}
}
Copy link
Member Author

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>();
Copy link
Member Author

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.

Copy link
Contributor

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?

namespace Microsoft.CodeAnalysis.Editor.Implementation.Formatting.Indentation
{
internal abstract class AbstractSmartTokenFormatterCommandHandler :
IChainedCommandHandler<ReturnKeyCommandArgs>
Copy link
Member Author

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.

Copy link
Contributor

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?

Copy link
Member Author

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)
Copy link
Member Author

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);
}
Copy link
Member Author

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 jinujoseph added the Community The pull request was submitted by a contributor who is not a Microsoft employee. label Jun 12, 2019
@heejaechang
Copy link
Contributor

@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.

@CyrusNajmabadi
Copy link
Member Author

@heejaechang Feel free to merge when you have a chance :)

@CyrusNajmabadi
Copy link
Member Author

Also, @heejaechang, if you merge this, please do not squash. It will make further downstream PRs very difficult. Thanks! :)

@sharwell sharwell dismissed their stale review June 13, 2019 15:00

stale

@CyrusNajmabadi
Copy link
Member Author

@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 jinujoseph changed the base branch from master to release/dev16.3-preview1 June 14, 2019 19:02
@jinujoseph jinujoseph added this to the 16.3.P1 milestone Jun 14, 2019
@CyrusNajmabadi
Copy link
Member Author

@jinujoseph can you let me know when this will get through the review process? Thanks!

@CyrusNajmabadi
Copy link
Member Author

@jinujoseph @jasonmalinowski can you advise on what's going with this PR? Thanks!

@jinujoseph
Copy link
Contributor

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
To be merged for 16.3.Preview2 ( Master should be available for 16.3 by EOW)

@jinujoseph jinujoseph added Blocked and removed Need Design Review The end user experience design needs to be reviewed and approved. labels Jun 24, 2019
@jinujoseph jinujoseph modified the milestones: 16.3.P1, 16.3 Jun 24, 2019
@jinujoseph
Copy link
Contributor

blocked so we don't merge this in 16.3.Preview1 branch

@CyrusNajmabadi
Copy link
Member Author

@jinujoseph why is this blocked?

@CyrusNajmabadi
Copy link
Member Author

@jinujoseph @jasonmalinowski Where can this be merged into?

@jasonmalinowski jasonmalinowski changed the base branch from release/dev16.3-preview1 to master June 27, 2019 19:07
@jasonmalinowski
Copy link
Member

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?

@mavasani
Copy link
Contributor

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.

@CyrusNajmabadi
Copy link
Member Author

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.

@sharwell can you take a look please?

Copy link
Contributor

@mavasani mavasani left a 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.

@mavasani mavasani merged commit c52002b into dotnet:master Jul 2, 2019
@CyrusNajmabadi
Copy link
Member 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.

6 participants