[performance] IJPL-148944 Test access to PSI from icon providers for JSON and YAML

GitOrigin-RevId: 627766e1bdc5e53ae9df368298ccaf7753422752
This commit is contained in:
Yuriy Artamonov
2024-04-27 22:43:53 +00:00
committed by intellij-monorepo-bot
parent 94da61a580
commit 66bdcd58fe
2 changed files with 71 additions and 0 deletions
@@ -0,0 +1,37 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.json
import com.intellij.openapi.util.registry.Registry
import com.intellij.testFramework.fixtures.BasePlatformTestCase
import com.intellij.util.AstLoadingFilter
import com.intellij.util.PsiIconUtil
import com.intellij.util.ThrowableRunnable
import java.util.function.Supplier
class JsonIconsAstLoadingTest : BasePlatformTestCase() {
override fun setUp() {
super.setUp()
Registry.get("ast.loading.filter").setValue(true, testRootDisposable);
}
/**
* If this test fails for your [com.intellij.ide.IconProvider] you MUST avoid loading PSI by either:
* - indexing and accessing index instead from [com.intellij.ide.IconProvider];
* - cached computation on AST, e.g., using [com.intellij.util.gist.GistAstMarker].
*/
fun testNoAstLoadedFromIconProviders() {
val file = myFixture.addFileToProject("package.json", """
{
"name": "my-awesome-package",
"version": "1.0.0",
"author": "Your Name <email@example.com>"
}
""".trimIndent())
AstLoadingFilter.disallowTreeLoading(ThrowableRunnable {
PsiIconUtil.getIconFromProviders(file, 0)
}, Supplier { "IconProvider must not access PSI of files directly! Use either indexes or GistManager to cache computation" })
}
}
@@ -0,0 +1,34 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package org.jetbrains.yaml
import com.intellij.openapi.util.registry.Registry
import com.intellij.testFramework.fixtures.BasePlatformTestCase
import com.intellij.util.AstLoadingFilter
import com.intellij.util.PsiIconUtil
import com.intellij.util.ThrowableRunnable
import java.util.function.Supplier
class YamlIconsAstLoadingTest : BasePlatformTestCase() {
override fun setUp() {
super.setUp()
Registry.get("ast.loading.filter").setValue(true, testRootDisposable);
}
/**
* If this test fails for your [com.intellij.ide.IconProvider] you MUST avoid loading PSI by either:
* - indexing and accessing index instead from [com.intellij.ide.IconProvider];
* - cached computation on AST, e.g., using [com.intellij.util.gist.GistAstMarker].
*/
fun testNoAstLoadedFromIconProviders() {
val file = myFixture.addFileToProject("deployment.yaml", """
apiVersion: apps/v1
kind: Pod
""".trimIndent())
AstLoadingFilter.disallowTreeLoading(ThrowableRunnable {
PsiIconUtil.getIconFromProviders(file, 0)
}, Supplier { "IconProvider must not access PSI of files directly! Use either indexes or GistManager to cache computation" })
}
}