diff --git a/platform/testFramework/src/com/intellij/testFramework/fixtures/IdeaTestFixtureFactory.java b/platform/testFramework/src/com/intellij/testFramework/fixtures/IdeaTestFixtureFactory.java index 8f58847de195..3d5f01a364df 100644 --- a/platform/testFramework/src/com/intellij/testFramework/fixtures/IdeaTestFixtureFactory.java +++ b/platform/testFramework/src/com/intellij/testFramework/fixtures/IdeaTestFixtureFactory.java @@ -1,6 +1,7 @@ // Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.testFramework.fixtures; +import com.intellij.openapi.project.Project; import com.intellij.testFramework.LightProjectDescriptor; import com.intellij.testFramework.builders.ModuleFixtureBuilder; import com.intellij.testFramework.fixtures.impl.IdeaTestFixtureFactoryImpl; @@ -55,4 +56,7 @@ public abstract class IdeaTestFixtureFactory { public abstract @NotNull TempDirTestFixture createTempDirTestFixture(); public abstract @NotNull BareTestFixture createBareFixture(); + + public abstract @NotNull CodeInsightTestFixture createCodeInsightFixtureForExistingProject(@NotNull Project project); + } diff --git a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/IdeaTestFixtureFactoryImpl.java b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/IdeaTestFixtureFactoryImpl.java index ab0c5458eb53..49fa7ef6b4f3 100644 --- a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/IdeaTestFixtureFactoryImpl.java +++ b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/IdeaTestFixtureFactoryImpl.java @@ -1,6 +1,9 @@ // Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.testFramework.fixtures.impl; +import com.intellij.openapi.module.Module; +import com.intellij.openapi.module.ModuleManager; +import com.intellij.openapi.project.Project; import com.intellij.testFramework.LightProjectDescriptor; import com.intellij.testFramework.builders.EmptyModuleFixtureBuilder; import com.intellij.testFramework.builders.ModuleFixtureBuilder; @@ -94,6 +97,28 @@ public final class IdeaTestFixtureFactoryImpl extends IdeaTestFixtureFactory { return new BareTestFixtureImpl(); } + @Override + public @NotNull CodeInsightTestFixture createCodeInsightFixtureForExistingProject(@NotNull Project project) { + IdeaProjectTestFixture projectTestFixture = new IdeaProjectTestFixture() { + @Override + public Project getProject() { + return project; + } + + @Override + public Module getModule() { + return ModuleManager.getInstance(project).getModules()[0]; + } + + @Override + public void setUp() {} + + @Override + public void tearDown() {} + }; + return new CodeInsightTestFixtureImpl(projectTestFixture, new TempDirTestFixtureImpl()); + } + public static final class MyEmptyModuleFixtureBuilderImpl extends EmptyModuleFixtureBuilderImpl { public MyEmptyModuleFixtureBuilderImpl(@NotNull TestFixtureBuilder testFixtureBuilder) { super(testFixtureBuilder); diff --git a/platform/testFramework/src/com/intellij/testFramework/utils/inlays/InlayParameterHintsTest.kt b/platform/testFramework/src/com/intellij/testFramework/utils/inlays/InlayParameterHintsTest.kt index 93852286a19b..fe72367b1807 100644 --- a/platform/testFramework/src/com/intellij/testFramework/utils/inlays/InlayParameterHintsTest.kt +++ b/platform/testFramework/src/com/intellij/testFramework/utils/inlays/InlayParameterHintsTest.kt @@ -18,7 +18,7 @@ import org.junit.Assert.assertFalse import java.util.regex.Pattern -class InlayHintsChecker(private val myFixture: CodeInsightTestFixture) { +open class InlayHintsChecker(private val myFixture: CodeInsightTestFixture) { companion object { val pattern: Pattern = Pattern.compile("()|()|()|<(hint|HINT|Hint|hINT)\\s+text=\"([^\n\r]+?(?=\"\\s*/>))\"\\s*/>") @@ -126,11 +126,13 @@ class InlayHintsChecker(private val myFixture: CodeInsightTestFixture) { isHighlighted = false isCurrent = false } - InlayInfo(it.offset, inlayPresenter(it), isHighlighted, isCurrent) + InlayInfo(getInlayOffset(it), inlayPresenter(it), isHighlighted, isCurrent) } .sortedBy { it.offset } } + protected open fun getInlayOffset(inlay: Inlay<*>): Int = inlay.offset + fun extractInlaysAndCaretInfo(document: Document): CaretAndInlaysInfo { val text = document.text val matcher = pattern.matcher(text)