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

Comments formatting #100

Open
schungx opened this issue Sep 4, 2022 · 7 comments
Open

Comments formatting #100

schungx opened this issue Sep 4, 2022 · 7 comments
Labels
A-fmt Area: Formatter E-Unknown enhancement T-comments Comments in formatting and rhai source

Comments

@schungx
Copy link
Collaborator

schungx commented Sep 4, 2022

Format this:

let file = external::load_file(); foo::bar::hello(); let a = foo::bar::hello;

// We can access nested modules defined inline as well.
nested::inner::need::to::go_deeper::YEAH;

yields this:

let file = external::load_file();

// We can access nested modules defined inline as well.
foo::bar::hello();

// We can access nested modules defined inline as well.
let a = foo::bar::hello;

// We can access nested modules defined inline as well.
nested::inner::need::to::go_deeper::YEAH;

The comment on the following line is duplicated.

@schungx
Copy link
Collaborator Author

schungx commented Sep 4, 2022

Also, some minor annoyances:

some_statement();        // some comment

always gets formatted into either:

some_statement();

// some comment

or

some_statement();// some comment

without at least a space before the //.

Sometimes it formats nicely:

some_statement(); // some comment

so the pattern is not deterministic.

This is specifically on if statements, where the space is missing:

if something {// some comments
    ...
}

@schungx
Copy link
Collaborator Author

schungx commented Sep 4, 2022

And comments within a statement are gone:

let /* comment */ x = 42;

is turned into

let x = 42;

@schungx
Copy link
Collaborator Author

schungx commented Sep 4, 2022

This make formatting a bit troublesome for code with comments that are not line-level (i.e. on their own lines).

In particular, comments at the end of a statement beginning with // which is quite common.

@tamasfe tamasfe added bug Something isn't working E-Unknown A-fmt Area: Formatter T-comments Comments in formatting and rhai source labels Sep 4, 2022
@tamasfe tamasfe closed this as completed in c954855 Sep 4, 2022
@schungx
Copy link
Collaborator Author

schungx commented Sep 5, 2022

Fixed, but a minor artifact:

image

After formatting:

image

Notice that an extra space is added after let.

@schungx schungx reopened this Sep 5, 2022
@schungx schungx changed the title Duplicated comment when breaking lines. Comments formatting Sep 5, 2022
@schungx
Copy link
Collaborator Author

schungx commented Sep 5, 2022

Also, comments following an if statement is swallowed:

if foo {
    bar();
}

// I am an comment

gets formatted to:

if foo {
    bar();
}

@schungx
Copy link
Collaborator Author

schungx commented Sep 5, 2022

a = 42; // I am a very very very very very very very very  loooooooooooooooooooooooong comment

Very long end-of-line comments move to the line below, which is probably not the intended place:

a = 42;
// I am a very very very very very very very very  loooooooooooooooooooooooong comment

In general, end-of-line comments should stay on that same line.

@schungx
Copy link
Collaborator Author

schungx commented Sep 5, 2022

Comments on map properties:

let a = #{
  a: 123,   // comment for a
  b: 234    // comment for b
};

is formatted to:

let a = #{
  a: 123,
  // comment for a


  b:
    234 // comment for b
  ,
};

@tamasfe tamasfe added enhancement and removed bug Something isn't working labels Sep 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-fmt Area: Formatter E-Unknown enhancement T-comments Comments in formatting and rhai source
Projects
None yet
Development

No branches or pull requests

2 participants