Sublime Forum

Highlighting user-defined data types (C) in Sublime

#1

This is sample code from a project I’m working on, but one thing about Sublime that I have noticed with C is that declaring or initializing variables using user-defined data types don’t get highlighted the same way as normal variables.

For example: the atoms pointer, where my cursor is at in the image attached, doesn’t have its data type ‘atoms’ highlighted, which bugs me a little. If you see how my atom struct is defined, you can see atom is highlighted with the same colour as the other standard data types (char, double, unsigned short, and unsigned char).

I’m curious if there is a way to modify my colour scheme (I’m using Ayu-Mirage currently) to account for variables that are of a user-defined type? I know this seems a bit OCDish, but I promise I’ll be very grateful if someone helps! Basically, I want the atom and bond data types in the molecule structure to have the same highlighted colour as atom_max, atom_no, bond_max, and bond_ptrs.

VS Code’s default dark theme actually differentiates between variables that are of primitive or standard data types and variables that are user-defined. I am wondering if there is something similar in Sublime Text 4? I don’t mind tinkering with my colour scheme, if necessary.

0 Likes

#2

ST’s syntax engine is not capable of fully parsing C/C++ syntax (or it’s too complicated so it’s not done? whatever, it’s not done) so it’s not possible to fulfill your request.

VS Code’s default dark theme actually differentiates between variables that are of primitive or standard data types and variables that are user-defined. I am wondering if there is something similar in Sublime Text 4?

Great. Since you mention VSCode, it’s called semantic highlighting from LSP spec. You can install LSP and LSP-clangd plugins in ST. Then you are using the same backend with VSCode’s (including other advanced feature like symbol renaming, accurate goto definition/reference etc). Restarting ST may be required btw.

1 Like

#3

Thank you Jack. This reply clears up a lot and I’ll look into the VS Code clang plugin as recommended. I’ll give it a go and update this thread if it works.

I noticed that with Java, Sublime has no problem highlighting the classes that the instantiated objects belong to. However with C (possibly because it’s a rather old and unpopular programming language), I can see why the development team didn’t get around to this small feature.

Still, C++ is C with classes and I can see myself moving on from C soon. With C++, I am going to use its OOP features instead of using structs (which are quite limited compared to OOP classes). I doubt I would come across a minor issue like this in the future, but hopefully the dev team sees this thread and adds this small feature to their engine.

0 Likes

#4

The difference between Java and C is that Java has a grammar that doesn’t include a preprocessor so it’s possible to determine what is a variable declaration and what is not. In C this is impossible due to the preprocessor.

2 Likes

#5

Hi Raoul,

I actually did not know this fact about Java. That is really cool and explains a lot.

I am wondering: C++ code can be written in a few different ways (OOP and procedural, for example), which raises the question of will C++ code behave similarly to Java code in-terms of syntax highlighting in Sublime (assuming I write OOP code in C++ and avoid using structs or anything that requires pre-processing)?

Many thanks,
Ali

0 Likes