@@ -30,57 +30,62 @@ public class PhpServiceArgumentIntention extends PsiElementBaseIntentionAction {
3030 @ Override
3131 public void invoke (@ NotNull Project project , Editor editor , @ NotNull PsiElement psiElement ) throws IncorrectOperationException {
3232 PhpClass phpClass = PsiTreeUtil .getParentOfType (psiElement , PhpClass .class );
33- if (phpClass != null ) {
34- Set <String > serviceNames = ContainerCollectionResolver .ServiceCollector .create (project ).convertClassNameToServices (phpClass .getFQN ());
35- if (serviceNames .size () > 0 ) {
36- Collection <PsiElement > psiElements = new ArrayList <>();
37- for (String serviceName : serviceNames ) {
38- psiElements .addAll (ServiceIndexUtil .findServiceDefinitions (project , serviceName ));
39- }
40-
41- if (psiElements .size () > 0 ) {
42- Map <String , PsiElement > map = new HashMap <>();
43-
44- for (PsiElement element : psiElements ) {
45- map .put (VfsUtil .getRelativePath (element .getContainingFile ().getVirtualFile (), element .getProject ().getBaseDir ()), element );
46- }
47-
48- final JBList <String > list = new JBList <>(map .keySet ());
49-
50- JBPopupFactory .getInstance ().createListPopupBuilder (list )
51- .setTitle ("Symfony: Services Definitions" )
52- .setItemChoosenCallback (() -> new WriteCommandAction .Simple (editor .getProject (), "Service Update" ) {
53- @ Override
54- protected void run () {
55- String selectedValue = list .getSelectedValue ();
56-
57- PsiElement target = map .get (selectedValue );
58- invokeByScope (target , editor );
59- }
60- }.execute ())
61- .createPopup ()
62- .showInBestPositionFor (editor );
63- }
64- }
33+ if (phpClass == null ) {
34+
35+ return ;
36+ }
37+
38+ Set <String > serviceNames = ContainerCollectionResolver .ServiceCollector .create (project ).convertClassNameToServices (phpClass .getFQN ());
39+ if (serviceNames .isEmpty ()) {
40+
41+ return ;
42+ }
43+
44+ Collection <PsiElement > psiElements = new ArrayList <>();
45+ for (String serviceName : serviceNames ) {
46+ psiElements .addAll (ServiceIndexUtil .findServiceDefinitions (project , serviceName ));
6547 }
48+
49+ if (psiElements .isEmpty ()) {
50+
51+ return ;
52+ }
53+
54+ Map <String , PsiElement > map = new HashMap <>();
55+
56+ for (PsiElement element : psiElements ) {
57+ map .put (VfsUtil .getRelativePath (element .getContainingFile ().getVirtualFile (), element .getProject ().getBaseDir ()), element );
58+ }
59+
60+ final JBList <String > list = new JBList <>(map .keySet ());
61+ JBPopupFactory .getInstance ().createListPopupBuilder (list )
62+ .setTitle ("Symfony: Services Definitions" )
63+ .setItemChoosenCallback (() -> {
64+ WriteCommandAction .writeCommandAction (project ).withName ("Service Update" ).run (() -> {
65+ invokeByScope (map .get (list .getSelectedValue ()), editor );
66+ });
67+ })
68+ .createPopup ()
69+ .showInBestPositionFor (editor )
70+ ;
6671 }
6772
6873 private void invokeByScope (@ NotNull PsiElement psiElement , @ NotNull Editor editor ) {
6974 boolean success = false ;
7075
71- if (psiElement instanceof XmlTag ) {
76+ if (psiElement instanceof XmlTag ) {
7277 List <String > args = ServiceActionUtil .getXmlMissingArgumentTypes ((XmlTag ) psiElement , true , new ContainerCollectionResolver .LazyServiceCollector (psiElement .getProject ()));
7378
7479 success = args .size () > 0 ;
7580 if (success ) {
7681 ServiceActionUtil .fixServiceArgument (args , (XmlTag ) psiElement );
7782 }
78- } else if (psiElement instanceof YAMLKeyValue ) {
83+ } else if (psiElement instanceof YAMLKeyValue ) {
7984 List <String > args = ServiceActionUtil .getYamlMissingArgumentTypes (
80- psiElement .getProject (),
81- ServiceActionUtil .ServiceYamlContainer .create ((YAMLKeyValue ) psiElement ),
82- false ,
83- new ContainerCollectionResolver .LazyServiceCollector (psiElement .getProject ())
85+ psiElement .getProject (),
86+ ServiceActionUtil .ServiceYamlContainer .create ((YAMLKeyValue ) psiElement ),
87+ false ,
88+ new ContainerCollectionResolver .LazyServiceCollector (psiElement .getProject ())
8489 );
8590
8691 success = args .size () > 0 ;
@@ -89,13 +94,14 @@ private void invokeByScope(@NotNull PsiElement psiElement, @NotNull Editor edito
8994 }
9095 }
9196
92- if (!success ) {
97+ if (!success ) {
9398 HintManager .getInstance ().showErrorHint (editor , "No argument update needed" );
99+
94100 return ;
95101 }
96102
97103 String relativePath = VfsUtil .getRelativePath (psiElement .getContainingFile ().getVirtualFile (), psiElement .getProject ().getBaseDir ());
98- if (relativePath == null ) {
104+ if (relativePath == null ) {
99105 relativePath = "n/a" ;
100106 }
101107
@@ -125,7 +131,7 @@ private Set<String> getServicesInScope(@NotNull PsiElement psiElement) {
125131 PhpClass phpClass = PsiTreeUtil .getParentOfType (psiElement , PhpClass .class );
126132
127133 return phpClass == null
128- ? Collections .emptySet ()
129- : ContainerCollectionResolver .ServiceCollector .create (psiElement .getProject ()).convertClassNameToServices (phpClass .getFQN ());
134+ ? Collections .emptySet ()
135+ : ContainerCollectionResolver .ServiceCollector .create (psiElement .getProject ()).convertClassNameToServices (phpClass .getFQN ());
130136 }
131137}
0 commit comments