fix: project initialization does not start if the project is closed and reopened quickly

This commit is contained in:
Akash Yadav
2022-12-24 22:29:53 +05:30
parent 7facb96a43
commit d97ba5e415
2 changed files with 16 additions and 91 deletions
@@ -95,11 +95,20 @@ abstract class ProjectHandlerActivity : BaseEditorActivity(), IProjectHandler {
startServices()
}
override fun onPause() {
super.onPause()
if (isFinishing) {
// reset these values here
// sometimes, when the IDE closed and reopened instantly, these values prevent initialization
// of the project
projectInitialized = false
cachedInitResult = null
}
}
override fun preDestroy() {
if (isDestroying) {
closeProject(false)
projectInitialized = false
cachedInitResult = null
}
super.preDestroy()
@@ -129,7 +138,6 @@ abstract class ProjectHandlerActivity : BaseEditorActivity(), IProjectHandler {
}
override fun startServices() {
val service = Lookup.DEFAULT.lookup(BuildService.KEY_BUILD_SERVICE) as GradleBuildService?
if (viewModel.isBoundToBuildSerice && service != null) {
log.info("Reusing already started Gradle build service")
@@ -162,10 +170,11 @@ abstract class ProjectHandlerActivity : BaseEditorActivity(), IProjectHandler {
}
val initialized = projectInitialized && cachedInitResult != null
log.debug("Is project initialized: $initialized")
// When returning after a configuration change between the initialization process,
// we do not want to start another project initialization
if (initialized && !wasInitializing) {
log.debug("Skipping init process because initialized && !wasInitializing")
return
}
@@ -180,10 +189,12 @@ abstract class ProjectHandlerActivity : BaseEditorActivity(), IProjectHandler {
val future =
if (!(isConfigChange && wasInitializing) && !initialized) {
log.debug("Sending init request to tooling server..")
buildService.initializeProject(projectDir.absolutePath)
} else {
// The project initialization was in progress before the configuration change
// In this case, we should not start another project initialization
log.debug("Using cached initialize result as the project is already initialized")
CompletableFuture.supplyAsync {
log.warn("Project has already been initialized. Skipping initialization process.")
cachedInitResult
@@ -228,6 +239,7 @@ abstract class ProjectHandlerActivity : BaseEditorActivity(), IProjectHandler {
protected open fun onProjectInitialized(result: InitializeResult) {
if (isConfigChange && projectInitialized && result == cachedInitResult) {
log.debug("Not setting up project as this a configuration change")
return
}
@@ -1,87 +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.editor.language.treesitter
import android.os.Bundle
import com.itsaky.androidide.editor.language.IDELanguage
import com.itsaky.androidide.editor.schemes.IDEColorSchemeProvider
import io.github.rosemoe.sora.editor.ts.TsLanguage
import io.github.rosemoe.sora.editor.ts.TsLanguageSpec
import io.github.rosemoe.sora.lang.completion.CompletionPublisher
import io.github.rosemoe.sora.lang.format.Formatter
import io.github.rosemoe.sora.lang.smartEnter.NewlineHandler
import io.github.rosemoe.sora.text.CharPosition
import io.github.rosemoe.sora.text.ContentReference
import io.github.rosemoe.sora.widget.SymbolPairMatch
/**
* Tree Sitter language implementation.
*
* @author Akash Yadav
*/
class TreeSitterLanguage(
private val lang: IDELanguage,
languageSpec: TsLanguageSpec,
type: String,
) :
TsLanguage(
languageSpec = languageSpec,
tab = false,
themeDescription = {
IDEColorSchemeProvider.readScheme { scheme ->
val langScheme =
checkNotNull(scheme.languages[type]) { "No color scheme found for file type '$type'" }
langScheme.styles.forEach { it.value.makeStyle() applyTo it.key }
}
}
) {
override fun getInterruptionLevel(): Int {
return lang.interruptionLevel
}
override fun requireAutoComplete(
content: ContentReference,
position: CharPosition,
publisher: CompletionPublisher,
extraArguments: Bundle
) {
lang.requireAutoComplete(content, position, publisher, extraArguments)
}
override fun useTab(): Boolean {
return lang.useTab()
}
override fun getFormatter(): Formatter {
return lang.formatter
}
override fun getSymbolPairs(): SymbolPairMatch {
return lang.symbolPairs
}
override fun getNewlineHandlers(): Array<NewlineHandler> {
return lang.newlineHandlers ?: emptyArray()
}
override fun destroy() {
super.destroy()
lang.destroy()
}
}