From fedf5828fff10d281e865cc3883a0a7d703d1cab Mon Sep 17 00:00:00 2001 From: Andrey Vlasovskikh Date: Sun, 31 May 2020 02:14:57 +0300 Subject: [PATCH] PY-35921 Pick the content root containing *.iml as the base directory of the module A module may have many content roots. We used to pick the first mentioned in its settings. It didn't match the expectations. If you have a content root that contains the *.iml file of the module, it is likely the one you want to use. If there are no content roots that contain your *.iml, then we still use the first content root. GitOrigin-RevId: 7670730eab25d0ff1e269cfec79f4d85a186f62e --- .../src/com/jetbrains/python/sdk/BasePySdkExt.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/python/python-sdk/src/com/jetbrains/python/sdk/BasePySdkExt.kt b/python/python-sdk/src/com/jetbrains/python/sdk/BasePySdkExt.kt index b3b529b9ed7c..553a273fae30 100644 --- a/python/python-sdk/src/com/jetbrains/python/sdk/BasePySdkExt.kt +++ b/python/python-sdk/src/com/jetbrains/python/sdk/BasePySdkExt.kt @@ -2,13 +2,18 @@ package com.jetbrains.python.sdk import com.intellij.openapi.module.Module import com.intellij.openapi.roots.ModuleRootManager +import com.intellij.openapi.vfs.VfsUtil import com.intellij.openapi.vfs.VirtualFile val Module.rootManager: ModuleRootManager get() = ModuleRootManager.getInstance(this) val Module.baseDir: VirtualFile? - get() = rootManager.contentRoots.firstOrNull() + get() { + val moduleFile = moduleFile ?: return null + val roots = rootManager.contentRoots + return roots.firstOrNull { VfsUtil.isAncestor(it, moduleFile, true) } ?: roots.firstOrNull() + } val Module.basePath: String? get() = baseDir?.path \ No newline at end of file