fix: replace 'ProcessCancelledException' with 'CancellationException'

This commit is contained in:
Akash Yadav
2023-12-02 23:42:59 +05:30
parent 4de1a6acb2
commit 5d1faba441
7 changed files with 22 additions and 54 deletions
@@ -25,12 +25,12 @@ import com.itsaky.androidide.lsp.models.FailureType.COMPLETION
import com.itsaky.androidide.lsp.models.LSPFailure
import com.itsaky.androidide.lsp.util.setupLookupForCompletion
import com.itsaky.androidide.models.Position
import com.itsaky.androidide.progress.ProcessCancelledException
import com.itsaky.androidide.utils.ILogger
import io.github.rosemoe.sora.lang.completion.CompletionCancelledException
import io.github.rosemoe.sora.text.CharPosition
import io.github.rosemoe.sora.text.ContentReference
import java.nio.file.Path
import java.util.concurrent.CancellationException
/**
* Common implementation of completion provider which requests completions to provided language
@@ -75,12 +75,12 @@ internal class CommonCompletionProvider(
server.complete(params)
} catch (e: Throwable) {
if (e is ProcessCancelledException) {
if (e is CancellationException) {
log.debug("Completion process cancelled")
}
// Do not log if completion was interrupted or cancelled
if (!(e is ProcessCancelledException || e is CompletionCancelledException)) {
if (!(e is CancellationException || e is CompletionCancelledException)) {
if (!server.handleFailure(LSPFailure(COMPLETION, e))) {
log.error("Unable to compute completions", e)
}
@@ -17,19 +17,12 @@
package com.itsaky.androidide.lsp.java
import java.util.concurrent.CancellationException
/**
* Thrown when a compilation process is cancelled.
* @author Akash Yadav
*/
class CompilationCancellationException : java.lang.RuntimeException {
constructor() : super()
constructor(message: String?) : super(message)
constructor(message: String?, cause: Throwable?) : super(message, cause)
constructor(cause: Throwable?) : super(cause)
constructor(
message: String?,
cause: Throwable?,
enableSuppression: Boolean,
writableStackTrace: Boolean
) : super(message, cause, enableSuppression, writableStackTrace)
}
class CompilationCancellationException @JvmOverloads constructor(
override val cause: Throwable? = null
) : CancellationException()
@@ -18,8 +18,7 @@
package com.itsaky.androidide.lsp.java.utils
import com.itsaky.androidide.javac.services.CancelAbort
import com.itsaky.androidide.lsp.java.CompilationCancellationException
import com.itsaky.androidide.progress.ProcessCancelledException
import java.util.concurrent.CancellationException
/** @author Akash Yadav */
class CancelChecker {
@@ -32,10 +31,9 @@ class CancelChecker {
return false
}
return err is CancelAbort ||
err is CompilationCancellationException ||
err is ProcessCancelledException ||
isCancelled(err.cause)
return err is CancellationException ||
err is CancelAbort ||
isCancelled(err.cause)
}
}
}
@@ -17,6 +17,7 @@
package com.itsaky.androidide.progress
import java.util.concurrent.CancellationException
import java.util.concurrent.atomic.AtomicBoolean
/**
@@ -39,9 +40,9 @@ interface ICancelChecker {
fun isCancelled(): Boolean
/**
* Throw [ProcessCancelledException] if this process has been cancelled.
* Throw [CancellationException] if this process has been cancelled.
*/
@Throws(ProcessCancelledException::class)
@Throws(CancellationException::class)
fun abortIfCancelled()
open class Default(cancelled: Boolean = false) : ICancelChecker {
@@ -58,7 +59,7 @@ interface ICancelChecker {
override fun abortIfCancelled() {
if (isCancelled()) {
throw ProcessCancelledException()
throw CancellationException()
}
}
}
@@ -1,25 +0,0 @@
/*
* This file is part of AndroidIDE.
*
* AndroidIDE is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* AndroidIDE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with AndroidIDE. If not, see <https://www.gnu.org/licenses/>.
*/
package com.itsaky.androidide.progress
/**
* Thrown when a process is cancelled.
*
* @author Akash Yadav
*/
class ProcessCancelledException internal constructor() : RuntimeException()
@@ -19,6 +19,7 @@ package com.itsaky.androidide.progress
import com.itsaky.androidide.progress.ICancelChecker.Default
import java.util.WeakHashMap
import java.util.concurrent.CancellationException
/**
* @author Akash Yadav
@@ -54,7 +55,7 @@ class ProgressManager private constructor() {
val checker = threads[thisThread]
if (checker != null && checker.isCancelled()) {
threads.remove(thisThread)
throw ProcessCancelledException()
throw CancellationException()
}
}
}
@@ -22,7 +22,6 @@ import com.itsaky.androidide.eventbus.events.editor.DocumentCloseEvent
import com.itsaky.androidide.eventbus.events.editor.DocumentOpenEvent
import com.itsaky.androidide.eventbus.events.file.FileDeletionEvent
import com.itsaky.androidide.eventbus.events.file.FileRenameEvent
import com.itsaky.androidide.progress.ProcessCancelledException
import com.itsaky.androidide.progress.ProgressManager
import com.itsaky.androidide.projects.models.ActiveDocument
import com.itsaky.androidide.utils.ILogger
@@ -35,6 +34,7 @@ import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.Paths
import java.time.Instant
import java.util.concurrent.CancellationException
import java.util.concurrent.ConcurrentHashMap
/**
@@ -160,7 +160,7 @@ object FileManager {
} catch (noFile: java.nio.file.NoSuchFileException) {
log.warn("No such file", noFile)
"".reader().buffered()
} catch (cancelled: ProcessCancelledException) {
} catch (cancelled: CancellationException) {
"".reader().buffered()
}
}
@@ -171,7 +171,7 @@ object FileManager {
} catch (noFile: java.nio.file.NoSuchFileException) {
log.warn("No such file", noFile)
"".byteInputStream()
} catch (cancelled: ProcessCancelledException) {
} catch (cancelled: CancellationException) {
"".byteInputStream()
}
}
@@ -187,7 +187,7 @@ object FileManager {
} catch (noFile: java.nio.file.NoSuchFileException) {
log.warn("No such file", noFile)
""
} catch (cancelled: ProcessCancelledException) {
} catch (cancelled: CancellationException) {
""
}
}