PY-84031: Replace getInstance with direct openProjectAndFile call in CommandLineProjectOpenProcessor.

This change allows inheritors of CommandLineProjectOpenProcessor to optinally openProjectAndFile by returning null.
If null is returned, next CommandLineProjectOpenProcessor will be taken.
In previous implementation it would take the first CommandLineProjectOpenProcessor, but there is no guarantee that it will open a project.

Space-RevId: 8294fbbd603519a0c348a1d97346ac168794c2ed

GitOrigin-RevId: 91bb048e921f265681c92606fb71c107d28c3867
This commit is contained in:
Ilia Zakoulov
2026-02-03 23:35:47 +00:00
committed by intellij-monorepo-bot
parent 50b7a0e6b7
commit cd7026ba94
5 changed files with 20 additions and 23 deletions
@@ -10469,8 +10469,6 @@ f:com.intellij.platform.AttachProjectAction$Companion
- f:attachProject(com.intellij.openapi.vfs.VirtualFile,com.intellij.openapi.project.Project):V
- f:getTO_SELECT_KEY():com.intellij.openapi.util.Key
f:com.intellij.platform.CommandLineProjectOpenProcessor$Companion
- f:getInstance():com.intellij.platform.CommandLineProjectOpenProcessor
- f:getInstanceIfExists():com.intellij.platform.CommandLineProjectOpenProcessor
a:com.intellij.platform.DirectoryProjectConfigurator$AsyncDirectoryProjectConfigurator
- com.intellij.platform.DirectoryProjectConfigurator
- <init>():V
+3
View File
@@ -1089,6 +1089,9 @@ com.intellij.platform.CommandLineProjectOpenProcessor
- sf:Companion:com.intellij.platform.CommandLineProjectOpenProcessor$Companion
- a:openProjectAndFile(java.nio.file.Path,Z,com.intellij.ide.impl.OpenProjectTask,kotlin.coroutines.Continuation):java.lang.Object
- bs:openProjectAndFile$default(com.intellij.platform.CommandLineProjectOpenProcessor,java.nio.file.Path,Z,com.intellij.ide.impl.OpenProjectTask,kotlin.coroutines.Continuation,I,java.lang.Object):java.lang.Object
f:com.intellij.platform.CommandLineProjectOpenProcessor$Companion
- f:openProjectAndFile(java.nio.file.Path,Z,com.intellij.ide.impl.OpenProjectTask,kotlin.coroutines.Continuation):java.lang.Object
- bs:openProjectAndFile$default(com.intellij.platform.CommandLineProjectOpenProcessor$Companion,java.nio.file.Path,Z,com.intellij.ide.impl.OpenProjectTask,kotlin.coroutines.Continuation,I,java.lang.Object):java.lang.Object
com.intellij.platform.DirectoryProjectConfigurator
- a:configureProject(com.intellij.openapi.project.Project,com.intellij.openapi.vfs.VirtualFile,com.intellij.openapi.util.Ref,Z):V
- isEdtRequired():Z
@@ -135,7 +135,7 @@ object CommandLineProcessor {
}
if (projects.isEmpty()) {
val project = CommandLineProjectOpenProcessor.getInstance().openProjectAndFile(ioFile, tempProject, OpenProjectTask {
val project = CommandLineProjectOpenProcessor.openProjectAndFile(ioFile, tempProject, OpenProjectTask {
this.line = line
this.column = column
}) ?: return createError(IdeBundle.message("dialog.message.no.project.found.to.open.file.in"))
@@ -549,18 +549,15 @@ object ProjectUtil {
LOG.debug { "$location: open file $file" }
if (projectToClose == null) {
val processor = CommandLineProjectOpenProcessor.getInstanceIfExists()
if (processor != null) {
val opened = FUSProjectHotStartUpMeasurer.withProjectContextElement(file) {
processor.openProjectAndFile(file = file, tempProject = false)
val openedProject = FUSProjectHotStartUpMeasurer.withProjectContextElement(file) {
CommandLineProjectOpenProcessor.openProjectAndFile(file = file, tempProject = false)
}
if (openedProject != null) {
if (result == null) {
result = openedProject
}
if (opened != null) {
if (result == null) {
result = opened
}
else {
FUSProjectHotStartUpMeasurer.openingMultipleProjects(false, list.size, false)
}
else {
FUSProjectHotStartUpMeasurer.openingMultipleProjects(false, list.size, false)
}
}
}
@@ -4,7 +4,6 @@ package com.intellij.platform
import com.intellij.ide.impl.OpenProjectTask
import com.intellij.openapi.project.Project
import com.intellij.projectImport.ProjectOpenProcessor
import org.jetbrains.annotations.ApiStatus
import java.nio.file.Path
/**
@@ -18,20 +17,20 @@ interface CommandLineProjectOpenProcessor {
* @param file the file to open
* @param tempProject if `true`, always opens the file in a new temporary project, otherwise searches the parent directories
* for `.idea` subdirectory, and if found, opens that directory.
*
* @return project or null if it cannot be opened with that open processor
*/
suspend fun openProjectAndFile(file: Path, tempProject: Boolean, options: OpenProjectTask = OpenProjectTask()): Project?
companion object {
fun getInstance(): CommandLineProjectOpenProcessor = getInstanceIfExists() ?: getDefaultInstance()
@ApiStatus.Internal
fun getDefaultInstance(): CommandLineProjectOpenProcessor = PlatformProjectOpenProcessor.getInstance()
fun getInstanceIfExists(): CommandLineProjectOpenProcessor? {
return ProjectOpenProcessor.EXTENSION_POINT_NAME.getIterable()
suspend fun openProjectAndFile(file: Path, tempProject: Boolean, options: OpenProjectTask = OpenProjectTask()): Project? {
val project = ProjectOpenProcessor.EXTENSION_POINT_NAME.getIterable()
.asSequence()
.filterIsInstance<CommandLineProjectOpenProcessor>()
.firstOrNull()
.firstNotNullOfOrNull {
it.openProjectAndFile(file, tempProject, options)
}
return project
}
}
}