Skip to content

Commit f8622ef

Browse files
committed
fix(intellij): stabilized getting the correct python sdk for a project
1 parent a90ce60 commit f8622ef

File tree

3 files changed

+24
-11
lines changed

3 files changed

+24
-11
lines changed

intellij-client/src/main/kotlin/dev/robotcode/robotcode4ij/RobotCodeHelpers.kt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import com.intellij.openapi.application.ApplicationManager
66
import com.intellij.openapi.application.PathManager
77
import com.intellij.openapi.diagnostic.thisLogger
88
import com.intellij.openapi.project.Project
9+
import com.intellij.openapi.project.modules
910
import com.intellij.openapi.util.Key
1011
import com.jetbrains.python.sdk.pythonSdk
1112
import java.nio.file.Path
@@ -26,14 +27,21 @@ class RobotCodeHelpers {
2627
}
2728
}
2829

30+
val Project.robotPythonSdk: com.intellij.openapi.projectRoots.Sdk?
31+
get() {
32+
return this.pythonSdk ?: this.projectFile?.let {
33+
this.modules.firstNotNullOfOrNull { it.pythonSdk }
34+
}
35+
}
36+
2937
fun Project.checkPythonAndRobotVersion(reset: Boolean = false): Boolean {
3038
if (!reset && this.getUserData(RobotCodeHelpers.PYTHON_AND_ROBOT_OK_KEY) == true) {
3139
return true
3240
}
3341

3442
val result = ApplicationManager.getApplication().executeOnPooledThread<Boolean> {
3543

36-
val pythonInterpreter = this.pythonSdk?.homePath
44+
val pythonInterpreter = this.robotPythonSdk?.homePath
3745

3846
if (pythonInterpreter == null) {
3947
thisLogger().info("No Python Interpreter defined for project '${this.name}'")
@@ -93,7 +101,7 @@ fun Project.buildRobotCodeCommandLine(
93101
throw IllegalArgumentException("PythonSDK is not defined or robot version is not valid for project ${this.name}")
94102
}
95103

96-
val pythonInterpreter = this.pythonSdk?.homePath
104+
val pythonInterpreter = this.robotPythonSdk?.homePath
97105
val commandLine = GeneralCommandLine(
98106
pythonInterpreter,
99107
"-u",
Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package dev.robotcode.robotcode4ij
22

3-
import com.intellij.openapi.Disposable
43
import com.intellij.openapi.project.Project
54
import com.intellij.openapi.startup.ProjectActivity
65
import com.intellij.openapi.vfs.VirtualFileManager
@@ -13,12 +12,12 @@ import dev.robotcode.robotcode4ij.testing.testManger
1312
import kotlinx.coroutines.flow.collect
1413
import kotlinx.coroutines.flow.onEach
1514

16-
class RobotCodePostStartupActivity : ProjectActivity, Disposable {
15+
class RobotCodePostStartupActivity : ProjectActivity {
1716
override suspend fun execute(project: Project) {
1817
project.langServerManager.start()
1918
project.testManger.refresh()
2019

21-
VirtualFileManager.getInstance().addAsyncFileListener(RobotCodeVirtualFileListener(project), this)
20+
VirtualFileManager.getInstance().addAsyncFileListener(RobotCodeVirtualFileListener(project), project.testManger)
2221

2322
project.workspaceModel.eventLog.onEach {
2423
val moduleChanges = it.getChanges(ModuleEntity::class.java)
@@ -29,10 +28,5 @@ class RobotCodePostStartupActivity : ProjectActivity, Disposable {
2928
}
3029
}.collect()
3130
}
32-
33-
override fun dispose() {
34-
// do nothing
35-
}
36-
3731
}
3832

intellij-client/src/main/kotlin/dev/robotcode/robotcode4ij/testing/RobotCodeTestManager.kt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,13 @@ import java.util.*
115115
}
116116
}
117117

118-
119118
private val refreshScope = CoroutineScope(Dispatchers.Default)
120119

121120
fun refreshDebounced(file: VirtualFile) {
121+
if (!project.isOpen || project.isDisposed) {
122+
return
123+
}
124+
122125
val job = refreshJobs[file]
123126

124127
if (job != null) {
@@ -137,6 +140,10 @@ import java.util.*
137140
}
138141

139142
fun refreshDebounced() {
143+
if (!project.isOpen || project.isDisposed) {
144+
return
145+
}
146+
140147
refreshJobs.values.forEach { it.cancel() }
141148
refreshJob?.cancel()
142149

@@ -148,6 +155,10 @@ import java.util.*
148155
}
149156

150157
fun refresh(uri: String) {
158+
if (!project.isOpen || project.isDisposed) {
159+
return
160+
}
161+
151162
thisLogger().info("Refreshing test items for $uri")
152163
try {
153164
val testItem = findTestItem(uri) ?: return

0 commit comments

Comments
 (0)