generated from JetBrains/intellij-platform-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Fix DrupalContainerTypeProvider
- Loading branch information
1 parent
96851a5
commit 14f1d3b
Showing
5 changed files
with
75 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 0 additions & 16 deletions
16
...m/github/nvelychenko/drupalextend/symfonyIntegration/SymfonyIntegrationStartupActivity.kt
This file was deleted.
Oops, something went wrong.
83 changes: 71 additions & 12 deletions
83
...om/github/nvelychenko/drupalextend/symfonyIntegration/type/DrupalContainerTypeProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,99 @@ | ||
package com.github.nvelychenko.drupalextend.symfonyIntegration.type | ||
|
||
import com.github.nvelychenko.drupalextend.project.drupalExtendSettings | ||
import com.intellij.openapi.project.Project | ||
import com.intellij.psi.PsiElement | ||
import com.jetbrains.php.PhpIndex | ||
import com.jetbrains.php.lang.psi.elements.Method | ||
import com.jetbrains.php.lang.psi.elements.MethodReference | ||
import com.jetbrains.php.lang.psi.elements.PhpNamedElement | ||
import com.jetbrains.php.lang.psi.resolve.types.PhpType | ||
import fr.adrienbrault.idea.symfony2plugin.Symfony2ProjectComponent | ||
import fr.adrienbrault.idea.symfony2plugin.dic.SymfonyContainerTypeProvider | ||
import com.jetbrains.php.lang.psi.resolve.types.PhpTypeProvider4 | ||
import fr.adrienbrault.idea.symfony2plugin.Settings | ||
import fr.adrienbrault.idea.symfony2plugin.stubs.ContainerCollectionResolver | ||
import fr.adrienbrault.idea.symfony2plugin.util.MethodMatcher.CallToSignature | ||
import fr.adrienbrault.idea.symfony2plugin.util.PhpElementsUtil | ||
import fr.adrienbrault.idea.symfony2plugin.util.PhpTypeProviderUtil | ||
|
||
|
||
/** | ||
* Add support for \Drupal::service('database')->| | ||
*/ | ||
class DrupalContainerTypeProvider : SymfonyContainerTypeProvider() { | ||
class DrupalContainerTypeProvider : PhpTypeProvider4 { | ||
|
||
private val trimKey = '\u0182' | ||
private val trimKey = '\u9956' | ||
|
||
override fun getKey(): Char { | ||
return '\u9955' | ||
} | ||
|
||
override fun getType(psiElement: PsiElement): PhpType? { | ||
if (!Symfony2ProjectComponent.isEnabled(psiElement.project) || !psiElement.project.drupalExtendSettings.isEnabled) { | ||
if (psiElement !is MethodReference) { | ||
return null | ||
} | ||
|
||
if (psiElement !is MethodReference || !PhpElementsUtil.isMethodWithFirstStringOrFieldReference( | ||
psiElement, | ||
"service" | ||
) | ||
) { | ||
val project = psiElement.project | ||
if (!Settings.getInstance(project).pluginEnabled) { | ||
return null | ||
} | ||
|
||
if (!PhpElementsUtil.isMethodWithFirstStringOrFieldReference(psiElement, "service")) { | ||
return null | ||
} | ||
|
||
val signature = PhpTypeProviderUtil.getReferenceSignatureByFirstParameter(psiElement, trimKey) | ||
return if (signature == null) null else PhpType().add("#" + this.key + signature) | ||
} | ||
|
||
override fun complete(s: String?, project: Project?): PhpType? { | ||
return null | ||
} | ||
|
||
override fun getBySignature( | ||
expression: String, | ||
visited: Set<String?>, | ||
depth: Int, | ||
project: Project | ||
): Collection<PhpNamedElement?> { | ||
val endIndex = expression.lastIndexOf(trimKey) | ||
|
||
if (endIndex == -1) { | ||
return emptySet() | ||
} | ||
|
||
val originalSignature = expression.substring(0, endIndex) | ||
var parameter: String = expression.substring(endIndex + 1) | ||
|
||
// search for called method | ||
val phpIndex: PhpIndex = PhpIndex.getInstance(project) | ||
val phpNamedElementCollections: Collection<PhpNamedElement?> = | ||
PhpTypeProviderUtil.getTypeSignature(phpIndex, originalSignature) | ||
|
||
if (phpNamedElementCollections.isEmpty()) { | ||
return emptySet() | ||
} | ||
|
||
// get first matched item | ||
val phpNamedElement: PhpNamedElement = phpNamedElementCollections.iterator().next() as? Method | ||
?: return phpNamedElementCollections | ||
|
||
parameter = PhpTypeProviderUtil.getResolvedParameter(phpIndex, parameter) ?: return phpNamedElementCollections | ||
|
||
// finally search the classes | ||
if (!PhpElementsUtil.isMethodInstanceOf( | ||
phpNamedElement as Method, | ||
CallToSignature("\\Drupal", "service") | ||
) | ||
) { | ||
return phpNamedElementCollections | ||
} | ||
|
||
val containerService = | ||
ContainerCollectionResolver.getService(project, parameter) ?: return phpNamedElementCollections | ||
val phpClasses: MutableCollection<PhpNamedElement?> = HashSet() | ||
|
||
for (s in containerService.classNames) { | ||
phpClasses.addAll(PhpIndex.getInstance(project).getAnyByFQN(s)) | ||
} | ||
|
||
return phpClasses | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,8 @@ | ||
<?xml version="1.0"?> | ||
<idea-plugin> | ||
|
||
<extensions defaultExtensionNs="com.intellij"> | ||
<postStartupActivity | ||
implementation="com.github.nvelychenko.drupalextend.symfonyIntegration.SymfonyIntegrationStartupActivity"/> | ||
</extensions> | ||
<extensions defaultExtensionNs="com.jetbrains.php"> | ||
<typeProvider4 | ||
implementation="com.github.nvelychenko.drupalextend.symfonyIntegration.type.DrupalContainerTypeProvider"/> | ||
<typeProvider4 implementation="com.github.nvelychenko.drupalextend.symfonyIntegration.type.DrupalContainerTypeProvider"/> | ||
</extensions> | ||
|
||
</idea-plugin> |