@@ -6,6 +6,7 @@ import com.intellij.codeInsight.hints.presentation.InlayPresentation
6
6
import com.intellij.openapi.editor.Editor
7
7
import com.intellij.psi.PsiElement
8
8
import com.jetbrains.python.psi.*
9
+ import com.jetbrains.python.psi.impl.PyKeywordArgumentImpl
9
10
10
11
@Suppress(" UnstableApiUsage" )
11
12
class PytestParametrizeInlayHintsCollector (
@@ -48,11 +49,21 @@ class PytestParametrizeInlayHintsCollector(
48
49
49
50
val hintName: InlayPresentation = factory.seq()
50
51
for ((idx, paramset) in valList.elements.withIndex()) {
51
- if (paramset !is PyParenthesizedExpression ) { continue }
52
+ if (paramset !is PyParenthesizedExpression
53
+ && ! (paramset is PyCallExpression && " pytest.param" == paramset.firstChild.text) ) { continue }
52
54
53
55
// Sequence number of parameter set
54
56
if (settings.showParametrizeOrderHints) {
55
- val idxHint = if (idx < ids.size) ids[idx] else idx
57
+ val idxHintOfPytestParam =
58
+ if (paramset is PyCallExpression && " pytest.param" == paramset.firstChild.text) {
59
+ val texts = paramset.lastChild.children
60
+ .filter { it is PyKeywordArgumentImpl && " id" == it.firstChild.text }
61
+ .map { it.lastChild.text }
62
+ if (texts.isNotEmpty())
63
+ texts.first().removeSurrounding(" \" " ).removeSurrounding(" \' " )
64
+ else null
65
+ } else null
66
+ val idxHint = idxHintOfPytestParam ? : if (idx < ids.size) ids[idx] else idx
56
67
sink.addInlineElement(
57
68
paramset.textOffset,
58
69
false ,
@@ -62,16 +73,22 @@ class PytestParametrizeInlayHintsCollector(
62
73
}
63
74
64
75
if (! settings.showParametrizeNameHints) { continue }
65
- val paramsetTuple = paramset.children.first()
76
+ val paramsetTuple = when (paramset) {
77
+ is PyParenthesizedExpression
78
+ -> paramset.children.first()
79
+ is PyCallExpression
80
+ -> paramset.children.last()
81
+ else -> null
82
+ } ? : return true
66
83
for ((pidx, param) in paramsetTuple.children.withIndex()) {
67
84
if (pidx >= nameKeys.size || param !is PyExpression ) { break }
68
85
69
86
// parameter name
70
87
sink.addInlineElement(
71
- param.textOffset,
72
- false ,
73
- factory.roundWithBackground(factory.seq(factory.smallText(" ${nameKeys[pidx]} :" ), hintName)),
74
- false
88
+ param.textOffset,
89
+ false ,
90
+ factory.roundWithBackground(factory.seq(factory.smallText(" ${nameKeys[pidx]} :" ), hintName)),
91
+ false
75
92
)
76
93
}
77
94
}
0 commit comments