Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(intellij): use configPath to determine runIde vs production mode #2286

Merged
merged 1 commit into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import com.intellij.lang.javascript.service.JSLanguageServiceUtil
import com.intellij.openapi.diagnostic.logger
import com.intellij.openapi.diagnostic.thisLogger
import com.intellij.openapi.project.Project
import com.intellij.util.application
import com.intellij.util.io.awaitExit
import dev.nx.console.NxConsoleBundle
import dev.nx.console.utils.isDevelopmentInstance
import dev.nx.console.utils.nodeInterpreter
import dev.nx.console.utils.nxBasePath
import java.io.File
Expand Down Expand Up @@ -112,7 +112,7 @@ class NxlsProcess(private val project: Project, private val cs: CoroutineScope)
logger.info("nxls found via ${lsp.path}")
return GeneralCommandLine().apply {
withParentEnvironmentType(GeneralCommandLine.ParentEnvironmentType.CONSOLE)
if (application.isInternal) {
if (isDevelopmentInstance()) {
withEnvironment("NODE_OPTIONS", "--inspect=6009 --enable-source-maps")
}
withCharset(Charsets.UTF_8)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import com.intellij.openapi.application.ApplicationInfo
import com.intellij.openapi.application.PermanentInstallationID
import com.intellij.openapi.diagnostic.logger
import com.intellij.openapi.util.SystemInfo
import com.intellij.util.application
import dev.nx.console.settings.NxConsoleSettingsProvider
import dev.nx.console.utils.isDevelopmentInstance
import io.ktor.client.*
import io.ktor.client.call.*
import io.ktor.client.request.*
Expand All @@ -18,6 +18,7 @@ val SESSION_ID = UUID.randomUUID().toString()
private val logger = logger<MeasurementProtocolService>()

class MeasurementProtocolService(private val client: HttpClient) : Telemetry {
private val isDevelopmentInstance = isDevelopmentInstance()

override suspend fun featureUsed(feature: String, data: Map<String, Any>?) {
val payload = this.buildPayload(feature, data)
Expand Down Expand Up @@ -68,7 +69,7 @@ class MeasurementProtocolService(private val client: HttpClient) : Telemetry {
put(
"value",
PluginManager.getPluginByClass(TelemetryService::class.java)?.version
?: "0.0.0"
?: "0.0.0",
)
}
}
Expand All @@ -78,7 +79,7 @@ class MeasurementProtocolService(private val client: HttpClient) : Telemetry {
putJsonObject("params") {
put("engagement_time_msec", "1")
put("session_id", SESSION_ID)
put("debug_mode", if (application.isInternal) 1 else null)
put("debug_mode", if (isDevelopmentInstance) 1 else null)

put("action_type", eventName)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package dev.nx.console.telemetry
import com.intellij.openapi.components.Service
import com.intellij.openapi.diagnostic.logger
import com.intellij.openapi.project.Project
import com.intellij.util.application
import dev.nx.console.utils.isDevelopmentInstance
import io.ktor.client.*
import io.ktor.client.engine.cio.*
import io.ktor.client.plugins.logging.*
Expand All @@ -16,6 +16,7 @@ interface Telemetry {

@Service(Service.Level.PROJECT)
class TelemetryService(private val cs: CoroutineScope) {
private val isDevelopmentInstance = isDevelopmentInstance()
val logger = logger<TelemetryService>()

companion object {
Expand All @@ -24,7 +25,7 @@ class TelemetryService(private val cs: CoroutineScope) {
}

private val service: Telemetry =
if (application.isInternal) {
if (isDevelopmentInstance) {
LoggerTelemetryService()
} else {
MeasurementProtocolService(
Expand All @@ -48,7 +49,7 @@ class TelemetryService(private val cs: CoroutineScope) {
source != null &&
source is String &&
TelemetryEventSource.isValidSource(source) &&
application.isInternal
isDevelopmentInstance
) {
logger.error("source has to be of type TelemetryEventSource")
return
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package dev.nx.console.utils

import com.intellij.openapi.application.PathManager

fun isDevelopmentInstance(): Boolean {
val configPath = PathManager.getConfigPath()

return configPath.contains("idea-sandbox")
}
Loading