diff --git a/editor/src/main/java/com/itsaky/androidide/editor/language/CommonCompletionProvider.kt b/editor/src/main/java/com/itsaky/androidide/editor/language/CommonCompletionProvider.kt index 00678787f..4ca5e650a 100644 --- a/editor/src/main/java/com/itsaky/androidide/editor/language/CommonCompletionProvider.kt +++ b/editor/src/main/java/com/itsaky/androidide/editor/language/CommonCompletionProvider.kt @@ -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) } diff --git a/lsp/java/src/main/java/com/itsaky/androidide/lsp/java/CompilationCancellationException.kt b/lsp/java/src/main/java/com/itsaky/androidide/lsp/java/CompilationCancellationException.kt index ccd96d007..82e42d24c 100644 --- a/lsp/java/src/main/java/com/itsaky/androidide/lsp/java/CompilationCancellationException.kt +++ b/lsp/java/src/main/java/com/itsaky/androidide/lsp/java/CompilationCancellationException.kt @@ -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() diff --git a/lsp/java/src/main/java/com/itsaky/androidide/lsp/java/utils/CancelChecker.kt b/lsp/java/src/main/java/com/itsaky/androidide/lsp/java/utils/CancelChecker.kt index ed80b4fea..1646c2c1a 100644 --- a/lsp/java/src/main/java/com/itsaky/androidide/lsp/java/utils/CancelChecker.kt +++ b/lsp/java/src/main/java/com/itsaky/androidide/lsp/java/utils/CancelChecker.kt @@ -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) } } } diff --git a/shared/src/main/java/com/itsaky/androidide/progress/ICancelChecker.kt b/shared/src/main/java/com/itsaky/androidide/progress/ICancelChecker.kt index bd8d822c0..059824966 100644 --- a/shared/src/main/java/com/itsaky/androidide/progress/ICancelChecker.kt +++ b/shared/src/main/java/com/itsaky/androidide/progress/ICancelChecker.kt @@ -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() } } } diff --git a/shared/src/main/java/com/itsaky/androidide/progress/ProcessCancelledException.kt b/shared/src/main/java/com/itsaky/androidide/progress/ProcessCancelledException.kt deleted file mode 100644 index 063a440b7..000000000 --- a/shared/src/main/java/com/itsaky/androidide/progress/ProcessCancelledException.kt +++ /dev/null @@ -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 . - */ - -package com.itsaky.androidide.progress - -/** - * Thrown when a process is cancelled. - * - * @author Akash Yadav - */ -class ProcessCancelledException internal constructor() : RuntimeException() diff --git a/shared/src/main/java/com/itsaky/androidide/progress/ProgressManager.kt b/shared/src/main/java/com/itsaky/androidide/progress/ProgressManager.kt index 921ea0f6e..759f9c01c 100644 --- a/shared/src/main/java/com/itsaky/androidide/progress/ProgressManager.kt +++ b/shared/src/main/java/com/itsaky/androidide/progress/ProgressManager.kt @@ -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() } } } \ No newline at end of file diff --git a/subprojects/projects/src/main/java/com/itsaky/androidide/projects/FileManager.kt b/subprojects/projects/src/main/java/com/itsaky/androidide/projects/FileManager.kt index 3c4f889c2..4aad21601 100644 --- a/subprojects/projects/src/main/java/com/itsaky/androidide/projects/FileManager.kt +++ b/subprojects/projects/src/main/java/com/itsaky/androidide/projects/FileManager.kt @@ -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) { "" } }