Repository: continuedev/continue
File: extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/IntelliJIde.kt (Kotlin)

Code before:
import com.intellij.util.containers.toArray
import kotlinx.coroutines.*
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.RequestBody.Companion.toRequestBody
import java.awt.Toolkit
import java.awt.datatransfer.DataFlavor
import java.io.BufferedReader
import java.io.File
import java.io.FileInputStream
import java.io.InputStreamReader
import java.net.URI
import java.net.URL
import java.nio.charset.Charset
import java.nio.file.Paths

class IntelliJIDE(
    private val project: Project,
    private val continuePluginService: ContinuePluginService,
    private var lastFileSaveTimestamp: Long = System.currentTimeMillis()

) : IDE {

    // Add a simple cache for diff results
    private data class DiffCache(
        val timestamp: Long,
        val diffs: List<String>
    )

    // Cache the last diff result
    private var diffCache: DiffCache? = null

    private val ripgrep: String

    init {
        val myPluginId = "com.github.continuedev.continueintellijextension"
        val pluginDescriptor =
            PluginManager.getPlugin(PluginId.getId(myPluginId)) ?: throw Exception("Plugin not found")

        val pluginPath = pluginDescriptor.pluginPath
        val os = getOS()
        ripgrep =
            Paths.get(pluginPath.toString(), "ripgrep", "bin", "rg" + if (os == OS.WINDOWS) ".exe" else "").toString()
    }

    /**
     * Updates the timestamp when a file is saved
     */
    override fun updateLastFileSaveTimestamp() {
        println("Updating last file save timestamp")

Review comment (performance):
This class is very simple currently but I'd still prefer to pull it out into it's own file.

Some other misc thoughts:
- There should be a max size on this so that it can't grow indefinitely
- ^ Ideally there is a lib we can pull in for this to avoid having to maintain the logic ourselves
- Rather than a "DiffCache" class, perhaps we build a "DiffService" that allows us to move all of the `getDiff` logic out of this IDE class where it doesn't belong, and just move the caching logic into that service as well
- This will also make it easier to test

Code after:
import java.io.File
import java.io.FileInputStream
import java.io.InputStreamReader
import java.net.URI
import java.nio.charset.Charset
import java.nio.file.Paths

class IntelliJIDE(
    private val project: Project,
    private val continuePluginService: ContinuePluginService,

) : IDE {

    private val gitService = GitService(project, continuePluginService)


    private val ripgrep: String

    init {
        val myPluginId = "com.github.continuedev.continueintellijextension"
        val pluginDescriptor =
            PluginManager.getPlugin(PluginId.getId(myPluginId)) ?: throw Exception("Plugin not found")

        val pluginPath = pluginDescriptor.pluginPath
        val os = getOS()
        ripgrep =
            Paths.get(pluginPath.toString(), "ripgrep", "bin", "rg" + if (os == OS.WINDOWS) ".exe" else "").toString()
    }

    /**
     * Updates the timestamp when a file is saved
     */
    override fun updateLastFileSaveTimestamp() {
        gitService.updateLastFileSaveTimestamp()
    }

    override suspend fun getIdeInfo(): IdeInfo {
        val applicationInfo = ApplicationInfo.getInstance()
        val ideName: String = applicationInfo.fullApplicationName
        val ideVersion = applicationInfo.fullVersion
        val sshClient = System.getenv("SSH_CLIENT")
        val sshTty = System.getenv("SSH_TTY")

        var remoteName = "local"
        if (sshClient != null || sshTty != null) {
            remoteName = "ssh"
        }

        val pluginId = "com.github.continuedev.continueintellijextension"
        val plugin = PluginManagerCore.getPlugin(PluginId.getId(pluginId))
        val extensionVersion = plugin?.version ?: "Unknown"