Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I suppress Intellisense errors for certain files?

Visual Studio 2015 offers the option to show Intellisense errors in the same window that also displays regular build errors. I like it because I don't even need to build in order to see if the syntax of my code is correct.

However, the window also shows one false positive error which seems to be related to an Intellisense bug. Is there any way to suppress intellisense errors for specific code regions or entire files?

like image 745
Adrian Grigore Avatar asked Sep 21 '15 13:09

Adrian Grigore


2 Answers

Old question, I know, but I just had a similar complaint with Visual Studio 2019 / IntelliSense and found a solution.

My particular example is C++ and relates to the use of Variable-Length Arrays. Clang supports/compiles them and I can suppress build warnings by adding a -Wno-vla option (Properties -> C/C++ -> Command Line -> Additional Options).
However, IntelliSense ignores the "-Wno-vla" seeing VLA as an error, not warning. So come the red squiggles in the code and in its Error List: E0028 expression must have a constant value
(this error number 28 is significant below)

The key is to remember that IntelliSense uses a different compiler front-end, so may have a different idea about what's "correct" than your selected build compiler and options. The front-end is licensed from EDG and fortunately, they document some of its operation, including command-line options, pragmas, etc. here: C++ Front End PDF

I couldn't figure out how to direct their command-line options exclusively to their front-end, which appears to pull its options from the project, the same ones the build compiler uses... and it chokes on those options, especially ones expecting a parameter after a space (for instance --diag_suppress 28 never worked).

Yet what I could get to work were the front-end-specific pragmas! So that required a small amount of non-portable code. Specifically, I put the following into one of my top-level ("included by everyone") header files, and it worked great:

#ifdef __INTELLISENSE__
  #pragma diag_suppress 28
#endif

Without the __INTELLISENSE__ clause, you could also do: #pragma clang diagnostic ignored "-Wunknown-pragmas"

like image 149
electromaggot Avatar answered Jan 02 '23 23:01

electromaggot


Did you find an answer? You can do it by writing the following in your code on the line prior to where the error is raised

#pragma warning disable XXXX

where XXXX is the error code without the "CS"

Or you can try these steps to suppress specific warnings for Visual C# or F#

  1. In Solution Explorer, choose the project in which you want to suppress warnings.
  2. On the menu bar, choose View, Property Pages.
  3. Choose the Build page.
  4. In the Suppress warnings box, specify the error codes of the warnings that you want to suppress, separated by semicolons, and then rebuild the solution.

taken from here https://msdn.microsoft.com/en-us/library/jj715718.aspx

Note that warnings are mentioned rather than errors, but for me they are listed as errors if I choose to show Suppressed Errors in the Error List window. You might need to enable this column in the Error List window.

like image 38
James Gardner Avatar answered Jan 03 '23 00:01

James Gardner