Skip to content

Commit

Permalink
Merge #8872
Browse files Browse the repository at this point in the history
8872: QDOC: avoid NPE during documentation generation r=mchernyavsky a=Undin

Fixes the bug introduced in #6492

Fixes #8732

changelog: Don't throw `NullPointerException` during quick documentation generation in some cases


Co-authored-by: Arseniy Pendryak <a.pendryak@yandex.ru>
  • Loading branch information
bors[bot] and Undin committed May 25, 2022
2 parents d8ed978 + 10d81a3 commit 5d08dd0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/main/kotlin/org/rust/lang/core/psi/ext/PsiElement.kt
Expand Up @@ -77,6 +77,9 @@ val PsiElement.childrenWithLeaves: Sequence<PsiElement>
* Extracts node's element type
*/
val PsiElement.elementType: IElementType
get() = elementTypeOrNull!!

val PsiElement.elementTypeOrNull: IElementType?
// XXX: be careful not to switch to AST
get() = if (this is RsFile) RsFileStub.Type else PsiUtilCore.getElementType(this)

Expand Down Expand Up @@ -304,7 +307,7 @@ inline val <T : StubElement<*>> StubBasedPsiElement<T>.greenStub: T?
get() = (this as? StubBasedPsiElementBase<T>)?.greenStub

fun PsiElement.isKeywordLike(): Boolean {
return when (elementType) {
return when (elementTypeOrNull) {
in RS_KEYWORDS,
RsElementTypes.BOOL_LITERAL -> true
RsElementTypes.IDENTIFIER -> {
Expand Down
8 changes: 8 additions & 0 deletions src/test/kotlin/org/rust/ide/docs/RsQuickDocumentationTest.kt
Expand Up @@ -1336,6 +1336,14 @@ class RsQuickDocumentationTest : RsDocumentationProviderTest() {
<div class='content'><p>Some docs</p></div>
""")

// https://github.com/intellij-rust/intellij-rust/issues/8732
fun `test do not throw exceptions on fake psi elements`() = doTest("""
fn main() {
let s = "http://localhost:8080";
//^
}
""", null)

private fun doTest(@Language("Rust") code: String, @Language("Html") expected: String?)
= doTest(code, expected, block = RsDocumentationProvider::generateDoc)

Expand Down

0 comments on commit 5d08dd0

Please sign in to comment.