From 9a7f2179d9ed600f333e4e539644ced9e62fa7f3 Mon Sep 17 00:00:00 2001 From: Ilia Zakoulov Date: Tue, 25 Nov 2025 20:18:51 +0100 Subject: [PATCH] PY-83395: Reuse context for resolving source roots GitOrigin-RevId: 0e8111679f8fd385fb11daf3d9ad7c1ed893bb60 --- .../messages/PyBundle.properties | 2 +- .../resources/messages/PyPsiBundle.properties | 2 +- .../PyUnresolvedReferencesInspection.kt | 24 +++++++++---------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/python/pluginResources/messages/PyBundle.properties b/python/pluginResources/messages/PyBundle.properties index f2b3c0f47407..8e8fe3026290 100644 --- a/python/pluginResources/messages/PyBundle.properties +++ b/python/pluginResources/messages/PyBundle.properties @@ -1758,7 +1758,7 @@ python.sdk.read.only=Python SDK ''{0}'' is read-only and operation cannot be per python.source.root.detection.notification.group=Python source root detection python.source.root.detection.confirm.notification.group=Python source root detection -python.source.root.detection.confirm.notification.title=''{0}'' has been marked as source root. +python.source.root.detection.confirm.notification.title=''{0}'' has been marked as source root python.source.root.detection.confirm.notification.action.ok=Ok python.source.root.detection.confirm.notification.action.revert=Revert python.source.root.detection.confirm.notification.action.mute=Don't show again diff --git a/python/python-psi-impl/resources/messages/PyPsiBundle.properties b/python/python-psi-impl/resources/messages/PyPsiBundle.properties index 40c556f741b4..d7fa68071183 100644 --- a/python/python-psi-impl/resources/messages/PyPsiBundle.properties +++ b/python/python-psi-impl/resources/messages/PyPsiBundle.properties @@ -1373,6 +1373,6 @@ INSP.unnecessary.cast.message=Unnecessary cast; type is already ''{0}'' QFIX.remove.cast.call=Remove 'cast' call # Quick fix: mark directory as source root -QFIX.add.source.root.notification.text=''{0}'' has been marked as source root. +QFIX.add.source.root.notification.text=''{0}'' has been marked as source root QFIX.add.source.root.notification.ok=Ok QFIX.add.source.root.notification.revert=Revert diff --git a/python/src/com/jetbrains/python/inspections/unresolvedReference/PyUnresolvedReferencesInspection.kt b/python/src/com/jetbrains/python/inspections/unresolvedReference/PyUnresolvedReferencesInspection.kt index b99fbb5c9754..1aa36b876ee1 100644 --- a/python/src/com/jetbrains/python/inspections/unresolvedReference/PyUnresolvedReferencesInspection.kt +++ b/python/src/com/jetbrains/python/inspections/unresolvedReference/PyUnresolvedReferencesInspection.kt @@ -137,24 +137,24 @@ class PyUnresolvedReferencesInspection : PyUnresolvedReferencesInspectionBase() val filesByName = FilenameIndex.getVirtualFilesByName(folderNameToSearchFor, scope) + val context = fromModule(module) + .copyWithoutStubs() + .copyWithoutRoots() + .run { + // resolve members only for 'from .. import ..' + if (importStatementBase is PyAstFromImportStatement) { + copyWithMembers() + } else { + this + } + } + for (file in filesByName) { val containingDirectory = file.getParent() ?: continue if (isAlreadySourceRoot(containingDirectory, module)) { continue } - - val context = fromModule(module) - .copyWithoutStubs() - .copyWithoutRoots() - .run { - // resolve members only for 'from .. import ..' - if (importStatementBase is PyAstFromImportStatement) { - copyWithMembers() - } else { - this - } - } val resolveResult: List = resolveInRoot(qname, containingDirectory, context) if (!resolveResult.isEmpty()) {