<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 org.jetbrains.plugins.github.pullrequest.ui.timeline

import com.intellij.diff.util.DiffDrawUtil
import com.intellij.openapi.diff.impl.patch.PatchHunk
import com.intellij.openapi.diff.impl.patch.PatchLine
import com.intellij.openapi.diff.impl.patch.PatchReader
import com.intellij.openapi.diff.impl.patch.apply.GenericPatchApplier
import com.intellij.openapi.editor.Document
import com.intellij.openapi.editor.EditorFactory
import com.intellij.openapi.editor.EditorKind
import com.intellij.openapi.editor.ex.EditorEx
import com.intellij.openapi.fileTypes.FileTypeRegistry
import com.intellij.openapi.project.Project
import com.intellij.openapi.vcs.changes.patch.AppliedTextPatch
import com.intellij.openapi.vcs.changes.patch.tool.PatchChangeBuilder
import com.intellij.ui.SimpleColoredComponent
import com.intellij.ui.SimpleTextAttributes
import com.intellij.util.PathUtil
import com.intellij.util.ui.JBUI
import javax.swing.JComponent

class GHPRReviewThreadDiffComponentFactory(private val fileTypeRegistry: FileTypeRegistry,
                                           private val project: Project,
                                           private val editorFactory: EditorFactory) {
  fun createComponent(filePath: String, diffHunk: String): JComponent = JBUI.Panels
    .simplePanel(createDiff(filePath, diffHunk))
    .addToTop(createFileName(filePath))
    .andTransparent()

  private fun createFileName(filePath: String): SimpleColoredComponent {
    val name = PathUtil.getFileName(filePath)
    val path = PathUtil.getParentPath(filePath)
    val fileType = fileTypeRegistry.getFileTypeByFileName(name)

    return SimpleColoredComponent().apply {
      isOpaque = false

      icon = fileType.icon
      append(name).appendTextPadding(5)
      append(path, SimpleTextAttributes.GRAYED_ATTRIBUTES)
    }
  }

  private fun createDiff(filePath: String, diffHunk: String): JComponent {<commit_msg>[github] Add space between file name and file path in PR timeline diff<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 org.jetbrains.plugins.github.pullrequest.ui.timeline

import com.intellij.diff.util.DiffDrawUtil
import com.intellij.openapi.diff.impl.patch.PatchHunk
import com.intellij.openapi.diff.impl.patch.PatchLine
import com.intellij.openapi.diff.impl.patch.PatchReader
import com.intellij.openapi.diff.impl.patch.apply.GenericPatchApplier
import com.intellij.openapi.editor.Document
import com.intellij.openapi.editor.EditorFactory
import com.intellij.openapi.editor.EditorKind
import com.intellij.openapi.editor.ex.EditorEx
import com.intellij.openapi.fileTypes.FileTypeRegistry
import com.intellij.openapi.project.Project
import com.intellij.openapi.vcs.changes.patch.AppliedTextPatch
import com.intellij.openapi.vcs.changes.patch.tool.PatchChangeBuilder
import com.intellij.ui.SimpleColoredComponent
import com.intellij.ui.SimpleTextAttributes
import com.intellij.util.PathUtil
import com.intellij.util.ui.JBUI
import javax.swing.JComponent

class GHPRReviewThreadDiffComponentFactory(private val fileTypeRegistry: FileTypeRegistry,
                                           private val project: Project,
                                           private val editorFactory: EditorFactory) {
  fun createComponent(filePath: String, diffHunk: String): JComponent = JBUI.Panels
    .simplePanel(createDiff(filePath, diffHunk))
    .addToTop(createFileName(filePath))
    .andTransparent()

  private fun createFileName(filePath: String): SimpleColoredComponent {
    val name = PathUtil.getFileName(filePath)
    val path = PathUtil.getParentPath(filePath)
    val fileType = fileTypeRegistry.getFileTypeByFileName(name)

    return SimpleColoredComponent().apply {
      isOpaque = false

      icon = fileType.icon
      append(name)
      if (!path.isBlank()) append(" ").append(path, SimpleTextAttributes.GRAYED_ATTRIBUTES)
    }
  }

  private fun createDiff(filePath: String, diffHunk: String): JComponent {
{'fraction_non_alphanumeric': 0.08359059605794349, 'fraction_numerical': 0.004986938969365947, 'mean_word_length': 4.2715894868585735, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6278338', 'n_tokens_mistral': 1262, 'n_tokens_neox': 1225, 'n_words': 249}