Skip to content

Commit

Permalink
the correct resolve for global variables (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
Danil42Russia authored Jul 24, 2024
1 parent e00a05a commit 006d176
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import com.intellij.refactoring.suggested.startOffset
import com.jetbrains.php.lang.psi.elements.*
import com.vk.modulite.modulite.ModuliteRestrictionChecker
import com.vk.modulite.psi.extensions.files.containingModulite
import com.vk.modulite.psi.extensions.php.resolveElement
import com.vk.modulite.utils.fromStubs
import com.vk.modulite.utils.fromTests

Expand Down Expand Up @@ -46,7 +47,7 @@ class ModulitePhpAnnotator : Annotator {
reference: PhpReference,
problemElement: PsiElement? = reference
) {
val references = reference.resolveGlobal(false)
val references = reference.resolveElement()
if (references.isEmpty()) {
// LOG.warn("Unknown reference for symbol '${reference.safeFqn()}'")
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import com.vk.modulite.modulite.Modulite
import com.vk.modulite.modulite.ModuliteRestrictionChecker
import com.vk.modulite.psi.extensions.files.containingComposerPackage
import com.vk.modulite.psi.extensions.files.containingModulite
import com.vk.modulite.psi.extensions.php.resolveElement
import com.vk.modulite.psi.extensions.php.symbolName
import com.vk.modulite.utils.fromStubs
import com.vk.modulite.utils.fromTests
Expand Down Expand Up @@ -123,7 +124,7 @@ class InternalSymbolUsageInspection : LocalInspectionTool() {
}

private fun checkReferenceUsage(reference: PhpReference, problemElement: PsiElement? = reference) {
val references = reference.resolveGlobal(false)
val references = reference.resolveElement()
if (references.isEmpty()) {
// LOG.warn("Unknown reference for symbol '${reference.safeFqn()}'")
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,11 @@ fun PhpReference.safeFqn(): String {
signature
}
}

fun PhpReference.resolveElement(): MutableCollection<out PhpNamedElement> {
return if (this is VariableImpl) {
this.resolveLocal()
} else {
this.resolveGlobal(false)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import com.vk.modulite.modulite.Modulite
import com.vk.modulite.notifications.ModuliteWarningNotification
import com.vk.modulite.psi.PhpRecursiveElementVisitor
import com.vk.modulite.psi.extensions.files.*
import com.vk.modulite.psi.extensions.php.resolveElement
import com.vk.modulite.psi.extensions.php.safeFqn
import com.vk.modulite.psi.extensions.php.symbolName
import com.vk.modulite.utils.fromKphpPolyfills
Expand Down Expand Up @@ -295,7 +296,7 @@ class ModuliteDependenciesCollector(val project: Project) {
private fun handleReference(reference: PhpReference?, traverseFurther: Boolean = true) {
if (reference == null) return

val references = reference.resolveGlobal(false)
val references = reference.resolveElement()
if (references.isEmpty()) {
LOG.warn("Unknown reference '${reference.safeFqn()}'")
return
Expand Down

0 comments on commit 006d176

Please sign in to comment.