Skip to content

Commit

Permalink
fix(intellij): show better warning & help when no node interpreter is…
Browse files Browse the repository at this point in the history
… selected
  • Loading branch information
MaxKless committed Sep 11, 2024
1 parent 6c97180 commit 7cf7d02
Showing 1 changed file with 83 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.intellij.ide.DefaultTreeExpander
import com.intellij.ide.TreeExpander
import com.intellij.ide.actions.RefreshAction
import com.intellij.ide.util.PropertiesComponent
import com.intellij.javascript.nodejs.settings.NodeSettingsConfigurable
import com.intellij.openapi.actionSystem.*
import com.intellij.openapi.actionSystem.impl.SimpleDataContext
import com.intellij.openapi.application.EDT
Expand Down Expand Up @@ -35,6 +36,7 @@ import dev.nx.console.telemetry.TelemetryEvent
import dev.nx.console.telemetry.TelemetryEventSource
import dev.nx.console.telemetry.TelemetryService
import dev.nx.console.utils.ProjectLevelCoroutineHolderService
import dev.nx.console.utils.nodeInterpreter
import java.awt.*
import java.awt.event.ActionEvent
import java.net.URI
Expand All @@ -51,6 +53,7 @@ class NxToolWindowPanel(private val project: Project) : SimpleToolWindowPanel(tr

private val projectTreeComponent = ScrollPaneFactory.createScrollPane(projectTree, 0)
private val noProjectsComponent = createNoProjectsComponent()
private val noNodeInterpreterComponent = createNoNodeInterpreterComponent()
private val toolBar = createToolbar()
private var errorCountAndComponent: Pair<Int, JComponent>? = null

Expand All @@ -59,23 +62,23 @@ class NxToolWindowPanel(private val project: Project) : SimpleToolWindowPanel(tr
with(project.messageBus.connect()) {
subscribe(
NxlsService.NX_WORKSPACE_REFRESH_TOPIC,
NxWorkspaceRefreshListener { invokeLater { setToolwindowContent() } }
NxWorkspaceRefreshListener { invokeLater { setToolwindowContent() } },
)
subscribe(
NX_TOOLWINDOW_STYLE_SETTING_TOPIC,
object : NxToolWindowStyleSettingListener {
override fun onNxToolWindowStyleChange() {
invokeLater { setToolwindowContent() }
}
}
},
)
subscribe(
ToggleNxCloudViewAction.NX_TOOLWINDOW_CLOUD_VIEW_COLLAPSED_TOPIC,
object : ToggleNxCloudViewAction.NxToolwindowCloudViewCollapsedListener {
override fun onCloudViewCollapsed() {
invokeLater { setToolwindowContent() }
}
}
},
)
}
}
Expand All @@ -89,8 +92,17 @@ class NxToolWindowPanel(private val project: Project) : SimpleToolWindowPanel(tr

withContext(Dispatchers.EDT) {
val hasProjects = workspace?.workspace?.projects?.isNotEmpty() == true
val hasNodeInterpreter =
try {
project.nodeInterpreter
true
} catch (e: Exception) {
false
}
val mainContent: JComponent =
if (
if (!hasNodeInterpreter) {
noNodeInterpreterComponent
} else if (
workspace?.let {
!it.errors.isNullOrEmpty() && (it.isPartial != true || !hasProjects)
} == true
Expand All @@ -115,7 +127,7 @@ class NxToolWindowPanel(private val project: Project) : SimpleToolWindowPanel(tr
createContentWithCloud(
mainContent,
cloudStatus?.isConnected,
cloudStatus?.nxCloudUrl
cloudStatus?.nxCloudUrl,
)
)

Expand Down Expand Up @@ -155,7 +167,9 @@ class NxToolWindowPanel(private val project: Project) : SimpleToolWindowPanel(tr
TelemetryService.getInstance(project)
.featureUsed(
TelemetryEvent.MISC_REFRESH_WORKSPACE,
mapOf("source" to TelemetryEventSource.WELCOME_VIEW)
mapOf(
"source" to TelemetryEventSource.WELCOME_VIEW
),
)
NxRefreshWorkspaceService.getInstance(project)
.refreshWorkspace()
Expand All @@ -177,7 +191,7 @@ class NxToolWindowPanel(private val project: Project) : SimpleToolWindowPanel(tr
ShowSettingsUtil.getInstance()
.showSettingsDialog(
project,
NxConsoleSettingsConfigurable::class.java
NxConsoleSettingsConfigurable::class.java,
)
} else {
Desktop.getDesktop().browse(URI.create(it.description))
Expand Down Expand Up @@ -219,7 +233,7 @@ class NxToolWindowPanel(private val project: Project) : SimpleToolWindowPanel(tr
AnActionEvent.createFromDataContext(
NX_TOOLBAR_PLACE,
null,
dataContext
dataContext,
)
action.actionPerformed(actionEvent)
} else {
Expand All @@ -231,6 +245,60 @@ class NxToolWindowPanel(private val project: Project) : SimpleToolWindowPanel(tr
}
}

private fun createNoNodeInterpreterComponent(): JComponent {
return JPanel().apply {
layout = BoxLayout(this, BoxLayout.Y_AXIS)

add(
JPanel().apply {
layout = BoxLayout(this, BoxLayout.Y_AXIS)
border = BorderFactory.createEmptyBorder(10, 10, 10, 10)

add(
JLabel(
"<html><h3>Node.js interpreter not configured.</h3> Nx Console needs this setting to start the Nx language server & run Nx processes.</html>"
)
.apply { alignmentX = Component.CENTER_ALIGNMENT }
)

add(Box.createRigidArea(Dimension(0, 10)))

add(
JButton("Configure Node interpreter").apply {
action =
object : AbstractAction("Configure Node interpreter") {
override fun actionPerformed(e: java.awt.event.ActionEvent?) {
ShowSettingsUtil.getInstance()
.showSettingsDialog(
project,
NodeSettingsConfigurable::class.java,
)
}
}
alignmentX = Component.CENTER_ALIGNMENT
}
)
add(Box.createRigidArea(Dimension(0, 10)))

add(
panel {
row {
text(
"Please configure the Node interpreter and then <a href='refresh'>refresh the workspace</a>"
) {
if (it.description == "refresh") {
NxRefreshWorkspaceService.getInstance(project)
.refreshWorkspace()
}
}
}
}
)
}
)
}
}

private fun createToolbar(): ActionToolbar {
return run {
val actionManager = ActionManager.getInstance()
Expand All @@ -245,7 +313,7 @@ class NxToolWindowPanel(private val project: Project) : SimpleToolWindowPanel(tr
RefreshAction(
"Reload Nx Projects",
"Reload Nx projects",
AllIcons.Actions.Refresh
AllIcons.Actions.Refresh,
) {
override fun getActionUpdateThread() = ActionUpdateThread.BGT

Expand Down Expand Up @@ -309,7 +377,7 @@ class NxToolWindowPanel(private val project: Project) : SimpleToolWindowPanel(tr
private fun createContentWithCloud(
mainContent: JComponent,
isConnectedToCloud: Boolean?,
nxCloudUrl: String?
nxCloudUrl: String?,
): JComponent {
val cloudPanelCollapsed = getCloudPanelCollapsed(project)
if (cloudPanelCollapsed) {
Expand All @@ -332,8 +400,8 @@ class NxToolWindowPanel(private val project: Project) : SimpleToolWindowPanel(tr
0,
0,
0,
JBColor.border()
)
JBColor.border(),
),
)

add(JLabel().apply { icon = AllIcons.RunConfigurations.TestPassed })
Expand Down Expand Up @@ -374,7 +442,7 @@ class NxToolWindowPanel(private val project: Project) : SimpleToolWindowPanel(tr
border =
CompoundBorder(
BorderFactory.createMatteBorder(1, 0, 0, 0, JBColor.border()),
JBUI.Borders.empty(5, 10, 0, 10)
JBUI.Borders.empty(5, 10, 0, 10),
)

add(
Expand Down Expand Up @@ -443,7 +511,7 @@ class ToggleNxCloudViewAction : ToggleAction("Show Nx Cloud Panel") {
val project = e.project ?: return
NxToolWindowPanel.setCloudPanelCollapsed(
project,
!NxToolWindowPanel.getCloudPanelCollapsed(project)
!NxToolWindowPanel.getCloudPanelCollapsed(project),
)
project.messageBus
.syncPublisher(NX_TOOLWINDOW_CLOUD_VIEW_COLLAPSED_TOPIC)
Expand All @@ -466,7 +534,7 @@ class ToggleNxCloudViewAction : ToggleAction("Show Nx Cloud Panel") {
Topic<NxToolwindowCloudViewCollapsedListener> =
Topic(
"NxToolwindowCloudViewCollapsedTopic",
NxToolwindowCloudViewCollapsedListener::class.java
NxToolwindowCloudViewCollapsedListener::class.java,
)
}

Expand Down

0 comments on commit 7cf7d02

Please sign in to comment.