Skip to content

Commit

Permalink
Merged branch idea243.release into idea243.x
Browse files Browse the repository at this point in the history
  • Loading branch information
builduser committed Jan 21, 2025
2 parents 1bc9004 + 023e66d commit 12d7b09
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.intellij.openapi.projectRoots.{JavaSdk, SdkTypeId}
import com.intellij.platform.templates.github.ZipUtil
import org.jetbrains.annotations.ApiStatus
import org.jetbrains.plugins.scala.extensions.ObjectExt
import org.jetbrains.plugins.scala.project.template.DefaultModuleContentEntryFolders
import org.jetbrains.sbt.project.template.AbstractArchivedSbtProjectBuilder.{replacePatterns, replacePatterns2}

import java.io.File
Expand Down Expand Up @@ -43,7 +44,7 @@ abstract class AbstractArchivedSbtProjectBuilder extends SbtModuleBuilderBase {
testSources = Seq("src/test/scala"),
resources = Seq("resources"),
testResources = Seq(),
excluded = DefaultModuleContentEntryFolders.RootTargets,
excluded = DefaultModuleContentEntryFolders.SbtRootTargets,
))
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.jetbrains.sbt.project.template

import com.intellij.ide.util.EditorHelper
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.externalSystem.model.ProjectSystemId
Expand All @@ -11,9 +10,7 @@ import com.intellij.openapi.project.Project
import com.intellij.openapi.roots.ModifiableRootModel
import com.intellij.openapi.util.io.FileUtilRt
import com.intellij.openapi.vfs.{VirtualFile, VirtualFileManager}
import com.intellij.psi.PsiManager
import org.jetbrains.plugins.scala.extensions.invokeLater
import org.jetbrains.plugins.scala.project.template.FileExt
import org.jetbrains.plugins.scala.project.template.{DefaultModuleContentEntryFolders, FileExt, ModuleBuilderUtil}
import org.jetbrains.plugins.scala.util.ScalaPluginUtils
import org.jetbrains.sbt.Sbt

Expand Down Expand Up @@ -80,17 +77,7 @@ abstract class ModuleBuilderBase[T <: ExternalProjectSettings](
else
Option(VirtualFileManager.getInstance().findFileByNioPath((contentDir / externalSystemConfigFile).toPath)).toSeq

if (filesToOpen.nonEmpty) {
val psiManager = PsiManager.getInstance(project)
filesToOpen.foreach { file =>
Option(psiManager.findFile(file))
.foreach { psiFile =>
invokeLater {
EditorHelper.openInEditor(psiFile)
}
}
}
}
ModuleBuilderUtil.openFilesInEditor(filesToOpen, project)
}

protected def externalSystemConfigFile: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import com.intellij.openapi.util.io.FileUtil
import org.jetbrains.annotations.{ApiStatus, NonNls, TestOnly}
import org.jetbrains.plugins.scala.ScalaVersion
import org.jetbrains.plugins.scala.extensions._
import org.jetbrains.plugins.scala.project.template.patchProjectLabels
import org.jetbrains.plugins.scala.project.template.{DefaultModuleContentEntryFolders, patchProjectLabels}
import org.jetbrains.plugins.scala.project.{ScalaLanguageLevel, Version, Versions}
import org.jetbrains.plugins.scala.util.ui.extensions.JComboBoxOps
import org.jetbrains.sbt.project.template.wizard.SbtModuleStepLike
Expand Down Expand Up @@ -225,6 +225,7 @@ object SbtModuleBuilder {
Seq(testSourcesPath),
Nil,
Nil,
DefaultModuleContentEntryFolders.SbtRootTargets
))
}
else None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import org.jetbrains.plugins.scala.ScalaVersion
import org.jetbrains.bsp.BSP
import org.jetbrains.bsp.settings.BspProjectSettings
import org.jetbrains.plugins.scala.extensions._
import org.jetbrains.plugins.scala.project.template.DefaultModuleContentEntryFolders

import java.io.File
import org.jetbrains.sbt.project.template.{DefaultModuleContentEntryFolders, ModuleBuilderBase, ScalaModuleBuilderSelections}
import org.jetbrains.sbt.project.template.{ModuleBuilderBase, ScalaModuleBuilderSelections}
import org.jetbrains.scalaCli.project.ScalaCliProjectUtils

class ScalaCliModuleBuilder (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package org.jetbrains.sbt.project.template
package org.jetbrains.plugins.scala.project.template

/**
* Represents set of folders to be marked as "source", "resource", "excluded" folders just after project is created.
* These values will be rewritten after sbt project will be reimported (it will be read from sbt project dumped structure).
* These values will be rewritten after a project is reimported (it will be read from sbt project dumped structure).
* So this class contains a "guess" set of folders.
* (Luckily it's quite well known for simple sbt projects: src/main|test/scala, target, project/target)
* (Luckily it's quite well known for simple e.g. sbt projects: src/main|test/scala, target, project/target)
* Without this class we would need to wait for the project reimport even to create a simple scala file in sources folder.
*
* @note all paths are relative to model content root
Expand All @@ -14,12 +14,9 @@ final case class DefaultModuleContentEntryFolders(
testSources: Seq[String],
resources: Seq[String],
testResources: Seq[String],
excluded: Seq[String] = DefaultModuleContentEntryFolders.RootTargets,
excluded: Seq[String],
)

object DefaultModuleContentEntryFolders {
val RootTargets = Seq("target", "project/target")

val rootTargets: DefaultModuleContentEntryFolders =
DefaultModuleContentEntryFolders(Nil, Nil, Nil, Nil, RootTargets)
val SbtRootTargets: Seq[String] = Seq("target", "project/target")
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.jetbrains.sbt.project.template
package org.jetbrains.plugins.scala.project.template

import com.intellij.ide.util.EditorHelper
import com.intellij.openapi.externalSystem.ExternalSystemModulePropertyManager
import com.intellij.openapi.externalSystem.importing.ImportSpecBuilder
import com.intellij.openapi.externalSystem.model.ProjectSystemId
Expand All @@ -10,9 +11,12 @@ import com.intellij.openapi.externalSystem.settings.{AbstractExternalSystemSetti
import com.intellij.openapi.externalSystem.util.{ExternalSystemApiUtil, ExternalSystemUtil}
import com.intellij.openapi.fileEditor.FileDocumentManager
import com.intellij.openapi.module.Module
import com.intellij.openapi.project.Project
import com.intellij.openapi.roots.{ContentEntry, ModifiableRootModel}
import com.intellij.openapi.startup.StartupManager
import com.intellij.openapi.util.io.FileUtilRt
import com.intellij.openapi.vfs.{LocalFileSystem, VirtualFile}
import com.intellij.psi.PsiManager
import org.jetbrains.annotations.{ApiStatus, Nullable}
import org.jetbrains.jps.model.java.{JavaResourceRootType, JavaSourceRootType}
import org.jetbrains.plugins.scala.extensions._
Expand Down Expand Up @@ -94,6 +98,21 @@ object ModuleBuilderUtil {
}
}

def openFilesInEditor(files: Seq[VirtualFile], project: Project): Unit = {
if (files.isEmpty) return
val psiManager = PsiManager.getInstance(project)
StartupManager.getInstance(project).runAfterOpened(() =>
files.foreach { file =>
val psiFile = inReadAction { psiManager.findFile(file) }
if (psiFile != null) {
invokeLater {
EditorHelper.openInEditor(psiFile)
}
}
}
)
}

private def doSetupRootModel(
model: ModifiableRootModel,
vContentRootDir: VirtualFile,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.jetbrains.plugins.scala.project.template

import com.intellij.facet.impl.ui.libraries.LibraryCompositionSettings
import com.intellij.ide.util.EditorHelper
import com.intellij.ide.util.projectWizard.{JavaModuleBuilder, ModuleWizardStep, SettingsStep}
import com.intellij.openapi.module.{JavaModuleType, Module}
import com.intellij.openapi.project.Project
Expand All @@ -10,8 +9,6 @@ import com.intellij.openapi.roots.libraries.Library
import com.intellij.openapi.roots.ui.configuration.projectRoot.{LibrariesContainer, LibrariesContainerFactory}
import com.intellij.openapi.util.Disposer
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.psi.PsiManager
import org.jetbrains.plugins.scala.extensions.invokeLater

import java.{util => ju}
import javax.swing.JComponent
Expand Down Expand Up @@ -45,19 +42,9 @@ class ScalaModuleBuilder extends JavaModuleBuilder {
new ScalaStep(settingsStep)
}

//open code sample or buildSbt
private def openEditorForCodeSample(project: Project): Unit =
//open code sample or buildSbt
if (openFileEditorAfterProjectOpened.nonEmpty) {
val psiManager = PsiManager.getInstance(project)
openFileEditorAfterProjectOpened.foreach { file =>
Option(psiManager.findFile(file))
.foreach { psiFile =>
invokeLater {
EditorHelper.openInEditor(psiFile)
}
}
}
}
ModuleBuilderUtil.openFilesInEditor(openFileEditorAfterProjectOpened, project)

private class ScalaStep(settingsStep: SettingsStep) extends ModuleWizardStep with ScalaSDKStepLike {
private val javaStep = JavaModuleType.getModuleType.modifyProjectTypeStep(settingsStep, ScalaModuleBuilder.this)
Expand Down

0 comments on commit 12d7b09

Please sign in to comment.