atom / language-c

C support in Atom

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Comments on #define are not highlighted

cjastone opened this issue · comments

Prerequisites

Description

Comments on a line that starts with #define are not highlighted

Steps to Reproduce

  1. Create a line of code with #define (e.g. #define MY_VAR 123) and add a comment to the end (either // comment or /* comment */
  2. Observe that comment is not highlighted correctly.

Expected behavior: Comment is dark grey and italicised.

Actual behavior: Comment remains default light grey and non-italicised.

Reproduces how often: Consistently for the above example.

Versions

Atom : 1.32.0
Electron: 2.0.9
Chrome : 61.0.3163.100
Node : 8.9.3
Windows 10 x64 1803

Thanks for the report! Confirmed on macOS 10.12.6 with 1.34.0-nightly5.

I commented in this issue that in 1.32.0 syntax highlighting is broken when Use Tree Sitter Parsers is enabled. What I'm seeing is similar to what's described by OP in that issue, but for C what happens is highlighting gets messed up when #ifdefs are present.

Not sure if this is related to this issue, or is a new issue, so commenting here first. I'm guessing it might be related since, for example, if you do:

#if 0
void someCodeHere(void);
#endif

In 1.31.2 and earlier that code will be grayed-out. But in 1.32.0 it is just black text when Use Tree Sitter Parsers is ticked. When unticked it looks as it should.

@cjastone This issue was fixed via 2302f78, which will ship in Atom 1.32.1, today or tomorrow.

@someburner Yeah, that is a known change due to our new parsing system. It is possible for us to fix, but probably not a super high priority, because it was never a very general behavior. The old parser was just hard-coded to look for #if 0, (as opposed to actually determining if the macro evaluated to false), which would be much more generally useful.

For the time being, if that behavior is very useful to you, you can keep it by unchecking the Use Tree-sitter Parsers checkbox, but we are moving away from maintaining the old parsers, because the new parsers fix a large number of issues. For example, we can finally highlight types and struct fields consistently, which we never could do before.

You can also fold #ifdef blocks now, which you usually couldn't do before because the contents are not traditionally indented.

Okay maybe my issue is different and/or related to the syntax I'm using (fizzy).

With Treesitter ticked, I get the following two issues:

1: built-in types not highlighted correctly (int, bool, etc)

2: Multi-line macros do not highlight

I can make a new issue if needed.

Edit: And actually you can see even more issues, like the % not being red. I do see the struct member definitions change color but to me that is a very minor improvement at the cost of these other things not working anymore.

@someburner Please make a new issue and include the code in text so we can take a look, thanks 🙇

The multi line macro thing is already fixed.

What theme are you using? Can you compare with the built in ‘one light syntax’ theme? The highlighting of types used to only work for built in types, but now should work for all types.

I'm using this one: https://github.com/jglovier/fizzy

But these issues are also present when using standard themes like "Atom Light".

A good example to see the behavior is: https://github.com/nodejs/http-parser/blob/master/http_parser.h

Expected highlighting would be what it looks like in the browser on github. But in Atom it looks like:

image

👍 Yeah, agreed. When I said that issue was "already fixed", I mean that the bug has been fixed, but the fix has not yet been published. We're working on getting Atom 1.32.1 out right now.

Ah, okay thanks. I'll wait for 1.32.1 and see how it goes.

But actually, the issue that's fixed is just the macro body thing. I am still curious about any problems you're seeing with types being highlighted, because as far as I know, that should work on 1.32. Does that problem show up for you on the default theme?

Yeah actually only with fizzy. But when Treesitters is unticked it does highlight. Are there some new directives needed to get that working? I'm a CSS noob :)

Hmm, I'll take a look; our intention was to maintain compatibility with most themes in general use, so sorry about that. Maybe there's some extra classes we can add. Unfortunately, that work won't make it into 1.32.1, but it's on our radar.

Thanks @maxbrunsfeld - have the update and this is back to normal, keep up the great work everyone!

Seems like this is because some of the primitive types are scoped as support.support.type instead of support.storage.type. I opened a PR.