Skip to content

Commit cccd909

Browse files
authored
Merge pull request #10 from takemikami/support-ids
support ids parameter
2 parents 9d9d7b4 + 4d2efee commit cccd909

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

src/main/kotlin/com/github/takemikami/intellij/plugin/pytestparametrize/PytestParametrizeInlayHintsCollector.kt

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,35 @@ class PytestParametrizeInlayHintsCollector(
2424
&& element.arguments.size >= 2) {
2525
val names = element.arguments[0]
2626
val valList = element.arguments[1]
27-
if (valList !is PyListLiteralExpression
28-
|| (names !is PyStringLiteralExpression && names !is PyListLiteralExpression)) { return true }
2927

30-
val nameKeys = if (names is PyStringLiteralExpression)
31-
names.stringValue.split(",").map{it.trim()}
32-
else
33-
names.children.map{it.text.removeSurrounding("\"").removeSurrounding("\'")}
28+
if (valList !is PyListLiteralExpression) { return true }
29+
val nameKeys = when (names) {
30+
is PyStringLiteralExpression
31+
-> names.stringValue.split(",").map{it.trim()}
32+
is PyListLiteralExpression
33+
-> names.children.map{it.text.removeSurrounding("\"").removeSurrounding("\'")}
34+
is PyParenthesizedExpression
35+
-> names.children.joinToString{it.text}.split(",")
36+
.map{it.trim().removeSurrounding("\"").removeSurrounding("\'")}
37+
else -> null
38+
} ?: return true
39+
val ids = element.arguments.filter { it -> it.name.equals("ids") }.first()
40+
.children.joinToString{it.children.joinToString { it.text }}
41+
.split(",").map{
42+
it.trim().removeSurrounding("\"").removeSurrounding("\'")
43+
}.filter{it -> it.isNotEmpty() }
44+
3445
val hintName: InlayPresentation = factory.seq()
3546
for ((idx, paramset) in valList.elements.withIndex()) {
3647
if (paramset !is PyParenthesizedExpression) { continue }
3748

3849
// Sequence number of parameter set
3950
if(settings.showParametrizeOrderHints) {
51+
val idxHint = if (idx < ids.size) ids[idx] else idx
4052
sink.addInlineElement(
4153
paramset.textOffset,
4254
false,
43-
factory.roundWithBackground(factory.seq(factory.smallText("${idx}:"), hintName)),
55+
factory.roundWithBackground(factory.seq(factory.smallText("${idxHint}:"), hintName)),
4456
false
4557
)
4658
}

0 commit comments

Comments
 (0)