Skip to content

Commit 190122c

Browse files
committed
improve
try suppress errors
1 parent 17086c0 commit 190122c

File tree

2 files changed

+39
-9
lines changed

2 files changed

+39
-9
lines changed

src/main/kotlin/com/wsl/symlinks/vfs/WslVirtualFileSystem.kt

+33-9
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,47 @@
11
package com.wsl.symlinks.vfs
22

33
import ai.grazie.utils.WeakHashMap
4+
import com.intellij.ide.AppLifecycleListener
45
import com.intellij.openapi.components.service
6+
import com.intellij.openapi.diagnostic.Attachment
57
import com.intellij.openapi.diagnostic.DefaultLogger
68
import com.intellij.openapi.diagnostic.Logger
79
import com.intellij.openapi.util.io.FileAttributes
810
import com.intellij.openapi.vfs.VirtualFile
911
import com.intellij.openapi.vfs.VirtualFileManager
1012
import com.intellij.openapi.vfs.VirtualFileSystem
13+
import com.intellij.openapi.vfs.impl.VirtualFileManagerImpl
1114
import com.intellij.openapi.vfs.impl.local.LocalFileSystemImpl
1215
import com.intellij.platform.workspace.storage.url.VirtualFileUrl
1316
import com.intellij.util.io.URLUtil
1417
import java.io.*
15-
import java.util.ResourceBundle
1618
import java.util.concurrent.LinkedBlockingQueue
19+
import java.util.concurrent.TimeUnit
1720
import java.util.concurrent.locks.ReentrantLock
1821
import kotlin.concurrent.thread
1922
import kotlin.concurrent.withLock
2023

2124

22-
class StartupListener {
23-
25+
class StartupListener: AppLifecycleListener {
26+
override fun appFrameCreated(commandLineArgs: MutableList<String>) {
27+
MyLogger.setup()
28+
}
2429
}
2530

2631
class MyLogger(category: String): DefaultLogger(category) {
27-
override fun error(message: String?, t: Throwable?, vararg details: String?) {
2832

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)
2945
}
3046

3147
companion object {
@@ -37,7 +53,6 @@ class MyLogger(category: String): DefaultLogger(category) {
3753
}
3854

3955
val myResourceLock = ReentrantLock()
40-
val xxx = MyLogger.setup()
4156

4257
class WslSymlinksProvider(distro: String) {
4358

@@ -47,10 +62,13 @@ class WslSymlinksProvider(distro: String) {
4762
internal var value: String? = null
4863
internal val condition = myResourceLock.newCondition()
4964
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")
5472
}
5573
return this.value
5674
}
@@ -78,6 +96,12 @@ class WslSymlinksProvider(distro: String) {
7896
this.processReader = reader;
7997
this.processWriter = writer;
8098

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+
81105
thread {
82106
while (true) {
83107
val a = outQueue.take()

src/main/resources/META-INF/plugin.xml

+6
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ see <a href="https://github.com/patricklx/intellij-wsl-symlinks/blob/main/CHANGE
2222
<depends>com.intellij.modules.lang</depends>
2323
<depends>com.intellij.modules.platform</depends>
2424

25+
<applicationListeners>
26+
<listener
27+
class="com.wsl.symlinks.vfs.StartupListener"
28+
topic="com.intellij.ide.AppLifecycleListener"/>
29+
</applicationListeners>
30+
2531
<extensions defaultExtensionNs="com.intellij">
2632
<virtualFileSystem key="file" implementationClass="com.wsl.symlinks.vfs.WslVirtualFileSystem" order="first"/>
2733
</extensions>

0 commit comments

Comments
 (0)