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

REPL: Fix macro completion inside Rust Console #4971

Merged
merged 1 commit into from Feb 19, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/main/kotlin/org/rust/lang/core/psi/ext/PsiElement.kt
Expand Up @@ -17,6 +17,7 @@ import com.intellij.psi.util.PsiTreeUtil
import com.intellij.psi.util.PsiUtilCore
import com.intellij.util.SmartList
import org.rust.lang.core.psi.RsFile
import org.rust.lang.core.psi.RsReplCodeFragment
import org.rust.lang.core.stubs.RsFileStub
import org.rust.openapiext.findDescendantsWithMacrosOfAnyType

Expand Down Expand Up @@ -207,7 +208,14 @@ inline fun <reified T : PsiElement> PsiElement.descendantsWithMacrosOfType(): Co
* Same as [PsiElement.getContainingFile], but return a "fake" file. See [org.rust.lang.core.macros.RsExpandedElement].
*/
val PsiElement.contextualFile: PsiFile
get() = contextOrSelf() ?: error("Element outside of file: $text")
get() {
val file = contextOrSelf<PsiFile>() ?: error("Element outside of file: $text")
return if (file is RsReplCodeFragment) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw looks like this should be applied to any types of code fragments

file.context.contextualFile
} else {
file
}
}

/**
* Finds first sibling that is neither comment, nor whitespace before given element.
Expand Down