codemaid icon indicating copy to clipboard operation
codemaid copied to clipboard

Question/Enhancement - Format Selection of Single File

Open caseyredisatwork opened this issue 7 years ago • 3 comments

Using VS 2017 Pro. I searched issues and SO and couldn't find an answer. Is there a way to format just the selected text in a file, say a .cs file? I've been asked NOT to format the entire file by another member of our dev team out of the concern that newer developers will have a hard time finding functional vs. whitespace diffs... I'd still like to be able to format the part of the code I'm adding or working on and can't seem to find a way to do this.

caseyredisatwork avatar Apr 17 '18 13:04 caseyredisatwork

Thanks for the suggestion, and no there is not currently a way to highlight a section of code and cleanup only that piece. I have thought about it before, but it would have a number of hurdles including that we utilize Visual Studio's native "Format Document" command as a starting point and that is also whole-document based.

These aren't great workarounds, but a few ideas to consider if you want it bad enough:

  1. You can move your code into a separate file, clean it, then move it back.
  2. You can utilize partial classes in C# to isolate your code into a new file.
  3. You can run the whole document format, and then use a comparison tool to "bring back" all the old lines/whitespace from the other sections of the file.

None of those are really good ideas, but hopefully that helps a little and maybe spurs an idea.

codecadwallader avatar Apr 20 '18 10:04 codecadwallader

Thanks for getting back to me. It's interesting, the reason I found CodeMaid in the first place was because the VS "Format Selection" wasn't/isn't working for me. Thanks also for your suggestions, I'd thought of 1 and ended-up doing a variation on #3 - I format the document, select my code and copy it, then undo the format and paste back my formatted code.

On Fri, Apr 20, 2018 at 6:04 AM, Steve Cadwallader <[email protected]

wrote:

Thanks for the suggestion, and no there is not currently a way to highlight a section of code and cleanup only that piece. I have thought about it before, but it would have a number of hurdles including that we utilize Visual Studio's native "Format Document" command as a starting point and that is also whole-document based.

These aren't great workarounds, but a few ideas to consider if you want it bad enough:

  1. You can move your code into a separate file, clean it, then move it back.
  2. You can utilize partial classes in C# to isolate your code into a new file.
  3. You can run the whole document format, and then use a comparison tool to "bring back" all the old lines/whitespace from the other sections of the file.

None of those are really good ideas, but hopefully that helps a little and maybe spurs an idea.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/codecadwallader/codemaid/issues/542#issuecomment-383049780, or mute the thread https://github.com/notifications/unsubscribe-auth/AELzUorPxNOyiROgTvKJxdnPIM249wtCks5tqbK1gaJpZM4TYQ6I .

caseyredisatwork avatar Apr 20 '18 13:04 caseyredisatwork

Just want to explain you guys why this feature is important. We started using Codemaid in our team of 5 to make code clearer and more readable. But after few weeks we found out we have lots of conflicts between our branches. So we stopped using Codemaid . We can only use Codemaid if there is an option to format only selected lines, the peace of code where programmer is currently working on. It reduces the amount of merge conflicts and at the same time gradually makes code's look better.

So currently the Codemaid is only useful for single programmer projects.

Thanks guys for your great job.

fairking avatar Nov 06 '20 13:11 fairking