From 839f9e3292e7d0bfc35c2a6fbb2fb930b81a60bc Mon Sep 17 00:00:00 2001 From: Koudai Aono Date: Tue, 7 Sep 2021 02:00:50 +0900 Subject: [PATCH 1/2] Fix toml header problem --- .../PoetryExtrasLineMarkerContributor.kt | 2 +- .../PoetryScriptsLineMarkerContributor.kt | 2 +- .../poetry/PoetryVersionInspection.kt | 2 +- src/com/koxudaxi/poetry/poetry.kt | 26 ------------------- 4 files changed, 3 insertions(+), 29 deletions(-) diff --git a/src/com/koxudaxi/poetry/PoetryExtrasLineMarkerContributor.kt b/src/com/koxudaxi/poetry/PoetryExtrasLineMarkerContributor.kt index e7da86c..e974a5c 100644 --- a/src/com/koxudaxi/poetry/PoetryExtrasLineMarkerContributor.kt +++ b/src/com/koxudaxi/poetry/PoetryExtrasLineMarkerContributor.kt @@ -18,7 +18,7 @@ object PoetryExtrasLineMarkerContributor : RunLineMarkerContributor() { } val keyValue = element.parent as? TomlKeyValue ?: return null val header = (keyValue.parent as? TomlTable)?.header ?: return null - if (header.keyText != "tool.poetry.extras") return null + if (header.key?.text != "tool.poetry.extras") return null if (keyValue.key.text == null) return null val value = keyValue.value as? TomlArray ?: return null if (value.elements.isEmpty() || value.elements.any { it !is TomlLiteral || it.textLength < 3}) return null diff --git a/src/com/koxudaxi/poetry/PoetryScriptsLineMarkerContributor.kt b/src/com/koxudaxi/poetry/PoetryScriptsLineMarkerContributor.kt index 27caeb8..6a30830 100644 --- a/src/com/koxudaxi/poetry/PoetryScriptsLineMarkerContributor.kt +++ b/src/com/koxudaxi/poetry/PoetryScriptsLineMarkerContributor.kt @@ -22,7 +22,7 @@ object PoetryScriptsLineMarkerContributor : RunLineMarkerContributor() { } val keyValue = element.parent as? TomlKeyValue ?: return null val header = (keyValue.parent as? TomlTable)?.header ?: return null - if (header.keyText != "tool.poetry.scripts") return null + if (header.key?.text != "tool.poetry.scripts") return null if (keyValue.key.text == null) return null val value = keyValue.value as? TomlLiteral ?: return null if (value.textLength < 3) return null diff --git a/src/com/koxudaxi/poetry/PoetryVersionInspection.kt b/src/com/koxudaxi/poetry/PoetryVersionInspection.kt index c381fe1..9aefdea 100644 --- a/src/com/koxudaxi/poetry/PoetryVersionInspection.kt +++ b/src/com/koxudaxi/poetry/PoetryVersionInspection.kt @@ -32,7 +32,7 @@ class PoetryVersionInspection : LocalInspectionTool() { if (file.virtualFile != module.pyProjectToml) return file.children .filter { element -> - (element as? TomlTable)?.header?.keyText in listOf("tool.poetry.dependencies", "tool.poetry.dev-dependencies") + (element as? TomlTable)?.header?.key?.text in listOf("tool.poetry.dependencies", "tool.poetry.dev-dependencies") }.flatMap { it.children.mapNotNull { line -> line as? TomlKeyValue } }.forEach { keyValue -> diff --git a/src/com/koxudaxi/poetry/poetry.kt b/src/com/koxudaxi/poetry/poetry.kt index 5ea5b74..4cdf308 100644 --- a/src/com/koxudaxi/poetry/poetry.kt +++ b/src/com/koxudaxi/poetry/poetry.kt @@ -726,29 +726,3 @@ data class PoetryOutdatedVersion( @SerializedName("currentVersion") var currentVersion: String, @SerializedName("latestVersion") var latestVersion: String) - -private fun tomlTableHeaderHasKey(): Boolean = TomlTableHeader::class.memberProperties.any { it.name == "key" } -var tomlTableHeaderHasKeyCache: Boolean? = null -val TomlTableHeader.keyText: String? get() = getKeyByTomlTableHeader(this) - - -private fun getKeyByTomlTableHeader(header: TomlTableHeader): String? { - return try { - when (tomlTableHeaderHasKeyCache) { - true -> header.key?.text - false -> (header::class.java.getMethod("getNames").invoke(header) as? List<*>) - ?.filterIsInstance()?.joinToString(".") { it.text } - else -> { - tomlTableHeaderHasKeyCache = tomlTableHeaderHasKey() - getKeyByTomlTableHeader(header) - } - } - } catch (e: Exception) { - val updatedTomlTableHeaderHasKey = tomlTableHeaderHasKey() - if (updatedTomlTableHeaderHasKey == tomlTableHeaderHasKeyCache) { - throw Exception("unsupported TomlTableHeader type") - } - tomlTableHeaderHasKeyCache = updatedTomlTableHeaderHasKey - getKeyByTomlTableHeader(header) - } -} From 2aac05d49f7fd8accb64dfd4ba8bce889f780a03 Mon Sep 17 00:00:00 2001 From: Koudai Aono Date: Tue, 7 Sep 2021 02:06:33 +0900 Subject: [PATCH 2/2] Update history --- resources/META-INF/plugin.xml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/resources/META-INF/plugin.xml b/resources/META-INF/plugin.xml index d174e98..e728821 100644 --- a/resources/META-INF/plugin.xml +++ b/resources/META-INF/plugin.xml @@ -5,6 +5,10 @@ Koudai Aono @koxudaxi version 1.1.5-212 +

Bug fixes

+
    +
  • Fix toml header problem [#271]
  • +

Features

  • Update versions [#270]