diff --git a/platform/platform-impl/internal/src/com/intellij/internal/statistic/collectors/fus/environment/EditorsCollector.kt b/platform/platform-impl/internal/src/com/intellij/internal/statistic/collectors/fus/environment/EditorsCollector.kt index 8056f84f6848..2551842a33f9 100644 --- a/platform/platform-impl/internal/src/com/intellij/internal/statistic/collectors/fus/environment/EditorsCollector.kt +++ b/platform/platform-impl/internal/src/com/intellij/internal/statistic/collectors/fus/environment/EditorsCollector.kt @@ -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 = 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)) + } } } } diff --git a/platform/platform-impl/internal/src/com/intellij/internal/statistic/collectors/fus/environment/ZedCollectionDataProvider.kt b/platform/platform-impl/internal/src/com/intellij/internal/statistic/collectors/fus/environment/ZedCollectionDataProvider.kt new file mode 100644 index 000000000000..7c1578a07098 --- /dev/null +++ b/platform/platform-impl/internal/src/com/intellij/internal/statistic/collectors/fus/environment/ZedCollectionDataProvider.kt @@ -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() + +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 + } +} \ No newline at end of file