From c6f8a0c0890227392ce6088dc54e857cdbbabacf Mon Sep 17 00:00:00 2001 From: Timur Aliberdov Date: Thu, 31 Oct 2024 19:10:07 +0100 Subject: [PATCH 01/11] [NPW] always add a .gitignore file for Scala projects #SCL-22056 fixed --- .../resources/assets/ignore/scala-gitignore.txt | 0 .../template/wizard/AssetsProvider.scala | 13 +++++++++++++ .../ScalaAssetsNewProjectWizardStep.scala | 17 +++++++++++++++++ .../IntelliJScalaNewProjectWizard.scala | 7 +++++-- .../buildSystem/SbtScalaNewProjectWizard.scala | 7 +++++-- .../SbtScalaNewProjectWizardStep.scala | 3 --- .../ScalaGitNewProjectWizardData.scala | 5 ++++- .../buildSystem/ScalaNewProjectWizardStep.scala | 8 -------- .../template/wizard/buildSystem/package.scala | 3 +++ .../sbt/project/NewSbtProjectWizardTest.scala | 2 -- .../wizard/ScalaCliNewProjectWizard.scala | 7 +++++-- 11 files changed, 52 insertions(+), 20 deletions(-) rename scala/scala-impl/resources/fileTemplates/internal/scala-gitignore.txt.ft => sbt/sbt-impl/resources/assets/ignore/scala-gitignore.txt (100%) create mode 100644 sbt/sbt-impl/src/org/jetbrains/sbt/project/template/wizard/AssetsProvider.scala create mode 100644 sbt/sbt-impl/src/org/jetbrains/sbt/project/template/wizard/ScalaAssetsNewProjectWizardStep.scala diff --git a/scala/scala-impl/resources/fileTemplates/internal/scala-gitignore.txt.ft b/sbt/sbt-impl/resources/assets/ignore/scala-gitignore.txt similarity index 100% rename from scala/scala-impl/resources/fileTemplates/internal/scala-gitignore.txt.ft rename to sbt/sbt-impl/resources/assets/ignore/scala-gitignore.txt diff --git a/sbt/sbt-impl/src/org/jetbrains/sbt/project/template/wizard/AssetsProvider.scala b/sbt/sbt-impl/src/org/jetbrains/sbt/project/template/wizard/AssetsProvider.scala new file mode 100644 index 00000000000..b39376b8cd1 --- /dev/null +++ b/sbt/sbt-impl/src/org/jetbrains/sbt/project/template/wizard/AssetsProvider.scala @@ -0,0 +1,13 @@ +package org.jetbrains.sbt.project.template.wizard + +import com.intellij.ide.starters.local.{GeneratorAsset, GeneratorResourceFile} + +final class AssetsProvider { + // we might add different .gitignore files for different project wizards (SCL-22056) + def getScalaIgnoreAssets: Seq[GeneratorAsset] = Seq( + new GeneratorResourceFile( + ".gitignore", + getClass.getResource("/assets/ignore/scala-gitignore.txt") + ) + ) +} diff --git a/sbt/sbt-impl/src/org/jetbrains/sbt/project/template/wizard/ScalaAssetsNewProjectWizardStep.scala b/sbt/sbt-impl/src/org/jetbrains/sbt/project/template/wizard/ScalaAssetsNewProjectWizardStep.scala new file mode 100644 index 00000000000..a0065e3896f --- /dev/null +++ b/sbt/sbt-impl/src/org/jetbrains/sbt/project/template/wizard/ScalaAssetsNewProjectWizardStep.scala @@ -0,0 +1,17 @@ +package org.jetbrains.sbt.project.template.wizard + +import com.intellij.ide.projectWizard.generators.AssetsNewProjectWizardStep +import com.intellij.ide.wizard.NewProjectWizardStep +import com.intellij.openapi.project.Project + +import scala.jdk.CollectionConverters.IterableHasAsJava + +//noinspection ApiStatus,UnstableApiUsage +class ScalaAssetsNewProjectWizardStep(parent: NewProjectWizardStep) extends AssetsNewProjectWizardStep(parent) { + override def setupAssets(project: Project): Unit = { + if (getContext.isCreatingNewProject) { + addAssets(new AssetsProvider().getScalaIgnoreAssets.asJava) + } + // TODO: move onboarding tips and sample code creation to the assets step + } +} diff --git a/sbt/sbt-impl/src/org/jetbrains/sbt/project/template/wizard/buildSystem/IntelliJScalaNewProjectWizard.scala b/sbt/sbt-impl/src/org/jetbrains/sbt/project/template/wizard/buildSystem/IntelliJScalaNewProjectWizard.scala index 03322a998c5..b550868db84 100644 --- a/sbt/sbt-impl/src/org/jetbrains/sbt/project/template/wizard/buildSystem/IntelliJScalaNewProjectWizard.scala +++ b/sbt/sbt-impl/src/org/jetbrains/sbt/project/template/wizard/buildSystem/IntelliJScalaNewProjectWizard.scala @@ -1,13 +1,16 @@ package org.jetbrains.sbt.project.template.wizard.buildSystem import com.intellij.ide.projectWizard.NewProjectWizardConstants -import org.jetbrains.sbt.project.template.wizard.ScalaNewProjectWizardMultiStep +import com.intellij.ide.wizard.NewProjectWizardStep +import org.jetbrains.plugins.scala.util.ui.KotlinDslWrappers.StepChainOps +import org.jetbrains.sbt.project.template.wizard.{ScalaAssetsNewProjectWizardStep, ScalaNewProjectWizardMultiStep} final class IntelliJScalaNewProjectWizard extends BuildSystemScalaNewProjectWizard { override val getName: String = NewProjectWizardConstants.BuildSystem.INTELLIJ - override def createStep(parent: ScalaNewProjectWizardMultiStep): IntelliJScalaNewProjectWizardStep = + override def createStep(parent: ScalaNewProjectWizardMultiStep): NewProjectWizardStep = new IntelliJScalaNewProjectWizardStep(parent) + .nextStep(new ScalaAssetsNewProjectWizardStep(_)) override def getOrdinal: Int = 1 } diff --git a/sbt/sbt-impl/src/org/jetbrains/sbt/project/template/wizard/buildSystem/SbtScalaNewProjectWizard.scala b/sbt/sbt-impl/src/org/jetbrains/sbt/project/template/wizard/buildSystem/SbtScalaNewProjectWizard.scala index 193ce9796ca..0d089caf05e 100644 --- a/sbt/sbt-impl/src/org/jetbrains/sbt/project/template/wizard/buildSystem/SbtScalaNewProjectWizard.scala +++ b/sbt/sbt-impl/src/org/jetbrains/sbt/project/template/wizard/buildSystem/SbtScalaNewProjectWizard.scala @@ -1,13 +1,16 @@ package org.jetbrains.sbt.project.template.wizard.buildSystem import com.intellij.ide.projectWizard.NewProjectWizardConstants -import org.jetbrains.sbt.project.template.wizard.ScalaNewProjectWizardMultiStep +import com.intellij.ide.wizard.NewProjectWizardStep +import org.jetbrains.plugins.scala.util.ui.KotlinDslWrappers.StepChainOps +import org.jetbrains.sbt.project.template.wizard.{ScalaAssetsNewProjectWizardStep, ScalaNewProjectWizardMultiStep} final class SbtScalaNewProjectWizard extends BuildSystemScalaNewProjectWizard { override def getName: String = NewProjectWizardConstants.BuildSystem.SBT - override def createStep(parent: ScalaNewProjectWizardMultiStep): SbtScalaNewProjectWizardStep = + override def createStep(parent: ScalaNewProjectWizardMultiStep): NewProjectWizardStep = new SbtScalaNewProjectWizardStep(parent) + .nextStep(new ScalaAssetsNewProjectWizardStep(_)) override def getOrdinal: Int = 0 } diff --git a/sbt/sbt-impl/src/org/jetbrains/sbt/project/template/wizard/buildSystem/SbtScalaNewProjectWizardStep.scala b/sbt/sbt-impl/src/org/jetbrains/sbt/project/template/wizard/buildSystem/SbtScalaNewProjectWizardStep.scala index 4385ca70165..a6de8632318 100644 --- a/sbt/sbt-impl/src/org/jetbrains/sbt/project/template/wizard/buildSystem/SbtScalaNewProjectWizardStep.scala +++ b/sbt/sbt-impl/src/org/jetbrains/sbt/project/template/wizard/buildSystem/SbtScalaNewProjectWizardStep.scala @@ -33,7 +33,6 @@ import scala.annotation.nowarn final class SbtScalaNewProjectWizardStep(parent: ScalaNewProjectWizardMultiStep) extends ScalaNewProjectWizardStep(parent) with SbtScalaNewProjectWizardData - with ScalaGitNewProjectWizardData with ScalaSampleCodeNewProjectWizardData with SbtModuleStepLike { @@ -48,7 +47,6 @@ final class SbtScalaNewProjectWizardStep(parent: ScalaNewProjectWizardMultiStep) @TestOnly override private[project] def setGenerateOnboardingTips(value: java.lang.Boolean): Unit = generateOnboardingTipsProperty.set(value) private def needToGenerateOnboardingTips: Boolean = needToAddSampleCode && generateOnboardingTipsProperty.get() - @TestOnly override private[project] def setGit(value: java.lang.Boolean): Unit = gitProperty.set(value) @TestOnly override def setScalaVersion(version: String): Unit = scalaVersionComboBox.setSelectedItemEnsuring(version) @TestOnly override private[project] def setSbtVersion(version: String): Unit = sbtVersionComboBox.setSelectedItemEnsuring(version) @TestOnly override private[project] def setPackagePrefix(prefix: String): Unit = packagePrefixTextField.setText(prefix) @@ -62,7 +60,6 @@ final class SbtScalaNewProjectWizardStep(parent: ScalaNewProjectWizardMultiStep) locally { getData.putUserData(SbtScalaNewProjectWizardData.KEY, this) - getData.putUserData(ScalaGitNewProjectWizardData.KEY, this) getData.putUserData(ScalaSampleCodeNewProjectWizardData.KEY, this) } diff --git a/sbt/sbt-impl/src/org/jetbrains/sbt/project/template/wizard/buildSystem/ScalaGitNewProjectWizardData.scala b/sbt/sbt-impl/src/org/jetbrains/sbt/project/template/wizard/buildSystem/ScalaGitNewProjectWizardData.scala index 9613c31374a..05267990f07 100644 --- a/sbt/sbt-impl/src/org/jetbrains/sbt/project/template/wizard/buildSystem/ScalaGitNewProjectWizardData.scala +++ b/sbt/sbt-impl/src/org/jetbrains/sbt/project/template/wizard/buildSystem/ScalaGitNewProjectWizardData.scala @@ -2,13 +2,16 @@ package org.jetbrains.sbt.project.template.wizard.buildSystem import com.intellij.ide.wizard.NewProjectWizardStep import com.intellij.openapi.util.Key -import org.jetbrains.annotations.{Nullable, TestOnly} +import org.jetbrains.annotations.{ApiStatus, Nullable, TestOnly} +@deprecated("Don't use this trait. .gitignore is now added in the wizard via AssetsNewProjectWizardStep") +@ApiStatus.ScheduledForRemoval(inVersion = "2025.1") trait ScalaGitNewProjectWizardData { @TestOnly private[project] def setGit(value: java.lang.Boolean): Unit } +@deprecated("See the details in the trait's annotation") object ScalaGitNewProjectWizardData { val KEY: Key[ScalaGitNewProjectWizardData] = Key.create(classOf[ScalaGitNewProjectWizardData].getName) diff --git a/sbt/sbt-impl/src/org/jetbrains/sbt/project/template/wizard/buildSystem/ScalaNewProjectWizardStep.scala b/sbt/sbt-impl/src/org/jetbrains/sbt/project/template/wizard/buildSystem/ScalaNewProjectWizardStep.scala index eb43127babf..aec448c3824 100644 --- a/sbt/sbt-impl/src/org/jetbrains/sbt/project/template/wizard/buildSystem/ScalaNewProjectWizardStep.scala +++ b/sbt/sbt-impl/src/org/jetbrains/sbt/project/template/wizard/buildSystem/ScalaNewProjectWizardStep.scala @@ -2,7 +2,6 @@ package org.jetbrains.sbt.project.template.wizard.buildSystem import com.intellij.ide.projectWizard.NewProjectWizardCollector.BuildSystem.{INSTANCE => BSLog} import com.intellij.ide.wizard.AbstractNewProjectWizardStep -import com.intellij.openapi.GitRepositoryInitializer import com.intellij.openapi.externalSystem.model.ExternalSystemDataKeys import com.intellij.openapi.externalSystem.service.project.manage.ExternalProjectsManagerImpl import com.intellij.openapi.observable.properties.{GraphProperty, ObservableProperty, PropertyGraph} @@ -40,9 +39,6 @@ abstract class ScalaNewProjectWizardStep(parent: ScalaNewProjectWizardMultiStep) protected val addSampleCodeProperty: GraphProperty[java.lang.Boolean] = propertyGraph.property(java.lang.Boolean.FALSE) BindUtil.bindBooleanStorage(addSampleCodeProperty, "NewProjectWizard.addSampleCodeState") - protected val gitProperty: GraphProperty[java.lang.Boolean] = propertyGraph.property(java.lang.Boolean.FALSE) - BindUtil.bindBooleanStorage(gitProperty, "NewProjectWizard.gitState") - protected def needToAddSampleCode: Boolean = addSampleCodeProperty.get() protected def getSdk: Option[Sdk] @@ -71,7 +67,6 @@ abstract class ScalaNewProjectWizardStep(parent: ScalaNewProjectWizardMultiStep) if (needToAddSampleCode) builder.openFileEditorAfterProjectOpened = _addScalaSampleCode(project, projectRoot) - if (isGitRepository) addGitIgnore(project, projectRoot.toString) builder.commit(project) } @@ -96,8 +91,5 @@ abstract class ScalaNewProjectWizardStep(parent: ScalaNewProjectWizardMultiStep) KUnit }).topGap(TopGap.SMALL) - private def isGitRepository: Boolean = - Option(GitRepositoryInitializer.getInstance()).isDefined && gitProperty.get() - private def getModuleName: String = moduleNameProperty.get() } diff --git a/sbt/sbt-impl/src/org/jetbrains/sbt/project/template/wizard/buildSystem/package.scala b/sbt/sbt-impl/src/org/jetbrains/sbt/project/template/wizard/buildSystem/package.scala index 8bc6ef1b8e5..5715e7a04db 100644 --- a/sbt/sbt-impl/src/org/jetbrains/sbt/project/template/wizard/buildSystem/package.scala +++ b/sbt/sbt-impl/src/org/jetbrains/sbt/project/template/wizard/buildSystem/package.scala @@ -13,6 +13,7 @@ import com.intellij.openapi.roots.ProjectRootManager import com.intellij.openapi.util.registry.Registry import com.intellij.openapi.vfs.{VfsUtil, VirtualFile} import kotlin.jvm.functions.Function1 +import org.jetbrains.annotations.ApiStatus import org.jetbrains.plugins.scala.actions.ShowTypeInfoAction import org.jetbrains.plugins.scala.extensions.{CharSeqExt, inWriteAction} @@ -76,6 +77,8 @@ package object buildSystem { } } + @deprecated("Don't use this method. .gitignore is now added in the wizard via AssetsNewProjectWizardStep") + @ApiStatus.ScheduledForRemoval(inVersion = "2025.1") private[buildSystem] def addGitIgnore(project: Project, path: String): VirtualFile = { val manager = FileTemplateManager.getInstance(project) diff --git a/sbt/sbt-impl/test/org/jetbrains/sbt/project/NewSbtProjectWizardTest.scala b/sbt/sbt-impl/test/org/jetbrains/sbt/project/NewSbtProjectWizardTest.scala index 229aad75f85..b63bd3fce14 100644 --- a/sbt/sbt-impl/test/org/jetbrains/sbt/project/NewSbtProjectWizardTest.scala +++ b/sbt/sbt-impl/test/org/jetbrains/sbt/project/NewSbtProjectWizardTest.scala @@ -7,7 +7,6 @@ import org.jetbrains.plugins.scala.project.Versions import org.jetbrains.sbt.project.ProjectStructureDsl._ import org.jetbrains.sbt.project.template.wizard.buildSystem.BuildSystemScalaNewProjectWizardData.scalaBuildSystemData import org.jetbrains.sbt.project.template.wizard.buildSystem.SbtScalaNewProjectWizardData.scalaSbtData -import org.jetbrains.sbt.project.template.wizard.buildSystem.ScalaGitNewProjectWizardData.scalaGitData import org.jetbrains.sbt.project.template.wizard.buildSystem.ScalaSampleCodeNewProjectWizardData.scalaSampleCodeData // TODO: @@ -83,7 +82,6 @@ class NewSbtProjectWizardTest extends NewScalaProjectWizardTestBase with ExactMa // TODO: test different values scalaSampleCodeData(step).setAddSampleCode(false) - scalaGitData(step).setGit(false) } useProject(project, false, assertProjectsEqual(expectedProject, _: Project)) diff --git a/scala-cli/src/org/jetbrains/scalaCli/project/template/wizard/ScalaCliNewProjectWizard.scala b/scala-cli/src/org/jetbrains/scalaCli/project/template/wizard/ScalaCliNewProjectWizard.scala index 1db17fd3c3f..6b6c59c709d 100644 --- a/scala-cli/src/org/jetbrains/scalaCli/project/template/wizard/ScalaCliNewProjectWizard.scala +++ b/scala-cli/src/org/jetbrains/scalaCli/project/template/wizard/ScalaCliNewProjectWizard.scala @@ -1,15 +1,18 @@ package org.jetbrains.scalaCli.project.template.wizard -import org.jetbrains.sbt.project.template.wizard.ScalaNewProjectWizardMultiStep +import com.intellij.ide.wizard.NewProjectWizardStep +import org.jetbrains.plugins.scala.util.ui.KotlinDslWrappers.StepChainOps import org.jetbrains.sbt.project.template.wizard.buildSystem.BuildSystemScalaNewProjectWizard +import org.jetbrains.sbt.project.template.wizard.{ScalaAssetsNewProjectWizardStep, ScalaNewProjectWizardMultiStep} import org.jetbrains.scalaCli.ScalaCliBundle final class ScalaCliNewProjectWizard extends BuildSystemScalaNewProjectWizard { override val getName: String = ScalaCliBundle.message("scala.cli.project.system.readable.name") - override def createStep(parent: ScalaNewProjectWizardMultiStep): ScalaCliNewProjectWizardStep = + override def createStep(parent: ScalaNewProjectWizardMultiStep): NewProjectWizardStep = new ScalaCliNewProjectWizardStep(parent) + .nextStep(new ScalaAssetsNewProjectWizardStep(_)) override def getOrdinal: Int = 1 } From fc8c86f87b6d4864e7f106f8b4827e62c0b440d5 Mon Sep 17 00:00:00 2001 From: Timur Aliberdov Date: Tue, 22 Oct 2024 20:23:08 +0200 Subject: [PATCH 02/11] [completion] disable word completion in dumb mode for Scala #SCL-21859 --- .../scala-impl/resources/META-INF/scala-plugin-common.xml | 4 ++++ .../scala/lang/completion/ScalaWordCompletionFilter.scala | 7 +++++++ 2 files changed, 11 insertions(+) create mode 100644 scala/scala-impl/src/org/jetbrains/plugins/scala/lang/completion/ScalaWordCompletionFilter.scala diff --git a/scala/scala-impl/resources/META-INF/scala-plugin-common.xml b/scala/scala-impl/resources/META-INF/scala-plugin-common.xml index 289f80c2558..c6b48d84dbf 100644 --- a/scala/scala-impl/resources/META-INF/scala-plugin-common.xml +++ b/scala/scala-impl/resources/META-INF/scala-plugin-common.xml @@ -246,6 +246,10 @@ factoryClass="org.jetbrains.plugins.scala.caches.stats.InternalProfilerToolWindowFactory"/> + + + diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/completion/ScalaWordCompletionFilter.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/completion/ScalaWordCompletionFilter.scala new file mode 100644 index 00000000000..6c45859e315 --- /dev/null +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/completion/ScalaWordCompletionFilter.scala @@ -0,0 +1,7 @@ +package org.jetbrains.plugins.scala.lang.completion + +import com.intellij.lang.DefaultWordCompletionFilter + +final class ScalaWordCompletionFilter extends DefaultWordCompletionFilter { + override def isWordCompletionInDumbModeEnabled: Boolean = false +} From 0c2628e1e252beae5268f75f624cb9839f7181d5 Mon Sep 17 00:00:00 2001 From: Timur Aliberdov Date: Tue, 22 Oct 2024 20:24:19 +0200 Subject: [PATCH 03/11] [completion] enable keyword completion during indexing #SCL-21859 --- .../completion/ScalaKeywordCompletionContributor.scala | 3 ++- .../completion/keyword/KeywordCompletionTestBase.scala | 3 +++ .../lang/completion3/Scala3KeywordCompletionTest.scala | 9 ++++----- .../lang/completion3/ScalaKeywordCompletionTest.scala | 4 +++- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/completion/ScalaKeywordCompletionContributor.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/completion/ScalaKeywordCompletionContributor.scala index 1cb27bacbc8..34d923f9903 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/completion/ScalaKeywordCompletionContributor.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/completion/ScalaKeywordCompletionContributor.scala @@ -1,6 +1,7 @@ package org.jetbrains.plugins.scala.lang.completion import com.intellij.codeInsight.completion._ +import com.intellij.openapi.project.DumbAware import com.intellij.patterns.PlatformPatterns import com.intellij.psi.filters.position.FilterPattern import com.intellij.psi.filters.{AndFilter, ElementFilter, NotFilter, OrFilter} @@ -11,7 +12,7 @@ import org.jetbrains.plugins.scala.ScalaBundle import org.jetbrains.plugins.scala.lang.completion.filters.toplevel.IsTopLevelElementInProductionScalaFileFilter import org.jetbrains.plugins.scala.lang.lexer.ScalaTokenTypes -final class ScalaKeywordCompletionContributor extends ScalaCompletionContributor { +final class ScalaKeywordCompletionContributor extends ScalaCompletionContributor with DumbAware { import ScalaKeyword._ import ScalaKeywordCompletionContributor._ diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/completion/keyword/KeywordCompletionTestBase.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/completion/keyword/KeywordCompletionTestBase.scala index b76d458c7cb..e96604499eb 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/completion/keyword/KeywordCompletionTestBase.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/completion/keyword/KeywordCompletionTestBase.scala @@ -7,11 +7,13 @@ import com.intellij.openapi.util.io.FileUtil import com.intellij.openapi.util.text.StringUtil import com.intellij.openapi.vfs.{CharsetToolkit, LocalFileSystem} import com.intellij.testFramework.EditorTestUtil +import com.intellij.testFramework.TestIndexingModeSupporter.IndexingMode import org.jetbrains.plugins.scala.base.ScalaLightCodeInsightFixtureTestCase import org.jetbrains.plugins.scala.lang.completion.lookups.ScalaKeywordLookupItem.KeywordInsertHandler import org.jetbrains.plugins.scala.lang.psi.api.ScalaFile import org.jetbrains.plugins.scala.util.TestUtils import org.jetbrains.plugins.scala.util.TestUtils.ExpectedResultFromLastComment +import org.jetbrains.plugins.scala.util.runners.WithIndexingMode import org.jetbrains.plugins.scala.{CompletionTests, ScalaVersion} import org.junit.Assert._ import org.junit.experimental.categories.Category @@ -25,6 +27,7 @@ import scala.jdk.CollectionConverters._ * - [[org.jetbrains.plugins.scala.lang.completion3.Scala3KeywordCompletionTest]] */ @Category(Array(classOf[CompletionTests])) +@WithIndexingMode(mode = IndexingMode.DUMB_EMPTY_INDEX) abstract class KeywordCompletionTestBase extends ScalaLightCodeInsightFixtureTestCase { override protected def supportedIn(version: ScalaVersion): Boolean = version >= ScalaVersion.Latest.Scala_2_13 diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/completion3/Scala3KeywordCompletionTest.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/completion3/Scala3KeywordCompletionTest.scala index aa6c76cd381..82ceb662b02 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/completion3/Scala3KeywordCompletionTest.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/completion3/Scala3KeywordCompletionTest.scala @@ -1,17 +1,16 @@ package org.jetbrains.plugins.scala.lang.completion3 +import com.intellij.testFramework.TestIndexingModeSupporter.IndexingMode import org.jetbrains.plugins.scala.ScalaVersion import org.jetbrains.plugins.scala.lang.completion.ScalaKeyword import org.jetbrains.plugins.scala.lang.completion3.base.ScalaCompletionTestBase -import org.jetbrains.plugins.scala.util.runners.{RunWithScalaVersions, TestScalaVersion} +import org.jetbrains.plugins.scala.util.runners.WithIndexingMode -@RunWithScalaVersions(Array( - TestScalaVersion.Scala_3_Latest -)) +@WithIndexingMode(mode = IndexingMode.DUMB_EMPTY_INDEX) class Scala3KeywordCompletionTest extends ScalaCompletionTestBase { override protected def supportedIn(version: ScalaVersion): Boolean = - version >= ScalaVersion.Latest.Scala_3_0 + version == ScalaVersion.Latest.Scala_3 /// INFIX diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/completion3/ScalaKeywordCompletionTest.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/completion3/ScalaKeywordCompletionTest.scala index 63c19b8a3d0..d387daf4ff0 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/completion3/ScalaKeywordCompletionTest.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/completion3/ScalaKeywordCompletionTest.scala @@ -1,10 +1,12 @@ package org.jetbrains.plugins.scala.lang.completion3 import com.intellij.codeInsight.lookup.Lookup +import com.intellij.testFramework.TestIndexingModeSupporter.IndexingMode import org.jetbrains.plugins.scala.lang.completion3.base.ScalaCompletionTestBase -import org.jetbrains.plugins.scala.util.runners.{MultipleScalaVersionsRunner, RunWithScalaVersions, TestScalaVersion} +import org.jetbrains.plugins.scala.util.runners.{MultipleScalaVersionsRunner, RunWithScalaVersions, TestScalaVersion, WithIndexingMode} import org.junit.runner.RunWith +@WithIndexingMode(mode = IndexingMode.DUMB_EMPTY_INDEX) class ScalaKeywordCompletionTest extends ScalaCompletionTestBase { def testPrivateVal(): Unit = doCompletionTest( From 49823f41c5cebba34de79e067cd01e399cd6cc97 Mon Sep 17 00:00:00 2001 From: Timur Aliberdov Date: Tue, 22 Oct 2024 21:53:50 +0200 Subject: [PATCH 04/11] [completion] enable scala directive completion contributors during indexing #SCL-21859 --- .../lang/completion/ScalaDirectiveCompletionContributor.scala | 3 ++- .../ScalaDirectiveDependencyCompletionContributor.scala | 3 ++- .../completion/ScalaDirectiveKeyCompletionContributor.scala | 3 ++- .../ScalaDirectiveScalaVersionCompletionContributor.scala | 3 ++- .../lang/completion/ScalaDirectiveAutoPopupTest.scala | 4 +++- .../lang/completion/ScalaDirectiveCompletionTest.scala | 3 +++ .../completion/ScalaDirectiveDependencyCompletionTest.scala | 3 +++ .../lang/completion/ScalaDirectiveKeyCompletionTest.scala | 3 +++ .../completion/ScalaDirectiveScalaVersionCompletionTest.scala | 3 +++ 9 files changed, 23 insertions(+), 5 deletions(-) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scalaDirective/lang/completion/ScalaDirectiveCompletionContributor.scala b/scala/scala-impl/src/org/jetbrains/plugins/scalaDirective/lang/completion/ScalaDirectiveCompletionContributor.scala index 9b6359c62a7..2f30870f02a 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scalaDirective/lang/completion/ScalaDirectiveCompletionContributor.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scalaDirective/lang/completion/ScalaDirectiveCompletionContributor.scala @@ -1,13 +1,14 @@ package org.jetbrains.plugins.scalaDirective.lang.completion import com.intellij.codeInsight.completion.{CompletionInitializationContext, CompletionParameters, CompletionProvider, CompletionResultSet, CompletionType} +import com.intellij.openapi.project.DumbAware import com.intellij.patterns.PlatformPatterns.psiComment import com.intellij.patterns.StandardPatterns import com.intellij.util.ProcessingContext import org.jetbrains.plugins.scala.lang.completion.{ScalaCompletionContributor, positionFromParameters} import org.jetbrains.plugins.scalaDirective.lang.completion.lookups.ScalaDirectiveLookupItem -final class ScalaDirectiveCompletionContributor extends ScalaCompletionContributor { +final class ScalaDirectiveCompletionContributor extends ScalaCompletionContributor with DumbAware { private val pattern = psiComment.withText(StandardPatterns.string.startsWith(DirectivePrefix)) extend(CompletionType.BASIC, pattern, new CompletionProvider[CompletionParameters] { diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scalaDirective/lang/completion/ScalaDirectiveDependencyCompletionContributor.scala b/scala/scala-impl/src/org/jetbrains/plugins/scalaDirective/lang/completion/ScalaDirectiveDependencyCompletionContributor.scala index c5fabb84ed7..61f974e1925 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scalaDirective/lang/completion/ScalaDirectiveDependencyCompletionContributor.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scalaDirective/lang/completion/ScalaDirectiveDependencyCompletionContributor.scala @@ -1,8 +1,9 @@ package org.jetbrains.plugins.scalaDirective.lang.completion import com.intellij.codeInsight.completion.{CompletionContributor, CompletionType} +import com.intellij.openapi.project.DumbAware import org.jetbrains.plugins.scalaDirective.dependencies.ScalaDirectiveDependencyPattern -final class ScalaDirectiveDependencyCompletionContributor extends CompletionContributor { +final class ScalaDirectiveDependencyCompletionContributor extends CompletionContributor with DumbAware { extend(CompletionType.BASIC, ScalaDirectiveDependencyPattern, new ScalaDirectiveDependencyCompletionProvider) } diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scalaDirective/lang/completion/ScalaDirectiveKeyCompletionContributor.scala b/scala/scala-impl/src/org/jetbrains/plugins/scalaDirective/lang/completion/ScalaDirectiveKeyCompletionContributor.scala index 0901378f31f..e9f1109829b 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scalaDirective/lang/completion/ScalaDirectiveKeyCompletionContributor.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scalaDirective/lang/completion/ScalaDirectiveKeyCompletionContributor.scala @@ -1,6 +1,7 @@ package org.jetbrains.plugins.scalaDirective.lang.completion import com.intellij.codeInsight.completion.{CompletionParameters, CompletionProvider, CompletionResultSet, CompletionType} +import com.intellij.openapi.project.DumbAware import com.intellij.util.ProcessingContext import org.jetbrains.plugins.scala.lang.completion.ScalaCompletionContributor import org.jetbrains.plugins.scalaDirective.dependencies.ScalaDirectiveDependencyKeys @@ -8,7 +9,7 @@ import org.jetbrains.plugins.scalaDirective.lang.completion.lookups.ScalaDirecti import scala.jdk.CollectionConverters.IterableHasAsJava -final class ScalaDirectiveKeyCompletionContributor extends ScalaCompletionContributor { +final class ScalaDirectiveKeyCompletionContributor extends ScalaCompletionContributor with DumbAware { register(ScalaDirectiveDependencyKeys) register(ScalaDirectiveScalaKey) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scalaDirective/lang/completion/ScalaDirectiveScalaVersionCompletionContributor.scala b/scala/scala-impl/src/org/jetbrains/plugins/scalaDirective/lang/completion/ScalaDirectiveScalaVersionCompletionContributor.scala index 718edf22325..e38b169f968 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scalaDirective/lang/completion/ScalaDirectiveScalaVersionCompletionContributor.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scalaDirective/lang/completion/ScalaDirectiveScalaVersionCompletionContributor.scala @@ -2,6 +2,7 @@ package org.jetbrains.plugins.scalaDirective.lang.completion import com.intellij.codeInsight.completion._ import com.intellij.codeInsight.completion.impl.RealPrefixMatchingWeigher +import com.intellij.openapi.project.DumbAware import com.intellij.util.ProcessingContext import org.apache.maven.artifact.versioning.ComparableVersion import org.jetbrains.plugins.scala.lang.completion.positionFromParameters @@ -13,7 +14,7 @@ import org.jetbrains.plugins.scalaDirective.util.ScalaDirectiveValueKind import scala.jdk.CollectionConverters.IterableHasAsJava -final class ScalaDirectiveScalaVersionCompletionContributor extends CompletionContributor { +final class ScalaDirectiveScalaVersionCompletionContributor extends CompletionContributor with DumbAware { extend(CompletionType.BASIC, ScalaDirectiveScalaVersionPattern, new CompletionProvider[CompletionParameters] { override def addCompletions(params: CompletionParameters, processingContext: ProcessingContext, resultSet: CompletionResultSet): Unit = { val place = positionFromParameters(params) diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scalaDirective/lang/completion/ScalaDirectiveAutoPopupTest.scala b/scala/scala-impl/test/org/jetbrains/plugins/scalaDirective/lang/completion/ScalaDirectiveAutoPopupTest.scala index e7a1fa1c8f7..2dcb8689995 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scalaDirective/lang/completion/ScalaDirectiveAutoPopupTest.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scalaDirective/lang/completion/ScalaDirectiveAutoPopupTest.scala @@ -1,11 +1,12 @@ package org.jetbrains.plugins.scalaDirective.lang.completion import com.intellij.codeInsight.editorActions.CompletionAutoPopupHandler +import com.intellij.testFramework.TestIndexingModeSupporter.IndexingMode import com.intellij.testFramework.{TestModeFlags, UsefulTestCase} import org.jetbrains.plugins.scala.base.ScalaCompletionAutoPopupTestCase import org.jetbrains.plugins.scala.packagesearch.api.{PackageSearchClient, PackageSearchClientTesting} import org.jetbrains.plugins.scala.packagesearch.util.DependencyUtil -import org.jetbrains.plugins.scala.util.runners.{MultipleScalaVersionsRunner, RunWithScalaVersions, TestScalaVersion} +import org.jetbrains.plugins.scala.util.runners.{MultipleScalaVersionsRunner, RunWithScalaVersions, TestScalaVersion, WithIndexingMode} import org.junit.Assert.assertNull import org.junit.runner.RunWith @@ -16,6 +17,7 @@ import java.util.Arrays.asList TestScalaVersion.Scala_2_13, TestScalaVersion.Scala_3_Latest )) +@WithIndexingMode(mode = IndexingMode.DUMB_EMPTY_INDEX) final class ScalaDirectiveAutoPopupTest extends ScalaCompletionAutoPopupTestCase with PackageSearchClientTesting { diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scalaDirective/lang/completion/ScalaDirectiveCompletionTest.scala b/scala/scala-impl/test/org/jetbrains/plugins/scalaDirective/lang/completion/ScalaDirectiveCompletionTest.scala index 6bd8f442eea..7b160052de0 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scalaDirective/lang/completion/ScalaDirectiveCompletionTest.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scalaDirective/lang/completion/ScalaDirectiveCompletionTest.scala @@ -1,7 +1,10 @@ package org.jetbrains.plugins.scalaDirective.lang.completion +import com.intellij.testFramework.TestIndexingModeSupporter.IndexingMode import org.jetbrains.plugins.scala.lang.completion3.base.ScalaCompletionTestBase +import org.jetbrains.plugins.scala.util.runners.WithIndexingMode +@WithIndexingMode(mode = IndexingMode.DUMB_EMPTY_INDEX) final class ScalaDirectiveCompletionTest extends ScalaCompletionTestBase { def testUsingCompletion_InsertSpacesBeforeAndAfter(): Unit = doCompletionTest( fileText = s"//>u$CARET", diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scalaDirective/lang/completion/ScalaDirectiveDependencyCompletionTest.scala b/scala/scala-impl/test/org/jetbrains/plugins/scalaDirective/lang/completion/ScalaDirectiveDependencyCompletionTest.scala index 793ca641173..01eb880fd0d 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scalaDirective/lang/completion/ScalaDirectiveDependencyCompletionTest.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scalaDirective/lang/completion/ScalaDirectiveDependencyCompletionTest.scala @@ -1,11 +1,14 @@ package org.jetbrains.plugins.scalaDirective.lang.completion +import com.intellij.testFramework.TestIndexingModeSupporter.IndexingMode import org.jetbrains.plugins.scala.lang.completion3.base.ScalaCompletionTestBase import org.jetbrains.plugins.scala.packagesearch.api.{PackageSearchClient, PackageSearchClientTesting} import org.jetbrains.plugins.scala.packagesearch.util.DependencyUtil +import org.jetbrains.plugins.scala.util.runners.WithIndexingMode import java.util.Arrays.asList +@WithIndexingMode(mode = IndexingMode.DUMB_EMPTY_INDEX) final class ScalaDirectiveDependencyCompletionTest extends ScalaCompletionTestBase with PackageSearchClientTesting { diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scalaDirective/lang/completion/ScalaDirectiveKeyCompletionTest.scala b/scala/scala-impl/test/org/jetbrains/plugins/scalaDirective/lang/completion/ScalaDirectiveKeyCompletionTest.scala index d7fbbb846de..3a1b9a132f9 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scalaDirective/lang/completion/ScalaDirectiveKeyCompletionTest.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scalaDirective/lang/completion/ScalaDirectiveKeyCompletionTest.scala @@ -1,7 +1,10 @@ package org.jetbrains.plugins.scalaDirective.lang.completion +import com.intellij.testFramework.TestIndexingModeSupporter.IndexingMode import org.jetbrains.plugins.scala.lang.completion3.base.ScalaCompletionTestBase +import org.jetbrains.plugins.scala.util.runners.WithIndexingMode +@WithIndexingMode(mode = IndexingMode.DUMB_EMPTY_INDEX) final class ScalaDirectiveKeyCompletionTest extends ScalaCompletionTestBase { private def checkCompletion(key: String): Unit = { diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scalaDirective/lang/completion/ScalaDirectiveScalaVersionCompletionTest.scala b/scala/scala-impl/test/org/jetbrains/plugins/scalaDirective/lang/completion/ScalaDirectiveScalaVersionCompletionTest.scala index de1091422c4..b0b7e462b3b 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scalaDirective/lang/completion/ScalaDirectiveScalaVersionCompletionTest.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scalaDirective/lang/completion/ScalaDirectiveScalaVersionCompletionTest.scala @@ -1,11 +1,14 @@ package org.jetbrains.plugins.scalaDirective.lang.completion +import com.intellij.testFramework.TestIndexingModeSupporter.IndexingMode import org.jetbrains.plugins.scala.lang.completion3.base.ScalaCompletionTestBase import org.jetbrains.plugins.scala.lang.completion3.base.ScalaCompletionTestBase.DefaultInvocationCount import org.jetbrains.plugins.scala.packagesearch.api.PackageSearchClientTesting import org.jetbrains.plugins.scala.packagesearch.util.DependencyUtil import org.jetbrains.plugins.scala.packagesearch.util.DependencyUtil.{Scala2CompilerArtifactId, Scala3CompilerArtifactId, ScalaCompilerGroupId} +import org.jetbrains.plugins.scala.util.runners.WithIndexingMode +@WithIndexingMode(mode = IndexingMode.DUMB_EMPTY_INDEX) final class ScalaDirectiveScalaVersionCompletionTest extends ScalaCompletionTestBase with PackageSearchClientTesting { From 4f1ab0dceaea96201db89d436da2440a7c887c3d Mon Sep 17 00:00:00 2001 From: Timur Aliberdov Date: Tue, 22 Oct 2024 22:08:34 +0200 Subject: [PATCH 05/11] [completion] enable sbt version completion contributor during indexing #SCL-21859 --- .../language/completion/SbtVersionCompletionContributor.scala | 3 ++- .../language/completion/SbtVersionPropertyCompletionTest.scala | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/scala/integration/properties/src/org/jetbrains/sbt/language/completion/SbtVersionCompletionContributor.scala b/scala/integration/properties/src/org/jetbrains/sbt/language/completion/SbtVersionCompletionContributor.scala index 6724d6b7e20..0eb85ce2b5a 100644 --- a/scala/integration/properties/src/org/jetbrains/sbt/language/completion/SbtVersionCompletionContributor.scala +++ b/scala/integration/properties/src/org/jetbrains/sbt/language/completion/SbtVersionCompletionContributor.scala @@ -4,6 +4,7 @@ import com.intellij.codeInsight.lookup.LookupElementBuilder import com.intellij.lang.Language import com.intellij.lang.properties.PropertiesLanguage import com.intellij.lang.properties.psi.impl.PropertyValueImpl +import com.intellij.openapi.project.DumbAware import com.intellij.patterns.ElementPattern import com.intellij.patterns.PlatformPatterns.psiElement import com.intellij.psi.{PsiDocumentManager, PsiElement} @@ -13,7 +14,7 @@ import org.jetbrains.plugins.scala.packagesearch.util.DependencyUtil import org.jetbrains.sbt.language.completion.SbtScalaVersionCompletionContributor.SbtScalaVersionCompletionProvider import org.jetbrains.sbt.language.completion.SbtVersionCompletionContributor.{SbtGroupId, SbtLaunchArtifactId} -private class SbtVersionCompletionContributor extends SbtScalaVersionCompletionContributor { +private class SbtVersionCompletionContributor extends SbtScalaVersionCompletionContributor with DumbAware { override protected def pattern: ElementPattern[_ <: PsiElement] = SbtPsiElementPatterns.propertiesFilePattern && psiElement().inside(SbtPsiElementPatterns.versionPropertyPattern) diff --git a/scala/integration/properties/test/org/jetbrains/sbt/language/completion/SbtVersionPropertyCompletionTest.scala b/scala/integration/properties/test/org/jetbrains/sbt/language/completion/SbtVersionPropertyCompletionTest.scala index a49580521d3..de5fc500bd4 100644 --- a/scala/integration/properties/test/org/jetbrains/sbt/language/completion/SbtVersionPropertyCompletionTest.scala +++ b/scala/integration/properties/test/org/jetbrains/sbt/language/completion/SbtVersionPropertyCompletionTest.scala @@ -1,12 +1,15 @@ package org.jetbrains.sbt.language.completion import com.intellij.lang.properties.PropertiesFileType +import com.intellij.testFramework.TestIndexingModeSupporter.IndexingMode import org.jetbrains.plugins.scala.lang.completion3.base.ScalaCompletionTestBase import org.jetbrains.plugins.scala.lang.completion3.base.ScalaCompletionTestBase.DefaultInvocationCount import org.jetbrains.plugins.scala.packagesearch.api.PackageSearchClientTesting import org.jetbrains.plugins.scala.packagesearch.util.DependencyUtil +import org.jetbrains.plugins.scala.util.runners.WithIndexingMode import org.jetbrains.sbt.language.completion.SbtVersionCompletionContributor.{SbtGroupId, SbtLaunchArtifactId} +@WithIndexingMode(mode = IndexingMode.DUMB_EMPTY_INDEX) final class SbtVersionPropertyCompletionTest extends ScalaCompletionTestBase with PackageSearchClientTesting { From 7251863ae49142d577d35c9d8df47b4988db9ac5 Mon Sep 17 00:00:00 2001 From: Timur Aliberdov Date: Tue, 22 Oct 2024 22:16:21 +0200 Subject: [PATCH 06/11] [completion] enable sbt scala version completion contributor during indexing #SCL-21859 --- .../completion/SbtScalaVersionCompletionContributor.scala | 3 ++- .../sbt/lang/completion/SbtScalaVersionCompletionTest.scala | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/sbt/sbt-impl/src/org/jetbrains/sbt/language/completion/SbtScalaVersionCompletionContributor.scala b/sbt/sbt-impl/src/org/jetbrains/sbt/language/completion/SbtScalaVersionCompletionContributor.scala index 17dbda72d08..e39f2e1f0b0 100644 --- a/sbt/sbt-impl/src/org/jetbrains/sbt/language/completion/SbtScalaVersionCompletionContributor.scala +++ b/sbt/sbt-impl/src/org/jetbrains/sbt/language/completion/SbtScalaVersionCompletionContributor.scala @@ -4,6 +4,7 @@ import com.intellij.codeInsight.completion._ import com.intellij.codeInsight.completion.impl.RealPrefixMatchingWeigher import com.intellij.codeInsight.lookup.LookupElementBuilder import com.intellij.lang.Language +import com.intellij.openapi.project.DumbAware import com.intellij.patterns.ElementPattern import com.intellij.patterns.PlatformPatterns.psiElement import com.intellij.psi.{PsiDocumentManager, PsiElement} @@ -58,7 +59,7 @@ private object SbtScalaVersionCompletionContributor { } } -private class ScalaVersionCompletionContributor extends SbtScalaVersionCompletionContributor { +private class ScalaVersionCompletionContributor extends SbtScalaVersionCompletionContributor with DumbAware { override protected def pattern: ElementPattern[_ <: PsiElement] = (SbtPsiElementPatterns.sbtFilePattern || SbtPsiElementPatterns.scalaFilePattern) && psiElement().inside(SbtPsiElementPatterns.versionPattern) diff --git a/sbt/sbt-impl/test/org/jetbrains/sbt/lang/completion/SbtScalaVersionCompletionTest.scala b/sbt/sbt-impl/test/org/jetbrains/sbt/lang/completion/SbtScalaVersionCompletionTest.scala index df59a486ce0..a70d05a4808 100644 --- a/sbt/sbt-impl/test/org/jetbrains/sbt/lang/completion/SbtScalaVersionCompletionTest.scala +++ b/sbt/sbt-impl/test/org/jetbrains/sbt/lang/completion/SbtScalaVersionCompletionTest.scala @@ -1,10 +1,13 @@ package org.jetbrains.sbt.lang.completion +import com.intellij.testFramework.TestIndexingModeSupporter.IndexingMode import org.jetbrains.plugins.scala.lang.completion3.base.ScalaCompletionTestBase.DefaultInvocationCount import org.jetbrains.plugins.scala.packagesearch.api.PackageSearchClientTesting import org.jetbrains.plugins.scala.packagesearch.util.DependencyUtil import org.jetbrains.plugins.scala.packagesearch.util.DependencyUtil.{Scala2CompilerArtifactId, Scala3CompilerArtifactId, ScalaCompilerGroupId} +import org.jetbrains.plugins.scala.util.runners.WithIndexingMode +@WithIndexingMode(mode = IndexingMode.DUMB_EMPTY_INDEX) final class SbtScalaVersionCompletionTest extends SbtCompletionTestBase with PackageSearchClientTesting { From 7f80d18ef3c5e259300e8d45e153f66a1c2bbeca Mon Sep 17 00:00:00 2001 From: Timur Aliberdov Date: Tue, 22 Oct 2024 22:22:58 +0200 Subject: [PATCH 07/11] [completion] enable sbt shell completion contributor during indexing #SCL-21859 --- .../src/org/jetbrains/sbt/shell/completion.scala | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/sbt/sbt-impl/src/org/jetbrains/sbt/shell/completion.scala b/sbt/sbt-impl/src/org/jetbrains/sbt/shell/completion.scala index 2ff760ebe96..42a5348086d 100644 --- a/sbt/sbt-impl/src/org/jetbrains/sbt/shell/completion.scala +++ b/sbt/sbt-impl/src/org/jetbrains/sbt/shell/completion.scala @@ -2,17 +2,16 @@ package org.jetbrains.sbt.shell import com.intellij.codeInsight.completion._ import com.intellij.codeInsight.lookup.LookupElementBuilder +import com.intellij.openapi.project.DumbAware import com.intellij.patterns.PlatformPatterns import com.intellij.util.ProcessingContext import org.jetbrains.annotations.NonNls -class SbtShellCompletionContributor extends CompletionContributor { - +final class SbtShellCompletionContributor extends CompletionContributor with DumbAware { extend( CompletionType.BASIC, PlatformPatterns.psiElement().withLanguage(SbtShellLanguage), SbtShellCompletionProvider) - } object SbtShellCompletionProvider extends CompletionProvider[CompletionParameters] { @@ -32,14 +31,9 @@ object SbtShellCompletionProvider extends CompletionProvider[CompletionParameter override def addCompletions(parameters: CompletionParameters, context: ProcessingContext, - result: CompletionResultSet): Unit = { - - + result: CompletionResultSet): Unit = all.foreach { key => val elem = LookupElementBuilder.create(key) result.addElement(elem) } - - } - -} \ No newline at end of file +} From 28008c9d24a942828a5aa8dd2fe2f42880c1fd8c Mon Sep 17 00:00:00 2001 From: Timur Aliberdov Date: Tue, 22 Oct 2024 22:36:09 +0200 Subject: [PATCH 08/11] [completion] enable scaladoc tags completion contributor during indexing #SCL-21859 --- .../ScalaDocCompletionContributor.scala | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/scaladoc/completion/ScalaDocCompletionContributor.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/scaladoc/completion/ScalaDocCompletionContributor.scala index f47904dd496..f3f91c34f54 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/scaladoc/completion/ScalaDocCompletionContributor.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/scaladoc/completion/ScalaDocCompletionContributor.scala @@ -2,39 +2,43 @@ package org.jetbrains.plugins.scala.lang.scaladoc.completion import com.intellij.codeInsight.completion._ import com.intellij.codeInsight.lookup.LookupElement +import com.intellij.openapi.project.DumbAware import com.intellij.patterns.PlatformPatterns import com.intellij.util.ProcessingContext import org.jetbrains.plugins.scala.lang.completion.{ScalaCompletionContributor, positionFromParameters} import org.jetbrains.plugins.scala.lang.psi.api.statements.{ScFunction, ScTypeAlias} import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.{ScClass, ScTrait} +import org.jetbrains.plugins.scala.extensions.{ObjectExt, OptionExt, PsiElementExt} import org.jetbrains.plugins.scala.lang.scaladoc.lexer.ScalaDocTokenType import org.jetbrains.plugins.scala.lang.scaladoc.parser.parsing.MyScaladocParsing import org.jetbrains.plugins.scala.lang.scaladoc.psi.api.ScDocComment -class ScalaDocCompletionContributor extends ScalaCompletionContributor { - extend(CompletionType.BASIC, PlatformPatterns.psiElement(ScalaDocTokenType.DOC_TAG_NAME), new CompletionProvider[CompletionParameters]() { +final class ScalaDocCompletionContributor extends ScalaCompletionContributor with DumbAware { + extend(CompletionType.BASIC, PlatformPatterns.psiElement(ScalaDocTokenType.DOC_TAG_NAME), new CompletionProvider[CompletionParameters] { override def addCompletions(parameters: CompletionParameters, context: ProcessingContext, result: CompletionResultSet): Unit = { - var posParent = positionFromParameters(parameters).getContext - while (posParent != null && !posParent.isInstanceOf[ScDocComment]) { - posParent = posParent.getContext - } - - if (posParent != null) { - val allowedTags = posParent.asInstanceOf[ScDocComment].getOwner match { + val position = positionFromParameters(parameters) + val posParent = position.contexts + .dropWhile(!_.is[ScDocComment]) + .nextOption() + .filterByType[ScDocComment] + + posParent.foreach { parent => + val allowedTags = parent.getOwner match { case _ : ScFunction => MyScaladocParsing.allTags case _ : ScClass => MyScaladocParsing.allTags - MyScaladocParsing.RETURN_TAG case _ : ScTypeAlias | _: ScTrait => MyScaladocParsing.allTags -- - Set(MyScaladocParsing.RETURN_TAG, MyScaladocParsing.THROWS_TAG, MyScaladocParsing.PARAM_TAG) + Set(MyScaladocParsing.RETURN_TAG, MyScaladocParsing.THROWS_TAG, MyScaladocParsing.PARAM_TAG) case _ => MyScaladocParsing.allTags -- MyScaladocParsing.tagsWithParameters - MyScaladocParsing.RETURN_TAG } - for (tag <- allowedTags) { + allowedTags.foreach { tag => result.addElement(new LookupElement { override def getLookupString: String = tag.substring(1) }) } } + result.stopHere() } }) -} \ No newline at end of file +} From 771a87494ee7031cd70be6aa2530925fa38fcf86 Mon Sep 17 00:00:00 2001 From: Timur Aliberdov Date: Thu, 24 Oct 2024 14:24:23 +0200 Subject: [PATCH 09/11] [completion] move `beforeCompletion` logic to a DumbAware contributor to be available during indexing #SCL-21859 `CompletionInitializationUtil.runContributorsBeforeCompletion` runs applicable contributors' `beforeCompletion` method for a given language. Since this logic was in `ScalaBasicCompletionContributor` that is not `DumbAware`, the `dummyIdentifier` has not been fixed in dumb mode --- .../resources/META-INF/scala-plugin-common.xml | 2 ++ .../ScalaBasicCompletionContributor.scala | 7 +------ .../ScalaDumbAwareCompletionContributor.scala | 18 ++++++++++++++++++ 3 files changed, 21 insertions(+), 6 deletions(-) create mode 100644 scala/scala-impl/src/org/jetbrains/plugins/scala/lang/completion/ScalaDumbAwareCompletionContributor.scala diff --git a/scala/scala-impl/resources/META-INF/scala-plugin-common.xml b/scala/scala-impl/resources/META-INF/scala-plugin-common.xml index c6b48d84dbf..1f208faba01 100644 --- a/scala/scala-impl/resources/META-INF/scala-plugin-common.xml +++ b/scala/scala-impl/resources/META-INF/scala-plugin-common.xml @@ -253,6 +253,8 @@ + diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/completion/ScalaBasicCompletionContributor.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/completion/ScalaBasicCompletionContributor.scala index 2f9041698da..4466a2d9fc0 100644 --- a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/completion/ScalaBasicCompletionContributor.scala +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/completion/ScalaBasicCompletionContributor.scala @@ -10,9 +10,4 @@ class ScalaBasicCompletionContributor extends ScalaCompletionContributor { PlatformPatterns.psiElement(), new ScalaBasicCompletionProvider ) - - override def beforeCompletion(context: CompletionInitializationContext): Unit = { - context.setDummyIdentifier(dummyIdentifier(context.getFile, context.getStartOffset - 1)) - super.beforeCompletion(context) - } -} \ No newline at end of file +} diff --git a/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/completion/ScalaDumbAwareCompletionContributor.scala b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/completion/ScalaDumbAwareCompletionContributor.scala new file mode 100644 index 00000000000..06dc783dcd5 --- /dev/null +++ b/scala/scala-impl/src/org/jetbrains/plugins/scala/lang/completion/ScalaDumbAwareCompletionContributor.scala @@ -0,0 +1,18 @@ +package org.jetbrains.plugins.scala.lang.completion + +import com.intellij.codeInsight.completion.CompletionInitializationContext +import com.intellij.openapi.project.DumbAware + +final class ScalaDumbAwareCompletionContributor extends ScalaCompletionContributor with DumbAware { + + /** + * Provide fixed dummy identifier for Scala completion even during indexing + * + * NOTE: `context.setDummyIdentifier` should be called only once per language + * @see [[com.intellij.codeInsight.completion.CompletionInitializationUtil.runContributorsBeforeCompletion]] + */ + override def beforeCompletion(context: CompletionInitializationContext): Unit = { + context.setDummyIdentifier(dummyIdentifier(context.getFile, context.getStartOffset - 1)) + super.beforeCompletion(context) + } +} From ff0117147e41fe2b620daaea6c68a19ca49133e2 Mon Sep 17 00:00:00 2001 From: Timur Aliberdov Date: Thu, 24 Oct 2024 14:39:37 +0200 Subject: [PATCH 10/11] [completion] enable sbt library dependency completion contributor during indexing #SCL-21859 --- ...SbtMavenPackageSearchDependencyCompletionContributor.scala | 4 ++-- .../sbt/lang/completion/SbtCompletionDependenciesTest.scala | 3 +++ .../SbtDependenciesCompletionInsertHandlerTest.scala | 3 +++ .../lang/completion/FileTestDataCompletionTestBase.scala | 2 +- 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/sbt/sbt-impl/src/org/jetbrains/sbt/language/completion/SbtMavenPackageSearchDependencyCompletionContributor.scala b/sbt/sbt-impl/src/org/jetbrains/sbt/language/completion/SbtMavenPackageSearchDependencyCompletionContributor.scala index 4a4a09246bb..52cce1410d6 100644 --- a/sbt/sbt-impl/src/org/jetbrains/sbt/language/completion/SbtMavenPackageSearchDependencyCompletionContributor.scala +++ b/sbt/sbt-impl/src/org/jetbrains/sbt/language/completion/SbtMavenPackageSearchDependencyCompletionContributor.scala @@ -4,7 +4,7 @@ import com.intellij.codeInsight.completion._ import com.intellij.codeInsight.completion.impl.RealPrefixMatchingWeigher import com.intellij.codeInsight.lookup.{LookupElement, LookupElementBuilder, LookupElementPresentation} import com.intellij.openapi.application.ApplicationManager -import com.intellij.openapi.project.Project +import com.intellij.openapi.project.{DumbAware, Project} import com.intellij.patterns.PlatformPatterns.psiElement import com.intellij.psi.PsiElement import com.intellij.util.ProcessingContext @@ -19,7 +19,7 @@ import org.jetbrains.sbt.language.utils.SbtDependencyUtils.GetMode.GetDep import org.jetbrains.sbt.language.utils._ // TODO(SCL-19130, SCL-22206): refactor -class SbtMavenPackageSearchDependencyCompletionContributor extends CompletionContributor { +class SbtMavenPackageSearchDependencyCompletionContributor extends CompletionContributor with DumbAware { private val PATTERN = (SbtPsiElementPatterns.sbtFilePattern || SbtPsiElementPatterns.scalaFilePattern) && psiElement.inside(SbtPsiElementPatterns.sbtModuleIdPattern) diff --git a/sbt/sbt-impl/test/org/jetbrains/sbt/lang/completion/SbtCompletionDependenciesTest.scala b/sbt/sbt-impl/test/org/jetbrains/sbt/lang/completion/SbtCompletionDependenciesTest.scala index 5e431be0638..3168a904f68 100644 --- a/sbt/sbt-impl/test/org/jetbrains/sbt/lang/completion/SbtCompletionDependenciesTest.scala +++ b/sbt/sbt-impl/test/org/jetbrains/sbt/lang/completion/SbtCompletionDependenciesTest.scala @@ -1,9 +1,12 @@ package org.jetbrains.sbt package lang.completion +import com.intellij.testFramework.TestIndexingModeSupporter.IndexingMode import org.jetbrains.plugins.scala.packagesearch.api.{PackageSearchClient, PackageSearchClientTesting} import org.jetbrains.plugins.scala.packagesearch.util.DependencyUtil +import org.jetbrains.plugins.scala.util.runners.WithIndexingMode +@WithIndexingMode(mode = IndexingMode.DUMB_EMPTY_INDEX) class SbtCompletionDependenciesTest extends SbtFileTestDataCompletionTestBase with MockSbt_1_0 diff --git a/sbt/sbt-impl/test/org/jetbrains/sbt/lang/completion/SbtDependenciesCompletionInsertHandlerTest.scala b/sbt/sbt-impl/test/org/jetbrains/sbt/lang/completion/SbtDependenciesCompletionInsertHandlerTest.scala index 4590c8b5f5f..1402fdbc89f 100644 --- a/sbt/sbt-impl/test/org/jetbrains/sbt/lang/completion/SbtDependenciesCompletionInsertHandlerTest.scala +++ b/sbt/sbt-impl/test/org/jetbrains/sbt/lang/completion/SbtDependenciesCompletionInsertHandlerTest.scala @@ -1,7 +1,10 @@ package org.jetbrains.sbt.lang.completion +import com.intellij.testFramework.TestIndexingModeSupporter.IndexingMode import org.jetbrains.plugins.scala.packagesearch.api.{PackageSearchClient, PackageSearchClientTesting} +import org.jetbrains.plugins.scala.util.runners.WithIndexingMode +@WithIndexingMode(mode = IndexingMode.DUMB_EMPTY_INDEX) class SbtDependenciesCompletionInsertHandlerTest extends SbtCompletionTestBase with PackageSearchClientTesting { diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/completion/FileTestDataCompletionTestBase.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/completion/FileTestDataCompletionTestBase.scala index f6faf5faea7..86b5df0ff7e 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/completion/FileTestDataCompletionTestBase.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/completion/FileTestDataCompletionTestBase.scala @@ -80,4 +80,4 @@ abstract class FileTestDataCompletionTestBase extends ScalaLightCodeInsightFixtu val expected = TestUtils.extractExpectedResultFromLastComment(getFile).expectedResult checkResult(items, expected) } -} \ No newline at end of file +} From e29d5026d34187cca3ecc3565b641c90d790ab58 Mon Sep 17 00:00:00 2001 From: Timur Aliberdov Date: Mon, 21 Oct 2024 21:53:34 +0200 Subject: [PATCH 11/11] [tests] refactor indexing modes setup in tests #SCL-21849 - do not require `MultipleScalaVersionsRunner` to be able to test something in dumb mode - do not run tests multiple times (test with the lowest IndexingMode possible to cut some CI time) --- .../macros/MainMethodLiveTemplateTest.scala | 11 ++--- ...ScalaLightCodeInsightFixtureTestCase.scala | 23 +++++++++- .../plugins/scala/base/package.scala | 35 +++++++++++++++ .../postfix/PostfixTemplateTest.scala | 9 ++-- .../Scala3MatchPostfixTemplateTest.scala | 18 ++++---- .../ScalaAssertPostfixTemplateTest.scala | 5 ++- .../ScalaForEachPostfixTemplateTest.scala | 5 ++- .../ScalaMatchPostfixTemplateTest.scala | 14 +++--- .../ScalaNotNullPostfixTemplateTest.scala | 5 ++- .../postfix/ScalaNotPostfixTemplateTest.scala | 5 ++- ...alaPostfixTemplateTabCompletionTests.scala | 41 +++++++++-------- .../ScalaWhilePostfixTemplateTest.scala | 5 ++- .../base/ScalaCompletionTestBase.scala | 14 +++--- .../navigation/GoToClassAndSymbolTest.scala | 38 ++++++++-------- .../runners/MultipleScalaVersionsRunner.scala | 42 ++++------------- .../util/runners/RunWithAllIndexingModes.java | 23 ---------- .../ScalaVersionAwareTestsCollector.scala | 45 ++++++------------- .../scala/util/runners/TestIndexingMode.java | 35 --------------- .../scala/util/runners/WithIndexingMode.java | 22 +++++++++ 19 files changed, 187 insertions(+), 208 deletions(-) create mode 100644 scala/scala-impl/test/org/jetbrains/plugins/scala/base/package.scala delete mode 100644 scala/scala-impl/test/org/jetbrains/plugins/scala/util/runners/RunWithAllIndexingModes.java delete mode 100644 scala/scala-impl/test/org/jetbrains/plugins/scala/util/runners/TestIndexingMode.java create mode 100644 scala/scala-impl/test/org/jetbrains/plugins/scala/util/runners/WithIndexingMode.java diff --git a/scala/codeInsight/test/org/jetbrains/plugins/scala/codeInsight/template/macros/MainMethodLiveTemplateTest.scala b/scala/codeInsight/test/org/jetbrains/plugins/scala/codeInsight/template/macros/MainMethodLiveTemplateTest.scala index 4ec36ea2296..f56385f0d06 100644 --- a/scala/codeInsight/test/org/jetbrains/plugins/scala/codeInsight/template/macros/MainMethodLiveTemplateTest.scala +++ b/scala/codeInsight/test/org/jetbrains/plugins/scala/codeInsight/template/macros/MainMethodLiveTemplateTest.scala @@ -2,7 +2,6 @@ package org.jetbrains.plugins.scala.codeInsight.template.macros import com.intellij.codeInsight.template.impl.LiveTemplateCompletionContributor import org.jetbrains.plugins.scala.ScalaVersion -import org.jetbrains.plugins.scala.base.ScalaCodeInsightTestFixture import org.jetbrains.plugins.scala.lang.completion3.base.ScalaCompletionTestFixture class MainMethodLiveTemplateTest extends ScalaLiveTemplateTestBase { @@ -12,13 +11,15 @@ class MainMethodLiveTemplateTest extends ScalaLiveTemplateTestBase { override protected def supportedIn(version: ScalaVersion): Boolean = version == ScalaVersion.Latest.Scala_3 - private lazy val scalaCompletionFixture: ScalaCompletionTestFixture = - new ScalaCompletionTestFixture(new ScalaCodeInsightTestFixture(myFixture)) + private[this] var _scalaCompletionFixture: ScalaCompletionTestFixture = _ + private def scalaCompletionFixture: ScalaCompletionTestFixture = _scalaCompletionFixture override def setUp(): Unit = { super.setUp() - //initialize lazy val fixtures - scalaCompletionFixture + + // pick up updated scala and java fixtures after super.setUp() + _scalaCompletionFixture = new ScalaCompletionTestFixture(scalaFixture) + LiveTemplateCompletionContributor.setShowTemplatesInTests(true, this.getTestRootDisposable) } diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/base/ScalaLightCodeInsightFixtureTestCase.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/base/ScalaLightCodeInsightFixtureTestCase.scala index 25fed26e4af..121d7b82d66 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/base/ScalaLightCodeInsightFixtureTestCase.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/base/ScalaLightCodeInsightFixtureTestCase.scala @@ -13,6 +13,7 @@ import com.intellij.openapi.util.text.StringUtil import com.intellij.openapi.vfs.VirtualFile import com.intellij.psi.PsiFile import com.intellij.psi.codeStyle.{CodeStyleSettings, CommonCodeStyleSettings} +import com.intellij.testFramework.TestIndexingModeSupporter.IndexingMode import com.intellij.testFramework.fixtures.{JavaCodeInsightTestFixture, LightJavaCodeInsightFixtureTestCase} import com.intellij.testFramework.{EditorTestUtil, IdeaTestUtil, LightProjectDescriptor} import com.intellij.util.lang.JavaVersion @@ -40,12 +41,22 @@ abstract class ScalaLightCodeInsightFixtureTestCase protected val START = EditorTestUtil.SELECTION_START_TAG protected val END = EditorTestUtil.SELECTION_END_TAG - protected lazy val scalaFixture: ScalaCodeInsightTestFixture = new ScalaCodeInsightTestFixture(getFixture) + // var is needed to pick up updated java fixture in setUp + private[this] var _scalaFixture: ScalaCodeInsightTestFixture = _ + protected def scalaFixture: ScalaCodeInsightTestFixture = _scalaFixture override def getTestDataPath: String = TestUtils.getTestDataPath + "/" protected def sourceRootPath: String = null + //start section: indexing mode setup + private[this] var indexingMode: IndexingMode = IndexingMode.SMART + + // SCL-21849 + override def getIndexingMode: IndexingMode = indexingMode + override def setIndexingMode(mode: IndexingMode): Unit = indexingMode = mode + //end section: indexing mode setup + //start section: project libraries configuration protected def loadScalaLibrary: Boolean = true @@ -125,8 +136,16 @@ abstract class ScalaLightCodeInsightFixtureTestCase //end section: project descriptor override protected def setUp(): Unit = { + // initialize indexing mode before java test fixture in super.setUp() + /** see also [[com.intellij.testFramework.fixtures.JavaIndexingModeCodeInsightTestFixture]] */ + indexingMode = this.findIndexingModeAnnotation() + .fold(IndexingMode.SMART)(_.mode()) + super.setUp() - scalaFixture //init fixture lazy val + + // pick up updated java fixture after super.setUp() + _scalaFixture = new ScalaCodeInsightTestFixture(getFixture) + Registry.get("ast.loading.filter").setValue(true, getTestRootDisposable) } diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/base/package.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/base/package.scala new file mode 100644 index 00000000000..de9bfa73846 --- /dev/null +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/base/package.scala @@ -0,0 +1,35 @@ +package org.jetbrains.plugins.scala + +import junit.framework.TestCase +import org.jetbrains.plugins.scala.extensions.ObjectExt +import org.jetbrains.plugins.scala.util.NotNothing +import org.jetbrains.plugins.scala.util.runners.WithIndexingMode + +import java.lang.annotation.Annotation +import scala.reflect.{ClassTag, classTag} +import scala.util.Try + +package object base { + final implicit class TestCaseExt(private val testCase: TestCase) extends AnyVal { + // SCL-21849 + def findIndexingModeAnnotation(): Option[WithIndexingMode] = findTestAnnotation[WithIndexingMode] + + /** + * Tries to find the specified annotation on the current test method and then on the current class. + * And then on the superclass if marked as [[java.lang.annotation.Inherited]]. + */ + def findTestAnnotation[A <: Annotation : ClassTag : NotNothing]: Option[A] = + testMethodAnnotation[A].orElse(classAnnotation[A]) + + private def testMethodAnnotation[A <: Annotation : ClassTag]: Option[A] = + for { + name <- testCase.getName.toOption + // java.lang.NoSuchMethodException can happen in generated tests (e.g.: FileSetTests) + method <- Try(testCase.getClass.getMethod(name)).toOption + annotation <- method.getAnnotation(classTag[A].runtimeClass.asInstanceOf[Class[A]]).toOption + } yield annotation + + private def classAnnotation[A <: Annotation : ClassTag]: Option[A] = + testCase.getClass.getAnnotation(classTag[A].runtimeClass.asInstanceOf[Class[A]]).toOption + } +} diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/completion/postfix/PostfixTemplateTest.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/completion/postfix/PostfixTemplateTest.scala index a9a4b222622..7a0f6104e9b 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/completion/postfix/PostfixTemplateTest.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/completion/postfix/PostfixTemplateTest.scala @@ -11,25 +11,26 @@ import com.intellij.openapi.util.io.FileUtil import com.intellij.openapi.util.text.StringUtil import com.intellij.openapi.vfs.CharsetToolkit import com.intellij.psi.PsiFile +import com.intellij.testFramework.TestIndexingModeSupporter.IndexingMode import org.jetbrains.plugins.scala.base.ScalaLightCodeInsightFixtureTestCase import org.jetbrains.plugins.scala.extensions.inWriteCommandAction import org.jetbrains.plugins.scala.lang.psi.ScalaPsiUtil import org.jetbrains.plugins.scala.lang.psi.api.ScalaPsiElement import org.jetbrains.plugins.scala.util.TestUtils -import org.jetbrains.plugins.scala.util.runners.{MultipleScalaVersionsRunner, RunWithAllIndexingModes, RunWithScalaVersions, TestScalaVersion} +import org.jetbrains.plugins.scala.util.runners.{MultipleScalaVersionsRunner, RunWithScalaVersions, TestScalaVersion, WithIndexingMode} import org.junit.Assert.{assertEquals, assertFalse, assertTrue} import org.junit.experimental.categories.Category import org.junit.runner.RunWith import java.io.File +@Category(Array(classOf[CompletionTests])) @RunWith(classOf[MultipleScalaVersionsRunner]) -@RunWithAllIndexingModes @RunWithScalaVersions(Array( TestScalaVersion.Scala_2_13, TestScalaVersion.Scala_3_Latest )) -@Category(Array(classOf[CompletionTests])) +@WithIndexingMode(mode = IndexingMode.DUMB_EMPTY_INDEX) abstract class PostfixTemplateTest extends ScalaLightCodeInsightFixtureTestCase { import PostfixTemplateTest._ @@ -127,4 +128,4 @@ object PostfixTemplateTest { editor.getCaretModel.moveToOffset(endOffset) editor.getSelectionModel.setSelection(range.getStartOffset, endOffset) } -} \ No newline at end of file +} diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/completion/postfix/Scala3MatchPostfixTemplateTest.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/completion/postfix/Scala3MatchPostfixTemplateTest.scala index ca63a62b422..1331774eefa 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/completion/postfix/Scala3MatchPostfixTemplateTest.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/completion/postfix/Scala3MatchPostfixTemplateTest.scala @@ -1,14 +1,14 @@ package org.jetbrains.plugins.scala.lang.completion.postfix -import com.intellij.testFramework.NeedsIndex -import org.jetbrains.plugins.scala.util.runners.{MultipleScalaVersionsRunner, RunWithAllIndexingModes, RunWithScalaVersions, TestScalaVersion} +import com.intellij.testFramework.TestIndexingModeSupporter.IndexingMode +import org.jetbrains.plugins.scala.util.runners.{MultipleScalaVersionsRunner, RunWithScalaVersions, TestScalaVersion, WithIndexingMode} import org.junit.runner.RunWith @RunWith(classOf[MultipleScalaVersionsRunner]) -@RunWithAllIndexingModes @RunWithScalaVersions(Array( TestScalaVersion.Scala_3_Latest )) +@WithIndexingMode(mode = IndexingMode.DUMB_EMPTY_INDEX) final class Scala3MatchPostfixTemplateTest extends PostfixTemplateTest { override def testPath(): String = super.testPath() + "match3/" @@ -22,22 +22,22 @@ final class Scala3MatchPostfixTemplateTest extends PostfixTemplateTest { def testInnerMatchInfixExpr(): Unit = doTest() - @NeedsIndex.SmartMode(reason = "exhaustive match needs type inference") + @WithIndexingMode(mode = IndexingMode.SMART, reason = "exhaustive match needs type inference") def testExhaustiveSealed(): Unit = doTest() - @NeedsIndex.SmartMode(reason = "exhaustive match needs type inference") + @WithIndexingMode(mode = IndexingMode.SMART, reason = "exhaustive match needs type inference") def testExhaustiveJavaEnum(): Unit = doTest() - @NeedsIndex.SmartMode(reason = "exhaustive match needs type inference") + @WithIndexingMode(mode = IndexingMode.SMART, reason = "exhaustive match needs type inference") def testExhaustiveScala2Enum(): Unit = doTest() - @NeedsIndex.SmartMode(reason = "exhaustive match needs type inference") + @WithIndexingMode(mode = IndexingMode.SMART, reason = "exhaustive match needs type inference") def testExhaustiveScala2Enum2(): Unit = doTest() - @NeedsIndex.SmartMode(reason = "exhaustive match needs type inference") + @WithIndexingMode(mode = IndexingMode.SMART, reason = "exhaustive match needs type inference") def testExhaustiveScala3Enum(): Unit = doTest() - @NeedsIndex.SmartMode(reason = "exhaustive match needs type inference") + @WithIndexingMode(mode = IndexingMode.SMART, reason = "exhaustive match needs type inference") def testExhaustiveScala3EnumInTheMiddle(): Unit = doTest() def testNoFunctionExprParent(): Unit = doNotApplicableTest() diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/completion/postfix/ScalaAssertPostfixTemplateTest.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/completion/postfix/ScalaAssertPostfixTemplateTest.scala index f54f0fe1da0..5581ea8ea02 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/completion/postfix/ScalaAssertPostfixTemplateTest.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/completion/postfix/ScalaAssertPostfixTemplateTest.scala @@ -1,8 +1,9 @@ package org.jetbrains.plugins.scala.lang.completion.postfix -import com.intellij.testFramework.NeedsIndex +import com.intellij.testFramework.TestIndexingModeSupporter.IndexingMode +import org.jetbrains.plugins.scala.util.runners.WithIndexingMode -@NeedsIndex.SmartMode(reason = "`assert` needs type inference to check conformance with Boolean") +@WithIndexingMode(mode = IndexingMode.SMART, reason = "`assert` needs type inference to check conformance with Boolean") class ScalaAssertPostfixTemplateTest extends PostfixTemplateTest { override def testPath(): String = super.testPath() + "assert/" diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/completion/postfix/ScalaForEachPostfixTemplateTest.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/completion/postfix/ScalaForEachPostfixTemplateTest.scala index bd9d827fdf8..e12c4f5f8ba 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/completion/postfix/ScalaForEachPostfixTemplateTest.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/completion/postfix/ScalaForEachPostfixTemplateTest.scala @@ -1,8 +1,9 @@ package org.jetbrains.plugins.scala.lang.completion.postfix -import com.intellij.testFramework.NeedsIndex +import com.intellij.testFramework.TestIndexingModeSupporter.IndexingMode +import org.jetbrains.plugins.scala.util.runners.WithIndexingMode -@NeedsIndex.SmartMode(reason = "`for` needs type inference to check sameOrInheritor") +@WithIndexingMode(mode = IndexingMode.SMART, reason = "`for` needs type inference to check sameOrInheritor") class ScalaForEachPostfixTemplateTest extends PostfixTemplateTest { override def testPath() = super.testPath() + "foreach/" diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/completion/postfix/ScalaMatchPostfixTemplateTest.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/completion/postfix/ScalaMatchPostfixTemplateTest.scala index 3b910ea56a1..58effdac9c2 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/completion/postfix/ScalaMatchPostfixTemplateTest.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/completion/postfix/ScalaMatchPostfixTemplateTest.scala @@ -2,15 +2,15 @@ package org.jetbrains.plugins.scala.lang package completion package postfix -import com.intellij.testFramework.NeedsIndex -import org.jetbrains.plugins.scala.util.runners.{MultipleScalaVersionsRunner, RunWithAllIndexingModes, RunWithScalaVersions, TestScalaVersion} +import com.intellij.testFramework.TestIndexingModeSupporter.IndexingMode +import org.jetbrains.plugins.scala.util.runners.{MultipleScalaVersionsRunner, RunWithScalaVersions, TestScalaVersion, WithIndexingMode} import org.junit.runner.RunWith @RunWith(classOf[MultipleScalaVersionsRunner]) -@RunWithAllIndexingModes @RunWithScalaVersions(Array( TestScalaVersion.Scala_2_13 )) +@WithIndexingMode(mode = IndexingMode.DUMB_EMPTY_INDEX) class ScalaMatchPostfixTemplateTest extends PostfixTemplateTest { override def testPath(): String = super.testPath() + "match/" @@ -25,16 +25,16 @@ class ScalaMatchPostfixTemplateTest extends PostfixTemplateTest { def testInnerMatchInfixExpr(): Unit = doTest() - @NeedsIndex.SmartMode(reason = "exhaustive match needs type inference") + @WithIndexingMode(mode = IndexingMode.SMART, reason = "exhaustive match needs type inference") def testExhaustiveSealed(): Unit = doTest() - @NeedsIndex.SmartMode(reason = "exhaustive match needs type inference") + @WithIndexingMode(mode = IndexingMode.SMART, reason = "exhaustive match needs type inference") def testExhaustiveJavaEnum(): Unit = doTest() - @NeedsIndex.SmartMode(reason = "exhaustive match needs type inference") + @WithIndexingMode(mode = IndexingMode.SMART, reason = "exhaustive match needs type inference") def testExhaustiveScalaEnum(): Unit = doTest() - @NeedsIndex.SmartMode(reason = "exhaustive match needs type inference") + @WithIndexingMode(mode = IndexingMode.SMART, reason = "exhaustive match needs type inference") def testExhaustiveScalaEnum2(): Unit = doTest() def testNoFunctionExprParent(): Unit = doNotApplicableTest() diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/completion/postfix/ScalaNotNullPostfixTemplateTest.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/completion/postfix/ScalaNotNullPostfixTemplateTest.scala index fecd2d78eb4..96fed24e7ef 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/completion/postfix/ScalaNotNullPostfixTemplateTest.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/completion/postfix/ScalaNotNullPostfixTemplateTest.scala @@ -1,8 +1,9 @@ package org.jetbrains.plugins.scala.lang.completion.postfix -import com.intellij.testFramework.NeedsIndex +import com.intellij.testFramework.TestIndexingModeSupporter.IndexingMode +import org.jetbrains.plugins.scala.util.runners.WithIndexingMode -@NeedsIndex.SmartMode(reason = "`notnull` needs type inference to check conformance with AnyRef") +@WithIndexingMode(mode = IndexingMode.SMART, reason = "`notnull` needs type inference to check conformance with AnyRef") class ScalaNotNullPostfixTemplateTest extends PostfixTemplateTest { override def testPath(): String = super.testPath() + "notnull/" diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/completion/postfix/ScalaNotPostfixTemplateTest.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/completion/postfix/ScalaNotPostfixTemplateTest.scala index 1b27957ec89..43f785a6417 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/completion/postfix/ScalaNotPostfixTemplateTest.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/completion/postfix/ScalaNotPostfixTemplateTest.scala @@ -1,8 +1,9 @@ package org.jetbrains.plugins.scala.lang.completion.postfix -import com.intellij.testFramework.NeedsIndex +import com.intellij.testFramework.TestIndexingModeSupporter.IndexingMode +import org.jetbrains.plugins.scala.util.runners.WithIndexingMode -@NeedsIndex.SmartMode(reason = "`not` needs type inference to check conformance with Boolean") +@WithIndexingMode(mode = IndexingMode.SMART, reason = "`not` needs type inference to check conformance with Boolean") class ScalaNotPostfixTemplateTest extends PostfixTemplateTest { override def testPath(): String = super.testPath() + "not/" diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/completion/postfix/ScalaPostfixTemplateTabCompletionTests.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/completion/postfix/ScalaPostfixTemplateTabCompletionTests.scala index 6d83b8972c4..dbf4bd41ed8 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/completion/postfix/ScalaPostfixTemplateTabCompletionTests.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/completion/postfix/ScalaPostfixTemplateTabCompletionTests.scala @@ -7,20 +7,22 @@ import com.intellij.codeInsight.template.postfix.completion.PostfixTemplateLooku import com.intellij.codeInsight.template.postfix.templates.PostfixTemplate import com.intellij.openapi.application.impl.NonBlockingReadActionImpl import com.intellij.openapi.util.Condition +import com.intellij.testFramework.EdtTestUtil +import com.intellij.testFramework.TestIndexingModeSupporter.IndexingMode import com.intellij.testFramework.UsefulTestCase.{assertNotEmpty, assertSize} -import com.intellij.testFramework.{EdtTestUtil, NeedsIndex} import com.intellij.util.containers.ContainerUtil import junit.framework.TestCase.{assertNotNull, assertNull, fail} import org.jetbrains.plugins.scala.base.ScalaCompletionAutoPopupTestCase import org.jetbrains.plugins.scala.lang.completion.postfix.templates.{ScalaExhaustiveMatchPostfixTemplate, ScalaMatchPostfixTemplate} import org.jetbrains.plugins.scala.lang.completion3.base.ScalaCompletionTestFixture.lookupItemsDebugText -import org.jetbrains.plugins.scala.util.runners.{MultipleScalaVersionsRunner, RunWithAllIndexingModes, RunWithScalaVersions, TestScalaVersion} +import org.jetbrains.plugins.scala.util.runners.{MultipleScalaVersionsRunner, RunWithScalaVersions, TestScalaVersion, WithIndexingMode} import org.junit.experimental.categories.Category import org.junit.runner.RunWith import scala.jdk.CollectionConverters.CollectionHasAsScala @Category(Array(classOf[CompletionTests])) +@WithIndexingMode(mode = IndexingMode.DUMB_EMPTY_INDEX) abstract class ScalaPostfixTemplateTabCompletionTestBase extends ScalaCompletionAutoPopupTestCase { private val tab = "\t" private val resultFilePostfix = "-after.scala" @@ -65,29 +67,28 @@ abstract class ScalaPostfixTemplateTabCompletionTestBase extends ScalaCompletion } @RunWith(classOf[MultipleScalaVersionsRunner]) -@RunWithAllIndexingModes @RunWithScalaVersions(Array( TestScalaVersion.Scala_2_13, TestScalaVersion.Scala_3_Latest, )) class ScalaPostfixTemplateTabCompletionTest extends ScalaPostfixTemplateTabCompletionTestBase { - @NeedsIndex.SmartMode(reason = "`assert` needs type inference to check conformance with Boolean") + @WithIndexingMode(mode = IndexingMode.SMART, reason = "`assert` needs type inference to check conformance with Boolean") def testAssert(): Unit = doTestUniqueKeyTemplate()() def testCast(): Unit = doTestUniqueKeyTemplate()() - @NeedsIndex.SmartMode(reason = "`for` needs type inference to check sameOrInheritor") + @WithIndexingMode(mode = IndexingMode.SMART, reason = "`for` needs type inference to check sameOrInheritor") def testFor(): Unit = doTestUniqueKeyTemplate()() def testField(): Unit = doTestUniqueKeyTemplate()() def testVar(): Unit = doTestUniqueKeyTemplate()() - @NeedsIndex.SmartMode(reason = "`not` needs type inference to check conformance with Boolean") + @WithIndexingMode(mode = IndexingMode.SMART, reason = "`not` needs type inference to check conformance with Boolean") def testNot(): Unit = doTestUniqueKeyTemplate()() - @NeedsIndex.SmartMode(reason = "`!` needs type inference to check conformance with Boolean") + @WithIndexingMode(mode = IndexingMode.SMART, reason = "`!` needs type inference to check conformance with Boolean") def testNotBang(): Unit = doTestUniqueKeyTemplate("not")("!") def testPar(): Unit = doTestUniqueKeyTemplate()() @@ -98,22 +99,22 @@ class ScalaPostfixTemplateTabCompletionTest extends ScalaPostfixTemplateTabCompl def testPrtln(): Unit = doTestUniqueKeyTemplate("println")(".prtln") - @NeedsIndex.SmartMode(reason = "`throw` needs type inference to check sameOrInheritor") + @WithIndexingMode(mode = IndexingMode.SMART, reason = "`throw` needs type inference to check sameOrInheritor") def testThrow(): Unit = doTestUniqueKeyTemplate()() - @NeedsIndex.SmartMode(reason = "`while` needs type inference to check conformance with Boolean") + @WithIndexingMode(mode = IndexingMode.SMART, reason = "`while` needs type inference to check conformance with Boolean") def testWhile(): Unit = doTestUniqueKeyTemplate()() - @NeedsIndex.SmartMode(reason = "`do-while` needs type inference to check conformance with Boolean") + @WithIndexingMode(mode = IndexingMode.SMART, reason = "`do-while` needs type inference to check conformance with Boolean") def testDoWhile(): Unit = doTestUniqueKeyTemplate()(".dowhile") - @NeedsIndex.SmartMode(reason = "`null` needs type inference to check conformance with AnyRef") + @WithIndexingMode(mode = IndexingMode.SMART, reason = "`null` needs type inference to check conformance with AnyRef") def testIsNull(): Unit = doTestUniqueKeyTemplate()(".null") - @NeedsIndex.SmartMode(reason = "`notnull` needs type inference to check conformance with AnyRef") + @WithIndexingMode(mode = IndexingMode.SMART, reason = "`notnull` needs type inference to check conformance with AnyRef") def testNotNull(): Unit = doTestUniqueKeyTemplate()(".notnull") - @NeedsIndex.SmartMode(reason = "`nn` needs type inference to check conformance with AnyRef") + @WithIndexingMode(mode = IndexingMode.SMART, reason = "`nn` needs type inference to check conformance with AnyRef") def testNotNullNn(): Unit = doTestUniqueKeyTemplate("notNull")(".nn") def testOption(): Unit = doTestUniqueKeyTemplate()(".Option") @@ -138,13 +139,12 @@ class ScalaPostfixTemplateTabCompletionTest extends ScalaPostfixTemplateTabCompl } } -@RunWith(classOf[MultipleScalaVersionsRunner]) -@RunWithAllIndexingModes -@RunWithScalaVersions(Array(TestScalaVersion.Scala_2_13)) class ScalaPostfixTemplateTabCompletionTest_2_13 extends ScalaPostfixTemplateTabCompletionTestBase { + override def supportedIn(version: ScalaVersion): Boolean = version == ScalaVersion.Latest.Scala_2_13 + def testMatch(): Unit = doTest(classOf[ScalaMatchPostfixTemplate])() - @NeedsIndex.SmartMode(reason = "exhaustive match needs type inference") + @WithIndexingMode(mode = IndexingMode.SMART, reason = "exhaustive match needs type inference") def testExhaustiveMatch(): Unit = doTest(classOf[ScalaExhaustiveMatchPostfixTemplate])(".match") def testTry(): Unit = doTestUniqueKeyTemplate()() @@ -154,15 +154,14 @@ class ScalaPostfixTemplateTabCompletionTest_2_13 extends ScalaPostfixTemplateTab def testIf(): Unit = doTestUniqueKeyTemplate()() } -@RunWith(classOf[MultipleScalaVersionsRunner]) -@RunWithAllIndexingModes -@RunWithScalaVersions(Array(TestScalaVersion.Scala_3_Latest)) class ScalaPostfixTemplateTabCompletionTest_3_Latest extends ScalaPostfixTemplateTabCompletionTestBase { + override def supportedIn(version: ScalaVersion): Boolean = version == ScalaVersion.Latest.Scala_3 + override def getTestDataPath: String = super.getTestDataPath + "/scala3" def testMatch(): Unit = doTest(classOf[ScalaMatchPostfixTemplate])() - @NeedsIndex.SmartMode(reason = "exhaustive match needs type inference") + @WithIndexingMode(mode = IndexingMode.SMART, reason = "exhaustive match needs type inference") def testExhaustiveMatch(): Unit = doTest(classOf[ScalaExhaustiveMatchPostfixTemplate])(".match") def testTry(): Unit = doTestUniqueKeyTemplate()() diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/completion/postfix/ScalaWhilePostfixTemplateTest.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/completion/postfix/ScalaWhilePostfixTemplateTest.scala index d435ccb5016..1d6cf30c20c 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/completion/postfix/ScalaWhilePostfixTemplateTest.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/completion/postfix/ScalaWhilePostfixTemplateTest.scala @@ -1,8 +1,9 @@ package org.jetbrains.plugins.scala.lang.completion.postfix -import com.intellij.testFramework.NeedsIndex +import com.intellij.testFramework.TestIndexingModeSupporter.IndexingMode +import org.jetbrains.plugins.scala.util.runners.WithIndexingMode -@NeedsIndex.SmartMode(reason = "`while` needs type inference to check conformance with Boolean") +@WithIndexingMode(mode = IndexingMode.SMART, reason = "`while` needs type inference to check conformance with Boolean") class ScalaWhilePostfixTemplateTest extends PostfixTemplateTest { override def testPath(): String = super.testPath() + "while/" diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/completion3/base/ScalaCompletionTestBase.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/completion3/base/ScalaCompletionTestBase.scala index e3ab770079b..a3f1b125aba 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/completion3/base/ScalaCompletionTestBase.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/completion3/base/ScalaCompletionTestBase.scala @@ -24,15 +24,17 @@ abstract class ScalaCompletionTestBase extends ScalaLightCodeInsightFixtureTestC import Lookup.REPLACE_SELECT_CHAR import ScalaCompletionTestBase._ - protected lazy val scalaCompletionTestFixture: ScalaCompletionTestFixture = new ScalaCompletionTestFixture( - scalaFixture, - DefaultInvocationCount - ) + private[this] var _scalaCompletionTestFixture: ScalaCompletionTestFixture = _ + protected def scalaCompletionTestFixture: ScalaCompletionTestFixture = _scalaCompletionTestFixture protected override def setUp(): Unit = { super.setUp() - scalaCompletionTestFixture //init lazy val fixture + // pick up updated scala and java fixtures after super.setUp() + _scalaCompletionTestFixture = new ScalaCompletionTestFixture( + scalaFixture, + DefaultInvocationCount + ) StatisticsManager.getInstance match { case impl: StatisticsManagerImpl => impl.enableStatistics(getTestRootDisposable) @@ -143,4 +145,4 @@ object ScalaCompletionTestBase { case _ => false } -} \ No newline at end of file +} diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/navigation/GoToClassAndSymbolTest.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/navigation/GoToClassAndSymbolTest.scala index 699b4a6b288..e4df2826616 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/navigation/GoToClassAndSymbolTest.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/lang/navigation/GoToClassAndSymbolTest.scala @@ -5,14 +5,14 @@ package navigation import com.intellij.ide.util.gotoByName._ import com.intellij.openapi.application.ModalityState import com.intellij.psi.{PsiClass, PsiElement} -import com.intellij.testFramework.{NeedsIndex, PlatformTestUtil} +import com.intellij.testFramework.PlatformTestUtil +import com.intellij.testFramework.TestIndexingModeSupporter.IndexingMode import com.intellij.util.concurrency.Semaphore import org.jetbrains.plugins.scala.lang.psi.api.statements.ScFunction import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.{ScClass, ScObject, ScTrait} import org.jetbrains.plugins.scala.util.assertions.CollectionsAssertions.assertCollectionEquals -import org.jetbrains.plugins.scala.util.runners.{MultipleScalaVersionsRunner, RunWithAllIndexingModes} +import org.jetbrains.plugins.scala.util.runners.WithIndexingMode import org.junit.Assert._ -import org.junit.runner.RunWith import scala.jdk.CollectionConverters._ @@ -72,9 +72,10 @@ abstract class GoToClassAndSymbolTestBase extends GoToTestBase { ) } +@WithIndexingMode(mode = IndexingMode.DUMB_EMPTY_INDEX) abstract class GoToClassAndSymbolCommonTests extends GoToClassAndSymbolTestBase { - @NeedsIndex.Full + @WithIndexingMode(mode = IndexingMode.DUMB_FULL_INDEX) def testTrait(): Unit = { myFixture.addFileToProject("GoToClassSimpleTrait.scala", "trait GoToClassSimpleTrait") @@ -84,7 +85,7 @@ abstract class GoToClassAndSymbolCommonTests extends GoToClassAndSymbolTestBase checkSize(elements, 1) } - @NeedsIndex.Full + @WithIndexingMode(mode = IndexingMode.DUMB_FULL_INDEX) def testTrait2(): Unit = { myFixture.addFileToProject("GoToClassSimpleTrait.scala", "trait GoToClassSimpleTrait") @@ -94,7 +95,7 @@ abstract class GoToClassAndSymbolCommonTests extends GoToClassAndSymbolTestBase checkSize(elements, 1) } - @NeedsIndex.Full + @WithIndexingMode(mode = IndexingMode.DUMB_FULL_INDEX) def testObject(): Unit = { myFixture.addFileToProject("GoToClassSimpleObject.scala", "object GoToClassSimpleObject") @@ -104,7 +105,7 @@ abstract class GoToClassAndSymbolCommonTests extends GoToClassAndSymbolTestBase checkSize(elements, 1) } - @NeedsIndex.Full + @WithIndexingMode(mode = IndexingMode.DUMB_FULL_INDEX) def testPackageObject(): Unit = { myFixture.addFileToProject("foo/somePackageName/package.scala", """package foo @@ -118,7 +119,7 @@ abstract class GoToClassAndSymbolCommonTests extends GoToClassAndSymbolTestBase checkSize(elements, 1) } - @NeedsIndex.Full + @WithIndexingMode(mode = IndexingMode.DUMB_FULL_INDEX) def testGoToSymbol(): Unit = { myFixture.addFileToProject("GoToSymbol.scala", """class FooClass { @@ -140,7 +141,7 @@ abstract class GoToClassAndSymbolCommonTests extends GoToClassAndSymbolTestBase ) } - @NeedsIndex.Full + @WithIndexingMode(mode = IndexingMode.DUMB_FULL_INDEX) def testGoToSymbolWithPackagePrefix_ShouldNotContainLocalDefinitions(): Unit = { myFixture.addFileToProject("GoToSymbolWithPackagePrefix.scala", """package org.example @@ -183,7 +184,7 @@ abstract class GoToClassAndSymbolCommonTests extends GoToClassAndSymbolTestBase ) } - @NeedsIndex.Full + @WithIndexingMode(mode = IndexingMode.DUMB_FULL_INDEX) def testGoToClass(): Unit = { myFixture.addFileToProject("GoToClass.scala", """class FooClass { @@ -203,7 +204,7 @@ abstract class GoToClassAndSymbolCommonTests extends GoToClassAndSymbolTestBase ) } - @NeedsIndex.ForStandardLibrary + @WithIndexingMode(mode = IndexingMode.DUMB_RUNTIME_ONLY_INDEX) def testGoToClass_javaStdLib(): Unit = { checkContainExpected( gotoClassElements("AutoCloseable"), @@ -216,7 +217,7 @@ abstract class GoToClassAndSymbolCommonTests extends GoToClassAndSymbolTestBase ) } - @NeedsIndex.Full + @WithIndexingMode(mode = IndexingMode.DUMB_FULL_INDEX) def testClass_:::(): Unit = { myFixture.addFileToProject("Colons.scala", "class ::: { def ::: : Unit = () }") @@ -226,7 +227,7 @@ abstract class GoToClassAndSymbolCommonTests extends GoToClassAndSymbolTestBase checkSize(elements, 1) } - @NeedsIndex.Full + @WithIndexingMode(mode = IndexingMode.DUMB_FULL_INDEX) def testSymbol_:::(): Unit = { myFixture.addFileToProject("Colons.scala", "class ::: { def ::: : Unit = () }") @@ -236,7 +237,7 @@ abstract class GoToClassAndSymbolCommonTests extends GoToClassAndSymbolTestBase checkSize(elements, 2) } - @NeedsIndex.Full + @WithIndexingMode(mode = IndexingMode.DUMB_FULL_INDEX) def testSymbolInPackaging_:::(): Unit = { myFixture.addFileToProject("threeColons.scala", """package test @@ -250,8 +251,6 @@ abstract class GoToClassAndSymbolCommonTests extends GoToClassAndSymbolTestBase } } -@RunWith(classOf[MultipleScalaVersionsRunner]) -@RunWithAllIndexingModes class GoToClassAndSymbolTest_Scala213 extends GoToClassAndSymbolCommonTests { override protected def supportedIn(version: ScalaVersion): Boolean = version == ScalaVersion.Latest.Scala_2_13 @@ -259,16 +258,15 @@ class GoToClassAndSymbolTest_Scala213 extends GoToClassAndSymbolCommonTests { override protected def loadScalaLibrary = false } -@RunWith(classOf[MultipleScalaVersionsRunner]) -@RunWithAllIndexingModes class GoToClassAndSymbolTest_Scala3 extends GoToClassAndSymbolCommonTests { override protected def supportedIn(version: ScalaVersion): Boolean = version.isScala3 override protected def loadScalaLibrary = false - @NeedsIndex.Full - def testGoToSymbolWithPackagePrefix_ShouldContainAllTopLevelDefinitions(): Unit = { + // TODO: enable when SCL-23136 is fixed + @WithIndexingMode(mode = IndexingMode.DUMB_FULL_INDEX) + def _testGoToSymbolWithPackagePrefix_ShouldContainAllTopLevelDefinitions(): Unit = { myFixture.addFileToProject("GoToSymbolWithPackagePrefix.scala", """package org.example | diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/util/runners/MultipleScalaVersionsRunner.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/util/runners/MultipleScalaVersionsRunner.scala index 6604a3541af..7d2a6c259e9 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/util/runners/MultipleScalaVersionsRunner.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/util/runners/MultipleScalaVersionsRunner.scala @@ -118,11 +118,6 @@ private object MultipleScalaVersionsRunner { def this(version: JdkVersion) = this(sanitize(s"(jdk ${version.toString})")) } - // SCL-21849 - private case class IndexingModeTestSuite(name: String) extends MyBaseTestSuite(name) { - def this(indexingMode: TestIndexingMode) = this(s"(${indexingMode.label})") - } - def testSuite(klass: Class[_ <: TestCase]): TestSuite = { assert(classOf[ScalaSdkOwner].isAssignableFrom(klass)) @@ -133,10 +128,10 @@ private object MultipleScalaVersionsRunner { assert(classScalaVersions.nonEmpty, "at least one scala version should be specified") assert(classJdkVersions.nonEmpty, "at least one jdk version should be specified") - val allTestCases: Seq[(TestCase, ScalaVersion, JdkVersion, TestIndexingMode)] = { + val allTestCases: Seq[(TestCase, ScalaVersion, JdkVersion)] = { val collected = new ScalaVersionAwareTestsCollector(klass, classScalaVersions, classJdkVersions).collectTests() - collected.collect { case (test, sv, jv, im) if filterJdkVersionRegistry.forall(_ == jv) => - (test, sv.toProductionVersion, jv.toProductionVersion, im) + collected.collect { case (test, sv, jv) if filterJdkVersionRegistry.forall(_ == jv) => + (test, sv.toProductionVersion, jv.toProductionVersion) } } @@ -168,11 +163,11 @@ private object MultipleScalaVersionsRunner { // } // } - private def childTestsByScalaVersion(testCases: Seq[(TestCase, ScalaVersion, JdkVersion, TestIndexingMode)]): Seq[Test] = { + private def childTestsByScalaVersion(testCases: Seq[(TestCase, ScalaVersion, JdkVersion)]): Seq[Test] = { val scalaVersionToTests: Map[ScalaVersion, Seq[Test]] = testCases.groupBy(_._2) .view - .mapValues(_.map(t => (t._1, t._3, t._4))) + .mapValues(_.map(t => (t._1, t._3))) .mapValues(childTestsByJdkVersion) .toMap @@ -185,7 +180,7 @@ private object MultipleScalaVersionsRunner { } yield { val firstTest = tests.head val suite = firstTest match { - case _: JdkVersionTestSuite | _: IndexingModeTestSuite => + case _: JdkVersionTestSuite => new ScalaVersionTestSuite(version) case s: ScalaSdkOwner => // if only one jdk version is used, display it in the test name @@ -205,12 +200,11 @@ private object MultipleScalaVersionsRunner { } } - private def childTestsByJdkVersion(testCases: Seq[(TestCase, JdkVersion, TestIndexingMode)]): Seq[Test] = { + private def childTestsByJdkVersion(testCases: Seq[(TestCase, JdkVersion)]): Seq[Test] = { val jdkVersionToTests: Map[JdkVersion, Seq[Test]] = testCases.groupBy(_._2) .view - .mapValues(_.map(t => (t._1, t._3))) - .mapValues(childTestsByIndexingMode) + .mapValues(_.map(_._1)) .toMap if (jdkVersionToTests.size == 1) jdkVersionToTests.head._2 else { @@ -225,25 +219,6 @@ private object MultipleScalaVersionsRunner { } } - private def childTestsByIndexingMode(testCases: Seq[(TestCase, TestIndexingMode)]): Seq[Test] = { - val indexingModeToTests: Map[TestIndexingMode, Seq[Test]] = - testCases.groupBy(_._2) - .view - .mapValues(_.map(_._1)) - .toMap - - if (indexingModeToTests.size == 1) indexingModeToTests.head._2 else { - for { - (indexingMode, tests) <- indexingModeToTests.toSeq.sortBy(_._1) - if tests.nonEmpty - } yield { - val suite = new IndexingModeTestSuite(indexingMode) - tests.foreach(suite.addTest) - suite - } - } - } - private def scalaVersionsToRun(klass: Class[_ <: TestCase]): Seq[TestScalaVersion] = { val annotation = findAnnotation(klass, classOf[RunWithScalaVersions]) annotation @@ -309,4 +284,3 @@ private object MultipleScalaVersionsRunner { // dot is treated as a package separator by IntelliJ which causes broken rendering in tests tree private def sanitize(testName: String): String = testName.replace(".", "_") } - diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/util/runners/RunWithAllIndexingModes.java b/scala/scala-impl/test/org/jetbrains/plugins/scala/util/runners/RunWithAllIndexingModes.java deleted file mode 100644 index 7e4d362236c..00000000000 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/util/runners/RunWithAllIndexingModes.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.jetbrains.plugins.scala.util.runners; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * ATTENTION: this annotation should be used with care as it increases test execution time significantly. - *

- * Enables multiple indexing modes for each test: smart mode and different versions of dumb mode. - * Dumb mode indexing may be tuned with @NeedsIndex annotation on a class or a specific test method. - * - * @see TestIndexingMode - * @see MultipleScalaVersionsRunner - * @see com.intellij.testFramework.NeedsIndex - * @see SCL-21849 - * @see Make functionality available during indexing - */ -@Target(ElementType.TYPE) -@Retention(RetentionPolicy.RUNTIME) -public @interface RunWithAllIndexingModes { -} diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/util/runners/ScalaVersionAwareTestsCollector.scala b/scala/scala-impl/test/org/jetbrains/plugins/scala/util/runners/ScalaVersionAwareTestsCollector.scala index 204077728dc..d6612b1c065 100644 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/util/runners/ScalaVersionAwareTestsCollector.scala +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/util/runners/ScalaVersionAwareTestsCollector.scala @@ -1,9 +1,7 @@ package org.jetbrains.plugins.scala.util.runners -import com.intellij.testFramework.TestIndexingModeSupporter import junit.framework.{Test, TestCase, TestSuite} import org.jetbrains.plugins.scala.base.ScalaSdkOwner -import org.jetbrains.plugins.scala.util.runners.MultipleScalaVersionsRunner.findAnnotation import org.junit.internal.MethodSorter import java.lang.reflect.{Method, Modifier} @@ -14,36 +12,31 @@ class ScalaVersionAwareTestsCollector(klass: Class[_ <: TestCase], classScalaVersion: Seq[TestScalaVersion], classJdkVersion: Seq[TestJdkVersion]) { - def collectTests(): Seq[(TestCase, TestScalaVersion, TestJdkVersion, TestIndexingMode)] = { - val result = ArrayBuffer.empty[(Test, TestScalaVersion, TestJdkVersion, TestIndexingMode)] + def collectTests(): Seq[(TestCase, TestScalaVersion, TestJdkVersion)] = { + val result = ArrayBuffer.empty[(Test, TestScalaVersion, TestJdkVersion)] val tests = testsFromTestCase(klass) tests.foreach { - case (test: ScalaSdkOwner, _, scalaVersion, jdkVersion, indexingMode) => + case (test: ScalaSdkOwner, _, scalaVersion, jdkVersion) => val scalaVersionProd = scalaVersion.toProductionVersion val jdkVersionProd = jdkVersion.toProductionVersion test.injectedScalaVersion = scalaVersionProd // !! should be set before calling test.skip test.injectedJdkVersion = jdkVersionProd - test match { - case test: TestIndexingModeSupporter => test.setIndexingMode(indexingMode.mode) - case _ => - } - if (!test.skip) { - result.append((test, scalaVersion, jdkVersion, indexingMode)) + result.append((test, scalaVersion, jdkVersion)) } - case (warningTest, _, scalaVersion, jdkVersion, handler) => - result.append((warningTest, scalaVersion, jdkVersion, handler)) + case (warningTest, _, scalaVersion, jdkVersion) => + result.append((warningTest, scalaVersion, jdkVersion)) } - result.map(t => (t._1.asInstanceOf[TestCase], t._2, t._3, t._4)).toSeq + result.map(t => (t._1.asInstanceOf[TestCase], t._2, t._3)).toSeq } // warning test or collection of tests (each test method is multiplied by the amount of versions it is run with) - private def testsFromTestCase(klass: Class[_]): Seq[(Test, Method, TestScalaVersion, TestJdkVersion, TestIndexingMode)] = { - def warn(text: String) = Seq((TestSuite.warning(text), null, null, null, null)) + private def testsFromTestCase(klass: Class[_]): Seq[(Test, Method, TestScalaVersion, TestJdkVersion)] = { + def warn(text: String) = Seq((TestSuite.warning(text), null, null, null)) try TestSuite.getTestConstructor(klass) catch { case _: NoSuchMethodException => @@ -63,10 +56,10 @@ class ScalaVersionAwareTestsCollector(klass: Class[_ <: TestCase], superClass <- withSuperClasses method <- MethodSorter.getDeclaredMethods(superClass) if !isShadowed(method, visitedMethods) - (test, scalaVersion, jdkVersion, indexingMode) <- createTestMethods(klass, method) + (test, scalaVersion, jdkVersion) <- createTestMethods(klass, method) } yield { visitedMethods += method - (test, method, scalaVersion, jdkVersion, indexingMode) + (test, method, scalaVersion, jdkVersion) } if (tests.isEmpty) { @@ -86,7 +79,7 @@ class ScalaVersionAwareTestsCollector(klass: Class[_ <: TestCase], private def createTestMethods( theClass: Class[_], method: Method - ): Seq[(Test, TestScalaVersion, TestJdkVersion, TestIndexingMode)] = { + ): Seq[(Test, TestScalaVersion, TestJdkVersion)] = { val name = method.getName if (isTestMethod(method)) { @@ -94,18 +87,16 @@ class ScalaVersionAwareTestsCollector(klass: Class[_ <: TestCase], val effectiveScalaVersions = methodEffectiveScalaVersions(method, classScalaVersion) val effectiveJdkVersions = methodEffectiveJdkVersions(method, classJdkVersion) - val effectiveIndexingModes = methodEffectiveIndexingModes(method) for { scalaVersion <- effectiveScalaVersions jdkVersion <- effectiveJdkVersions - indexingMode <- effectiveIndexingModes } yield { val test = if (isPublic) { TestSuite.createTest(theClass, name) } else { TestSuite.warning(s"Test method isn't public: ${method.getName}(${theClass.getCanonicalName})") } - (test, scalaVersion, jdkVersion, indexingMode) + (test, scalaVersion, jdkVersion) } } else { Seq() @@ -140,16 +131,6 @@ class ScalaVersionAwareTestsCollector(klass: Class[_ <: TestCase], (baseVersions ++ extraVersions).sorted.distinct } - // SCL-21849 - private def methodEffectiveIndexingModes(method: Method): Seq[TestIndexingMode] = - if (!classOf[TestIndexingModeSupporter].isAssignableFrom(klass) || findAnnotation(klass, classOf[RunWithAllIndexingModes]).isEmpty) { - Seq(TestIndexingMode.SMART) - } else { - TestIndexingMode.values().toSeq.filterNot { mode => - mode.shouldIgnore(klass) || mode.shouldIgnore(method) - } - } - private def isPublicMethod(m: Method): Boolean = Modifier.isPublic(m.getModifiers) private def isTestMethod(m: Method): Boolean = diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/util/runners/TestIndexingMode.java b/scala/scala-impl/test/org/jetbrains/plugins/scala/util/runners/TestIndexingMode.java deleted file mode 100644 index 0632c731cde..00000000000 --- a/scala/scala-impl/test/org/jetbrains/plugins/scala/util/runners/TestIndexingMode.java +++ /dev/null @@ -1,35 +0,0 @@ -package org.jetbrains.plugins.scala.util.runners; - -import com.intellij.testFramework.TestIndexingModeSupporter; -import com.intellij.testFramework.TestIndexingModeSupporter.IndexingMode; -import com.intellij.testFramework.TestIndexingModeSupporter.IndexingModeTestHandler; -import org.jetbrains.annotations.Nullable; - -import java.lang.reflect.AnnotatedElement; - -// SCL-21849 -enum TestIndexingMode { - SMART("Smart mode", IndexingMode.SMART), - FULL(new TestIndexingModeSupporter.FullIndexSuite()), - RUNTIME(new TestIndexingModeSupporter.RuntimeOnlyIndexSuite()), - EMPTY(new TestIndexingModeSupporter.EmptyIndexSuite()); - - @Nullable - private IndexingModeTestHandler handler; - public final String label; - public final IndexingMode mode; - - public boolean shouldIgnore(AnnotatedElement element) { - return handler != null && handler.shouldIgnore(element); - } - - TestIndexingMode(IndexingModeTestHandler handler) { - this(handler.myTestNamePrefix, handler.getIndexingMode()); - this.handler = handler; - } - - TestIndexingMode(String label, IndexingMode mode) { - this.label = label; - this.mode = mode; - } -} diff --git a/scala/scala-impl/test/org/jetbrains/plugins/scala/util/runners/WithIndexingMode.java b/scala/scala-impl/test/org/jetbrains/plugins/scala/util/runners/WithIndexingMode.java new file mode 100644 index 00000000000..750ef66c1df --- /dev/null +++ b/scala/scala-impl/test/org/jetbrains/plugins/scala/util/runners/WithIndexingMode.java @@ -0,0 +1,22 @@ +package org.jetbrains.plugins.scala.util.runners; + +import com.intellij.testFramework.TestIndexingModeSupporter.IndexingMode; + +import java.lang.annotation.*; + +/** + * Enables one of the indexing modes for each test: smart mode or dumb mode with empty, partial or full index. + * + * @see IndexingMode + * @see org.jetbrains.plugins.scala.base.ScalaLightCodeInsightFixtureTestCase + * @see SCL-21849 + * @see Make functionality available during indexing + */ +@Inherited +@Target({ElementType.TYPE, ElementType.METHOD}) +@Retention(RetentionPolicy.RUNTIME) +public @interface WithIndexingMode { + IndexingMode mode(); + + String reason() default ""; +}