16
16
*/
17
17
package spp.jetbrains.sourcemarker.service.instrument.breakpoint.tree
18
18
19
- import com.intellij.lang.Language
20
- import com.intellij.openapi.application.ApplicationInfo
21
- import com.intellij.openapi.fileEditor.FileEditorManager
22
- import com.intellij.openapi.project.ProjectManager
23
- import com.intellij.psi.PsiManager
24
19
import com.intellij.ui.treeStructure.SimpleNode
25
20
import com.intellij.util.containers.hash.LinkedHashMap
26
21
import spp.jetbrains.marker.js.JavascriptVariableRootNode
27
22
import spp.jetbrains.marker.jvm.JVMVariableSimpleNode
28
23
import spp.jetbrains.marker.py.PythonVariableRootNode
29
- import spp.jetbrains.sourcemarker.activities.PluginSourceMarkerStartupActivity.Companion.PYCHARM_PRODUCT_CODES
30
24
import spp.jetbrains.sourcemarker.service.instrument.breakpoint.StackFrameManager
25
+ import spp.protocol.artifact.ArtifactLanguage
31
26
import spp.protocol.instrument.variable.LiveVariableScope
32
27
33
28
/* *
@@ -53,57 +48,48 @@ class VariableRootSimpleNode : SimpleNode() {
53
48
NO_CHILDREN
54
49
} else {
55
50
val vars = stackFrameManager.currentFrame!! .variables
56
-
57
- // todo: get language via LiveStackTrace
58
- var language: Language ? = null
59
- val project = ProjectManager .getInstance().openProjects.first()
60
- val manager = FileEditorManager .getInstance(project)
61
- val selectedFile = manager.selectedFiles.firstOrNull()
62
- if (selectedFile != null ) {
63
- val psiFile = PsiManager .getInstance(project).findFile(selectedFile)
64
- if (psiFile != null ) {
65
- language = psiFile.language
66
- }
67
- }
68
- if (language?.id == " ECMAScript 6" ) {
69
- return arrayOf(
70
- JavascriptVariableRootNode (
71
- vars.filter { it.scope == LiveVariableScope .LOCAL_VARIABLE },
72
- LiveVariableScope .LOCAL_VARIABLE
73
- ),
74
- JavascriptVariableRootNode (
75
- vars.filter { it.scope == LiveVariableScope .GLOBAL_VARIABLE },
76
- LiveVariableScope .GLOBAL_VARIABLE
51
+ when (stackFrameManager.stackTrace.language) {
52
+ ArtifactLanguage .NODEJS -> {
53
+ return arrayOf(
54
+ JavascriptVariableRootNode (
55
+ vars.filter { it.scope == LiveVariableScope .LOCAL_VARIABLE },
56
+ LiveVariableScope .LOCAL_VARIABLE
57
+ ),
58
+ JavascriptVariableRootNode (
59
+ vars.filter { it.scope == LiveVariableScope .GLOBAL_VARIABLE },
60
+ LiveVariableScope .GLOBAL_VARIABLE
61
+ )
77
62
)
78
- )
79
- }
63
+ }
80
64
81
- val productCode = ApplicationInfo .getInstance().build.productCode
82
- if ( PYCHARM_PRODUCT_CODES .contains(productCode)) {
83
- return arrayOf (
84
- PythonVariableRootNode (
85
- vars.filter { it.scope == LiveVariableScope .GLOBAL_VARIABLE },
86
- LiveVariableScope . GLOBAL_VARIABLE
87
- ),
88
- PythonVariableRootNode (
89
- vars.filter { it.scope == LiveVariableScope .LOCAL_VARIABLE },
90
- LiveVariableScope . LOCAL_VARIABLE
65
+ ArtifactLanguage . PYTHON -> {
66
+ return arrayOf(
67
+ PythonVariableRootNode (
68
+ vars.filter { it.scope == LiveVariableScope . GLOBAL_VARIABLE },
69
+ LiveVariableScope .GLOBAL_VARIABLE
70
+ ),
71
+ PythonVariableRootNode (
72
+ vars.filter { it.scope == LiveVariableScope . LOCAL_VARIABLE },
73
+ LiveVariableScope .LOCAL_VARIABLE
74
+ )
91
75
)
92
- )
93
- } else {
94
- val simpleNodeMap: MutableMap <String , JVMVariableSimpleNode > = LinkedHashMap ()
95
- vars.forEach {
96
- if (it.name.isNotEmpty()) {
97
- simpleNodeMap[it.name] = JVMVariableSimpleNode (it, mutableMapOf ())
98
- }
99
76
}
100
- simpleNodeMap.values.sortedWith { p0, p1 ->
101
- when {
102
- p0.variable.name == " this" -> - 1
103
- p1.variable.name == " this" -> 1
104
- else -> 0
77
+
78
+ else -> {
79
+ val simpleNodeMap: MutableMap <String , JVMVariableSimpleNode > = LinkedHashMap ()
80
+ vars.forEach {
81
+ if (it.name.isNotEmpty()) {
82
+ simpleNodeMap[it.name] = JVMVariableSimpleNode (it, mutableMapOf ())
83
+ }
105
84
}
106
- }.toTypedArray()
85
+ simpleNodeMap.values.sortedWith { p0, p1 ->
86
+ when {
87
+ p0.variable.name == " this" -> - 1
88
+ p1.variable.name == " this" -> 1
89
+ else -> 0
90
+ }
91
+ }.toTypedArray()
92
+ }
107
93
}
108
94
}
109
95
}
0 commit comments