@@ -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 ): Collection <InlayPresentation >? {
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).create( )
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).create( )
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 {
@@ -74,11 +89,10 @@ object Base64Presentations {
74
89
}
75
90
76
91
protected abstract fun create (adapter : Base64ValueAdapter ): InlayPresentation ?
77
-
78
92
}
79
93
80
- class StringPresentationsFactory (element : PsiElement , sink : InlayHintsSink , editor : Editor )
81
- : InlayPresentationsFactory (element, sink, editor) {
94
+ class StringPresentationsFactory (element : PsiElement , sink : InlayHintsSink , editor : Editor , factory : PresentationFactory )
95
+ : InlayPresentationsFactory (element, sink, editor, factory ) {
82
96
83
97
override fun create (adapter : Base64ValueAdapter ): InlayPresentation ? {
84
98
val decoded = adapter.getDecoded() ? : return null
@@ -88,20 +102,22 @@ object Base64Presentations {
88
102
onValidValue(adapter::set, editor.project),
89
103
editor
90
104
)::show
91
- val presentation = create(decoded, onClick, editor ) ? : return null
105
+ val presentation = create(decoded, onClick, factory ) ? : return null
92
106
sink.addInlineElement(offset, false , presentation, false )
93
107
return presentation
94
108
}
95
109
96
- private fun create (text : String , onClick : (event: MouseEvent ) -> Unit , editor : Editor ): InlayPresentation ? {
97
- val factory = PresentationFactory (editor)
110
+ private fun create (text : String , onClick : (event: MouseEvent ) -> Unit , factory : PresentationFactory ): InlayPresentation ? {
98
111
val trimmed = trimWithEllipsis(text, INLAY_HINT_MAX_WIDTH ) ? : return null
99
- val textPresentation = factory.smallText(trimmed)
100
- val hoverPresentation = factory.referenceOnHover(textPresentation) { event, _ ->
101
- onClick.invoke(event)
102
- }
103
- val tooltipPresentation = factory.withTooltip(" Click to change value" , hoverPresentation)
104
- 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
+ )
105
121
}
106
122
107
123
private fun onValidValue (setter : (value: String , wrapAt: Int ) -> Unit , project : Project ? )
@@ -117,8 +133,8 @@ object Base64Presentations {
117
133
118
134
}
119
135
120
- class BinaryPresentationsFactory (element : PsiElement , sink : InlayHintsSink , editor : Editor )
121
- : InlayPresentationsFactory (element, sink, editor) {
136
+ class BinaryPresentationsFactory (element : PsiElement , sink : InlayHintsSink , editor : Editor , factory : PresentationFactory )
137
+ : InlayPresentationsFactory (element, sink, editor, factory ) {
122
138
123
139
override fun create (adapter : Base64ValueAdapter ): InlayPresentation ? {
124
140
val decoded = adapter.getDecodedBytes() ? : return null
0 commit comments