Repository: intellij-rust/intellij-rust
Issue: REF | CLion | "Put Parameters on one line" deletes or modifies parameter name or deletes whole parameter

## Environment

* **IntelliJ Rust plugin version:** 0.3.138.3572-203
* **Rust toolchain version:** 1.51.0-nightly (0b644e419 2020-12-26) x86_64-pc-windows-msvc
* **IDE name and version:** CLion 2020.3 (CL-203.5981.166)
* **Operating system:** Windows 10 10.0
* **Macro expansion engine:** new
* **Name resolution engine:** old

## Problem description
When having a method or function with multiple parameters on multiple lines, where the first two parameters are one the first line with no space between them, using the context action "Put parameters on one line" leads to weird behaviour, like: 
- removing the third parameter completely
- removing only the name of the third parameter
- striping the third parameter name, so there's only the last letter left

## Steps to reproduce
(I know the code bellow does not compile, it's just a minimal example)
#### Removing parameter name
When having this function (note: there's no space between the first and second parameter. Also `parameter3` must be left-aligned with the opening parenthesis):
```rust
pub fn new(parameter1: u64,parameter2: u64,
           parameter3: u64) -> Self {
    unimplemented!()
}
```
and placing the cursor anywhere within the parameter list, and executing the context action "Put Parameters on one line" leads to:
```rust
pub fn new(parameter1: u64,parameter2: u64,  u64) -> Self {
    unimplemented!()
}
```

#### Removing whole parameter
Placing `new` in a `mod t`:
```rust
mod t {
    pub fn new(parameter1: u64,parameter2: u64,
               parameter3: u64) -> Self {
        unimplemented!()
    }
}
```
and doing the same thing again results in:
```rust
mod t {
    pub fn new(parameter1: u64,parameter2: u64, ) -> Self {
        unimplemented!()
    }
}
```

#### Stripping the parameter name
Now changing the names of the parameters:
```rust
mod t {
    pub fn new(max_size: u64,monthly_min_views: u64,
               weekly_min_views: u64,
               daily_min_views: u64) -> Self {
        unimplemented!()
    }
}
```
and doing the same thing again results in:
```rust
mod t {
    pub fn new(max_size: u64,monthly_min_views: u64, s: u64, daily_min_views: u64) -> Self {
        unimplemented!()
    }
}
```

### Note
It seems not to be deterministic. Different parameter names and placing the same code in different files will sometimes lead to different results. So you might have slightly different outcomes.

Changed files:
src/test/kotlin/org/rust/ide/intentions/JoinParameterListIntentionTest.kt, src/main/kotlin/org/rust/ide/intentions/ListIntention.kt

diff --git a/src/main/kotlin/org/rust/ide/intentions/ListIntention.kt b/src/main/kotlin/org/rust/ide/intentions/ListIntention.kt
index 15792d550..7d427bb91 100644
--- a/src/main/kotlin/org/rust/ide/intentions/ListIntention.kt
+++ b/src/main/kotlin/org/rust/ide/intentions/ListIntention.kt
@@ -53,7 +53,6 @@ abstract class ListIntentionBase<TList : RsElement, TElement : RsElement>(
         element.getNextNonCommentSibling()?.takeIf { it.elementType == COMMA }
 
     private fun Sequence<PsiElement>.lineBreak(): PsiWhiteSpace? =
-        dropWhile { it !is PsiWhiteSpace && it !is PsiComment }
-            .takeWhile { it is PsiWhiteSpace || it is PsiComment }
+        takeWhile { !elementClass.isInstance(it) }
             .firstOrNull { it is PsiWhiteSpace && it.textContains('\\n') } as? PsiWhiteSpace
 }
diff --git a/src/test/kotlin/org/rust/ide/intentions/JoinParameterListIntentionTest.kt b/src/test/kotlin/org/rust/ide/intentions/JoinParameterListIntentionTest.kt
index 80dc1f801..5a6b126c8 100644
--- a/src/test/kotlin/org/rust/ide/intentions/JoinParameterListIntentionTest.kt
+++ b/src/test/kotlin/org/rust/ide/intentions/JoinParameterListIntentionTest.kt
@@ -62,4 +62,12 @@ class JoinParameterListIntentionTest : RsIntentionTestBase(JoinParameterListInte
             p2: i32
         ) {}
     """)
+
+    fun `test no space between parameters`() = doAvailableTest("""
+        fn foo(/*caret*/parameter1: u64,parameter2: u64,
+               parameter3: u64
+        ) {}
+    """, """
+        fn foo(parameter1: u64,parameter2: u64, parameter3: u64) {}
+    """)
 }