@@ -10,20 +10,19 @@ import path from 'path';
1010import MarkdownMessageBuilder from 'common/MarkdownMessageBuilder' ;
1111import PhpNamespace from 'common/PhpNamespace' ;
1212import TextDocumentDecorationProvider from './TextDocumentDecorationProvider' ;
13- import PhpParser from 'parser/php/Parser' ;
1413import Position from 'util/Position' ;
1514import PluginSubjectInfo from 'common/php/PluginSubjectInfo' ;
1615import PluginInfo from 'common/php/PluginInfo' ;
1716import Magento from 'util/Magento' ;
1817import { ClasslikeInfo } from 'common/php/ClasslikeInfo' ;
1918import { PhpClass } from 'parser/php/PhpClass' ;
2019import { PhpInterface } from 'parser/php/PhpInterface' ;
20+ import { PhpMethod } from 'parser/php/PhpMethod' ;
2121import IndexManager from 'indexer/IndexManager' ;
2222import AutoloadNamespaceIndexer from 'indexer/autoload-namespace/AutoloadNamespaceIndexer' ;
2323import { AutoloadNamespaceIndexData } from 'indexer/autoload-namespace/AutoloadNamespaceIndexData' ;
2424import { DiPlugin } from 'indexer/di/types' ;
2525import PhpDocumentParser from 'common/php/PhpDocumentParser' ;
26- import Common from 'util/Common' ;
2726
2827export default class PluginClassDecorationProvider extends TextDocumentDecorationProvider {
2928 public getType ( ) : TextEditorDecorationType {
@@ -74,55 +73,57 @@ export default class PluginClassDecorationProvider extends TextDocumentDecoratio
7473 hoverMessage,
7574 } ) ;
7675
77- const promises = classPlugins . map ( async plugin => {
76+ const methodPlugins : Record < string , { plugin : DiPlugin ; subjectMethod : PhpMethod } [ ] > = { } ;
77+
78+ for ( const plugin of classPlugins ) {
7879 const fileUri = await namespaceIndexData . findClassByNamespace (
7980 PhpNamespace . fromString ( plugin . type )
8081 ) ;
8182
8283 if ( ! fileUri ) {
83- return ;
84+ continue ;
8485 }
8586
8687 const pluginPhpFile = await PhpDocumentParser . parseUri ( this . document , fileUri ) ;
8788 const pluginInfo = new PluginInfo ( pluginPhpFile ) ;
8889 const pluginMethods = pluginInfo . getPluginMethods ( pluginPhpFile . classes [ 0 ] ) ;
8990
90- return pluginMethods . map ( method => {
91+ for ( const method of pluginMethods ) {
9192 const subjectMethodName = Magento . pluginMethodToMethodName ( method . name ) ;
92-
93- if ( ! subjectMethodName ) {
94- return ;
95- }
96-
9793 const subjectMethod = classlikeInfo . getMethodByName ( classLikeNode , subjectMethodName ) ;
9894
9995 if ( ! subjectMethod ) {
100- return ;
96+ continue ;
10197 }
10298
103- if ( typeof subjectMethod . ast . name === 'string' || ! subjectMethod . ast . name . loc ) {
104- return ;
105- }
99+ methodPlugins [ subjectMethod . name ] = methodPlugins [ subjectMethod . name ] || [ ] ;
100+ methodPlugins [ subjectMethod . name ] . push ( {
101+ plugin,
102+ subjectMethod,
103+ } ) ;
104+ }
105+ }
106106
107- const range = new Range (
108- Position . phpAstPositionToVsCodePosition ( subjectMethod . ast . name . loc . start ) ,
109- Position . phpAstPositionToVsCodePosition ( subjectMethod . ast . name . loc . end )
110- ) ;
107+ for ( const [ , plugins ] of Object . entries ( methodPlugins ) ) {
108+ const hoverMessage = await this . getInterceptorHoverMessage (
109+ plugins . map ( p => p . plugin ) ,
110+ namespaceIndexData
111+ ) ;
112+ const subjectMethod = plugins [ 0 ] . subjectMethod ;
111113
112- const message = MarkdownMessageBuilder . create ( 'Interceptors' ) ;
113- const link = `[${ plugin . type } ](${ fileUri ? Uri . file ( fileUri . fsPath ) : '#' } )` ;
114- message . appendMarkdown ( `- ${ link } [(di.xml)](${ Uri . file ( plugin . diPath ) } )\n` ) ;
114+ if ( typeof subjectMethod . ast . name === 'string' || ! subjectMethod . ast . name . loc ) {
115+ continue ;
116+ }
117+ const range = new Range (
118+ Position . phpAstPositionToVsCodePosition ( subjectMethod . ast . name . loc . start ) ,
119+ Position . phpAstPositionToVsCodePosition ( subjectMethod . ast . name . loc . end )
120+ ) ;
115121
116- return {
117- range,
118- hoverMessage : message . build ( ) ,
119- } ;
122+ decorations . push ( {
123+ range,
124+ hoverMessage,
120125 } ) ;
121- } ) ;
122-
123- const pluginMethodsDecorations = await Promise . all ( promises ) ;
124-
125- decorations . push ( ...( pluginMethodsDecorations . flat ( ) . filter ( Boolean ) as DecorationOptions [ ] ) ) ;
126+ }
126127
127128 return decorations ;
128129 }
@@ -138,9 +139,8 @@ export default class PluginClassDecorationProvider extends TextDocumentDecoratio
138139 PhpNamespace . fromString ( interceptor . type )
139140 ) ;
140141
141- message . appendMarkdown (
142- `- [${ interceptor . type } ](${ fileUri ? Uri . file ( fileUri . fsPath ) : '#' } )\n`
143- ) ;
142+ const link = `[${ interceptor . type } ](${ fileUri ? Uri . file ( fileUri . fsPath ) : '#' } )` ;
143+ message . appendMarkdown ( `- ${ link } [(di.xml)](${ Uri . file ( interceptor . diPath ) } )\n` ) ;
144144 }
145145
146146 return message . build ( ) ;
0 commit comments