Skip to content

Commit 6676b37

Browse files
Add an option to show single hints (#42)
1 parent 7045470 commit 6676b37

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

src/main/kotlin/space/whitememory/pythoninlayparams/PythonInlayParameterHintsProvider.kt

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
@file:Suppress("UnstableApiUsage")
2+
13
package space.whitememory.pythoninlayparams
24

35
import com.intellij.codeInsight.hints.InlayInfo
@@ -14,12 +16,6 @@ import com.jetbrains.python.psi.types.TypeEvalContext
1416
@Suppress("UnstableApiUsage")
1517
class PythonInlayParameterHintsProvider : InlayParameterHintsProvider {
1618

17-
companion object {
18-
val classHints = Option("hints.classes.parameters", { "Class hints" }, true)
19-
val functionHints = Option("hints.functions.parameters", { "Function hints" }, true)
20-
val hideOverlaps = Option("hints.overlaps.parameters", { "Hide overlaps" }, true)
21-
}
22-
2319
private val forbiddenBuiltinFiles = setOf("builtins.pyi", "typing.pyi")
2420

2521
override fun getDefaultBlackList() = setOf<String>()
@@ -28,7 +24,7 @@ class PythonInlayParameterHintsProvider : InlayParameterHintsProvider {
2824

2925
override fun getDescription() = "Help you pass correct arguments by showing parameter names at call sites"
3026

31-
override fun getSupportedOptions() = listOf(classHints, functionHints, hideOverlaps)
27+
override fun getSupportedOptions() = listOf(classHints, functionHints, showOverlaps, showSingleHints)
3228

3329
override fun getProperty(key: String?): String? {
3430
val prefix = "inlay.parameters.hints"
@@ -69,9 +65,9 @@ class PythonInlayParameterHintsProvider : InlayParameterHintsProvider {
6965
!it.isSelf && it.parameter !is PySingleStarParameter && it.parameter !is PySlashParameter
7066
} ?: return inlayInfos
7167

72-
// Don't need a hint if there's only one parameter,
73-
// Make an exception for *args
74-
if (resolvedParameters.size == 1 && !resolvedParameters[0].isPositionalContainer) return inlayInfos
68+
// Don't need a hint if there's only one parameter, unless required by the settings or contains *args
69+
if (resolvedParameters.size == 1 && !showSingleHints.isEnabled() && !resolvedParameters[0].isPositionalContainer)
70+
return inlayInfos
7571

7672
resolvedParameters.zip(element.arguments).forEach { (param, arg) ->
7773
val paramName = param.name ?: return@forEach
@@ -115,7 +111,7 @@ class PythonInlayParameterHintsProvider : InlayParameterHintsProvider {
115111
argument.name?.lowercase() ?: return true
116112
}
117113

118-
if (hideOverlaps.isEnabled() && paramName in argumentName) return false
114+
if (!showOverlaps.isEnabled() && paramName in argumentName) return false
119115
return paramName != argumentName
120116
}
121117

@@ -128,4 +124,9 @@ class PythonInlayParameterHintsProvider : InlayParameterHintsProvider {
128124
val fileName = callableType.callable?.containingFile?.name ?: return false
129125
return fileName in forbiddenBuiltinFiles
130126
}
131-
}
127+
}
128+
129+
val classHints = Option("hints.classes.parameters", { "Class hints" }, true)
130+
val functionHints = Option("hints.functions.parameters", { "Function hints" }, true)
131+
val showOverlaps = Option("hints.overlaps.parameters", { "Show overlaps" }, false)
132+
val showSingleHints = Option("hints.single.parameters", { "Show single hints" }, false)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
def give_age(age: int) -> str:
2+
return f"Your age is {age}"
3+
4+
give_age(16)
5+
give_age(age=16)

0 commit comments

Comments
 (0)