Skip to content

Commit 4240a61

Browse files
committed
Reformat types code to match parameters
1 parent ced78a9 commit 4240a61

File tree

3 files changed

+19
-13
lines changed

3 files changed

+19
-13
lines changed

src/main/kotlin/space/whitememory/pythoninlayparams/types/AbstractPythonInlayTypeHintsCollector.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import space.whitememory.pythoninlayparams.types.hints.HintGenerator
1010
import space.whitememory.pythoninlayparams.types.hints.HintResolver
1111

1212
@Suppress("UnstableApiUsage")
13-
abstract class AbstractPythonInlayTypeHintsCollector(editor: Editor, open val settings: Any): FactoryInlayHintsCollector(editor) {
13+
abstract class AbstractPythonInlayTypeHintsCollector(editor: Editor, open val settings: Any) :
14+
FactoryInlayHintsCollector(editor) {
1415
abstract fun validateExpression(element: PsiElement): Boolean
1516

1617
abstract val textBeforeTypeHint: String

src/main/kotlin/space/whitememory/pythoninlayparams/types/hints/HintGenerator.kt

+13-11
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import com.jetbrains.python.psi.PyLambdaExpression
55
import com.jetbrains.python.psi.types.*
66

77
enum class HintGenerator {
8-
UNION_TYPE() {
8+
UNION_TYPE {
99
override fun handleType(type: PyType?, typeEvalContext: TypeEvalContext): String? {
1010
if (type !is PyUnionType) {
1111
return null
@@ -24,7 +24,7 @@ enum class HintGenerator {
2424
}
2525
},
2626

27-
COLLECTION_TYPE() {
27+
COLLECTION_TYPE {
2828
override fun handleType(type: PyType?, typeEvalContext: TypeEvalContext): String? {
2929
if (
3030
type is PyCollectionType
@@ -54,7 +54,7 @@ enum class HintGenerator {
5454
}
5555
},
5656

57-
TUPLE_TYPE() {
57+
TUPLE_TYPE {
5858
override fun handleType(type: PyType?, typeEvalContext: TypeEvalContext): String? {
5959
if (type !is PyTupleType) {
6060
return null
@@ -67,17 +67,17 @@ enum class HintGenerator {
6767
if (type.elementCount > 2) {
6868
val firstElement = generateTypeHintText(type.elementTypes[0], typeEvalContext)
6969
val secondElement = generateTypeHintText(type.elementTypes[1], typeEvalContext)
70-
70+
7171
return "${PyNames.TUPLE}[$firstElement, $secondElement, ...]"
7272
}
73-
73+
7474
return type.elementTypes
7575
.mapNotNull { generateTypeHintText(it, typeEvalContext) }
7676
.joinToString(separator = ", ", prefix = "${PyNames.TUPLE}[", postfix = "]")
7777
}
7878
},
7979

80-
CLASS_TYPE() {
80+
CLASS_TYPE {
8181
override fun handleType(type: PyType?, typeEvalContext: TypeEvalContext): String? {
8282
if (type is PyClassType && type.isDefinition) {
8383
return "${PyNames.TYPE.replaceFirstChar { it.titlecaseChar() }}[${type.declarationElement?.name}]"
@@ -87,17 +87,19 @@ enum class HintGenerator {
8787
}
8888
},
8989

90-
FUNCTION_TYPE() {
90+
FUNCTION_TYPE {
9191
override fun handleType(type: PyType?, typeEvalContext: TypeEvalContext): String? {
9292
if (type !is PyFunctionType) {
9393
return null
9494
}
9595

9696
val parametersText = when (type.callable) {
9797
is PyLambdaExpression -> type.callable.parameterList.getPresentableText(false, typeEvalContext)
98-
else -> "(${type.callable.parameterList.parameters
99-
.filter { !it.isSelf }
100-
.joinToString(separator = ", ") { "${HintUtil.getParameterAnnotationValue(it)}" }})"
98+
else -> "(${
99+
type.callable.parameterList.parameters
100+
.filter { !it.isSelf }
101+
.joinToString(separator = ", ") { "${HintUtil.getParameterAnnotationValue(it)}" }
102+
})"
101103
}
102104

103105
val callableReturnType = typeEvalContext.getReturnType(type.callable)
@@ -106,7 +108,7 @@ enum class HintGenerator {
106108
}
107109
},
108110

109-
ANY_TYPE() {
111+
ANY_TYPE {
110112
override fun handleType(type: PyType?, typeEvalContext: TypeEvalContext): String {
111113
return type?.name ?: PyNames.UNKNOWN_TYPE
112114
}

src/main/kotlin/space/whitememory/pythoninlayparams/types/variables/PythonVariablesInlayTypeHintsCollector.kt

+4-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ import space.whitememory.pythoninlayparams.types.AbstractPythonInlayTypeHintsCol
1010
import space.whitememory.pythoninlayparams.types.hints.HintResolver
1111

1212
@Suppress("UnstableApiUsage")
13-
class PythonVariablesInlayTypeHintsCollector(editor: Editor, override val settings: PythonVariablesInlayTypeHintsProvider.Settings) :
13+
class PythonVariablesInlayTypeHintsCollector(
14+
editor: Editor,
15+
override val settings: PythonVariablesInlayTypeHintsProvider.Settings
16+
) :
1417
AbstractPythonInlayTypeHintsCollector(editor, settings) {
1518

1619
override fun validateExpression(element: PsiElement): Boolean {

0 commit comments

Comments
 (0)