|
1 | | -/** |
| 1 | +/* |
2 | 2 | * Copyright © Magento, Inc. All rights reserved. |
3 | 3 | * See COPYING.txt for license details. |
4 | 4 | */ |
| 5 | + |
5 | 6 | package com.magento.idea.magento2plugin.reference.js; |
6 | 7 |
|
| 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; |
7 | 13 | 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; |
9 | 17 | import com.magento.idea.magento2plugin.reference.provider.FilePathReferenceProvider; |
10 | 18 | import com.magento.idea.magento2plugin.reference.provider.ModuleNameReferenceProvider; |
11 | 19 | import com.magento.idea.magento2plugin.reference.provider.RequireJsPreferenceReferenceProvider; |
12 | 20 | import com.magento.idea.magento2plugin.util.RegExUtil; |
13 | 21 | import org.jetbrains.annotations.NotNull; |
14 | 22 |
|
15 | | -import static com.intellij.patterns.StandardPatterns.string; |
16 | | - |
17 | 23 | public class JsReferenceContributor extends PsiReferenceContributor { |
| 24 | + |
18 | 25 | @Override |
19 | | - public void registerReferenceProviders(@NotNull PsiReferenceRegistrar registrar) { |
| 26 | + public void registerReferenceProviders(final @NotNull PsiReferenceRegistrar registrar) { |
20 | 27 | registrar.registerReferenceProvider( |
21 | 28 | JSPatterns.jsLiteralExpression() |
22 | 29 | .withText(string().matches(".*" + RegExUtil.Magento.MODULE_NAME + ".*")), |
23 | 30 | new ModuleNameReferenceProvider() |
24 | 31 | ); |
25 | 32 |
|
| 33 | + // Targets property value -> {test: 'Sandbox_Test/js/test'} |
26 | 34 | 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), |
28 | 45 | new FilePathReferenceProvider() |
29 | 46 | ); |
30 | 47 |
|
31 | 48 | registrar.registerReferenceProvider( |
32 | | - JSPatterns.jsLiteralExpression().withText(string().matches(".*\\W" + RegExUtil.FILE_PATH + ".*")), |
| 49 | + JSPatterns.jsLiteralExpression() |
| 50 | + .withText(string().matches(".*\\W" + RegExUtil.FILE_PATH + ".*")), |
33 | 51 | new RequireJsPreferenceReferenceProvider() |
34 | 52 | ); |
35 | 53 | } |
|
0 commit comments