I would like to know if there is any way to use intellisense suggestions with C/C++ defines. For example in this pic, I would like to have suggestion "TEST_1", but there is just nothing. Thanks
Asked
Active
Viewed 282 times
-1
-
1This doesn't address the question, but names that begin with an underscore followed by a capital letter (`_TEST_H_`) and names that contain two consecutive underscores are reserved for use by the implementation. Don't use them in your code. – Pete Becker Jan 13 '22 at 20:21
-
1Unrelated: [What are the rules about using an underscore in a C++ identifier?](https://stackoverflow.com/questions/228783/what-are-the-rules-about-using-an-underscore-in-a-c-identifier) Breaking these rules rarely bites you, but when it does bite, it really, really hurts. The results are utterly bizarre and nigh-inscrutable. Better to avoid the problem entirely by understanding and following the rules. Yeah. What Pete just said. – user4581301 Jan 13 '22 at 20:22
-
I'm not a user of VS Code, but in IDEs often you need to force a reparse of the file by saving it before new tokens are detected and added to the autocomplete options. Make sure the file's been saved. – user4581301 Jan 13 '22 at 20:25
-
@PeteBecker You mean implementation of what? VS Code or standard libraries? This is not my idea, It is standard in our company and moreover STMs CubeIDE generates headers with defines like __MAIN_H , so I was used to this naming. – Daniel Šebík Jan 13 '22 at 20:36
-
@user4581301 file saved, no changes. It is possible to get suggestion for example in IF statement, but not while new symbol definition. And it is really annoying when you write tons of macros like '#define USED_SPI SPI1' and you get no hint. – Daniel Šebík Jan 13 '22 at 20:41
-
Ahh, ok that underscoring is related to C++, isn't it. I use mainly C and C++ just rarely. So thanks for recommendation. – Daniel Šebík Jan 13 '22 at 20:47
-
You've investigated and eliminated the low-hanging fruit, so that ends my ability to help. The Implementation is Standard Committee speak for compiler and Standard Library. These rules are in place to prevent collisions between what's in a C++ Implementation and other people's code. The Implementation only uses identifiers with the reserved naming for the implementation details hidden behind the public interface, so if you never use the same naming, you won't have unexpected collisions. – user4581301 Jan 13 '22 at 20:47
-
C has similar rules, I'm just far less familiar with them at this point, and other libraries may add additional restrictions. POSIX, if I remember correctly, "owns" the `_t` extension. Don't use it and you're never collide with a POSIX typedef. – user4581301 Jan 13 '22 at 20:48
-
@user4581301 never mind, thanks for your time – Daniel Šebík Jan 13 '22 at 20:49
-
look at setting `editor.suggest.showWords`. `editor.wordBasedSuggestions`, `editor.wordBasedSuggestionsMode` – rioV8 Jan 13 '22 at 20:51
-
@rioV8 thanks for advice, but it has not helped :/ Does it work for you? – Daniel Šebík Jan 13 '22 at 20:59
-
sometimes I get word suggestions and sometimes not, maybe it is related to the language server, but it is an editor setting so should be languageId agnostic, have you tried in HTML and Markdown files, they have large text bodies – rioV8 Jan 13 '22 at 21:04
-
Daniel: I'm not a VS user so I can't play around with the problem. But a Popular Search Engine found me this link, which is possibly relevant: https://developercommunity.visualstudio.com/t/c-predictive-intellisense-please-do-not-filter-out/1416562 – rici Jan 13 '22 at 21:11
-
Thanks, I think I found the answer – Daniel Šebík Jan 13 '22 at 21:42
-
1Your could try clangd-based autocompletion instead of the stock one. – HolyBlackCat Jan 13 '22 at 21:44
-
@HolyBlackCat Thanks for advice, I will try it. – Daniel Šebík Jan 13 '22 at 21:51
1 Answers
0
Ok, I think I got and answer: not supported auto completition when beginning with "#". Bad luck...
I can think of solution in way that instead of:
#define TEST_2 TES....
you start typing it without #:
define TEST_2 TES....
and it autocompletes. Than it woud be nice to have shortcut to put # at the beggining of the line...

Peter Csala
- 17,736
- 16
- 35
- 75

Daniel Šebík
- 45
- 6
-
Tactical note: If C is excluded, the `#define` macros can be replaced with `constexpr` variables. Not only with this problem likely be avoided, there's better type checking and no possibility of unfortunate preprocessor text substitutions with `constexpr`. – user4581301 Jan 13 '22 at 23:13