IJPL-176548 FUS: Detect and log the presence of Zed

See https://zed.dev/docs/configuring-zed#settings-files for config location details

IJ-CR-154140

(cherry picked from commit f2ffa6a2c32c869edef87f62692257879fa6e807)

GitOrigin-RevId: 3d423a1603800f16efb3e846ea5ab5c8bc89707b
This commit is contained in:
Dmitry Pogrebnoy
2025-01-31 21:08:39 +01:00
committed by intellij-monorepo-bot
parent d302ab9c34
commit 44ecefbcc0
2 changed files with 65 additions and 2 deletions

View File

@@ -16,9 +16,10 @@ private const val VSCODE_ID = ".vscode"
private const val CURSOR_ID = ".cursor"
private const val WINDSURF_ID = ".windsurf"
private const val ECLIPSE_ID = ".eclipse"
private const val ZED_ID = ".zed"
internal class EditorsCollector : ApplicationUsagesCollector() {
private val EDITORS_GROUP: EventLogGroup = EventLogGroup("editors", 3)
private val EDITORS_GROUP: EventLogGroup = EventLogGroup("editors", 4)
override fun getGroup(): EventLogGroup = EDITORS_GROUP
@@ -27,7 +28,8 @@ internal class EditorsCollector : ApplicationUsagesCollector() {
VSCODE_ID,
CURSOR_ID,
WINDSURF_ID,
ECLIPSE_ID
ECLIPSE_ID,
ZED_ID
)
private val CONFIG_EXISTS: EventId1<String> = EDITORS_GROUP.registerEvent(
@@ -80,6 +82,11 @@ internal class EditorsCollector : ApplicationUsagesCollector() {
if (Files.isDirectory(Paths.get(homeDir, ".eclipse"))) {
add(CONFIG_EXISTS.metric(ECLIPSE_ID))
}
val zedCollectionDataProvider = ZedCollectionDataProvider()
if (zedCollectionDataProvider.isZedDetected()) {
add(CONFIG_EXISTS.metric(ZED_ID))
}
}
}
}

View File

@@ -0,0 +1,56 @@
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.internal.statistic.collectors.fus.environment
import com.intellij.openapi.diagnostic.debug
import com.intellij.openapi.diagnostic.logger
import com.intellij.openapi.util.SystemInfo
import java.nio.file.InvalidPathException
import java.nio.file.Path
import java.nio.file.Paths
import kotlin.io.path.exists
private val logger = logger<ZedCollectionDataProvider>()
internal class ZedCollectionDataProvider : ExternalEditorCollectionDataProvider() {
private val zedHomePath: Path? = getZedHomePath()
fun isZedDetected(): Boolean {
val isZedHomePathValid = zedHomePath?.exists() == true
logger.debug { "Zed detected: $isZedHomePathValid" }
return isZedHomePathValid
}
private fun getZedHomePath(): Path? {
if (SystemInfo.isMac || SystemInfo.isLinux) {
val xdgConfigHomeEnvValue = try {
System.getenv("XDG_CONFIG_HOME")
}
catch (e: SecurityException) {
logger.debug(e)
null
}
logger.debug { "XDG_CONFIG_HOME env var value: $xdgConfigHomeEnvValue" }
if (xdgConfigHomeEnvValue != null) {
return try {
val zedHomePath = Paths.get(xdgConfigHomeEnvValue, "zed")
logger.debug { "Zed home path: $zedHomePath" }
zedHomePath
}
catch (e: InvalidPathException) {
logger.debug(e)
null
}
}
val zedHomePath = homeDirectory?.resolve(Paths.get(".config", "zed"))
logger.debug { "Zed home path: $zedHomePath" }
return zedHomePath
}
logger.debug { "The current OS is not supported by Zed" }
return null
}
}