mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-10-01 13:11:39 +07:00
IJPL-248476 fix and simplify JsonLazyParsing enabling
GitOrigin-RevId: fcb584483499a68dece545f96321c8db52edb74a
This commit is contained in:
committed by
intellij-monorepo-bot
parent
88944e7a3e
commit
0de93e3dbd
@@ -1,6 +1,7 @@
|
||||
// Copyright 2000-2026 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.json.syntax.JsonLazyParsingKt;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -29,6 +30,6 @@ public class JsonNonLazyParsingTest extends JsonParsingTest {
|
||||
|
||||
@Override
|
||||
protected boolean isIgnore() {
|
||||
return JsonElementFactory.getJsonLazyParsingIJ();
|
||||
return JsonLazyParsingKt.getJsonLazyParsing();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,9 @@ package com.intellij.json;
|
||||
|
||||
import com.intellij.json.psi.JsonElementTypeConverterFactory;
|
||||
import com.intellij.json.syntax.JsonLanguageDefinition;
|
||||
import com.intellij.json.syntax.JsonLazyParsingKt;
|
||||
import com.intellij.json.syntax.JsonLazyParsingVetoer;
|
||||
import com.intellij.openapi.extensions.ExtensionPointName;
|
||||
import com.intellij.platform.syntax.psi.CommonElementTypeConverterFactory;
|
||||
import com.intellij.platform.syntax.psi.ElementTypeConverters;
|
||||
import com.intellij.platform.syntax.psi.LanguageSyntaxDefinitions;
|
||||
@@ -24,8 +27,12 @@ public class JsonParsingTest extends ParsingTestCase {
|
||||
addExplicitExtension(ElementTypeConverters.getInstance(), JsonLanguage.INSTANCE, new CommonElementTypeConverterFactory());
|
||||
addExplicitExtension(ElementTypeConverters.getInstance(), JsonLanguage.INSTANCE, new JsonFileTypeConverterFactory());
|
||||
addExplicitExtension(LanguageSyntaxDefinitions.getINSTANCE(), JsonLanguage.INSTANCE, new JsonLanguageDefinition());
|
||||
registerExtensionPoint(LAZY_PARSING_VETOER_EP, JsonLazyParsingVetoer.class);
|
||||
}
|
||||
|
||||
public static final ExtensionPointName<JsonLazyParsingVetoer> LAZY_PARSING_VETOER_EP =
|
||||
new ExtensionPointName<>("com.intellij.json.lazyParsingVetoer");
|
||||
|
||||
public JsonParsingTest() {
|
||||
super("psi", "json", new JsonParserDefinition());
|
||||
}
|
||||
@@ -43,7 +50,7 @@ public class JsonParsingTest extends ParsingTestCase {
|
||||
}
|
||||
|
||||
protected boolean isIgnore() {
|
||||
return !JsonElementFactory.getJsonLazyParsingIJ();
|
||||
return !JsonLazyParsingKt.getJsonLazyParsing();
|
||||
}
|
||||
|
||||
public void testKeywords() {
|
||||
|
||||
+3
-3
@@ -2,8 +2,8 @@
|
||||
package com.intellij.json.intentions
|
||||
|
||||
import com.intellij.json.JsonBundle
|
||||
import com.intellij.json.JsonElementFactory.JsonLazyParsingIJ
|
||||
import com.intellij.json.JsonTestCase
|
||||
import com.intellij.json.syntax.JsonLazyParsing
|
||||
import org.junit.AssumptionViolatedException
|
||||
|
||||
class JsonSortPropertiesIntentionTest : JsonTestCase() {
|
||||
@@ -20,12 +20,12 @@ class JsonSortPropertiesIntentionTest : JsonTestCase() {
|
||||
}
|
||||
|
||||
fun testSortMalformedJson() {
|
||||
if (!JsonLazyParsingIJ) throw AssumptionViolatedException("lazy pasting is off")
|
||||
if (!JsonLazyParsing) throw AssumptionViolatedException("lazy pasting is off")
|
||||
doTest()
|
||||
}
|
||||
|
||||
fun testSortMalformedJson_non_lazy() {
|
||||
if (JsonLazyParsingIJ) throw AssumptionViolatedException("Lazy pasting is on")
|
||||
if (JsonLazyParsing) throw AssumptionViolatedException("Lazy pasting is on")
|
||||
doTest()
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
// Copyright 2000-2026 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.json.json5;
|
||||
|
||||
import com.intellij.json.JsonFileTypeConverterFactory;
|
||||
import com.intellij.json.JsonParserDefinition;
|
||||
import com.intellij.json.JsonParsingTest;
|
||||
import com.intellij.json.psi.JsonElementTypeConverterFactory;
|
||||
import com.intellij.json.syntax.JsonLazyParsingVetoer;
|
||||
import com.intellij.json.syntax.json5.Json5LanguageDefinition;
|
||||
import com.intellij.platform.syntax.psi.CommonElementTypeConverterFactory;
|
||||
import com.intellij.platform.syntax.psi.ElementTypeConverters;
|
||||
@@ -25,6 +27,7 @@ public class Json5ParsingTest extends ParsingTestCase {
|
||||
addExplicitExtension(ElementTypeConverters.getInstance(), Json5Language.INSTANCE, new CommonElementTypeConverterFactory());
|
||||
addExplicitExtension(ElementTypeConverters.getInstance(), Json5Language.INSTANCE, new JsonFileTypeConverterFactory());
|
||||
addExplicitExtension(LanguageSyntaxDefinitions.getINSTANCE(), Json5Language.INSTANCE, new Json5LanguageDefinition());
|
||||
registerExtensionPoint(JsonParsingTest.LAZY_PARSING_VETOER_EP, JsonLazyParsingVetoer.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -8,6 +8,9 @@
|
||||
<extensionPoint qualifiedName="com.intellij.json.jsonLiteralChecker"
|
||||
interface="com.intellij.json.codeinsight.JsonLiteralChecker"
|
||||
dynamic="true"/>
|
||||
<extensionPoint qualifiedName="com.intellij.json.lazyParsingVetoer"
|
||||
interface="com.intellij.json.syntax.JsonLazyParsingVetoer"
|
||||
dynamic="true"/>
|
||||
</extensionPoints>
|
||||
|
||||
<extensions defaultExtensionNs="com.intellij">
|
||||
@@ -25,6 +28,7 @@
|
||||
language="JSON Lines"/>
|
||||
|
||||
<registryKey defaultValue="true" description="Enable lazy parsing of JSON" key="json.lazy.parsing" restartRequired="true"/>
|
||||
<json.lazyParsingVetoer implementation="com.intellij.json.JsonRegistryLazyParsingVetoer"/>
|
||||
|
||||
<lang.parserDefinition language="JSON" implementationClass="com.intellij.json.JsonParserDefinition"/>
|
||||
<lang.parserDefinition language="JSON5" implementationClass="com.intellij.json.json5.Json5ParserDefinition"/>
|
||||
|
||||
@@ -15,7 +15,6 @@ import com.intellij.lang.tree.util.parents
|
||||
import com.intellij.openapi.diagnostic.thisLogger
|
||||
import com.intellij.openapi.progress.ProgressManager
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.util.registry.Registry
|
||||
import com.intellij.platform.syntax.CancellationProvider
|
||||
import com.intellij.platform.syntax.lexer.Lexer
|
||||
import com.intellij.platform.syntax.lexer.TokenList
|
||||
@@ -33,20 +32,11 @@ import com.intellij.psi.tree.IReparseableElementType
|
||||
object JsonElementFactory {
|
||||
@JvmStatic
|
||||
fun getType(name: String): IElementType = when (name) {
|
||||
"OBJECT" -> if (JsonLazyParsingIJ) LAZY_OBJECT else OBJECT
|
||||
"ARRAY" -> if (JsonLazyParsingIJ) LAZY_ARRAY else ARRAY
|
||||
"OBJECT" -> if (JsonLazyParsing) LAZY_OBJECT else OBJECT
|
||||
"ARRAY" -> if (JsonLazyParsing) LAZY_ARRAY else ARRAY
|
||||
else -> throw IllegalArgumentException(name)
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles lazy parsing switch of JSON files in IntelliJ platform.
|
||||
*
|
||||
* @see JsonLazyParsing
|
||||
*/
|
||||
@JvmStatic
|
||||
val JsonLazyParsingIJ: Boolean =
|
||||
JsonLazyParsing || Registry.get("json.lazy.parsing").isBoolean
|
||||
|
||||
private val LAZY_OBJECT: IElementType = lazyElementType(
|
||||
name = "OBJECT",
|
||||
createNode = { JsonLazyObjectImpl(it) },
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
// Copyright 2000-2026 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.json.syntax.JsonLazyParsingVetoer
|
||||
import com.intellij.openapi.util.registry.Registry
|
||||
|
||||
/**
|
||||
* Vetoes lazy parsing of JSON when the `json.lazy.parsing` registry flag is turned off.
|
||||
*/
|
||||
internal class JsonRegistryLazyParsingVetoer : JsonLazyParsingVetoer {
|
||||
override fun isLazyParsingVetoed(): Boolean = !Registry.`is`("json.lazy.parsing", true)
|
||||
}
|
||||
@@ -23,9 +23,6 @@ jvm_library(
|
||||
"src/**/*.kt",
|
||||
"src/**/*.java",
|
||||
"src/**/*.form",
|
||||
"srcJvm/**/*.kt",
|
||||
"srcJvm/**/*.java",
|
||||
"srcJvm/**/*.form",
|
||||
],
|
||||
allow_empty = True,
|
||||
),
|
||||
@@ -41,6 +38,7 @@ jvm_library(
|
||||
"@lib//:kotlin-stdlib",
|
||||
"//platform/syntax/syntax-api:syntax",
|
||||
"//platform/syntax/syntax-util:util",
|
||||
"//platform/syntax/syntax-extensions:extensions",
|
||||
"@lib//:jetbrains-annotations",
|
||||
":platform_multiplatformSupport_provided",
|
||||
],
|
||||
@@ -61,6 +59,7 @@ jvm_library(
|
||||
":syntax",
|
||||
"//platform/syntax/syntax-api:syntax_test_lib",
|
||||
"//platform/syntax/syntax-util:util_test_lib",
|
||||
"//platform/syntax/syntax-extensions:extensions_test_lib",
|
||||
"//platform/multiplatformSupport",
|
||||
"//platform/multiplatformSupport:multiplatformSupport_test_lib",
|
||||
],
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/gen" isTestSource="false" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/srcJvm" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/resources" type="java-resource" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
@@ -29,6 +28,7 @@
|
||||
<orderEntry type="library" name="kotlin-stdlib" level="project" />
|
||||
<orderEntry type="module" module-name="intellij.platform.syntax" />
|
||||
<orderEntry type="module" module-name="intellij.platform.syntax.util" />
|
||||
<orderEntry type="module" module-name="intellij.platform.syntax.extensions" />
|
||||
<orderEntry type="library" name="jetbrains-annotations" level="project" />
|
||||
<orderEntry type="module" module-name="intellij.platform.multiplatformSupport" scope="PROVIDED" />
|
||||
</component>
|
||||
|
||||
@@ -1,13 +1,38 @@
|
||||
// Copyright 2000-2026 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.json.syntax
|
||||
|
||||
import fleet.util.multiplatform.linkToActual
|
||||
|
||||
internal fun jsonLazyParsing(): Boolean = linkToActual()
|
||||
import com.intellij.platform.syntax.extensions.ExtensionPointKey
|
||||
import com.intellij.platform.syntax.extensions.currentExtensionSupport
|
||||
import org.jetbrains.annotations.ApiStatus
|
||||
|
||||
/**
|
||||
* Handles lazy parsing switch of JSON files in syntax lib which has no dependency on IntelliJ platform.
|
||||
* Implement this extension point to disable ("veto") lazy parsing of JSON.
|
||||
*
|
||||
* @see jsonLazyParsingJvm, jsonLazyParsingWasmJs
|
||||
* Lazy parsing is enabled by default and stays enabled unless some vetoer vetoes it. This is how the syntax lib,
|
||||
* which has no dependency on the IntelliJ platform, learns about the IntelliJ-side `json.lazy.parsing` registry flag.
|
||||
*/
|
||||
val JsonLazyParsing: Boolean = jsonLazyParsing()
|
||||
@ApiStatus.Internal
|
||||
@ApiStatus.OverrideOnly
|
||||
interface JsonLazyParsingVetoer {
|
||||
fun isLazyParsingVetoed(): Boolean
|
||||
}
|
||||
|
||||
private val jsonLazyParsingVetoerEP: ExtensionPointKey<JsonLazyParsingVetoer> =
|
||||
ExtensionPointKey("com.intellij.json.lazyParsingVetoer")
|
||||
|
||||
/**
|
||||
* Handles the lazy parsing switch of JSON files in the syntax lib which has no dependency on the IntelliJ platform.
|
||||
*
|
||||
* Lazy parsing is enabled unless some [JsonLazyParsingVetoer] vetoes it. The query is defensive — if no extension
|
||||
* support / extension point is available (very early startup, or a lightweight test fixture that did not register the
|
||||
* extension point), lazy parsing stays enabled, matching the registry default.
|
||||
*
|
||||
* @see JsonLazyParsingVetoer
|
||||
*/
|
||||
val JsonLazyParsing: Boolean
|
||||
get() = try {
|
||||
currentExtensionSupport().getExtensions(jsonLazyParsingVetoerEP).none { it.isLazyParsingVetoed() }
|
||||
}
|
||||
catch (_: Throwable) {
|
||||
true
|
||||
}
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
// Copyright 2000-2026 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.json.syntax
|
||||
|
||||
import fleet.util.multiplatform.Actual
|
||||
|
||||
@Actual
|
||||
internal fun jsonLazyParsingJvm(): Boolean = System.getProperty("json.lazy.parsing") != "false"
|
||||
@@ -1,7 +0,0 @@
|
||||
// Copyright 2000-2026 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.json.syntax
|
||||
|
||||
import fleet.util.multiplatform.Actual
|
||||
|
||||
@Actual
|
||||
internal fun jsonLazyParsingWasmJs(): Boolean = true
|
||||
Reference in New Issue
Block a user