@@ -40,26 +40,41 @@ object Base64Presentations {
4040 private const val SECRET_RESOURCE_KIND = " Secret"
4141 private const val CONFIGMAP_RESOURCE_KIND = " ConfigMap"
4242
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 {
4561 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 )
4864 }
4965
5066 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 )
5369 }
54-
55- else -> null
5670 }
5771 }
5872
5973 abstract class InlayPresentationsFactory (
6074 private val element : PsiElement ,
6175 protected val sink : InlayHintsSink ,
62- protected val editor : Editor
76+ protected val editor : Editor ,
77+ protected val factory : PresentationFactory
6378 ) {
6479
6580 protected companion object {
@@ -74,11 +89,10 @@ object Base64Presentations {
7489 }
7590
7691 protected abstract fun create (adapter : Base64ValueAdapter ): InlayPresentation ?
77-
7892 }
7993
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 ) {
8296
8397 override fun create (adapter : Base64ValueAdapter ): InlayPresentation ? {
8498 val decoded = adapter.getDecoded() ? : return null
@@ -88,20 +102,22 @@ object Base64Presentations {
88102 onValidValue(adapter::set, editor.project),
89103 editor
90104 )::show
91- val presentation = create(decoded, onClick, editor ) ? : return null
105+ val presentation = create(decoded, onClick, factory ) ? : return null
92106 sink.addInlineElement(offset, false , presentation, false )
93107 return presentation
94108 }
95109
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 ? {
98111 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+ )
105121 }
106122
107123 private fun onValidValue (setter : (value: String , wrapAt: Int ) -> Unit , project : Project ? )
@@ -117,8 +133,8 @@ object Base64Presentations {
117133
118134 }
119135
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 ) {
122138
123139 override fun create (adapter : Base64ValueAdapter ): InlayPresentation ? {
124140 val decoded = adapter.getDecodedBytes() ? : return null
0 commit comments