-
Notifications
You must be signed in to change notification settings - Fork 43
/
MayaAttachDebuggerProvider.kt
91 lines (71 loc) · 3.5 KB
/
MayaAttachDebuggerProvider.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package debugattach
import settings.ApplicationSettings
import utils.pathForPid
import com.intellij.execution.process.ProcessInfo
import com.intellij.openapi.project.Project
import com.intellij.openapi.projectRoots.Sdk
import com.intellij.openapi.util.IconLoader
import com.intellij.openapi.util.Key
import com.intellij.openapi.util.UserDataHolder
import com.intellij.xdebugger.attach.*
import com.jetbrains.python.sdk.PythonSdkType
import com.jetbrains.python.sdk.PythonSdkUtil
import javax.swing.Icon
private val mayaPathsKey = Key<MutableMap<Int, String>>("mayaPathsMap")
class MayaAttachDebuggerProvider : XAttachDebuggerProvider {
override fun getPresentationGroup(): XAttachPresentationGroup<ProcessInfo> {
return MayaAttachGroup.INSTANCE
}
override fun getAvailableDebuggers(project: Project, attachHost: XAttachHost, processInfo: ProcessInfo, userData: UserDataHolder): MutableList<XAttachDebugger> {
if (!processInfo.executableName.toLowerCase().contains("maya")) return mutableListOf()
val exePath = processInfo.executableCannonicalPath.let {
if (it.isPresent) it.get() else pathForPid(processInfo.pid) ?: return mutableListOf()
}.toLowerCase()
val currentSdk = ApplicationSettings.INSTANCE.mayaSdkMapping.values.firstOrNull {
exePath.contains(it.mayaPath.toLowerCase())
} ?: return mutableListOf()
val mayaPathMap = userData.getUserData(mayaPathsKey) ?: mutableMapOf()
mayaPathMap[processInfo.pid] = currentSdk.mayaPath
userData.putUserData(mayaPathsKey, mayaPathMap)
PythonSdkUtil.findSdkByPath(currentSdk.mayaPyPath)?.let {
return mutableListOf(MayaAttachDebugger(it, currentSdk))
}
return mutableListOf()
}
override fun isAttachHostApplicable(attachHost: XAttachHost): Boolean = attachHost is LocalAttachHost
}
private class MayaAttachDebugger(sdk: Sdk, private val mayaSdk: ApplicationSettings.SdkInfo) : XAttachDebugger {
private val mySdkHome: String? = sdk.homePath
private val myName: String = "${PythonSdkType.getInstance().getVersionString(sdk)} ($mySdkHome)"
override fun getDebuggerDisplayName(): String {
return myName
}
override fun attachDebugSession(project: Project, attachHost: XAttachHost, processInfo: ProcessInfo) {
val runner = MayaAttachToProcessDebugRunner(project, processInfo.pid, mySdkHome, mayaSdk)
runner.launch()
}
}
private class MayaAttachGroup : XAttachProcessPresentationGroup {
companion object {
val INSTANCE = MayaAttachGroup()
}
override fun getItemDisplayText(project: Project, processInfo: ProcessInfo, userData: UserDataHolder): String {
val mayaPaths = userData.getUserData(mayaPathsKey) ?: return processInfo.executableDisplayName
return mayaPaths[processInfo.pid] ?: processInfo.executableDisplayName
}
override fun getProcessDisplayText(project: Project, info: ProcessInfo, userData: UserDataHolder): String {
return getItemDisplayText(project, info, userData)
}
override fun getItemIcon(project: Project, processInfo: ProcessInfo, userData: UserDataHolder): Icon {
return IconLoader.getIcon("/icons/MayaCharm_ToolWindow.png", this::class.java)
}
override fun getProcessIcon(project: Project, info: ProcessInfo, userData: UserDataHolder): Icon {
return getItemIcon(project, info, userData)
}
override fun getGroupName(): String {
return "Maya"
}
override fun getOrder(): Int {
return -100
}
}