From b340f5b876b5cd89022720d23787361b2bfbd015 Mon Sep 17 00:00:00 2001 From: Sergey Igushkin Date: Fri, 4 Oct 2024 21:16:42 +0400 Subject: [PATCH] Fix missing labels for missing configuring functions nodes --- .../actions/DeclarativeDomHelpers.kt | 13 +++++- .../actions/GetDeclarativeDocuments.kt | 44 +++++++++++-------- 2 files changed, 37 insertions(+), 20 deletions(-) diff --git a/gradle-client/src/jvmMain/kotlin/org/gradle/client/ui/connected/actions/DeclarativeDomHelpers.kt b/gradle-client/src/jvmMain/kotlin/org/gradle/client/ui/connected/actions/DeclarativeDomHelpers.kt index 0cb59ba..5fc6b7c 100644 --- a/gradle-client/src/jvmMain/kotlin/org/gradle/client/ui/connected/actions/DeclarativeDomHelpers.kt +++ b/gradle-client/src/jvmMain/kotlin/org/gradle/client/ui/connected/actions/DeclarativeDomHelpers.kt @@ -1,15 +1,24 @@ package org.gradle.client.ui.connected.actions +import org.gradle.declarative.dsl.schema.SchemaFunction import org.gradle.internal.declarativedsl.dom.DeclarativeDocument import org.gradle.internal.declarativedsl.dom.DeclarativeDocument.DocumentNode.ElementNode import org.gradle.internal.declarativedsl.dom.DeclarativeDocument.DocumentNode.PropertyNode import org.gradle.internal.declarativedsl.dom.DocumentNodeContainer +import org.gradle.internal.declarativedsl.dom.DocumentResolution.ElementResolution.SuccessfulElementResolution +import org.gradle.internal.declarativedsl.dom.resolution.DocumentResolutionContainer val DeclarativeDocument.singleSoftwareTypeNode: ElementNode? get() = content.filterIsInstance().singleOrNull() -fun DocumentNodeContainer.childElementNodes(name: String): List = - content.filterIsInstance().filter { it.name == name } +fun DocumentNodeContainer.childElementNodes( + resolutionContainer: DocumentResolutionContainer, + function: SchemaFunction +): List = + content.filterIsInstance().filter { + val resolution = resolutionContainer.data(it) + (resolution as? SuccessfulElementResolution)?.elementFactoryFunction == function + } fun DocumentNodeContainer.property(name: String): PropertyNode? = content.filterIsInstance().singleOrNull { it.name == name } diff --git a/gradle-client/src/jvmMain/kotlin/org/gradle/client/ui/connected/actions/GetDeclarativeDocuments.kt b/gradle-client/src/jvmMain/kotlin/org/gradle/client/ui/connected/actions/GetDeclarativeDocuments.kt index 679cd13..f2bfe05 100644 --- a/gradle-client/src/jvmMain/kotlin/org/gradle/client/ui/connected/actions/GetDeclarativeDocuments.kt +++ b/gradle-client/src/jvmMain/kotlin/org/gradle/client/ui/connected/actions/GetDeclarativeDocuments.kt @@ -493,7 +493,7 @@ class ModelTreeRendering( val args = valueNode.values.map { (it as? DeclarativeDocument.ValueNode.LiteralValueNode)?.value ?: "..." } - val argsString = args.joinToString(",", "(", ")") ?: "()" + val argsString = args.joinToString(",", "(", ")") "${valueNode.factoryName}$argsString" } } @@ -507,27 +507,35 @@ class ModelTreeRendering( ) { if (parentNode is ElementNode && resolutionContainer.isUnresolvedBase(parentNode)) return - - val functionNodes = parentNode.childElementNodes(subFunction.simpleName) - functionNodes.forEach { functionNode -> - val functionType = functionNode.type(resolutionContainer) as? DataClass - WithDecoration(functionNode) { - val title = subFunction.simpleName + + val functionNodes = parentNode.childElementNodes(resolutionContainer, subFunction) + if (functionNodes.isNotEmpty()) { + functionNodes.forEach { functionNode -> + val functionType = functionNode.type(resolutionContainer) as? DataClass + + WithDecoration(functionNode) { + val argsString = if (functionNode.elementValues.isNotEmpty()) "(${elementArgumentsString(functionNode)})" else "" - TitleSmall( - text = title, - modifier = Modifier - .withHoverCursor() - .semiTransparentIfNull(functionType) - .withClickTextRangeSelection(functionNode, highlightingContext) - ) + val title = subFunction.simpleName + argsString + TitleSmall( + text = title, + modifier = Modifier + .withHoverCursor() + .semiTransparentIfNull(functionType) + .withClickTextRangeSelection(functionNode, highlightingContext) + ) + } + ElementInfoOrNothingDeclared(functionType, functionNode, indentLevel + 1) } - ElementInfoOrNothingDeclared( - functionType, - functionNode, - indentLevel + 1 + } else { + TitleSmall( + text = subFunction.simpleName, + modifier = Modifier + .withHoverCursor() + .semiTransparentIfNull(null) + .withClickTextRangeSelection(null, highlightingContext) ) + ElementInfoOrNothingDeclared(null, null, indentLevel + 1) } }