consulo / consulo-csharp

Languages: C#
Apache License 2.0
50 stars 6 forks source link

#warning preprocessor directive is not understood #518

Closed NIA closed 6 years ago

NIA commented 6 years ago

When I use a #warning directive in a C# file it is highlighted as error, with a tooltip saying "Expected directive"

image

VISTALL commented 6 years ago

Hello, looks like i missed that directive. I will implement at current week.

Thanks

NIA commented 6 years ago

Hello, nice to hear, thanks!

By the way, noticed another strange thing: even though this preprocessor block is inactive (its condition resolves to false), the inside code is not colored gray, as I configured it in color scheme settigns: image Compare this with the screenshot at the top of the issue.

I just set up the consulo plugin and checked that preprocessor defines are obtained from Unity editor correctly: image

VISTALL commented 6 years ago

How disabled code is highlighted in IDE? For comparisons

NIA commented 6 years ago

It is highlighted just as normal code, no disabled coloring is applied: image

And now I see that problem is not only with highlighting: the IDE also does not ignore code in disabled block as it should: if I declare class with the same name in both sections, it is highlighted as error: image But it not an error actually: depending on whether FOO_BAR is defined, exactly one version of class FooBar exists

VISTALL commented 6 years ago

As i saw in your example - preprocessor not disable your code (must be no error or other highlight in that code)

Looks like preprocessor broken. Can you attach simple example ?

NIA commented 6 years ago

The complete example from screenshot:

https://gist.github.com/NIA/02f9cfd685153a0923204f9545a20c07 (Download)

VISTALL commented 6 years ago

Thanks!

VISTALL commented 6 years ago

fixed #warning. Issue extracted

VISTALL commented 6 years ago

problem with preprocessor fixed in nightly

NIA commented 6 years ago

@VISTALL thanks! I confirm that it works for a preprocessor block with simple code.

But now little UI problem: in the preprocessor block that opened this discussion (with #warning inside) the highlighting of #warning has higher priority over preprocessor disabling: image

But! This warining actuallly is reported by compiler only when preprocessor block is active. But here we see that block is disabled, so compiler does not report warning, and so should the IDE. Logically that is the normal use a #warning directive - inside a preprocessor block that should normally be disabled, just like MSDN shows this: image

Anyway, thanks for both fixes, it is already much better now.

VISTALL commented 6 years ago

It's normal reaction of compiler

About yellow code. It's default highlight for warning symbols. Unused symbols highlighted another since for better user experience.

Warning directive is warning - no sence highlight it as Unused symbol (or obsolete)

Thanks

NIA commented 6 years ago

@VISTALL seems like you did not understand? Yes, warning should be highlighted by yellow just like error should be hihglighted by red – in normal, active code. But in DISABLED preprocessor block any code should not be actually parsed nor highlighted at all, just because this code is actually thrown away and does not affect the program. Compare with visual studio 2015:

image

But in Consulo: image

Note that for errors Consulo does its job great: no error with private interface is highlighted in DISABLED preprocessor block, just as expected, and as VS does. Same should be for warning: yellow everywhere EXCEPT disabled preprocessor block. Am I right?

Code sample

#define TRUE_CONDITION
// active block
#if TRUE_CONDITION
// warning highlighted
#warning Do not forget to globally define one of {PREY_SERVER, PREY_CLIENT or PREY_CLIENT_UNITY} preprocessor constants in build settings! Otherwise some things might suddenly become broken now or in future
// error highlighted
private interface A { }
#endif

// disabled block
#if !TRUE_CONDITION
// warning NOT highlighted
#warning Do not forget to globally define one of {PREY_SERVER, PREY_CLIENT or PREY_CLIENT_UNITY} preprocessor constants in build settings! Otherwise some things might suddenly become broken now or in future
// error NOT highlighted
private interface A { }
#endif
VISTALL commented 6 years ago

Oh. It's works inside disable block, that mistake. O-O

VISTALL commented 6 years ago

extracted https://github.com/consulo/consulo-csharp/issues/521