6
6
import com .intellij .psi .PsiElement ;
7
7
import fr .adrienbrault .idea .symfony2plugin .Symfony2ProjectComponent ;
8
8
import fr .adrienbrault .idea .symfony2plugin .config .yaml .YamlElementPatternHelper ;
9
- import fr .adrienbrault .idea .symfony2plugin .dic .ContainerService ;
10
9
import fr .adrienbrault .idea .symfony2plugin .util .dict .ServiceUtil ;
11
10
import fr .adrienbrault .idea .symfony2plugin .util .yaml .YamlHelper ;
12
11
import org .apache .commons .lang .StringUtils ;
13
12
import org .jetbrains .annotations .NotNull ;
14
13
import org .jetbrains .annotations .Nullable ;
14
+ import org .jetbrains .yaml .YAMLTokenTypes ;
15
15
import org .jetbrains .yaml .psi .YAMLKeyValue ;
16
16
17
17
import java .util .Collection ;
18
18
import java .util .List ;
19
- import java .util .Map ;
20
19
21
20
/**
22
21
* @author Daniel Espendiller <daniel@espendiller.net>
@@ -34,21 +33,29 @@ public void collectSlowLineMarkers(@NotNull List<PsiElement> psiElements, @NotNu
34
33
return ;
35
34
}
36
35
37
- final LazyDecoratedServiceValues [] lazyDecoratedServices = { null } ;
36
+ LazyDecoratedServiceValues lazyDecoratedServices = null ;
38
37
39
- // services -> service_name
40
- psiElements .stream ()
41
- .filter (psiElement -> psiElement instanceof YAMLKeyValue && YamlElementPatternHelper .getServiceIdKeyValuePattern ().accepts (psiElement ))
42
- .forEach ((PsiElement psiElement ) -> {
43
- if (lazyDecoratedServices [0 ] == null ) {
44
- lazyDecoratedServices [0 ] = new LazyDecoratedServiceValues (psiElements .get (0 ).getProject ());
45
- }
46
38
47
- visitServiceId ((YAMLKeyValue ) psiElement , result , lazyDecoratedServices [0 ]);
48
- });
39
+ for (PsiElement psiElement : psiElements ) {
40
+ if (psiElement .getNode ().getElementType () != YAMLTokenTypes .SCALAR_KEY ) {
41
+ continue ;
42
+ }
43
+
44
+ PsiElement yamlKeyValue = psiElement .getParent ();
45
+ if (!(yamlKeyValue instanceof YAMLKeyValue ) || !YamlElementPatternHelper .getServiceIdKeyValuePattern ().accepts (yamlKeyValue )) {
46
+ continue ;
47
+ }
48
+
49
+ if (lazyDecoratedServices == null ) {
50
+ lazyDecoratedServices = new LazyDecoratedServiceValues (psiElement .getProject ());
51
+ }
52
+
53
+ // services -> service_name
54
+ visitServiceId (psiElement , (YAMLKeyValue ) yamlKeyValue , result , lazyDecoratedServices );
55
+ }
49
56
}
50
57
51
- private void visitServiceId (@ NotNull YAMLKeyValue yamlKeyValue , @ NotNull Collection <LineMarkerInfo > result , @ NotNull LazyDecoratedServiceValues lazyDecoratedServices ) {
58
+ private void visitServiceId (@ NotNull PsiElement leafTarget , @ NotNull YAMLKeyValue yamlKeyValue , @ NotNull Collection <LineMarkerInfo > result , @ NotNull LazyDecoratedServiceValues lazyDecoratedServices ) {
52
59
String id = yamlKeyValue .getKeyText ();
53
60
if (StringUtils .isBlank (id )) {
54
61
return ;
@@ -57,17 +64,19 @@ private void visitServiceId(@NotNull YAMLKeyValue yamlKeyValue, @NotNull Collect
57
64
// decorates: @foobar
58
65
String decorates = YamlHelper .getYamlKeyValueAsString (yamlKeyValue , "decorates" );
59
66
if (decorates != null && StringUtils .isNotBlank (decorates )) {
60
- result .add (ServiceUtil .getLineMarkerForDecoratesServiceId (yamlKeyValue , decorates ));
67
+ result .add (ServiceUtil .getLineMarkerForDecoratesServiceId (leafTarget , decorates ));
61
68
}
62
69
63
70
NavigationGutterIconBuilder <PsiElement > lineMarker = ServiceUtil .getLineMarkerForDecoratedServiceId (
64
- yamlKeyValue .getProject (), lazyDecoratedServices .getDecoratedServices (), id
71
+ yamlKeyValue .getProject (),
72
+ lazyDecoratedServices .getDecoratedServices (),
73
+ id
65
74
);
66
75
67
76
if (lineMarker == null ) {
68
77
return ;
69
78
}
70
79
71
- result .add (lineMarker .createLineMarkerInfo (yamlKeyValue ));
80
+ result .add (lineMarker .createLineMarkerInfo (leafTarget ));
72
81
}
73
82
}
0 commit comments