metaborg / spoofax-pie

Spoofax implementation using PIE pipelines
Apache License 2.0
12 stars 9 forks source link

Empty lines are considered "uncommented" for toggle-comment sakes #114

Open molenzwiebel opened 2 years ago

molenzwiebel commented 2 years ago

Summary

Consider the following snippet:

rules

//  foo :: string -> string
//  foo: a -> a

  bar :: string -> string
  bar: _ -> "x"

If you now select the commented out section, but also include the empty line above (selection range indicated by [ and ]):

rules
[  
//  foo :: string -> string
//  foo: a -> a]

  bar :: string -> string
  bar: _ -> "x"

And hit CTRL+/, you end up receiving a second set of comments:

rules
//  
////  foo :: string -> string
////  foo: a -> a

  bar :: string -> string
  bar: _ -> "x"

This is in my opinion surprising behavior, since I would expect it to ignore the empty line and instead uncomment the selection. Other editors (VS Code, IntelliJ) act as expected.

Should be trivially solvable by ignoring empty/space/tab-only lines when determining whether a section is already commented.

Context

Gohla commented 2 years ago

This can be solved by modifying the ToggleCommentHandler class in spoofax.eclipse. This class was copied from the Eclipse JDT plugin, and can probably be improved to support this.