Skip to content
This repository has been archived by the owner on Feb 9, 2022. It is now read-only.

Commit

Permalink
Merge pull request #39 from koxudaxi/improve_detecting_extras
Browse files Browse the repository at this point in the history
improve detecting extras
  • Loading branch information
koxudaxi authored May 22, 2020
2 parents 3205dea + d8660e5 commit 84c2949
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
1 change: 1 addition & 0 deletions resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<h2>version 0.0.8</h2>
<p>Features</p>
<ul>
<li>improve detecting extras [#39] </li>
<li>improve showing popup [#38] </li>
<li>improve handling invalid interpreter [#37] </li>
</ul>
Expand Down
8 changes: 4 additions & 4 deletions src/com/koxudaxi/poetry/PoetryExtrasLineMarkerContributor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import com.intellij.icons.AllIcons.Actions.Install
import com.intellij.openapi.actionSystem.ActionManager
import com.intellij.psi.PsiElement
import com.jetbrains.python.sdk.pythonSdk
import org.toml.lang.psi.TomlKey
import org.toml.lang.psi.TomlKeyValue
import org.toml.lang.psi.TomlTable
import org.toml.lang.psi.*

object PoetryExtrasLineMarkerContributor : RunLineMarkerContributor() {
override fun getInfo(element: PsiElement): Info? {
Expand All @@ -17,7 +15,9 @@ object PoetryExtrasLineMarkerContributor : RunLineMarkerContributor() {
val keyValue = element.parent as? TomlKeyValue ?: return null
val names = (keyValue.parent as? TomlTable)?.header?.names ?: return null
if (names.joinToString(".") { it.text } != "tool.poetry.extras") return null
if (keyValue.key.text == null || keyValue.value?.text == null) 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
val action =ActionManager.getInstance().getAction(PoetryInstallExtras.actionID)
return Info(Install, { parameter -> "Install " + ((parameter as? TomlKey)?.text ?: "extra")}, arrayOf(action))
}
Expand Down

0 comments on commit 84c2949

Please sign in to comment.