Skip to content

Commit

Permalink
fix AccessDeniedException
Browse files Browse the repository at this point in the history
  • Loading branch information
reymondzzzz committed Dec 4, 2023
1 parent 5e34ab5 commit 3379da9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ dependencies {


group = "com.smallcloud"
version = getVersionString("1.2.4")
version = getVersionString("1.2.5")

repositories {
mavenCentral()
Expand Down
30 changes: 20 additions & 10 deletions src/main/kotlin/com/smallcloud/refactai/lsp/LSPProcessHolder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import com.intellij.openapi.Disposable
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.util.SystemInfo
import com.intellij.util.SystemProperties.getUserHome
import com.intellij.openapi.util.io.FileUtil.getTempDirectory
import com.intellij.openapi.util.io.FileUtil.setExecutable
import com.intellij.util.concurrency.AppExecutorUtil
import com.intellij.util.messages.MessageBus
import com.intellij.util.messages.Topic
Expand Down Expand Up @@ -99,9 +100,7 @@ class LSPProcessHolder: Disposable {
val path = Paths.get(BIN_PATH)
path.parent.toFile().mkdirs()
Files.copy(input, path, StandardCopyOption.REPLACE_EXISTING)
if (!SystemInfo.isWindows) {
GeneralCommandLine(listOf("chmod", "+x", BIN_PATH)).createProcess()
}
setExecutable(path.toFile())
}
}
settingsChanged()
Expand Down Expand Up @@ -158,10 +157,22 @@ class LSPProcessHolder: Disposable {
terminate()
if (lastConfig == null || !lastConfig!!.isValid) return
logger.warn("LSP start_process " + BIN_PATH + " " + lastConfig!!.toArgs())
process = GeneralCommandLine(listOf(BIN_PATH) + lastConfig!!.toArgs())
.withRedirectErrorStream(true)
.createProcess()
process!!.waitFor(3, TimeUnit.SECONDS)
var attempt = 0
while (attempt < 5) {
try {
process = GeneralCommandLine(listOf(BIN_PATH) + lastConfig!!.toArgs())
.withRedirectErrorStream(true)
.createProcess()
process!!.waitFor(3, TimeUnit.SECONDS)
break
} catch (e: Exception) {
attempt++
logger.warn("LSP start_process didn't start attempt=${attempt}")
if (attempt == 5) {
throw e
}
}
}
loggerTask = scheduler.submit {
val reader = process!!.inputStream.bufferedReader()
var line = reader.readLine()
Expand Down Expand Up @@ -201,8 +212,7 @@ class LSPProcessHolder: Disposable {
}

companion object {
private val BIN_PATH = Path(getUserHome(), ".refact", "bin",
"refact-lsp${getExeSuffix()}").toString()
private val BIN_PATH = Path(getTempDirectory(), "refact-lsp${getExeSuffix()}").toString()
@JvmStatic
val instance: LSPProcessHolder
get() = ApplicationManager.getApplication().getService(LSPProcessHolder::class.java)
Expand Down

0 comments on commit 3379da9

Please sign in to comment.