microsoft / vscode-cpptools

Official repository for the Microsoft C/C++ extension for VS Code.
Other
5.54k stars 1.56k forks source link

IntelliSense: suggest definitions in not-yet-included file #4776

Open birgersp opened 4 years ago

birgersp commented 4 years ago

Currently (please correct me if I'm wrong), it seems VSCode will not suggest definitions that are not yet included in the source file. This is despite the fact that the definitions reside in header files in includePath. Example below.

For instance, say I wanted to create an instance of std::map in my source file. I have not yet added #include <map> at the top of my source file.

In some other C++ IDEs, a code suggestion will appear for std::map when I start typing it (see NetBeans example below). If I choose to accept the suggestion, #include <map> is automatically added at the top of my source file.

image

In VSCode, however, I'm not getting this suggestion unless I add #include <map> first.

image

Suggestion: Enable IntelliSense to suggest definitions that are (not yet) included in the source file. Automatically add #include (relevant header) when accepting such a suggestion.

sean-mcmanus commented 4 years ago

Yeah, TypeScript in VS Code has the auto-include adding capability. Our behavior matches C++ in VS which doesn't do this.

YalandHong commented 4 years ago

The feature will be helpful for me. But I think auto-completing for the contents that are not included may not be appropriate, since there would be a huge amount of partly or fully matched suggestions.

In my opinion, this feature should be added in "Quick Fix". I want it to show a list of choices for me and add the #include statement automatically (just like TypeScript in VS Code). Then I can save my time and don't need to RTFM.

(For now it just suggest me change the includePath) quick_fix

sean-mcmanus commented 4 years ago

@YalandHong If we were to implement this, it would probably only apply to a limited number of commonly used standard C++ types. But yeah, a Quick Fix for adding #includes would be good too.

birgersp commented 4 years ago

Yeah, TypeScript in VS Code has the auto-include adding capability.

I'd wager that this is a fairly common feature in IDEs.

The feature will be helpful for me. But I think auto-completing for the contents that are not included may not be appropriate, since there would be a huge amount of partly or fully matched suggestions.

Many suggestions is fine, as long as they're sorted by "relevance". It's the same as with any auto-completion feature.

duckladydinh commented 1 year ago

Any news yet after 3 years?