Skip to content
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

[Feature Request] Ability to ignore multiple lines of code #678

Closed
pingzing opened this issue May 31, 2022 · 1 comment · Fixed by #687
Closed

[Feature Request] Ability to ignore multiple lines of code #678

pingzing opened this issue May 31, 2022 · 1 comment · Fixed by #687

Comments

@pingzing
Copy link

pingzing commented May 31, 2022

Currently, // csharpier-ignore works on the next node, but that's not a very good fit if you've got a long block of very terse code.
Take this block of Xamarin Forms animation, for example:

var storyboard = new Animation();
var shakeUpHigh = new Animation(v => { GiftBase.TranslationY = v; GiftTop.TranslationY = v; }, 0, 20, Easing.SpringIn);
var fromHighToLow = new Animation(v => { GiftBase.TranslationY = v; GiftTop.TranslationY = v; }, 20, -20, Easing.SpringIn);
var fromLowToSmallHigh = new Animation(v => { GiftBase.TranslationY = v; GiftTop.TranslationY = v; }, -20, 10, Easing.SpringIn);
var fromSmallHighToSmallLow = new Animation(v => { GiftBase.TranslationY = v; GiftTop.TranslationY = v; }, 10, -10, Easing.SpringIn);
var fromSmallLowToTinyHigh = new Animation(v => { GiftBase.TranslationY = v; GiftTop.TranslationY = v; }, -10, 5, Easing.SpringIn);
var fromTinyHighToTinyLow = new Animation(v => { GiftBase.TranslationY = v; GiftTop.TranslationY = v; }, 5, -5, Easing.SpringIn);
var fromTinyLowToComplete = new Animation(v => { GiftBase.TranslationY = v; GiftTop.TranslationY = v; }, -5, 0, Easing.SpringOut);
storyboard.Add(0.0, 0.1, shakeUpHigh);
storyboard.Add(0.1, 0.2, fromHighToLow);
storyboard.Add(0.2, 0.3, fromLowToSmallHigh);
storyboard.Add(0.3, 0.4, fromSmallHighToSmallLow);
storyboard.Add(0.4, 0.5, fromSmallLowToTinyHigh);
storyboard.Add(0.5, 0.6, fromTinyHighToTinyLow);
storyboard.Add(0.6, 1.0, fromTinyLowToComplete);

storyboard.Commit(GiftBase, "ShakeAnimation", 16, 1000);

CSharpier expands this out a lot and makes it (arguably) more difficult to read. Because the ignore works at the node level, I can just surround my code in a set of braces, then ignore that, like so:

// csharpier-ignore
{
    // ... my problematic code
}

...but that's not ideal. From a practical standpoint, it introduces scoping issues, and from a more philosophical standpoint you're altering structure to accommodate a tool, rather than the other way around.

Something like being able to say // csharpier-disable followed by // csharpier-enable again would be nice. I can see that Prettier also has a block-level ignore, though apparently it's only really meant for file-level ignoring.

(Love this tool, though. Wonderfully fast, and kudos for shipping three extensions and an MSBuild NuGet)

@belav belav added this to the 0.18.0 milestone May 31, 2022
@belav
Copy link
Owner

belav commented May 31, 2022

I think it makes sense to support a ranged style ignore. Prettier has a similar feature request that has been open for years - prettier/prettier#5287 and has a decent amount of interest. I'm wondering if it is difficult to implement and that is the reason it hasn't been added to prettier yet.

It seems like it wouldn't be horribly difficult to implement as long as the start and end of the ignore are at the same level.
I think these levels make the most sense as a starting point.
Members of CompilationUnitSyntax - may be different for new top level statements, may want to include usings, a namespace could be at the top so maybe members of NamespaceDeclarationSyntax too.
Members of BaseTypeDeclarationSyntax - I think that would cover everything that can be at the top level of interfaces, classes, records and structs.
Statements of BlockSyntax - I think that covers statements in methods, statements in ifs/elses/whiles etc.

belav added a commit that referenced this issue Jun 6, 2022
belav added a commit that referenced this issue Jun 13, 2022
* Initial POC for ranged ignore

closes #678

* Gettings ranged ignore working with members of types

* Adding more tests, fixing a minor issue

* formatting file

* Updating documents
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants