rhaiscript / lsp

Language server for Rhai.
Apache License 2.0
43 stars 4 forks source link

Comments formatting #100

Open schungx opened 1 year ago

schungx commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

And comments within a statement are gone:

let /* comment */ x = 42;

is turned into

let x = 42;
schungx commented 1 year ago

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.

schungx commented 1 year ago

Fixed, but a minor artifact:

image

After formatting:

image

Notice that an extra space is added after let.

schungx commented 1 year ago

Also, comments following an if statement is swallowed:

if foo {
    bar();
}

// I am an comment

gets formatted to:

if foo {
    bar();
}
schungx commented 1 year ago
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 commented 1 year ago

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
  ,
};