From 16c27d5e50288384feda1b6c38cd3c61e57f6509 Mon Sep 17 00:00:00 2001 From: Christophe Rhodes Date: Thu, 23 Sep 2021 17:49:33 +0100 Subject: [PATCH] [toml] Handle quoted key segments in getName Keys `foo` and `"foo"` introduce the same named entity, and so should have the same name. closes https://github.com/JetBrains/intellij-community/pull/1754 GitOrigin-RevId: 2920a63b6a28fcfe374478434e2e017b7aaf502c --- .../toml/core/src/main/kotlin/org/toml/lang/psi/impl/Psi.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/plugins/toml/core/src/main/kotlin/org/toml/lang/psi/impl/Psi.kt b/plugins/toml/core/src/main/kotlin/org/toml/lang/psi/impl/Psi.kt index 0365a163572e..1d7ca6bb1f61 100644 --- a/plugins/toml/core/src/main/kotlin/org/toml/lang/psi/impl/Psi.kt +++ b/plugins/toml/core/src/main/kotlin/org/toml/lang/psi/impl/Psi.kt @@ -18,6 +18,7 @@ import com.intellij.psi.tree.IElementType import com.intellij.psi.util.PsiTreeUtil import org.toml.lang.psi.* import org.toml.lang.psi.TomlElementTypes.* +import org.toml.lang.psi.ext.TomlLiteralKind class TomlKeyValueImpl(type: IElementType) : CompositePsiElement(type), TomlKeyValue { @@ -36,7 +37,10 @@ class TomlKeyValueImpl(type: IElementType) : CompositePsiElement(type), TomlKeyV class TomlKeySegmentImpl(type: IElementType) : CompositePsiElement(type), TomlKeySegment { - override fun getName(): String = text + override fun getName(): String = when (val child = node.findChildByType(TOML_SINGLE_LINE_STRINGS)) { + null -> text + else -> (TomlLiteralKind.fromAstNode(child) as? TomlLiteralKind.String)?.value ?: text + } override fun setName(name: String): PsiElement { return replace(TomlPsiFactory(project).createKeySegment(name))