Skip to content

Disable action in editor for the file located in test source root #478

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
Jul 11, 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 @@ -45,8 +45,18 @@ class GenerateTestsAction : AnAction() {

if (psiElementHandler.isCreateTestActionAvailable(element)) {
val srcClass = psiElementHandler.containingClass(element) ?: return null
val srcSourceRoot = srcClass.getSourceRoot() ?: return null
val srcMethods = TestIntegrationUtils.extractClassMethods(srcClass, false)
val focusedMethod = focusedMethodOrNull(element, srcMethods, psiElementHandler)

val module = ModuleUtil.findModuleForFile(srcSourceRoot, project) ?: return null
val matchingRoot = ModuleRootManager.getInstance(module).contentEntries
.flatMap { entry -> entry.sourceFolders.toList() }
.singleOrNull { folder -> folder.file == srcSourceRoot }
if (matchingRoot == null || matchingRoot.rootType.isForTests) {
return null
}

return Pair(setOf(srcClass), focusedMethod)
}
} else {
Expand Down