Skip to content

Commit bd0dd8f

Browse files
committed
refactor: get lang from live stack trace
1 parent 45295a0 commit bd0dd8f

File tree

1 file changed

+38
-52
lines changed

1 file changed

+38
-52
lines changed

plugin/src/main/kotlin/spp/jetbrains/sourcemarker/service/instrument/breakpoint/tree/VariableRootSimpleNode.kt

Lines changed: 38 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,13 @@
1616
*/
1717
package spp.jetbrains.sourcemarker.service.instrument.breakpoint.tree
1818

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
2419
import com.intellij.ui.treeStructure.SimpleNode
2520
import com.intellij.util.containers.hash.LinkedHashMap
2621
import spp.jetbrains.marker.js.JavascriptVariableRootNode
2722
import spp.jetbrains.marker.jvm.JVMVariableSimpleNode
2823
import spp.jetbrains.marker.py.PythonVariableRootNode
29-
import spp.jetbrains.sourcemarker.activities.PluginSourceMarkerStartupActivity.Companion.PYCHARM_PRODUCT_CODES
3024
import spp.jetbrains.sourcemarker.service.instrument.breakpoint.StackFrameManager
25+
import spp.protocol.artifact.ArtifactLanguage
3126
import spp.protocol.instrument.variable.LiveVariableScope
3227

3328
/**
@@ -53,57 +48,48 @@ class VariableRootSimpleNode : SimpleNode() {
5348
NO_CHILDREN
5449
} else {
5550
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+
)
7762
)
78-
)
79-
}
63+
}
8064

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+
)
9175
)
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-
}
9976
}
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+
}
10584
}
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+
}
10793
}
10894
}
10995
}

0 commit comments

Comments
 (0)