@@ -40,26 +40,41 @@ object Base64Presentations {
40
40
private const val SECRET_RESOURCE_KIND = " Secret"
41
41
private const val CONFIGMAP_RESOURCE_KIND = " ConfigMap"
42
42
43
- fun create (element : PsiElement , info : KubernetesTypeInfo , sink : InlayHintsSink , editor : Editor ): InlayPresentationsFactory ? {
44
- return when {
43
+ fun create (
44
+ element : PsiElement ,
45
+ info : KubernetesTypeInfo ,
46
+ sink : InlayHintsSink ,
47
+ editor : Editor ,
48
+ factory : PresentationFactory ,
49
+ /* for testing purposes */
50
+ stringPresentationFactory : (element: PsiElement , sink: InlayHintsSink , editor: Editor , factory: PresentationFactory ) -> Unit
51
+ = { element, sink, editor, factory ->
52
+ StringPresentationsFactory (element, sink, editor, factory).create()
53
+ },
54
+ /* for testing purposes */
55
+ binaryPresentationFactory : (element: PsiElement , sink: InlayHintsSink , editor: Editor , factory: PresentationFactory ) -> Unit
56
+ = { element, sink, editor, factory ->
57
+ BinaryPresentationsFactory (element, sink, editor, factory).create()
58
+ },
59
+ ) {
60
+ when {
45
61
isKubernetesResource(SECRET_RESOURCE_KIND , info) -> {
46
- val data = getDataValue(element ) ? : return null
47
- StringPresentationsFactory (data, sink, editor)
62
+ val data = element. getDataValue() ? : return
63
+ stringPresentationFactory.invoke (data, sink, editor, factory )
48
64
}
49
65
50
66
isKubernetesResource(CONFIGMAP_RESOURCE_KIND , info) -> {
51
- val binaryData = getBinaryData(element ) ? : return null
52
- BinaryPresentationsFactory (binaryData, sink, editor)
67
+ val binaryData = element. getBinaryData() ? : return
68
+ binaryPresentationFactory.invoke (binaryData, sink, editor, factory )
53
69
}
54
-
55
- else -> null
56
70
}
57
71
}
58
72
59
73
abstract class InlayPresentationsFactory (
60
74
private val element : PsiElement ,
61
75
protected val sink : InlayHintsSink ,
62
- protected val editor : Editor
76
+ protected val editor : Editor ,
77
+ protected val factory : PresentationFactory
63
78
) {
64
79
65
80
protected companion object {
@@ -69,17 +84,15 @@ object Base64Presentations {
69
84
70
85
fun create (): Collection <InlayPresentation > {
71
86
return element.children.mapNotNull { child ->
72
- val adapter = Base64ValueAdapter (child)
73
- create(adapter)
87
+ create(Base64ValueAdapter (child))
74
88
}
75
89
}
76
90
77
91
protected abstract fun create (adapter : Base64ValueAdapter ): InlayPresentation ?
78
-
79
92
}
80
93
81
- class StringPresentationsFactory (element : PsiElement , sink : InlayHintsSink , editor : Editor )
82
- : InlayPresentationsFactory (element, sink, editor) {
94
+ class StringPresentationsFactory (element : PsiElement , sink : InlayHintsSink , editor : Editor , factory : PresentationFactory )
95
+ : InlayPresentationsFactory (element, sink, editor, factory ) {
83
96
84
97
override fun create (adapter : Base64ValueAdapter ): InlayPresentation ? {
85
98
val decoded = adapter.getDecoded() ? : return null
@@ -89,20 +102,22 @@ object Base64Presentations {
89
102
onValidValue(adapter::set, editor.project),
90
103
editor
91
104
)::show
92
- val presentation = create(decoded, onClick, editor ) ? : return null
105
+ val presentation = create(decoded, onClick, factory ) ? : return null
93
106
sink.addInlineElement(offset, false , presentation, false )
94
107
return presentation
95
108
}
96
109
97
- private fun create (text : String , onClick : (event: MouseEvent ) -> Unit , editor : Editor ): InlayPresentation ? {
98
- val factory = PresentationFactory (editor)
110
+ private fun create (text : String , onClick : (event: MouseEvent ) -> Unit , factory : PresentationFactory ): InlayPresentation ? {
99
111
val trimmed = trimWithEllipsis(text, INLAY_HINT_MAX_WIDTH ) ? : return null
100
- val textPresentation = factory.smallText(trimmed)
101
- val hoverPresentation = factory.referenceOnHover(textPresentation) { event, _ ->
102
- onClick.invoke(event)
103
- }
104
- val tooltipPresentation = factory.withTooltip(" Click to change value" , hoverPresentation)
105
- return factory.roundWithBackground(tooltipPresentation)
112
+ return factory.roundWithBackground(
113
+ factory.withTooltip(
114
+ " Click to change value" ,
115
+ factory.referenceOnHover(
116
+ factory.smallText(trimmed)) { event, _ ->
117
+ onClick.invoke(event)
118
+ }
119
+ )
120
+ )
106
121
}
107
122
108
123
private fun onValidValue (setter : (value: String , wrapAt: Int ) -> Unit , project : Project ? )
@@ -118,8 +133,8 @@ object Base64Presentations {
118
133
119
134
}
120
135
121
- class BinaryPresentationsFactory (element : PsiElement , sink : InlayHintsSink , editor : Editor )
122
- : InlayPresentationsFactory (element, sink, editor) {
136
+ class BinaryPresentationsFactory (element : PsiElement , sink : InlayHintsSink , editor : Editor , factory : PresentationFactory )
137
+ : InlayPresentationsFactory (element, sink, editor, factory ) {
123
138
124
139
override fun create (adapter : Base64ValueAdapter ): InlayPresentation ? {
125
140
val decoded = adapter.getDecodedBytes() ? : return null
0 commit comments