<commit_before>// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.codeInsight.hints.presentation

import com.intellij.codeInsight.hint.HintManager
import com.intellij.codeInsight.hint.HintManagerImpl
import com.intellij.codeInsight.hint.HintUtil
import com.intellij.ide.ui.AntialiasingType
import com.intellij.openapi.command.CommandProcessor
import com.intellij.openapi.editor.DefaultLanguageHighlighterColors
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.editor.colors.CodeInsightColors
import com.intellij.openapi.editor.colors.EditorColors
import com.intellij.openapi.editor.colors.EditorFontType
import com.intellij.openapi.editor.colors.TextAttributesKey
import com.intellij.openapi.editor.impl.EditorImpl
import com.intellij.openapi.editor.impl.FontInfo
import com.intellij.openapi.editor.markup.TextAttributes
import com.intellij.openapi.util.Key
import com.intellij.openapi.util.SystemInfo
import com.intellij.pom.Navigatable
import com.intellij.psi.PsiElement
import com.intellij.ui.LightweightHint
import com.intellij.util.ui.JBUI
import com.intellij.util.ui.UIUtil
import java.awt.*
import java.awt.event.MouseEvent
import java.awt.font.FontRenderContext
import java.util.*
import javax.swing.Icon
import javax.swing.UIManager

class PresentationFactory(private val editor: EditorImpl) {
  /**
   * Smaller text, than editor, required to be wrapped with [roundWithBackground]
   */
  fun smallText(text: String): InlayPresentation {
    val fontData = getFontData(editor)
    val plainFont = fontData.font
    val width = editor.contentComponent.getFontMetrics(plainFont).stringWidth(text)
    val ascent = editor.ascent
    val descent = editor.descent
    val height = editor.lineHeight
    val textWithoutBox = EffectInlayPresentation(
      TextInlayPresentation(width, fontData.lineHeight, text, fontData.baseline) {
        plainFont
      },
      plainFont, height, ascent, descent
    )
    return withInlayAttributes(textWithoutBox)
  }

  /**
   * Text, that is not expected to be drawn with rounding, the same font size as in editor.
   */
  fun text(text: String) : InlayPresentation {
    val font = editor.colorsScheme.getFont(EditorFontType.PLAIN)
    val width = editor.contentComponent.getFontMetrics(font).stringWidth(text)
    return withInlayAttributes(TextInlayPresentation(
      width,
      editor.lineHeight,
      text,
      editor.ascent
    ) { font })
  }

  /**
   * Adds inlay background and rounding with insets.
   * Intended to be used with [smallText]
   */
  fun roundWithBackground(base: InlayPresentation): InlayPresentation {
    val rounding = rounding(8, 8, withInlayAttributes(BackgroundPresentation(
      InsetPresentation(
        base,
        left = 7,
        right = 7,
        top = 0,
        down = 0
      )
    )))
    val offsetFromTop = getFontData(editor).offsetFromTop(editor)
    return InsetPresentation(rounding, top = offsetFromTop)
  }

  fun icon(icon: Icon): IconPresentation = IconPresentation(icon, editor.component)

  fun withTooltip(tooltip: String, base: InlayPresentation): InlayPresentation = when {
    tooltip.isEmpty() -> base
    else -> onHover(base, tooltipHandler(tooltip))
  }

  fun folding(placeholder: InlayPresentation, unwrapAction: () -> InlayPresentation): InlayPresentation {
    return AttributesTransformerPresentation(ChangeOnClickPresentation(placeholder, unwrapAction)) {
      it.with(attributesOf(EditorColors.FOLDED_TEXT_ATTRIBUTES))
    }
  }

  fun asWrongReference(presentation: InlayPresentation): InlayPresentation {<commit_msg>InlayHints: change folding placeholder on hover<commit_after>// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.codeInsight.hints.presentation

import com.intellij.codeInsight.hint.HintManager
import com.intellij.codeInsight.hint.HintManagerImpl
import com.intellij.codeInsight.hint.HintUtil
import com.intellij.ide.ui.AntialiasingType
import com.intellij.openapi.command.CommandProcessor
import com.intellij.openapi.editor.DefaultLanguageHighlighterColors
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.editor.colors.CodeInsightColors
import com.intellij.openapi.editor.colors.EditorColors
import com.intellij.openapi.editor.colors.EditorFontType
import com.intellij.openapi.editor.colors.TextAttributesKey
import com.intellij.openapi.editor.impl.EditorImpl
import com.intellij.openapi.editor.impl.FontInfo
import com.intellij.openapi.editor.markup.TextAttributes
import com.intellij.openapi.util.Key
import com.intellij.openapi.util.SystemInfo
import com.intellij.pom.Navigatable
import com.intellij.psi.PsiElement
import com.intellij.ui.LightweightHint
import com.intellij.util.ui.JBUI
import com.intellij.util.ui.UIUtil
import java.awt.*
import java.awt.event.MouseEvent
import java.awt.font.FontRenderContext
import java.util.*
import javax.swing.Icon
import javax.swing.UIManager

class PresentationFactory(private val editor: EditorImpl) {
  /**
   * Smaller text, than editor, required to be wrapped with [roundWithBackground]
   */
  fun smallText(text: String): InlayPresentation {
    val fontData = getFontData(editor)
    val plainFont = fontData.font
    val width = editor.contentComponent.getFontMetrics(plainFont).stringWidth(text)
    val ascent = editor.ascent
    val descent = editor.descent
    val height = editor.lineHeight
    val textWithoutBox = EffectInlayPresentation(
      TextInlayPresentation(width, fontData.lineHeight, text, fontData.baseline) {
        plainFont
      },
      plainFont, height, ascent, descent
    )
    return withInlayAttributes(textWithoutBox)
  }

  /**
   * Text, that is not expected to be drawn with rounding, the same font size as in editor.
   */
  fun text(text: String) : InlayPresentation {
    val font = editor.colorsScheme.getFont(EditorFontType.PLAIN)
    val width = editor.contentComponent.getFontMetrics(font).stringWidth(text)
    return withInlayAttributes(TextInlayPresentation(
      width,
      editor.lineHeight,
      text,
      editor.ascent
    ) { font })
  }

  /**
   * Adds inlay background and rounding with insets.
   * Intended to be used with [smallText]
   */
  fun roundWithBackground(base: InlayPresentation): InlayPresentation {
    val rounding = rounding(8, 8, withInlayAttributes(BackgroundPresentation(
      InsetPresentation(
        base,
        left = 7,
        right = 7,
        top = 0,
        down = 0
      )
    )))
    val offsetFromTop = getFontData(editor).offsetFromTop(editor)
    return InsetPresentation(rounding, top = offsetFromTop)
  }

  fun icon(icon: Icon): IconPresentation = IconPresentation(icon, editor.component)

  fun withTooltip(tooltip: String, base: InlayPresentation): InlayPresentation = when {
    tooltip.isEmpty() -> base
    else -> onHover(base, tooltipHandler(tooltip))
  }

  fun folding(placeholder: InlayPresentation, unwrapAction: () -> InlayPresentation): InlayPresentation {
    return ChangeOnClickPresentation(changeOnHover(placeholder, onHover = {
      AttributesTransformerPresentation(placeholder) {
        it.with(attributesOf(EditorColors.FOLDED_TEXT_ATTRIBUTES))
      }
    }), onClick = unwrapAction)
  }

  fun asWrongReference(presentation: InlayPresentation): InlayPresentation {
{'fraction_non_alphanumeric': 0.08715473317243229, 'fraction_numerical': 0.004290694556181282, 'mean_word_length': 4.308896797153025, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2020373', 'n_tokens_mistral': 2284, 'n_tokens_neox': 2235, 'n_words': 482}