Whole Tomato Software Forums
Whole Tomato Software Forums
Main Site | Profile | Register | Active Topics | Members | Search | FAQ
 All Forums
 Visual Assist
 Technical Support
 Implement virtual methods is double-spacing

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
MrDoomMaster Posted - Mar 13 2018 : 10:19:09 AM
I thought I had brought up this issue before, maybe a year or so ago, but I couldn't find my original post. If I am duplicating this issue please accept my apology in advance.

When I have a derived class that's empty and I right click -> Refactorings -> Implement Virtual Methods..., multiple members inserted in the header file for the class are double-spaced. I'm not sure why, however I do have a custom "Create Implementation" and "Extract Method", which adds a comment block above the functions. I'll provide those below, just in case those are being used when the virtual methods are implemented. Note I have a lot of blank lines in my snippets, so I will prefix each line with a number, like "1:", "2:", to show line numbers where the caret can be placed in the editor.

Create Implementation:


01: 
02: ///////////////////////////////////////////////////////////////////////////////
03: ///
04: ///////////////////////////////////////////////////////////////////////////////
05: $SymbolType$ $SymbolContext$($ParameterList$) $MethodQualifier$
06: {
07: 	$end$$MethodBody$
08: }
09: 
10: 


Extract Method:


01: 
02: ///////////////////////////////////////////////////////////////////////////////
03: ///
04: ///////////////////////////////////////////////////////////////////////////////
05: $end$$SymbolType$ $SymbolContext$($ParameterList$) $MethodQualifier$
06: {
07: 	$MethodBody$
08: }
09: 
10: 


I remember putting the extra spacing either at the top or bottom because when I use "Create Implementation", the functions were not being added in the CPP with at least 1 blank line between. I have a similar spacing issue with "Create Declaration", where there are no blank lines inserted above and/or below, depending on where in the class it's inserted.

I feel like between these 3 utilities, vertical spacing is not handled consistently. Either blank lines are consumed (create declaration, create implementation) or superfluously inserted (in the implement virtual methods case).
10   L A T E S T    R E P L I E S    (Newest First)
feline Posted - Mar 20 2018 : 04:56:01 AM
If it is something you notice then it is something that is important to you! Nothing wrong with that. If I could see a fairly straight forward solution here I would be happy to put in a feature request to see what our developers make of it. What I am rather more wary of is more complex and open ended requests

This sounds simple on first pass, but we have previously had reports / problems with VA not making sure the file ends with a new line / blank line. This can result in errors with some compilers. So I know this is an area with various edge cases we have to watch out for.
MrDoomMaster Posted - Mar 19 2018 : 11:31:34 AM
Sorry if it sounded like I was trivializing the issue. I can understand it gets complex. However I think it's technically solvable. What if VAX tied into the Visual Studio formatting rules for the specified language? Granted this only works on newer versions of VS, but it would certainly make rules clear for you since the formatting rules include new line behavior.

Granted this isn't the biggest issue in the world. And I'm doubtful many others run into these quirky situations. But I think there's value in making this behavior deterministic.

Thanks for your help and effort in investigating this issue.
feline Posted - Mar 19 2018 : 11:11:06 AM
I can see the problem here, but the fact that you are including comment blocks in these snippets helps to show why I am wary. We don't know what you are doing with the snippet, or what you are expecting to happen as a result.

Further complicating this, VA tries to place new implementations / declarations into the "correct" place in the file, based on the functions above and below it. So to do this properly we would need to start reformatting code, adding and removing existing blank lines. Then what happens when you use VA Outline to drag and drop functions in a file?

Where do you draw the line between generating these code blocks and code formatting?

This sounds simple, but has the potential to become quite a bit more complex in practice.
MrDoomMaster Posted - Mar 19 2018 : 09:52:16 AM
I did some playing around, and it looks like removing the blank line at the top and leaving the 2 at the bottom gives me what I want. When I remove one of the two at the bottom as you suggest, it does fix the double spacing but for the very last method declaration in the class, it doesn't leave an empty line. So it ends up looking like this:



   ///////////////////////////////////////////////////////////////////////////////
   ///
   ///////////////////////////////////////////////////////////////////////////////
   virtual std::string GetPaymentBlob() const override;
private:

   std::shared_ptr<MsrLibAdapter> m_msrLib;


However removing the blank line at the *top* results in a blank line above "private:". I really think you guys should do something to make spacing more consistent and explicitly defined. For example, empty lines in your snippets shouldn't do anything (they should be stripped when saved). Supplement options to control spacing for each snippet, such as "One blank line above", and "One blank line below".
feline Posted - Mar 16 2018 : 3:34:12 PM
To fix the blank line behaviour here, can you please edit your Extract Method snippet, and to remove one of the two blank lines at the bottom of this snippet.

For me, this results in a single blank line between the new methods in both header files and cpp files. Can you try this and see if you get the same result?

I asked the other questions since I assumed the spacing issue happened with specific code, rather than all of the time.
MrDoomMaster Posted - Mar 13 2018 : 4:10:54 PM
To keep things simple, let's focus on my last set of screenshots. The scenario there is more in line with your expectations:

1. I have a header file and a CPP file
2. I pasted the entirety of your example set in the header
3. I ran "implement virtual methods" in the header file, on the derived class

After this operation, here is what I observed:

1. Declarations added to the derived class in the header had 2 blank lines between each. In my very last screenshot, look at lines 24 and 25. Both of those lines are blank, but I only want 1 blank line between each method declaration.
2. Definitions added to the CPP file (the first screenshot in my last reply) is correct: There's only 1 blank line between each definition inserted by VAX.

So, overall, I expect consistent number of blank lines between each member in both the header and CPP cases, which should be 1 blank line.

To your other questions (which seem unrelated if I'm understanding you correctly):

> When you have the problem, are the function bodies (implementations) being moved to the cpp file, or are they staying in the header file?

The split between header and CPP is working correctly for me. That is, declarations go in the header and definitions of those functions go in the CPP file. In the post before my last one, I had the same sample code in a CPP file so that's why the definitions showed up inline in the class body. I guess that's what is causing confusion here, which is why I'm recommending we only focus on the screenshots from my very last response before this one.

> When you have the problem, are you using a mixture of private and public methods?

This certainly has the issue as well, but your sample from earlier (which I'm using) only has public methods which keeps the use case simple.
feline Posted - Mar 13 2018 : 3:48:45 PM
Sorry, the one time I don't double check the code compiles before I post it, and I have errors in it.

Am I missing something obvious here, or in this case is all of the spacing correct for you?

The clean install test is mainly to start somewhere well defined. It will produce different results since I don't have your settings, but I first wanted to see if we are getting even spacing at all.

When you have the problem, are the function bodies (implementations) being moved to the cpp file, or are they staying in the header file? If there is no matching cpp file then there is no where to move them to.

When you have the problem, are you using a mixture of private and public methods? This is normal enough, so seems likely. I am looking for a trigger or pattern here.
MrDoomMaster Posted - Mar 13 2018 : 2:57:43 PM
And to answer your other question, the double-spacing seems to only occur in the header file. When VAX adds the definitions of the virtual overrides to the CPP file, they are properly spaced. Please see the additional screenshots below.

In the CPP file:



In the header file:

MrDoomMaster Posted - Mar 13 2018 : 2:53:21 PM
I wasn't able to try your simple case, since that requires a fresh install of VAX and I didn't want to revert my snippet settings. However, I did test your example with my existing snippets (Modified slightly to compile; you had some syntax errors). I have screenshots below.

  1. Right-click to implement virtual methods...

  2. Select all members in the Implement Methods popup dialog...

  3. The resulting code is double-spaced...




feline Posted - Mar 13 2018 : 2:39:26 PM
I don't remember this coming up before, for what that's worth.

Are you seeing the odd spacing in the header file, the cpp file, or both? Starting simple, I have VS2017 with a clean install of VA 2258, so all default VA snippets. Into a header file I have placed the following code:

class simpleBaseClass
{
public:
	virtual void memberOne(int nParamOne);
	virtual int memberTwo(int nParamOne, int nParamTwo);
	virtual std::string memberThree(int nParamOne);
	virtual void memberFour(std::string strName;);
	virtual int memberFive(int nParamOne, int nParamTwo);
	virtual int memberSix(int nParamOne, int nParamTwo);
	virtual int memberSeven();
};

class simpleChildClass : public simpleBaseClass
{
};

when I then trigger Implement Virtual Methods on the child class I have even spacing in both files.

Can you please try the same simple test, and see what results you get?

I have now added your two snippets to my system, and I am still getting even spacing, and the empty comment blocks in both the header file and the cpp file.

If you are implementing methods into an empty class I would expect even spacing, simply because there is nothing present to work around. If new methods are being added to a class with existing methods then it is much easier to see how uneven spacing can happen. So the empty class is a good place to start, its a well defined test.

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