Skip to content

Commit 39a7284

Browse files
authored
feat(intellij): show information message when running a debug configuration (#2141)
1 parent 8d68e8e commit 39a7284

File tree

1 file changed

+57
-1
lines changed

1 file changed

+57
-1
lines changed

apps/intellij/src/main/kotlin/dev/nx/console/run/NxCommandLineState.kt

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import com.intellij.execution.process.ProcessTerminatedListener
77
import com.intellij.execution.runners.ExecutionEnvironment
88
import com.intellij.execution.target.value.TargetValue
99
import com.intellij.execution.wsl.WslPath
10+
import com.intellij.ide.util.PropertiesComponent
1011
import com.intellij.javascript.debugger.CommandLineDebugConfigurator
1112
import com.intellij.javascript.nodejs.NodeCommandLineUtil
1213
import com.intellij.javascript.nodejs.NodeCommandLineUtil.createConsole
@@ -15,8 +16,13 @@ import com.intellij.javascript.nodejs.execution.NodeBaseRunProfileState
1516
import com.intellij.javascript.nodejs.execution.NodeTargetRun
1617
import com.intellij.javascript.nodejs.execution.NodeTargetRunOptions
1718
import com.intellij.javascript.nodejs.npm.*
19+
import com.intellij.notification.NotificationAction
20+
import com.intellij.openapi.diagnostic.thisLogger
1821
import com.intellij.openapi.project.Project
22+
import com.intellij.openapi.ui.MessageType
23+
import com.intellij.openapi.wm.ToolWindowManager
1924
import com.intellij.util.execution.ParametersListUtil
25+
import com.intellij.xdebugger.impl.XDebuggerManagerImpl
2026
import dev.nx.console.telemetry.TelemetryService
2127
import dev.nx.console.utils.*
2228

@@ -57,7 +63,57 @@ class NxCommandLineState(
5763
"${nxProjects.first()}:${nxTargets.first()}${if(nxTargetsConfiguration.isBlank().not()) ":$nxTargetsConfiguration" else ""}"
5864
)
5965

60-
if (configurator === null) {
66+
if (configurator === null || configurator is CommandLineDebugConfigurator) {
67+
try {
68+
val hideNotificationPropertyKey =
69+
"dev.nx.console.hide_debug_source_map_notification"
70+
val lastNotificationTimeKey =
71+
"dev.nx.console.last_debug_source_map_notification_time"
72+
73+
val shouldHideNotification =
74+
PropertiesComponent.getInstance(project).getBoolean(hideNotificationPropertyKey)
75+
76+
// we don't want to spam users with notification but only show it in the correct
77+
// context
78+
val debugToolwindowIsVisible =
79+
ToolWindowManager.getInstance(project)
80+
.getToolWindow(XDebuggerManagerImpl.getNotificationGroup().toolWindowId)
81+
?.isVisible
82+
?: false
83+
84+
val currentTime = System.currentTimeMillis()
85+
val lastNotificationTime =
86+
PropertiesComponent.getInstance(project).getLong(lastNotificationTimeKey, 0)
87+
val tenMinutesPassed = (currentTime - lastNotificationTime) > 600000
88+
89+
if (!shouldHideNotification && debugToolwindowIsVisible && tenMinutesPassed) {
90+
val notification =
91+
XDebuggerManagerImpl.getNotificationGroup()
92+
.createNotification(
93+
"For debugging to work with Nx Console, pl" +
94+
"ease ensure source maps are generated by the underlying tooling.",
95+
MessageType.INFO
96+
)
97+
notification.addActions(
98+
setOf(
99+
NotificationAction.createSimpleExpiring("OK") { notification.expire() },
100+
NotificationAction.createSimpleExpiring("Don't show again") {
101+
notification.expire()
102+
PropertiesComponent.getInstance(project)
103+
.setValue(hideNotificationPropertyKey, true)
104+
}
105+
)
106+
)
107+
notification.notify(project)
108+
PropertiesComponent.getInstance(project)
109+
.setValue(lastNotificationTimeKey, currentTime.toString())
110+
}
111+
} catch (e: Throwable) {
112+
// this is a completely un-critical operation, so we don't care if something goes
113+
// wrong during it
114+
thisLogger().debug("Failed to show source map notification", e)
115+
}
116+
61117
TelemetryService.getInstance(project)
62118
.featureUsed("Nx Run - from context menu/target list/codelens - debug")
63119
} else {

0 commit comments

Comments
 (0)