File tree Expand file tree Collapse file tree 3 files changed +89
-0
lines changed
src/com/magento/idea/magento2plugin Expand file tree Collapse file tree 3 files changed +89
-0
lines changed Original file line number Diff line number Diff line change @@ -92,4 +92,45 @@ public static Collection<String> getAllKeys(
9292 ) {
9393 return FileBasedIndex .getInstance ().getAllKeys (identifier , project );
9494 }
95+
96+ /**
97+ * Get ui component files.
98+ *
99+ * @param project Project
100+ * @param fileName String
101+ * @return List
102+ */
103+ public static List <XmlFile > getUIComponentFiles (Project project , @ Nullable String fileName ) {
104+ List <XmlFile > results = new ArrayList <XmlFile >();
105+ Collection <VirtualFile > xmlFiles = FilenameIndex .getAllFilesByExt (project , "xml" );
106+
107+ PsiManager psiManager = PsiManager .getInstance (project );
108+ for (VirtualFile xmlFile : xmlFiles ) {
109+ if (isUIComponentFile (xmlFile )) {
110+ if (fileName != null && !xmlFile .getNameWithoutExtension ().equals (fileName )) {
111+ continue ;
112+ }
113+
114+ PsiFile file = psiManager .findFile (xmlFile );
115+ if (file != null ) {
116+ results .add ((XmlFile )file );
117+ }
118+ }
119+ }
120+
121+ return results ;
122+ }
123+
124+ /**
125+ * Available ui component file.
126+ *
127+ * @param virtualFile VirtualFile
128+ * @return boolean
129+ */
130+ public static boolean isUIComponentFile (VirtualFile virtualFile ) {
131+ VirtualFile parent = virtualFile .getParent ();
132+ return virtualFile .getFileType () == XmlFileType .INSTANCE && parent .isDirectory ()
133+ && parent .getName ().endsWith ("ui_component" );
134+ }
135+
95136}
Original file line number Diff line number Diff line change 1+ /**
2+ * Copyright © Magento, Inc. All rights reserved.
3+ * See COPYING.txt for license details.
4+ */
5+
6+ package com .magento .idea .magento2plugin .reference .provider ;
7+
8+ import com .intellij .openapi .util .text .StringUtil ;
9+ import com .intellij .psi .PsiElement ;
10+ import com .intellij .psi .PsiReference ;
11+ import com .intellij .psi .PsiReferenceProvider ;
12+ import com .intellij .psi .xml .XmlFile ;
13+ import com .intellij .util .ProcessingContext ;
14+ import com .magento .idea .magento2plugin .indexes .UIComponentIndex ;
15+ import com .magento .idea .magento2plugin .reference .xml .PolyVariantReferenceBase ;
16+ import java .util .List ;
17+ import org .jetbrains .annotations .NotNull ;
18+
19+
20+ public class UIComponentReferenceProvider extends PsiReferenceProvider {
21+
22+ @ NotNull
23+ @ Override
24+ public PsiReference [] getReferencesByElement (
25+ @ NotNull final PsiElement element ,
26+ @ NotNull final ProcessingContext context
27+ ) {
28+ final String value = StringUtil .unquoteString (element .getText ());
29+ final List <XmlFile > targets = UIComponentIndex .getUIComponentFiles (
30+ element .getProject (),
31+ value
32+ );
33+ if (!targets .isEmpty ()) {
34+ return new PsiReference [] {new PolyVariantReferenceBase (element , targets )};
35+ }
36+ return PsiReference .EMPTY_ARRAY ;
37+ }
38+ }
Original file line number Diff line number Diff line change @@ -132,6 +132,16 @@ public void registerReferenceProviders(@NotNull PsiReferenceRegistrar registrar)
132132 new LayoutUpdateReferenceProvider ()
133133 );
134134
135+ // <uiComponent name="completion"/>
136+ registrar .registerReferenceProvider (
137+ XmlPatterns .xmlAttributeValue ().withParent (
138+ XmlPatterns .xmlAttribute ().withName ("name" ).withParent (
139+ XmlPatterns .xmlTag ().withName ("uiComponent" )
140+ )
141+ ),
142+ new UIComponentReferenceProvider ()
143+ );
144+
135145 // <event name="reference" />
136146 registrar .registerReferenceProvider (
137147 XmlPatterns .xmlAttributeValue ().withParent (
You can’t perform that action at this time.
0 commit comments