pbeta
pbeta

Reputation: 864

Intellisense not showing syntax errors for cmake project in Visual Studio 2019

I am using a newly installed Visual Studio 2019 for a cmake project. The Intellisense for code completion (i.e. function and constant names) works fine. However, the red underlining syntax errors (i.e. missing semicolon, wrong param type, undefined variable) are missing from the text editor.

I set IntelliSense mode to windows-msvc-x64 in CMakeSettings.json and used Ninja as default cmake generator.

How do I enable real-time syntax error detection in a cmake project? Is this possible at all?

Upvotes: 1

Views: 1659

Answers (1)

LoLance
LoLance

Reputation: 28116

How do I enable real-time syntax error detection in a cmake project? Is this possible at all?

Please check if you get the No Configurations tip for the xx.cpp where the Intellisense is not supported.

enter image description here

For Cmake projects in VS, when you create or add a new xx.cpp file to current project, you need to define the source file in CMakeLists.txt and then regenerate the Cmake cache, After that the Intellisense can support all functions for the xx.cpp file.

enter image description here

Workaround:

So for your issue, assuming you have created a new Test.cpp file in the project, first you should make sure the Test.cpp file is defined in the first CMakeLists.txt file, then switch to the target view to check if the Test.cpp file is under the ProjectName(executable) level. If you can't find Test.cpp in ProjectName(executable) level like this:

enter image description here

Right-click the project=>generate cache and if it succeeds, you'll find the Test.cpp under ProjectName(executable). And only when you can find the xx.cpp under the ProjectName(executable), all code in the xx.cpp can get full support of Intellisense(i.e. missing semicolon).

enter image description here

Upvotes: 1

Related Questions