Skip to content

fix: show run icons only for files in tests directory #395

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 30, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.editor.markup.GutterIconRenderer
import com.intellij.psi.PsiElement
import javax.swing.Icon
import kotlin.io.path.name
import org.utbot.cpp.clion.plugin.actions.generate.RunWithCoverageAction
import org.utbot.cpp.clion.plugin.settings.settings
import org.utbot.cpp.clion.plugin.ui.services.TestsResultsStorage
import org.utbot.cpp.clion.plugin.utils.localPath
import testsgen.Testgen

class UTBotTestRunLineMarkerProvider : LineMarkerProvider {
Expand Down Expand Up @@ -42,6 +45,7 @@ class UTBotTestRunLineMarkerProvider : LineMarkerProvider {
if (element.firstChild != null
|| !elementRequiresIcon
|| element.containingFile.name.endsWith(".h")
|| !isElementInTestFileGeneratedByUTBot(element)
) {
return null
}
Expand All @@ -51,7 +55,13 @@ class UTBotTestRunLineMarkerProvider : LineMarkerProvider {
return UTBotRunWithCoverageLineMarkerInfo(element, message, getStatusIcon(element))
}

private fun getStatusIcon(element: PsiElement): Icon {
private fun isElementInTestFileGeneratedByUTBot(element: PsiElement) =
element.containingFile.virtualFile.localPath.let {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the same way we check the 'test' status in VSCode plugin?

Copy link
Member Author

@vol0n vol0n Aug 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// provide lenses only for test files

not exactly, in VSCode code lenses are placed in any file that are in tests directory. I think it is not quite good, because if you open any file in tests dir and type in 'TEST' then code lenses for running utbot tests will appear, that's why I added an extra condition

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not lenses but gutter to run a test.

it.toString().startsWith(element.project.settings.testsDirPath.toString()) &&
it.name.contains("test")
}

fun getStatusIcon(element: PsiElement): Icon {
// return icon for Running All Tests
if (element.canPlaceAllTestsIcon()) {
return AllIcons.RunConfigurations.TestState.Run_run
Expand Down