Skip to content

Commit 1c84ee4

Browse files
614: Provided file path references for JS:STRING_LITERAL psi elements in the js files
1 parent 6504566 commit 1c84ee4

File tree

2 files changed

+32
-7
lines changed

2 files changed

+32
-7
lines changed

src/com/magento/idea/magento2plugin/reference/js/JsReferenceContributor.java

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,53 @@
1-
/**
1+
/*
22
* Copyright © Magento, Inc. All rights reserved.
33
* See COPYING.txt for license details.
44
*/
5+
56
package com.magento.idea.magento2plugin.reference.js;
67

8+
import static com.intellij.patterns.StandardPatterns.string;
9+
import static com.magento.idea.magento2plugin.util.RegExUtil.JsRegex;
10+
11+
import com.intellij.lang.javascript.JSTokenTypes;
12+
import com.intellij.lang.javascript.JavascriptLanguage;
713
import com.intellij.lang.javascript.patterns.JSPatterns;
8-
import com.intellij.psi.*;
14+
import com.intellij.patterns.PlatformPatterns;
15+
import com.intellij.psi.PsiReferenceContributor;
16+
import com.intellij.psi.PsiReferenceRegistrar;
917
import com.magento.idea.magento2plugin.reference.provider.FilePathReferenceProvider;
1018
import com.magento.idea.magento2plugin.reference.provider.ModuleNameReferenceProvider;
1119
import com.magento.idea.magento2plugin.reference.provider.RequireJsPreferenceReferenceProvider;
1220
import com.magento.idea.magento2plugin.util.RegExUtil;
1321
import org.jetbrains.annotations.NotNull;
1422

15-
import static com.intellij.patterns.StandardPatterns.string;
16-
1723
public class JsReferenceContributor extends PsiReferenceContributor {
24+
1825
@Override
19-
public void registerReferenceProviders(@NotNull PsiReferenceRegistrar registrar) {
26+
public void registerReferenceProviders(final @NotNull PsiReferenceRegistrar registrar) {
2027
registrar.registerReferenceProvider(
2128
JSPatterns.jsLiteralExpression()
2229
.withText(string().matches(".*" + RegExUtil.Magento.MODULE_NAME + ".*")),
2330
new ModuleNameReferenceProvider()
2431
);
2532

33+
// Targets property value -> {test: 'Sandbox_Test/js/test'}
2634
registrar.registerReferenceProvider(
27-
JSPatterns.jsLiteralExpression().withText(string().matches(".*\\W" + RegExUtil.FILE_PATH + ".*")),
35+
JSPatterns.jsLiteralExpression()
36+
.withText(string().matches(JsRegex.FILE_PATH)),
37+
new FilePathReferenceProvider()
38+
);
39+
40+
// Targets property key (JS:STRING_LITERAL) -> {'Sandbox_Test/js/test': true}
41+
registrar.registerReferenceProvider(
42+
PlatformPatterns.psiElement(JSTokenTypes.STRING_LITERAL)
43+
.withText(string().matches(JsRegex.FILE_PATH))
44+
.withLanguage(JavascriptLanguage.INSTANCE),
2845
new FilePathReferenceProvider()
2946
);
3047

3148
registrar.registerReferenceProvider(
32-
JSPatterns.jsLiteralExpression().withText(string().matches(".*\\W" + RegExUtil.FILE_PATH + ".*")),
49+
JSPatterns.jsLiteralExpression()
50+
.withText(string().matches(".*\\W" + RegExUtil.FILE_PATH + ".*")),
3351
new RequireJsPreferenceReferenceProvider()
3452
);
3553
}

src/com/magento/idea/magento2plugin/util/RegExUtil.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,13 @@ public static class XmlRegex {
103103
"\\\\?" + PhpRegex.FQN + "(" + CLASS_MEMBER_NAME + ")?.*";
104104
}
105105

106+
public static class JsRegex {
107+
108+
// Targets paths like `'Sandbox_Test/js/test'`
109+
public static final String FILE_PATH
110+
= "(\\W{1}[A-Z][a-zA-Z0-9]+_[A-Z][a-zA-Z0-9]+[\\/\\w*-]{1,}\\W{1})";
111+
}
112+
106113
public static class CustomTheme {
107114
public static final String MODULE_NAME =
108115
"app\\/design\\/(adminhtml|frontend)\\/\\w*\\/\\w*\\/\\w*";

0 commit comments

Comments
 (0)