Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance Rust syntax #167

Open
logansquirel opened this issue Nov 11, 2020 · 0 comments
Open

Enhance Rust syntax #167

logansquirel opened this issue Nov 11, 2020 · 0 comments

Comments

@logansquirel
Copy link

logansquirel commented Nov 11, 2020

Issue type: improvement

Hi!

I would like to know if you are interested in better Rust syntax highlight.
As suggested by your issue template I want to make sure you are opened to new pull requests for this feature and if my idea fits with the scope of this color scheme.
(This repository has some pull request still waiting for review, is it fine for you that I had a PR on the stack?)

Description

JetBrains IDE (especially IntelliJ/CLion) is one of the mainstream IDE for Rust language development (due to the Rust plugin).
The main idea is to provide a possibly better Rust syntax highlight than the current one.

In the following sections I describe some of the possible improvements. All of them are of course opinion-based and I would like to have a review for some or guidelines for others. Thanks.

Format

For each section, a rust example code is presented and if available a screenshot of suggested change(s).
Left is the actual Nord theme, Right is the suggested change.

Functions

Rust provides four different "function" types:

#[derive(Debug)]
struct Point {
    x: f64,
    y: f64,
}

impl Point {
    fn new(x: f64, y: f64) -> Self {
        Point { x, y }
    }

    fn abscissa(&self) -> f64 {
        self.x
    }

    fn ordinate(&self) -> f64 {
        self.y
    }
}

fn hello_world() -> String {
    "hello world!".to_owned()
}

fn main() {
    println!("{}", hello_world());
    let point = Point::new(1.1, 4.2);
    println!("point = {:?}", point);
    println!("abscissa = {}", point.abscissa());
    println!("ordinate = {}", point.ordinate());
}
  • Associated function: new() ("static functions")
  • Methods: abscissa() or ordinate() (function taking self, &self or &mut self as first parameter)
  • Function: hello_world() (standard function)
  • Function-like macro: println!()

The main idea is to unify all these "functions" to a single Nord color (nord8 #88C0D0).

functions

The actual nord theme use #FFC66D for function/method call and #4EADE5 for macro.

Generics and lifetimes

Rust provides generics and lifetimes (for reference validation):

#[derive(Debug)]
struct Point<'a, T> {
    name: &'a str,
    x: T,
    y: T,
}

impl<'a, T> Point<'a, T>
where
    T: Copy,
{
    fn new(name: &'a str, x: T, y: T) -> Self {
        Point { name, x, y }
    }
}

fn main() {
    let pi = String::from("π");
    let point = Point::new(&pi, 1.1, 4.2);
    println!("point = {:?}", point);
}

The main idea here is to unify generics/lifetime and coherence with generics of other language using nord7 #8fbcbb.

generics

Italic font differentiate lifetime(s) from generic(s).

The actual Nord theme use #20999D for generics and lifetime.

Mutable variables/parameters

In rust all variables/parameters are immutable by default. Variables/parameters can be annotated with mut to make them mutable. The actual Nord theme underline the mutable variables/parameters.

fn function(immutable: &String, mutable: &mut String) {
    mutable.clear();
    mutable.push_str(immutable);
    mutable.push_str(" world!");
}

fn main() {
    let immutable = String::from("hello");
    let mut mutable = String::from("hello");
    println!("immutable = {}", immutable);
    println!("mutable = {}", mutable);
    function(&immutable, &mut mutable);
    println!("immutable = {}", immutable);
    println!("mutable = {}", mutable);
}

The main idea here is to reserve nord15 #b48ead for numbers only and just use nord4 #d8dee9 for underline.

mutable

Enums

In rust Enum-s are similar to algebraic data types and Enum variant(s) are first class citizens.

#[derive(Debug)]
enum Number {
    Signed(i64),
    Unsigned(u64),
    Float(f64),
}

fn main() {
    let number = Number::Float(3.14);
    println!("number = {:?}", number);
    let number = Number::Signed(-1);
    println!("number = {:?}", number);
    let number = Number::Unsigned(42);
    println!("number = {:?}", number);
}

The main idea is to identify Enum variants like any other types.

enums

Italic font differentiate Structure type from Enum variant(s).

Fields

Last point is the field(s) color.

struct Structure {
    field: (),
}

Disclaimer: If this issue leads to a pull request I will not include a change for this

I know that the Nord theme documentation states:

Nord 4
[...]
In the context of syntax highlighting it is used as text color for variables, constants, attributes and fields.

However identifying structure/structure enum variant field can be handy. Which Nord color do you recommend for fields if I want to highlight them? Thanks

Notes

If needed, I can update this issue and add more content. The main goal is to launch a discussion around the Rust syntax. Let me know if you are interested in these (or part of these) changes and I will submit a pull request accordingly.

Relevant issue in other ports

nordtheme/visual-studio-code#167

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant