EvgeniyPeshkov / syntax-highlighter

Syntax Highlighter extension for Visual Studio Code (VSCode). Based on Tree-sitter.
https://marketplace.visualstudio.com/items?itemName=evgeniypeshkov.syntax-highlighter
MIT License
210 stars 43 forks source link

[Rust] constant variables as type #17

Closed Geobert closed 5 years ago

Geobert commented 5 years ago

I have some consts defined, and they are coloured as type

example: image

from: https://github.com/ghost-in-the-sushi/efficio-server/blob/997e203c53fc7868a84e4066aa8959bd9386c23c/src/db/sessions.rs#L24

INTERNAL_ERROR of error:INTERNAL_ERROR is like a type

INTERNAL_ERROR is defined here: https://github.com/ghost-in-the-sushi/efficio-server/blob/997e203c53fc7868a84e4066aa8959bd9386c23c/src/error.rs#L13

Geobert commented 5 years ago

My bad, my config was wrong

Geobert commented 5 years ago

I was right, fixed the constant colour, and still showing as a type ^^'

EvgeniyPeshkov commented 5 years ago

Hello @Geobert , I'm sorry for such late response, I had very busy week. It appears, that syntax of class constants is similar to enum variants. But in certain cases they still can be distinguished based on outer context. Am I right that constants for example can be used in expressions, as function arguments, etc. While enum variants are used mostly in match expression or construction of variables?

Geobert commented 5 years ago

I'm sorry for such late response, I had very busy week.

Don't be sorry, we all have IRL stuff to deal with ^^

In this case, the constant is not event in a class, but in a module. In Rust, each file is a module so error.rs create the error module. And in this module, we define a constant.

If I try to compare to C++, I think error acts like a namespace in which we define a const.

Am I right that constants for example can be used in expressions, as function arguments, etc. While enum variants are used mostly in match expression or construction of variables?

Enum variants can also be used as function argument:


fn my_fct(arg: Option<MyType>) {
  // ...
}

my_fct(Some(value_of_type_MyType));
my_fct(None);

Some(T) and None being variants of the Option enum

EvgeniyPeshkov commented 5 years ago

I'll try ti investigate this. By the way, had this feature helped you with todo-tags in comments?

Geobert commented 5 years ago

I haven't take the time to test it yet ^^ I'll keep you posted :)

EvgeniyPeshkov commented 5 years ago

I'm sorry, I've closed this issue by accident. I didn't know that GitHub does this automatically when you put something like fixes #17 in commit message (=. Highlighting of consts now looks like this: image While not breaking highlighting of enums: image This fix will be included in the next version.