Skip to content

Commit

Permalink
Merge pull request #634 from JetBrains/bug/debug-players
Browse files Browse the repository at this point in the history
Fix listing of Unity players in Attach to Unity Process dialog
  • Loading branch information
citizenmatt authored Jul 10, 2018
2 parents d6b8559 + aafff0b commit 8e55245
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.intellij.openapi.actionSystem.AnActionEvent
import com.jetbrains.rider.plugins.unity.util.UnityIcons
import com.jetbrains.rider.plugins.unity.run.attach.UnityProcessPickerDialog

class AttachToUnityProcessAction : AnAction(UnityIcons.Icons.AttachEditorDebugConfiguration) {
class AttachToUnityProcessAction : AnAction("Attach to Unity Process…", "", UnityIcons.Icons.AttachEditorDebugConfiguration) {
override fun actionPerformed(e: AnActionEvent) {
val project = e.project?: return

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,9 @@ import com.intellij.openapi.project.Project
import com.intellij.xdebugger.attach.XLocalAttachDebugger

class UnityAttachDebugger : XLocalAttachDebugger {

override fun getDebuggerDisplayName(): String {
return "Mono Debugger"
}
override fun getDebuggerDisplayName() = "Unity debugger"

override fun attachDebugSession(project: Project, processInfo: ProcessInfo) {
UnityRunUtil.runAttach(processInfo.pid, project)
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.jetbrains.rider.plugins.unity.run.attach

import com.intellij.execution.process.ProcessInfo
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.UserDataHolder
import com.intellij.xdebugger.attach.*

class UnityAttachDebuggerProvider : XAttachDebuggerProvider {
override fun getAvailableDebuggers(project: Project, host: XAttachHost, process: ProcessInfo, userData: UserDataHolder): MutableList<XAttachDebugger> {
if (UnityRunUtil.isUnityEditorProcess(process))
return mutableListOf(UnityAttachDebugger())
return mutableListOf()
}

override fun isAttachHostApplicable(host: XAttachHost) = host is LocalAttachHost
override fun getPresentationGroup(): XAttachPresentationGroup<ProcessInfo> = UnityAttachPresentationGroup
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.jetbrains.rider.plugins.unity.run.attach

import com.intellij.execution.process.ProcessInfo
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.UserDataHolder
import com.intellij.xdebugger.attach.XAttachProcessPresentationGroup
import com.jetbrains.rider.plugins.unity.util.UnityIcons

object UnityAttachPresentationGroup : XAttachProcessPresentationGroup {
override fun getOrder(): Int = 3
override fun getGroupName(): String = "Local Unity processes"
override fun getItemIcon(project: Project, process: ProcessInfo, userData: UserDataHolder) = UnityIcons.Icons.UnityLogo
override fun getItemDisplayText(project: Project, process: ProcessInfo, userData: UserDataHolder) = process.executableDisplayName
override fun compare(p1: ProcessInfo, p2: ProcessInfo) = p1.pid.compareTo(p2.pid)

override fun getProcessDisplayText(p0: Project, p1: ProcessInfo, p2: UserDataHolder) = throw UnsupportedOperationException("Should not use this method")
override fun getProcessIcon(p0: Project, p1: ProcessInfo, p2: UserDataHolder) = throw UnsupportedOperationException("Should not use this method")
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import javax.swing.Icon
class UnityLocalAttachConfiguration(override var port: Int, private val playerId: String, host: String = "127.0.0.1") : RemoteConfiguration, RunProfile, IDotNetDebuggable {

override fun getName(): String = playerId
override fun getIcon(): Icon = AllIcons.General.Debug
override fun getIcon(): Icon = AllIcons.Actions.StartDebugger

override fun getState(executor: Executor, environment: ExecutionEnvironment): RunProfileState? {
if (executor.id != DefaultDebugExecutor.EXECUTOR_ID)
Expand All @@ -23,5 +23,4 @@ class UnityLocalAttachConfiguration(override var port: Int, private val playerId

override var address: String = host
override var listenPortForConnections: Boolean = false

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,13 @@ import com.intellij.execution.configurations.RunProfileState
import com.intellij.execution.runners.ExecutionEnvironment
import com.jetbrains.rider.debugger.IDotNetDebuggable
import com.jetbrains.rider.plugins.unity.util.UnityIcons
import javax.swing.Icon

class UnityLocalAttachRunProfile(private val configurationName: String, private val configuration: UnityLocalAttachConfiguration) : RemoteRunProfile, IDotNetDebuggable {

override fun getState(p0: Executor, p1: ExecutionEnvironment): RunProfileState? {
return UnityLocalAttachProfileState(configuration, p1)
override fun getState(executor: Executor, executionEnvironment: ExecutionEnvironment): RunProfileState? {
return UnityLocalAttachProfileState(configuration, executionEnvironment)
}

override fun getName(): String {
return configurationName
}

override fun getIcon(): Icon {
return UnityIcons.Icons.AttachEditorDebugConfiguration
}
override fun getName() = configurationName
override fun getIcon() = UnityIcons.Icons.AttachEditorDebugConfiguration
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class UnityProcessListener(private val onPlayerAdded: (UnityPlayer?) -> Unit, pr
private val logger = Logger.getInstance(UnityProcessListener::class.java)
}

private val unityPlayerDescriptorRegex = Pattern.compile("\\[IP\\] (?<ip>.*) \\[Port\\] (?<port>.*) \\[Flags\\] (?<flags>.*) \\[Guid\\] (?<guid>.*) \\[EditorId\\] (?<editorid>.*) \\[Version\\] (?<version>.*) \\[Id\\] (?<id>[^:]+)(:(?<debuggerPort>\\d+))? \\[Debug\\] (?<debug>.*)")
private val unityPlayerDescriptorRegex = Pattern.compile("""\[IP] (?<ip>.*) \[Port] (?<port>.*) \[Flags] (?<flags>.*) \[Guid] (?<guid>.*) \[EditorId] (?<editorid>.*) \[Version] (?<version>.*) \[Id] (?<id>[^:]+)(:(?<debuggerPort>\\d+))? \[Debug] (?<debug>.*)""")

private val defaultHeartbeat = 30

Expand All @@ -30,9 +30,11 @@ class UnityProcessListener(private val onPlayerAdded: (UnityPlayer?) -> Unit, pr

init {
for (networkInterface in NetworkInterface.getNetworkInterfaces()) {
if (!networkInterface.isUp || !networkInterface.supportsMulticast() || !networkInterface.inetAddresses.hasMoreElements()
|| networkInterface.inetAddresses.nextElement() is Inet6Address) //TODO: remove this workaround by setting java.net.preferIPv4Stack to true
if (!networkInterface.isUp || !networkInterface.supportsMulticast()
|| !networkInterface.inetAddresses.asSequence().any { it is Inet4Address }) {
continue
}

synchronized(socketsLock) {
for (port in multicastPorts) {
try {
Expand All @@ -50,9 +52,9 @@ class UnityProcessListener(private val onPlayerAdded: (UnityPlayer?) -> Unit, pr
}
}

refreshTimer = kotlin.concurrent.timer("Listen for Unity Players", true, 0L, refreshPeriod, {
refreshTimer = kotlin.concurrent.timer("Listen for Unity Players", true, 0L, refreshPeriod) {
refreshUnityPlayersList()
})
}

OSProcessUtil.getProcessList().filter { UnityRunUtil.isUnityEditorProcess(it) }.map { processInfo ->
val port = convertPortToDebuggerPort(processInfo.pid)
Expand Down
7 changes: 4 additions & 3 deletions rider/src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
<projectViewPane implementation="com.jetbrains.rider.plugins.unity.explorer.UnityExplorer" id="UnityExplorer" order="first, before SolutionExplorer"/>
<projectModelViewUpdater implementation="com.jetbrains.rider.plugins.unity.explorer.UnityExplorerUpdater"/>

<xdebugger.localAttachDebuggerProvider implementation="com.jetbrains.rider.plugins.unity.run.attach.UnityAttachProvider"/>
<xdebugger.attachDebuggerProvider implementation="com.jetbrains.rider.plugins.unity.run.attach.UnityAttachDebuggerProvider" />
</extensions>

<project-components>
Expand Down Expand Up @@ -87,6 +87,7 @@
<action class="com.jetbrains.rider.plugins.unity.actions.UnityPluginShowSettingsAction" id="ShowUnitySettingsInRider" />
<action class="com.jetbrains.rider.plugins.unity.actions.ShowUnityLogInRiderAction" id="ShowUnityLogInRiderAction" />
<action class="com.jetbrains.rider.plugins.unity.ui.SwitchUIMode" id="SwitchUIModeAction" />
<action class="com.jetbrains.rider.plugins.unity.actions.AttachToUnityProcessAction" id="AttachToUnityProcessAction" />
</group>

<action id="TriggerRefreshInUnity" class="com.jetbrains.rider.plugins.unity.actions.RefreshInUnityAction" text="Trigger Refresh In Unity Editor" />
Expand All @@ -98,11 +99,11 @@
<add-to-group group-id="ActiveRuntimeGroup" relative-to-action="BuildSolutionAction" anchor="after" />
</group>

<action id="AttachToUnityProcess" class="com.jetbrains.rider.plugins.unity.actions.AttachToUnityProcessAction" text="Attach to Unity Process...">
<action id="AttachToUnityProcess" class="com.jetbrains.rider.plugins.unity.actions.AttachToUnityProcessAction">
<add-to-group group-id="XDebugger.AttachGroup" anchor="after" relative-to-action="XDebugger.AttachToLocalProcess" />
</action>

<action id="ShowReferencePropertiesAction" class="com.jetbrains.rider.plugins.unity.explorer.ShowReferencePropertiesAction" text="Properties...">
<action id="ShowReferencePropertiesAction" class="com.jetbrains.rider.plugins.unity.explorer.ShowReferencePropertiesAction" text="Properties">
<add-to-group group-id="SolutionExplorerPopupMenu" anchor="last" />
</action>

Expand Down

0 comments on commit 8e55245

Please sign in to comment.