@@ -25,7 +25,6 @@ import com.intellij.psi.PsiDocumentManager
25
25
import com.intellij.psi.PsiElement
26
26
import com.intellij.psi.util.elementType
27
27
import com.intellij.psi.util.startOffset
28
- import com.intellij.util.io.URLUtil
29
28
import dev.robotcode.robotcode4ij.RobotSuiteFileType
30
29
import dev.robotcode.robotcode4ij.buildRobotCodeCommandLine
31
30
import dev.robotcode.robotcode4ij.psi.IRobotFrameworkElementType
@@ -38,10 +37,9 @@ import kotlinx.coroutines.launch
38
37
import kotlinx.coroutines.runBlocking
39
38
import kotlinx.serialization.encodeToString
40
39
import kotlinx.serialization.json.Json
41
- import java.net.URI
40
+ import java.nio.file.Paths
42
41
import java.util.*
43
42
44
-
45
43
@Service(Service .Level .PROJECT ) class RobotCodeTestManager (private val project : Project ) : Disposable, DocumentListener,
46
44
AsyncFileListener ,
47
45
FileEditorManagerListener {
@@ -229,7 +227,7 @@ import java.util.*
229
227
arrayOf(* defaultPaths, " discover" , " --read-from-stdin" , " all" ), format = " json"
230
228
).withCharset(Charsets .UTF_8 ).withWorkDirectory(project.basePath)
231
229
232
- var openFiles = mutableMapOf<String , String >()
230
+ val openFiles = mutableMapOf<String , String >()
233
231
234
232
ApplicationManager .getApplication().runReadAction {
235
233
FileEditorManagerEx .getInstanceEx(project).openFiles.forEach { file ->
@@ -239,7 +237,7 @@ import java.util.*
239
237
}
240
238
}
241
239
242
- var openFilesAsString = Json .encodeToString(openFiles)
240
+ val openFilesAsString = Json .encodeToString(openFiles)
243
241
244
242
val result = CapturingProcessHandler (cmdLine).apply {
245
243
process.outputStream.bufferedWriter().apply {
@@ -276,11 +274,11 @@ import java.util.*
276
274
): RobotCodeTestItem ? {
277
275
278
276
if (line == null ) {
279
- if (root.uri == uri ) {
277
+ if (root.isSameUri( uri) ) {
280
278
return root
281
279
}
282
280
} else {
283
- if (root.uri == uri && root.range != null && root.range.start.line == line) {
281
+ if (root.isSameUri( uri) && root.range != null && root.range.start.line == line) {
284
282
return root
285
283
}
286
284
}
@@ -334,9 +332,23 @@ import java.util.*
334
332
}
335
333
}
336
334
335
+ private fun getRfcCompliantUri (virtualFile : VirtualFile ): String {
336
+ val filePath = virtualFile.path
337
+
338
+ val normalizedPath = if (isWindows()) {
339
+ filePath.replace(" \\ " , " /" )
340
+ } else {
341
+ filePath
342
+ }
343
+
344
+ return Paths .get(normalizedPath).toUri().toString()
345
+ }
346
+
347
+ private fun isWindows (): Boolean = System .getProperty(" os.name" ).lowercase().contains(" win" )
348
+
337
349
val VirtualFile .uri: String
338
350
get() {
339
- return URI .create(fileSystem.protocol + URLUtil . SCHEME_SEPARATOR + " / " + path.replace( " : " , " %3A " )).toString( )
351
+ return getRfcCompliantUri( this )
340
352
}
341
353
342
354
val Project .testManger: RobotCodeTestManager
0 commit comments