mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
use kotlin coroutines instead of fork-join pool and completable future (part 17.1 - get rid of invokeAndWait in PyTemplatesAutoConfiguration)
GitOrigin-RevId: 43a91d3a0ebab7f6658263ece51acfd0f6d23a12
This commit is contained in:
committed by
intellij-monorepo-bot
parent
1337aff978
commit
505cc13614
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.projectImport;
|
||||
|
||||
import com.intellij.openapi.extensions.ExtensionPointName;
|
||||
@@ -9,7 +9,6 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
||||
|
||||
public class ProjectAttachProcessor {
|
||||
public static final ExtensionPointName<ProjectAttachProcessor> EP_NAME = new ExtensionPointName<>("com.intellij.projectAttachProcessor");
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.intellij.CommonBundle
|
||||
import com.intellij.configurationStore.StoreUtil
|
||||
import com.intellij.featureStatistics.fusCollectors.LifecycleUsageTriggerCollector
|
||||
import com.intellij.ide.impl.OpenProjectTask
|
||||
import com.intellij.ide.impl.runUnderModalProgressIfIsEdt
|
||||
import com.intellij.lang.LangBundle
|
||||
import com.intellij.openapi.application.runWriteAction
|
||||
import com.intellij.openapi.diagnostic.logger
|
||||
@@ -79,9 +80,11 @@ class ModuleAttachProcessor : ProjectAttachProcessor() {
|
||||
if (!dotIdeaDir.exists()) {
|
||||
val options = OpenProjectTask(useDefaultProjectAsTemplate = true, isNewProject = true)
|
||||
val newProject = ProjectManagerEx.getInstanceEx().newProject(projectDir, options) ?: return false
|
||||
PlatformProjectOpenProcessor.runDirectoryProjectConfigurators(baseDir = projectDir,
|
||||
project = newProject,
|
||||
newProject = true)
|
||||
runUnderModalProgressIfIsEdt {
|
||||
PlatformProjectOpenProcessor.runDirectoryProjectConfigurators(baseDir = projectDir,
|
||||
project = newProject,
|
||||
newProject = true)
|
||||
}
|
||||
StoreUtil.saveSettings(newProject)
|
||||
runWriteAction { Disposer.dispose(newProject) }
|
||||
}
|
||||
|
||||
@@ -851,7 +851,7 @@ open class ProjectManagerImpl : ProjectManagerEx(), Disposable {
|
||||
|
||||
if (options.runConfigurators &&
|
||||
(options.isNewProject || ModuleManager.getInstance(project).modules.isEmpty()) || project.isLoadedFromCacheButHasNoModules()) {
|
||||
val module = PlatformProjectOpenProcessor.runDirectoryProjectConfiguratorsV2(
|
||||
val module = PlatformProjectOpenProcessor.runDirectoryProjectConfigurators(
|
||||
baseDir = projectStoreBaseDir,
|
||||
project = project,
|
||||
newProject = options.isProjectCreatedWithWizard
|
||||
|
||||
@@ -1,32 +1,49 @@
|
||||
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.platform;
|
||||
package com.intellij.platform
|
||||
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Ref;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import com.intellij.openapi.module.Module
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.util.Ref
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
|
||||
/**
|
||||
* Configures various subsystems (facets etc.) when a user opens a directory with code but without `.idea` subdirectory.
|
||||
* <p>
|
||||
*
|
||||
* Example: to support some framework, you need to enable and configure a facet. A user opens a directory with code for the first time.
|
||||
* This class scans the code and detects the framework heuristically. It then configures facet without user action.
|
||||
*/
|
||||
public interface DirectoryProjectConfigurator {
|
||||
interface DirectoryProjectConfigurator {
|
||||
/**
|
||||
* @return if code must be called or EDT or not.
|
||||
* If {@link #configureProject(Project, VirtualFile, Ref, boolean)} is slow (heavy computations, network access etc) return "false" here.
|
||||
* If [.configureProject] is slow (heavy computations, network access etc) return "false" here.
|
||||
*/
|
||||
default boolean isEdtRequired() {
|
||||
return true;
|
||||
}
|
||||
@JvmDefault
|
||||
val isEdtRequired: Boolean
|
||||
get() = true
|
||||
|
||||
/**
|
||||
* @param isProjectCreatedWithWizard if true then new project created with wizard, existing folder opened otherwise
|
||||
*/
|
||||
void configureProject(@NotNull Project project,
|
||||
@NotNull VirtualFile baseDir,
|
||||
@NotNull Ref<Module> moduleRef,
|
||||
boolean isProjectCreatedWithWizard);
|
||||
}
|
||||
fun configureProject(project: Project,
|
||||
baseDir: VirtualFile,
|
||||
moduleRef: Ref<Module>,
|
||||
isProjectCreatedWithWizard: Boolean)
|
||||
|
||||
abstract class AsyncDirectoryProjectConfigurator : DirectoryProjectConfigurator {
|
||||
final override val isEdtRequired: Boolean
|
||||
get() = false
|
||||
|
||||
final override fun configureProject(project: Project,
|
||||
baseDir: VirtualFile,
|
||||
moduleRef: Ref<Module>,
|
||||
isProjectCreatedWithWizard: Boolean) {
|
||||
}
|
||||
|
||||
abstract suspend fun configure(
|
||||
project: Project,
|
||||
baseDir: VirtualFile,
|
||||
moduleRef: Ref<Module>,
|
||||
isProjectCreatedWithWizard: Boolean
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -174,32 +174,7 @@ class PlatformProjectOpenProcessor : ProjectOpenProcessor(), CommandLineProjectO
|
||||
return project
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun runDirectoryProjectConfigurators(baseDir: Path, project: Project, newProject: Boolean): Module {
|
||||
project.putUserData(PROJECT_CONFIGURED_BY_PLATFORM_PROCESSOR, true)
|
||||
val moduleRef = Ref<Module>()
|
||||
val virtualFile = ProjectUtilCore.getFileAndRefresh(baseDir)!!
|
||||
EP_NAME.forEachExtensionSafe { configurator ->
|
||||
fun task() {
|
||||
configurator.configureProject(project, virtualFile, moduleRef, newProject)
|
||||
}
|
||||
if (configurator.isEdtRequired) {
|
||||
ApplicationManager.getApplication().invokeAndWait {
|
||||
task()
|
||||
}
|
||||
}
|
||||
else {
|
||||
task()
|
||||
}
|
||||
}
|
||||
val module = moduleRef.get()
|
||||
if (module == null) {
|
||||
LOG.error("No extension configured a module for $baseDir; extensions = ${EP_NAME.extensionList}")
|
||||
}
|
||||
return module
|
||||
}
|
||||
|
||||
suspend fun runDirectoryProjectConfiguratorsV2(baseDir: Path, project: Project, newProject: Boolean): Module {
|
||||
suspend fun runDirectoryProjectConfigurators(baseDir: Path, project: Project, newProject: Boolean): Module {
|
||||
project.putUserData(PROJECT_CONFIGURED_BY_PLATFORM_PROCESSOR, true)
|
||||
|
||||
val moduleRef = Ref<Module>()
|
||||
@@ -210,18 +185,17 @@ class PlatformProjectOpenProcessor : ProjectOpenProcessor(), CommandLineProjectO
|
||||
}
|
||||
|
||||
for (configurator in EP_NAME.iterable) {
|
||||
fun task() {
|
||||
configurator.configureProject(project, virtualFile, moduleRef, newProject)
|
||||
}
|
||||
|
||||
try {
|
||||
if (configurator.isEdtRequired) {
|
||||
if (configurator is DirectoryProjectConfigurator.AsyncDirectoryProjectConfigurator) {
|
||||
configurator.configure(project, virtualFile, moduleRef, newProject)
|
||||
}
|
||||
else if (configurator.isEdtRequired) {
|
||||
withContext(Dispatchers.EDT) {
|
||||
task()
|
||||
configurator.configureProject(project, virtualFile, moduleRef, newProject)
|
||||
}
|
||||
}
|
||||
else {
|
||||
task()
|
||||
configurator.configureProject(project, virtualFile, moduleRef, newProject)
|
||||
}
|
||||
}
|
||||
catch (e: ProcessCanceledException) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.jetbrains.python.newProject.welcome
|
||||
|
||||
import com.intellij.execution.RunManager
|
||||
@@ -55,7 +55,8 @@ import java.util.concurrent.Callable
|
||||
import javax.swing.JPanel
|
||||
|
||||
internal class PyWelcomeConfigurator : DirectoryProjectConfigurator {
|
||||
override fun isEdtRequired() = false
|
||||
override val isEdtRequired: Boolean
|
||||
get() = false
|
||||
|
||||
override fun configureProject(project: Project, baseDir: VirtualFile, moduleRef: Ref<Module>, isProjectCreatedWithWizard: Boolean) {
|
||||
if (isProjectCreatedWithWizard || isInsideTempDirectory(baseDir)) {
|
||||
|
||||
Reference in New Issue
Block a user