10000 Merge pull request #1379 from Haehnchen/feature/extends-index · SylApps/idea-php-symfony2-plugin@bfff508 · GitHub
[go: up one dir, main page]

Skip to content

Commit bfff508

Browse files
authored
Merge pull request Haehnchen#1379 from Haehnchen/feature/extends-index
use "extends" for resolving parent extends template and reduce duplicate index based on new given FileIndex api
2 parents 33a8f8d + 1e0d56c commit bfff508

File tree

5 files changed

+40
-78
lines changed

5 files changed

+40
-78
lines changed

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ before_install:
2323
- "export ORG_GRADLE_PROJECT_annotationPluginVersion=${ANNOTATION_PLUGIN_VERSION}"
2424

2525
env:
26-
- PHPSTORM_ENV="skip incomplete" IDEA_VERSION="IU-2019.1.3" PHP_PLUGIN_VERSION="191.7141.52" TWIG_PLUGIN_VERSION="191.6183.95" TOOLBOX_PLUGIN_VERSION="0.4.6" ANNOTATION_PLUGIN_VERSION="5.3" DQL_PLUGIN_VERSION="191.5849.16"
2726
- PHPSTORM_ENV="skip incomplete" IDEA_VERSION="IU-2019.2" PHP_PLUGIN_VERSION="192.5728.108" TWIG_PLUGIN_VERSION="192.5728.26" TOOLBOX_PLUGIN_VERSION="0.4.6" ANNOTATION_PLUGIN_VERSION="5.3" DQL_PLUGIN_VERSION="192.5728.12"
2827

2928
script:

build.gradle

Lines changed: 26 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -31,67 +31,37 @@ targetCompatibility = 1.8
3131

3232
apply plugin: 'org.jetbrains.intellij'
3333

34-
if (ideaVersion == "IU-2019.1.3") {
35-
intellij {
36-
version ideaVersion
37-
updateSinceUntilBuild false
38-
plugins = [
39-
"com.jetbrains.php:${phpPluginVersion}",
40-
"com.jetbrains.twig:${twigPluginVersion}",
41-
"com.jetbrains.php.dql:${dqlPluginVersion}",
42-
"de.espend.idea.php.annotation:${annotationPluginVersion}",
43-
"de.espend.idea.php.toolbox:${toolboxPluginVersion}",
44-
'coverage',
45-
'webDeployment',
46-
'yaml',
47-
'CSS',
48-
'java-i18n',
49-
'properties',
50-
'xpath'
51-
]
52-
pluginName 'Symfony Support'
53-
54-
// Can't instantiate configurable for PHP Toolbox
55-
// at de.espend 8000 .idea.php.toolbox.ui.application.ToolboxApplicationForm.<init>(ToolboxApplicationForm.java:26)
56-
tasks {
57-
"buildSearchableOptions" {
58-
enabled = false
59-
}
60-
}
61-
}
62-
} else {
63-
intellij {
64-
version ideaVersion
65-
updateSinceUntilBuild false
66-
plugins = [
67-
"com.jetbrains.php:${phpPluginVersion}",
68-
"com.jetbrains.twig:${twigPluginVersion}",
69-
"com.jetbrains.php.dql:${dqlPluginVersion}",
70-
"de.espend.idea.php.annotation:${annotationPluginVersion}",
71-
"de.espend.idea.php.toolbox:${toolboxPluginVersion}",
72-
'coverage',
73-
'webDeployment',
74-
'yaml',
75-
'CSS',
76-
'java-i18n',
77-
'properties',
78-
'xpath',
79-
'java'
80-
]
81-
pluginName 'Symfony Support'
82-
83-
// Can't instantiate configurable for PHP Toolbox
84-
// at de.espend.idea.php.toolbox.ui.application.ToolboxApplicationForm.<init>(ToolboxApplicationForm.java:26)
85-
tasks {
86-
"buildSearchableOptions" {
87-
enabled = false
88-
}
34+
intellij {
35+
version ideaVersion
36+
updateSinceUntilBuild false
37+
plugins = [
38+
"com.jetbrains.php:${phpPluginVersion}",
39+
"com.jetbrains.twig:${twigPluginVersion}",
40+
"com.jetbrains.php.dql:${dqlPluginVersion}",
41+
"de.espend.idea.php.annotation:${annotationPluginVersion}",
42+
"de.espend.idea.php.toolbox:${toolboxPluginVersion}",
43+
'coverage',
44+
'webDeployment',
45+
'yaml',
46+
'CSS',
47+
'java-i18n',
48+
'properties',
49+
'xpath',
50+
'java'
51+
]
52+
pluginName 'Symfony Support'
53+
54+
// Can't instantiate configurable for PHP Toolbox
55+
// at de.espend.idea.php.toolbox.ui.application.ToolboxApplicationForm.<init>(ToolboxApplicationForm.java:26)
56+
tasks {
57+
"buildSearchableOptions" {
58+
enabled = false
8959
}
9060
}
9161
}
9262

9363
patchPluginXml {
94-
sinceBuild '191'
64+
sinceBuild '192'
9565
changeNotes = htmlFixer('src/main/resources/META-INF/change-notes.html')
9666
}
9767

src/main/java/fr/adrienbrault/idea/symfony2plugin/stubs/indexes/TwigBlockIndexExtension.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,7 @@ public DataIndexer<String, Set<String>, FileContent> getIndexer() {
5555
}
5656

5757
for(PsiElement psiElement : PsiTreeUtil.getChildrenOfAnyType(psiFile, TwigExtendsTag.class, TwigCompositeElement.class)) {
58-
if (psiElement instanceof TwigExtendsTag) {
59-
// {% extends 'foo.html.twig' %}
60-
for (String templateName : TwigUtil.getTwigExtendsTagTemplates((TwigExtendsTag) psiElement)) {
61-
blocks.putIfAbsent("extends", new HashSet<>());
62-
blocks.get("extends").add(TwigUtil.normalizeTemplateName(templateName));
63-
}
64-
} else if(psiElement instanceof TwigCompositeElement) {
58+
if(psiElement instanceof TwigCompositeElement) {
6559
// {% use 'foo.html.twig' %}
6660
if(psiElement.getNode().getElementType() == TwigElementTypes.TAG) {
6761
psiElement.acceptChildren(new PsiRecursiveElementWalkingVisitor() {

src/main/java/fr/adrienbrault/idea/symfony2plugin/twig/utils/TwigFileUtil.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.intellij.util.indexing.FileBasedIndex;
88
import com.jetbrains.twig.TwigFile;
99
import fr.adrienbrault.idea.symfony2plugin.stubs.indexes.TwigBlockIndexExtension;
10+
import fr.adrienbrault.idea.symfony2plugin.stubs.indexes.TwigExtendsStubIndex;
1011
import fr.adrienbrault.idea.symfony2plugin.templating.util.TwigUtil;
1112
import org.jetbrains.annotations.NotNull;
1213

@@ -52,20 +53,21 @@ private static void visitParentFiles(@NotNull PsiFile file, int depth, Collectio
5253
}
5354

5455
Set<VirtualFile> myVirtualFiles = new HashSet<>();
56+
Set<String> templates = new HashSet<>();
5557

56-
for (String s : new String[]{"extends", "use"}) {
57-
Set<String> templates = new HashSet<>();
58+
FileBasedIndex.getInstance()
59+
.getValues(TwigBlockIndexExtension.KEY, "use", GlobalSearchScope.fileScope(file))
60+
.forEach(templates::addAll);
5861

59-
FileBasedIndex.getInstance()
60-
.getValues(TwigBlockIndexExtension.KEY, s, GlobalSearchScope.fileScope(file))
61-
.forEach(templates::addAll);
62+
FileBasedIndex.getInstance()
63+
.getFileData(TwigExtendsStubIndex.KEY, file.getVirtualFile(), file.getProject())
64+
.forEach((templateName, aVoid) -> templates.add(templateName));
6265

63-
for (String template : templates) {
64-
for (VirtualFile virtualFile : TwigUtil.getTemplateFiles(file.getProject(), template)) {
65-
if (!virtualFiles.contains(virtualFile)) {
66-
myVirtualFiles.add(virtualFile);
67-
virtualFiles.add(virtualFile);
68-
}
66+
for (String template : templates) {
67+
for (VirtualFile virtualFile : TwigUtil.getTemplateFiles(file.getProject(), template)) {
68+
if (!virtualFiles.contains(virtualFile)) {
69+
myVirtualFiles.add(virtualFile);
70+
virtualFiles.add(virtualFile);
6971
}
7072
}
7173
}

src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/stubs/indexes/TwigBlockIndexExtensionTest.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,7 @@ public void testThatValuesAreInIndex() {
2727
assertIndexContainsKeyWithValue(TwigBlockIndexExtension.KEY, "block", value -> !value.contains("right_teaser"));
2828
assertIndexContainsKeyWithValue(TwigBlockIndexExtension.KEY, "block", value -> !value.contains("foobar_print_embed"));
2929

30-
assertIndexContainsKeyWithValue(TwigBlockIndexExtension.KEY, "extends", value -> value.contains("extends/foo.html.twig"));
3130
assertIndexContainsKeyWithValue(TwigBlockIndexExtension.KEY, "use", value -> value.contains("use/foo.html.twig"));
32-
33-
assertIndexContainsKeyWithValue(TwigBlockIndexExtension.KEY, "extends", value -> !value.contains("embed_extends/foo.html.twig"));
3431
assertIndexContainsKeyWithValue(TwigBlockIndexExtension.KEY, "use", value -> !value.contains("embed_use/foo.html.twig"));
3532
}
3633
}

0 commit comments

Comments
 (0)
0