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] Type as namespace #4

Closed Geobert closed 5 years ago

Geobert commented 5 years ago

Hi! I'll open one ticket per issue to keep the discussions targeted :) Hope you don't mind.

In the previous ticket, I didn't pay attention to one thing I've noticed this morning while testing the new version: image

WebEvent is properly coloured as a type on its declaration, but not when using the variants in the match statement.

Same thing here: image

HexView is a struct (a type) and is coloured as a namespace.

Geobert commented 5 years ago
use hex_view::HexView;
#[derive(Debug, Serialize, Deserialize)]
pub struct Token {
    pub session_token: String,
}

impl Deref for Token {
    type Target = String;

    fn deref(&self) -> &String {
        &self.session_token
    }
}

impl From<[u8; 32]> for Token {
    fn from(s: [u8; 32]) -> Self {
        Token {
            session_token: format!("{:x}", HexView::from(&s)),
        }
    }
}
EvgeniyPeshkov commented 5 years ago

And here we go (=. I'll try to explain my point. The main purpose of syntax highlighting, in my personal opinion, is to make code more readable. Let's look at comparison below:

image image

Which one is more readable? For me it's the first one. Because it emphasises on more meaningful part. Yes, enum is a type, no doubt. But it's also an aggregation for other types, so we can think of it as some kind of namespace, or scope if you like. Maybe it's my fault, and I should call it scope instead of namespace. But I realized it only now (=. For example in C++ we can define class inside class. And in this case OuterClass is in fact namespace for InnerClass, while it's still a type. And constructions like OuterClass::InnerClass is not very different from std::string. The same applies to SomeClass::staticFunction(), here SomeClass is nothing but namespace for staticFunction(). What I'm trying to say, is that maybe editors, you are used to, highlight every occurrence of type as "type". But here, making our own highlighter, we can do something better, provide more readable coloring. Maybe we are not like others, but it doesn't mean we're worse and should copy them.

Geobert commented 5 years ago

I totally understand your point here. Now I'm mitigated between semantically correctness and readability. I don't know what the Rust community will prefer ^^'

I think you're right on this one, I'll close the issue then :)

EvgeniyPeshkov commented 5 years ago

I believe several days with such highlighting and everyone will love it, maybe most people won't even notice ))). Thank you very much again. @Geobert , you should be a hero for Rust developers. If they will adopt this extension of course ))).

EvgeniyPeshkov commented 5 years ago

Meanwhile, I think, I'll refactor namespace to scope. Maybe it will help to avoid some misunderstandings in future. scope is more general and can be applied to namespace, module, package, outer class, etc.