Whole Tomato Software Forums
Whole Tomato Software Forums
Main Site | Profile | Register | Active Topics | Members | Search | FAQ
User name:
Password:
Save Password
Forgot your password?

 All Forums
 Visual Assist
 Feature Requests
 Add Include additional feature
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Adequat
Tomato Guru

182 Posts

Posted - Jul 30 2018 :  07:42:01 AM  Show Profile  Reply with Quote
The "Add Include" works great, when the cursor is on the type identifier.
What I wish, is a way to obtain the same result, but when having the cursor on a type's instance, and not the type itself.

For example, in the following code:

m_someVariable = x;

"Add include" would add the #include statement for the header file that declares the type of m_someVariable.

My current workaround, is to jump to the definition of m_someVariable, to copy the Type, to come back to the place where m_someVariable is used, to paste the type anywhere, then to call the "Add Include", then to erase the pasted text.

As you see, not a quick workaround.

This feature could be called "Add Include (indirect)" for example.

feline
Whole Tomato Software

United Kingdom
18749 Posts

Posted - Jul 30 2018 :  08:15:35 AM  Show Profile  Reply with Quote
I see the problem. From the naming, "m_" I am assuming this is a class member variable. Is there a reason you don't just add the required include to the class declaration header file, so it is always included when you are using the class?

This seems an "obvious" solution, so I am just wondering why this won't help.

With the caret in "m_someVariable" you will see the type displayed in the Definition field, normally at the top of the editor window, the field next to where the alt-m list appears.

zen is the art of being at one with the two'ness
Go to Top of Page

Adequat
Tomato Guru

182 Posts

Posted - Jul 31 2018 :  04:28:31 AM  Show Profile  Reply with Quote
These cases happen when doing heavy refactoring like moving code to new files. In that case, the moved code might come to a place where the header file is missing.
But don't stick to the "m_", this could be a function call chain, eg. foo().bar() with the return value of foo() requiring a header inclusion. This return value of foo() could be a forward declaration requiring a header inclusion.
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
18749 Posts

Posted - Jul 31 2018 :  06:49:09 AM  Show Profile  Reply with Quote
This makes sense. I actually think the idea is very good, but since we get lots of feature requests my first instinct is to see if I can work around the request using existing behaviour, since this offers an instant fix

I have just put together a simple test case of this, to include in the feature request, and for me, using VS2015 and VA 2283.1, this is already working. My test case looks like this:

// header not yet included
class felineForwardDeclareTest
{
	int m_nHeight;

public:
	int GetHeight() { return m_nHeight; }
	void SetHeight(int nNewHeight) { m_nHeight = nNewHeight; }
};

// test_general.h
class testForwardDeclaredType
{
public:
|	felineForwardDeclareTest m_memberData;

	const felineForwardDeclareTest& getDataRef() const;
};

// test_general.cpp
void callingAddIncludeOnForwardDeclare()
{
	testForwardDeclaredType fooBar;
	// add include for correct header offered here on "localData"
	auto localData = fooBar.getDataRef();
	// add include for correct header offered here on "localData"
	localData = fooBar.m_memberData;
}


but I assume this isn't working for you? Which version of VA are you currently using?

zen is the art of being at one with the two'ness
Go to Top of Page

Adequat
Tomato Guru

182 Posts

Posted - Aug 01 2018 :  04:38:09 AM  Show Profile  Reply with Quote
I am using the latest VA.

But I think your sample is not proper:

you should replace the line:

felineForwardDeclareTest m_memberData;

with

felineForwardDeclareTest* m_memberData;

That is, with a pointer (or a reference &).

In that case you compile ok until the the compiler complains about the missing definition of felineForwardDeclareTest.

And in that case, VA does not currently provide a solution to include the missing header (by clicking on m_memberData, or localData, or getDataRef())... and this is my original request :)



Go to Top of Page

feline
Whole Tomato Software

United Kingdom
18749 Posts

Posted - Aug 01 2018 :  08:52:03 AM  Show Profile  Reply with Quote
Sigh. So, I decided to be thorough, and make up a test case of all the obvious combinations of class types and return types, to test which ones work and which ones don't work... except in this situation all of them work.

So I have gone back and simplified everything right down. I have kept the type declaration the same, and now I am using the following code:

// test_general.h
class felineForwardDeclareTest;

class testForwardDeclaredType
{
public:
	felineForwardDeclareTest *m_memberPointer;
	const felineForwardDeclareTest *getDataPtr() const { return m_memberPointer; }
};

// test_general.cpp
void callingAddIncludeOnForwardDeclare()
{
	testForwardDeclaredType localInstance;
	// Test - Add Include is offered on this local variable
	auto localPtrInstance = localInstance.getDataPtr();
	// Test - Add Include is offered on this local variable
	auto localMemberInstance = localInstance.m_memberPointer;
}

which complies quite happily in VS2015. I have even rebuilt the VA symbol database, more than once, to make sure its not a hold over from one of my earlier tests.

This code makes sense, and the compiler is happy, I am happy, and VA is happy to offer Add Include. What am I missing here? I like your request, I just want a sensible code sample to show the need, so we can test the change works.

zen is the art of being at one with the two'ness
Go to Top of Page

Adequat
Tomato Guru

182 Posts

Posted - Aug 02 2018 :  1:27:31 PM  Show Profile  Reply with Quote
Thanks. Maybe I don't put the edit cursor at the right place, to call "Add Include". I will check it more closely next time this happens.
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
18749 Posts

Posted - Aug 02 2018 :  1:48:21 PM  Show Profile  Reply with Quote
I did find some code where Add Include would not be offered, but to be fair to VA, the code was a mess, and there was no way it was going to compile as it was. So mid refactoring is always going to be a possibly difficult time, but if VA understands the code and the type of the variable, it looks like we should be able to call Add Include.

So it will be interesting to see what VA shows in the context and definition fields for the variable next time you would like to call Add Include and it is not offered.

It could well be you have run into an edge case bug.

zen is the art of being at one with the two'ness
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
© 2023 Whole Tomato Software, LLC Go To Top Of Page
Snitz Forums 2000