Repository: intellij-rust/intellij-rust
Issue: Completion `use ..r#fnname` with raw identifier adds inapplicable`()`

<!--
Hello and thank you for the issue!
If you would like to report a bug, we have added some points below that you can fill out.
Feel free to remove all the irrelevant text to request a new feature.
-->

## Environment

* **IntelliJ Rust plugin version:** 0.4.175.4733-221-nightly
* **Rust toolchain version:** 1.64.0-nightly (7b46aa594 2022-07-05) x86_64-apple-darwin
* **IDE name and version:** CLion 2022.1.3 (CL-221.5921.27)
* **Operating system:** macOS 11.4
* **Macro expansion engine:** new
* **Name resolution engine:** new
* **Additional experimental features:** org.rust.cargo.features.settings.gutter, org.rust.cargo.emulate.terminal, org.rust.cargo.evaluate.build.scripts, org.rust.macros.proc

## Problem description

https://user-images.githubusercontent.com/49211026/178102167-2a795e86-13cd-4db5-a6d3-80795e34c1c0.mov



## Steps to reproduce
in kva.rs:
```rust
pub mod mymod {
    pub fn r#break(){
        println!("hello")
    }
}
```
in main.rs:
```rust
mod kva;
use kva::mymod::r#break(); 
```

<!--
Please include as much of your codebase as needed to reproduce the error.
If the relevant files are large, please provide a link to a public repository or a [Gist](https://gist.github.com/).
-->

Changed files:
src/test/kotlin/org/rust/lang/core/completion/RsCompletionTest.kt, src/main/kotlin/org/rust/lang/core/completion/LookupElements.kt

diff --git a/src/main/kotlin/org/rust/lang/core/completion/LookupElements.kt b/src/main/kotlin/org/rust/lang/core/completion/LookupElements.kt
index 43f1fe274..d74e680ab 100644
--- a/src/main/kotlin/org/rust/lang/core/completion/LookupElements.kt
+++ b/src/main/kotlin/org/rust/lang/core/completion/LookupElements.kt
@@ -268,18 +268,19 @@ open class RsDefaultInsertHandler : InsertHandler<LookupElement> {
         item: LookupElement
     ) {
         val document = context.document
-        val startOffset = context.startOffset
-        val curUseItem = context.getElementOfType<RsUseItem>()
+
         if (element is RsNameIdentifierOwner && !RsNamesValidator.isIdentifier(scopeName) && scopeName !in CAN_NOT_BE_ESCAPED) {
-            document.insertString(startOffset, RS_RAW_PREFIX)
+            document.insertString(context.startOffset, RS_RAW_PREFIX)
+            context.commitDocument() // Fixed PSI element escape
         }
 
         if (element is RsGenericDeclaration) {
             addGenericTypeCompletion(element, document, context)
         }
 
-        when (element) {
+        val curUseItem = context.getElementOfType<RsUseItem>()
 
+        when (element) {
             is RsMod -> {
                 when (scopeName) {
                     "self",
diff --git a/src/test/kotlin/org/rust/lang/core/completion/RsCompletionTest.kt b/src/test/kotlin/org/rust/lang/core/completion/RsCompletionTest.kt
index 3f38ab5f7..82780635c 100644
--- a/src/test/kotlin/org/rust/lang/core/completion/RsCompletionTest.kt
+++ b/src/test/kotlin/org/rust/lang/core/completion/RsCompletionTest.kt
@@ -1431,4 +1431,26 @@ class RsCompletionTest : RsCompletionTestBase() {
 
         fn foo<T: /*caret*/>() {}
     """)
+
+    fun `test complete the raw identifier in use`() = checkCompletion("break", """
+        mod foo {
+            pub fn r#break() {}
+        }
+
+        fn main() {
+            use self::foo::b/*caret*/
+
+            r#break();
+        }
+    """, """
+        mod foo {
+            pub fn r#break() {}
+        }
+
+        fn main() {
+            use self::foo::r#break;/*caret*/
+
+            r#break();
+        }
+    """)
 }