1
1
package com.wsl.symlinks.vfs
2
2
3
3
import ai.grazie.utils.WeakHashMap
4
+ import com.intellij.ide.AppLifecycleListener
4
5
import com.intellij.openapi.components.service
6
+ import com.intellij.openapi.diagnostic.Attachment
5
7
import com.intellij.openapi.diagnostic.DefaultLogger
6
8
import com.intellij.openapi.diagnostic.Logger
7
9
import com.intellij.openapi.util.io.FileAttributes
8
10
import com.intellij.openapi.vfs.VirtualFile
9
11
import com.intellij.openapi.vfs.VirtualFileManager
10
12
import com.intellij.openapi.vfs.VirtualFileSystem
13
+ import com.intellij.openapi.vfs.impl.VirtualFileManagerImpl
11
14
import com.intellij.openapi.vfs.impl.local.LocalFileSystemImpl
12
15
import com.intellij.platform.workspace.storage.url.VirtualFileUrl
13
16
import com.intellij.util.io.URLUtil
14
17
import java.io.*
15
- import java.util.ResourceBundle
16
18
import java.util.concurrent.LinkedBlockingQueue
19
+ import java.util.concurrent.TimeUnit
17
20
import java.util.concurrent.locks.ReentrantLock
18
21
import kotlin.concurrent.thread
19
22
import kotlin.concurrent.withLock
20
23
21
24
22
- class StartupListener {
23
-
25
+ class StartupListener : AppLifecycleListener {
26
+ override fun appFrameCreated (commandLineArgs : MutableList <String >) {
27
+ MyLogger .setup()
28
+ }
24
29
}
25
30
26
31
class MyLogger (category : String ): DefaultLogger(category) {
27
- override fun error (message : String? , t : Throwable ? , vararg details : String? ) {
28
32
33
+ override fun error (message : String? ) {
34
+ if (message?.contains(" >1 file system registered for protocol" ) == true ) {
35
+ return
36
+ }
37
+ super .error(message)
38
+ }
39
+
40
+ override fun error (message : String? , t : Throwable ? , vararg details : String? ) {
41
+ if (message?.contains(" >1 file system registered for protocol" ) == true ) {
42
+ return
43
+ }
44
+ super .error(message, t, * details)
29
45
}
30
46
31
47
companion object {
@@ -37,7 +53,6 @@ class MyLogger(category: String): DefaultLogger(category) {
37
53
}
38
54
39
55
val myResourceLock = ReentrantLock ()
40
- val xxx = MyLogger .setup()
41
56
42
57
class WslSymlinksProvider (distro : String ) {
43
58
@@ -47,10 +62,13 @@ class WslSymlinksProvider(distro: String) {
47
62
internal var value: String? = null
48
63
internal val condition = myResourceLock.newCondition()
49
64
fun getValue (): String? {
50
- while (value == null ) {
51
- myResourceLock.withLock {
52
- this .condition.await()
53
- }
65
+ var elapsed = 0
66
+ while (value == null && elapsed < 500 ) {
67
+ condition.await(10 , TimeUnit .MILLISECONDS )
68
+ elapsed + = 10
69
+ }
70
+ if (this .value == null ) {
71
+ throw Error (" failed to obtain file info for $request " )
54
72
}
55
73
return this .value
56
74
}
@@ -78,6 +96,12 @@ class WslSymlinksProvider(distro: String) {
78
96
this .processReader = reader;
79
97
this .processWriter = writer;
80
98
99
+ process.onExit().whenComplete { t, u ->
100
+ this .process = builder.start()
101
+ this .processReader = BufferedReader (InputStreamReader (process.inputStream))
102
+ this .processWriter = BufferedWriter (OutputStreamWriter (process.outputStream));
103
+ }
104
+
81
105
thread {
82
106
while (true ) {
83
107
val a = outQueue.take()
0 commit comments