Whole Tomato Software Forums
Whole Tomato Software Forums
Main Site | Profile | Register | Active Topics | Members | Search | FAQ
 All Forums
 Visual Assist
 Feature Requests
 Uncomment should handle leading spaces

You must be registered to post a reply.
Click here to register.

Screensize:
UserName:
Password:
Format: BoldItalicizeUnderlineStrikethrough Align leftCenterAlign right Insert horizontal ruleUpload and insert imageInsert hyperlinkInsert email addressInsert codeInsert quoted textInsert listInsert Emoji
   
Message:

Forum code is on.
Html is off.

 
Check to subscribe to this topic.
   

T O P I C    R E V I E W
geno Posted - Oct 29 2019 : 4:39:13 PM
Hi,

Could you please add an option to allow Line Comment toggling to either react to leading spaces or not?

I'm using this feature: VAssistX.SelectionToggleLineComment

Example 1

I have a line of code:
int x = 1;


Now I move my cursor to this code line and use the toggle comment feature which results in:
// int x = 1;


All fine. But ... In a real world scenario where the line is indented a few levels to the right and using some auto-formatter we have a problem.

Example 2

I have this code:

int calculate(int a, int b) {
  int result = 0;
  result = 42;
  return result;
}


I want to temporarily comment out the assignment statement so now I have:

int calculate(int a, int b) {
  int result = 0;
//  result = 42;
  return result;
}


Now I hit save which will trigger my auto formatter. Unfortunately, it will now indent the comment to match the indentation level of the surrounding code lines. I cannot control this. There's no option in the auto formatter (using the CodeMaid plugin).

So the end result after the formatter has done its (unwanted) work is this:



int calculate(int a, int b) {
  int result = 0;
  //  result = 42;
  return result;
}


Notice the two spaces in front of the commented line.

Here's the actual problem with the VAX comment toggling. VAX seems to expect single line comments to start with two forward slashes or else it is not a comment. The result is another two forward slashes instead of removing them. This is inconvenient to work with this way.

I also tested the comment / uncomment feature of Visual Studio itself and it does detect the comment properly. However, Visual Studio does not have a toggle shortcut for commenting/uncommenting and thus cannot bind it to just one shortcut for toggling comments. *Sigh*
7   L A T E S T    R E P L I E S    (Newest First)
tony.riviere Posted - Nov 04 2019 : 04:34:57 AM
You can setup your own shortcut on the Visual Studio (2019) toggle block comment: Tools > Options > Keyboard, search for Edit.ToggleBlockComment and then you can assign '/' so that you can use it the same way as the VAX shortcut works.

Edit: I don't know your setup but you can use VS2019 with VS2017 projects. You don't need to migrate them.
feline Posted - Nov 02 2019 : 08:08:23 AM
For now, have you considered using a find and replace regular expression on the selected lines to uncomment the blocks? On it's own this is less helpful, but if this works well for you, you may be able to use one of the IDE macro extensions to automate this.

A bit of a messy work around, but worth mentioning in case it helps.
geno Posted - Oct 30 2019 : 4:17:55 PM
Amazing. It's like getting Unix newline support in notepad.exe after decades of torture. :-D
Seriously, thanks for the info. Unfortunately I will be stuck on VS 17 for a while.
accord Posted - Oct 30 2019 : 2:52:19 PM
oh wow, Visual Studio 2019 16.3 is able to toggle comments via Ctrl + K, Ctrl + /



I've just read this:
https://devblogs.microsoft.com/visualstudio/dot-net-core-support-in-visual-studio-2019-version-16-3/
feline Posted - Oct 30 2019 : 07:56:53 AM
This makes more sense. This is something we are considering doing:

case=87353

but unfortunately I don't currently have an estimate for when we will have a go at this.
geno Posted - Oct 29 2019 : 10:57:36 PM
That could also work but maybe that's even another option ;-)

That's because when I'm writing code I actually like those commented out lines to stand out a bit from the rest.

So personally speaking, I'd prefer the '//'s to appear at the start of the line (just as it is already) but in the case that the commented out line or lines are having leading whitespace the toggle feature should still understand this and execute the "uncomment" action instead of "comment" action on top of the commented out line(s).

What I currently get due to the interplay of "VAX toggle comment" and "CodeMaid Code Formatter" is something like this:

Step 1: Starting with this snippet


int calculate(int a, int b) {
  int result = 0;
  result = 42;
  return result;
}


Step 2: Toggle line with VAX


int calculate(int a, int b) {
  int result = 0;
//  result = 42;
  return result;
}


Step 3: Saving the file (CodeMaid Code Formatter kicks in by doing this)


int calculate(int a, int b) {
  int result = 0;
  // result = 42;
  return result;
}


Step 4: Changed my mind, going to uncomment the same line again using VAX toggle line -> problem


int calculate(int a, int b) {
  int result = 0;
// // result = 42;
  return result;
}


And this is kind of annoying. I hope this step-by-step procedure makes it more clear what I mean. :-)
accord Posted - Oct 29 2019 : 7:23:20 PM
Ideally, you would like a setting which would make VA toggle comment work the same way as Visual Studio's variant of comment/uncomment? Meaning that it would put leading spaces before the '//'s, essentially starting where the indentation is, and then able to remove it.

© 2023 Whole Tomato Software, LLC Go To Top Of Page
Snitz Forums 2000