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
 Technical Support
 C++ Structured Bindings Autocomplete
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

marovira
Junior Member

12 Posts

Posted - Feb 15 2021 :  02:06:40 AM  Show Profile  Reply with Quote
I'm using Visual Studio 2019 Community 16.8.5 with Visual Assist version 10.9.2399.0. Currently, whenever I use structured bindings in C++, the autocomplete from Visual Assist is not able to complete the elements of the binding as I type. For example, consider the following:

struct Params
{
    int var_a{0};
    int var_b{1};
};

void print_params(Params const& params)
{
    auto& [var_a, var_b] = params;
    int foo = var_a; // autocomplete cannot fill in var_a.
    std::cout << var_b; // same here, it cannot fill in var_b.
}


I encounter this issue quite frequently in the code and can make development more difficult as I cannot autocomplete variable names. Hovering over the variables does work and will produce the correct types. The issue only appears while typing. Does Visual Assist support autocomplete with structured bindings? If not, is this a planned feature?

Interestingly enough, if I disable Visual Assist, Intellisense is able to autocomplete the elements of the binding. If Visual Assist doesn't support them yet, is there a way of getting the results from Intellisense to show in the suggestion lists?

feline
Whole Tomato Software

United Kingdom
19020 Posts

Posted - Feb 15 2021 :  09:56:33 AM  Show Profile  Reply with Quote
Unfortunately VA does not currently understand C++ 17 structured bindings. This is something we are hoping to fix fairly soon, but I don't currently have an accurate estimate for when this will be done:

case=113210

Assuming you have set:

VA Options -> Enhanced Listboxes -> Source of C/C++ content: Default Intellisense

then the "full" listboxes will suggest the symbol names. However, if you have VA suggestions enabled then you will mainly be seeing VA suggestion listboxes, that won't suggest these symbols. You can go from a suggestion listbox to a full listbox by pressing CTRL-SPACE, or you can disable the VA suggestion listboxes via:

VA Options -> Suggestions -> Suggestion and Completion lists -> Enable in C++

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

marovira
Junior Member

12 Posts

Posted - Feb 15 2021 :  1:06:09 PM  Show Profile  Reply with Quote
Thanks for the quick reply! Hopefully this gets fixed soon.
Go to Top of Page

LACRGUIL
New Member

3 Posts

Posted - Feb 15 2022 :  5:35:44 PM  Show Profile  Reply with Quote
Thanks. It did not bother me at first, but we have more and more structured bindings in our code, so I hope it gets fixed soon too!
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
19020 Posts

Posted - Feb 16 2022 :  05:39:10 AM  Show Profile  Reply with Quote
Thank you for letting us know you are also looking for this. Knowing how much interest there is in something helps us when working out priorities.

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

barto
Junior Member

Germany
19 Posts

Posted - Feb 22 2022 :  05:14:25 AM  Show Profile  Reply with Quote
yeah, this is really annoying



Go to Top of Page

feline
Whole Tomato Software

United Kingdom
19020 Posts

Posted - Feb 22 2022 :  07:45:55 AM  Show Profile  Reply with Quote
Definitely not helping, and thank you for letting us know you are also seeing this problem. Am I correct in assuming you have disabled IDE intellisense?

VA only underlines code if it detects that IDE intellisense has been disabled, otherwise the underlining is coming from the IDE, not from VA. The easy way to double check is to set VA's underlining colour:

VA Options -> Underlining -> Underline unrecognized symbols using <colour>

to something other than red, so you know who is doing the underlining.

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

barto
Junior Member

Germany
19 Posts

Posted - Feb 22 2022 :  08:12:27 AM  Show Profile  Reply with Quote
So, the squiggles are definitely coming from VA, but I don't think I have IntelliSense disabled in VS. Any ideas?



Go to Top of Page

barto
Junior Member

Germany
19 Posts

Posted - Feb 22 2022 :  08:24:32 AM  Show Profile  Reply with Quote
It seems setting "Disable Error Reporting" to "False" got rid of the squiggles, but the autocomplete still doesn't work for the variables declared in the structured bindings.
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
19020 Posts

Posted - Feb 22 2022 :  11:47:13 AM  Show Profile  Reply with Quote
VA doesn't currently understand structured bindings, which we are aware of. But so long as you have IDE intellisense running, and have set:

VA Options -> Enhanced Listboxes -> Source of C/C++ content: Default Intellisense

then you should be getting IDE listboxes for the structured binding components. I have tested this here, and that is how it works for me, using VS2019 and VA 2443.0. I have even set up a test where there is a struct inside the structured binding, so I can access the struct members from the structured binding variable, as you are doing in your screen shot.

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

swinefeaster
Tomato Guru

310 Posts

Posted - Apr 11 2023 :  11:19:03 AM  Show Profile  Reply with Quote
What's New was touting:

NEW Added support for C++17's structured binding declarations.
NEW C++: Add parser support for C++ 17's structured binding from a constructor.

so i got excited and renewed my maintenance. sadly, this is still not working. the indenting is still wrong and no suggestions pop up.
VA_X64.dll file version 10.9.2476.0 built 2023.01.19

(i'd attach an image, but can't figure out how)
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
19020 Posts

Posted - Apr 11 2023 :  1:06:15 PM  Show Profile  Reply with Quote
Using C++17 and VS 2022 I have the following simple test function:

void structBindingTests()
{
	auto tuple = std::make_tuple(1, 'a', 2.3); // #StdTuple

	// unpack the tuple into individual variables declared at the call site
	// VA understands the components, Find References and Alt-G work on them
	auto [tupleOne, tupleTwo, tupleThree] = tuple; // #StructuredBinding
	std::cout << "tuple 1=" << tupleOne << " tuple 2=" << tupleTwo << " tuple 3=" << tupleThree << '\n';
}

can you please try this simple test function on your system and see if you get the same results or different results?

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

feline
Whole Tomato Software

United Kingdom
19020 Posts

Posted - Apr 11 2023 :  1:07:39 PM  Show Profile  Reply with Quote
For attaching an image, if you are using the "full" reply window, on the toolbar of Format buttons there is one between the HR button and the link button. This button allows you to upload an image to your post.

Alternatively you can just email me at:

[email protected]

including this thread ID or URL in the description, so we can match it up, and attach the screen shot to the email.

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

swinefeaster
Tomato Guru

310 Posts

Posted - Apr 17 2023 :  4:59:01 PM  Show Profile  Reply with Quote
maybe it's a different issue, but this is what i meant:


using your code snippet, Find References doesn't work on the symbols so vax doesn't recognize that either.





Go to Top of Page

feline
Whole Tomato Software

United Kingdom
19020 Posts

Posted - Apr 18 2023 :  08:16:58 AM  Show Profile  Reply with Quote
For the first screen shot, the blog I found describing this called it designated initializers, which is different to structured binding.

What are you looking for here? The dot is not indented correctly, but currently I cannot find any IDE settings to control the formatting here, but it might be possible with a clang-format file. Generally VA doesn't get to involved in code indenting, since there are so many settings and views on this.

The listbox is showing, and it has a faint tomato icon in your screen shot.

We are considering adding a command to create a default designated initializer list for a struct, if that is what you are interested in, since the members have to be listed in the order they are declared in the struct, which the listbox doesn't help you with.

case=146419


For the structured binding, can you please try adding my simple test code to the top of a cpp file, or even a new, empty cpp file? I am trying to work out if this is caused by something further up the file, or if you really are getting different results in your solution / on your system.

I am also puzzled by the colouring in your screen shot. "tupleOne" is a different colour to "tupleTwo" and "tupleThree", which is odd. It is almost as if some of the symbol names are known from elsewhere in your solution.

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

swinefeaster
Tomato Guru

310 Posts

Posted - Apr 18 2023 :  1:51:13 PM  Show Profile  Reply with Quote

ok i couldn't repro the tupleOne etc bug anymore. perhaps it was only on my other computer, which i don't have with me today. i will try again tonight.


as for the indentation, why is putting the . at the beginning correct? is this some new c++ insanity? i would expect the following (and when i cut and re-paste, it don't get reformatted, which suggests that the ide doesn't care?)


Go to Top of Page

feline
Whole Tomato Software

United Kingdom
19020 Posts

Posted - Apr 19 2023 :  06:21:51 AM  Show Profile  Reply with Quote
If you can reproduce the problem with tupleOne I would be most interested in your results. It is quite possible you are running into a VA bug here, finding the bug will be the "fun" bit.

For the formatting, it turns out you are running into a VA bug with virtual tabs. When you start the new line, and the line is indented by the IDE, no characters are actually entered into the line. When you type the dot VA is trying to work out if the dot should be converted into ->, which is causing the line to end up with zero indent:

case=57139

Until now a rather obscure bug that hard ever came up. Suddenly a bug that is somewhat more important.

Set the indent to any random level, select the block of code and tell the IDE to format the code. It has no effect on the indent at all. Currently the IDE doesn't have any setting for this indenting that I can find. I also cannot find a setting in clang-format either, so no obvious work around here yet.

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

LACRGUIL
New Member

3 Posts

Posted - Feb 09 2024 :  1:49:23 PM  Show Profile  Reply with Quote
I am on the latest version of Visual Assist. Visual Studio Pro 2022, c++ 17 compiler and Intellisense database disabled and source is Visual Assist.

If my variable is const, it does not work. If the variable is not const, it does work. Here is my example.


#include <iostream>
#include <map>
#include <string>
#include <vector>

using namespace std;

class Employees_c
   {
   public:
   Employees_c()
      {
      m_Map["0"] = "Siri";
      m_Map["1"] = "Alexa";
      }
   std::map<string, string>& Map()
      {
      return m_Map;
      }

   private:
      std::map<string, string> m_Map;
   };

static void PrintEmployee(string ID, string Name)
{
std::cout << "ID: " << ID << " Name: " << Name << std::endl;
}

int main()
{

                             // Does not work
const std::map<string, string> TestMapA = {};
for (auto& [ID, Name] : TestMapA)
   PrintEmployee(ID, Name);

                             // Works
std::map<string, string> TestMapB;
for (auto& [ID, Name] : TestMapB)
   PrintEmployee(ID, Name);
                             // Works
std::map<string, string> TestMapC;
for (const auto& [ID, Name] : TestMapC)
   PrintEmployee(ID, Name);
                             // Works
std::map<string, string> TestMapD;
for (const auto& [ID, Name] : TestMapD)
   PrintEmployee(ID, Name);


Employees_c Employees;
                             // Does not work
const std::map<string, string>& TestMapE = Employees.Map();
for (const auto& [ID, Name] : TestMapE)
   PrintEmployee(ID, Name);

                             // Works
std::map<string, string>& TestMapF = Employees.Map();
for (const auto& [ID, Name] : TestMapF)
   PrintEmployee(ID, Name);
}


Go to Top of Page

LACRGUIL
New Member

3 Posts

Posted - Feb 09 2024 :  1:54:36 PM  Show Profile  Reply with Quote
Does not work:


Does work:

Edited by - LACRGUIL on Feb 09 2024 1:54:57 PM
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
19020 Posts

Posted - Feb 12 2024 :  09:58:12 AM  Show Profile  Reply with Quote
Many thanks for the sample code and clear description. This shows the problem very clearly, and I have put a bug report in for this:

case=164162

Without the code sample it would have been somewhat harder to understand what problem you were seeing

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