@@ -3,7 +3,7 @@ import { map, switchMap } from 'rxjs/operators'
3
3
import { Location } from 'vscode-languageserver-types'
4
4
import { ReferenceParams , TextDocumentPositionParams , TextDocumentRegistrationOptions } from '../../protocol'
5
5
import { FeatureProviderRegistry } from './registry'
6
- import { flattenAndCompact } from './util'
6
+ import { flattenAndCompact , flattenAndCompactNonNull } from './util'
7
7
8
8
/**
9
9
* Function signature for retrieving related locations given a location (e.g., definition, implementation, and type
@@ -22,6 +22,23 @@ export class TextDocumentLocationProviderRegistry<
22
22
public getLocation ( params : P ) : Observable < L | L [ ] | null > {
23
23
return getLocation < P , L > ( this . providers , params )
24
24
}
25
+
26
+ public getLocationsWithProviderName ( params : P ) : Observable < { providerName : string ; location : L } [ ] | null > {
27
+ return getLocationsWithProviderName < P , L > ( this . providersWithName , params )
28
+ }
29
+
30
+ public readonly providersWithName : Observable <
31
+ { name : string ; provider : ProvideTextDocumentLocationSignature < P , L > } [ ]
32
+ > = this . entries . pipe (
33
+ map ( providers =>
34
+ providers . map ( ( { provider, registrationOptions } ) => {
35
+ return {
36
+ name : registrationOptions . providerName ,
37
+ provider,
38
+ }
39
+ } )
40
+ )
41
+ )
25
42
}
26
43
27
44
/**
@@ -62,6 +79,35 @@ export function getLocations<
62
79
)
63
80
}
64
81
82
+ export function getLocationsWithProviderName <
83
+ P extends TextDocumentPositionParams = TextDocumentPositionParams ,
84
+ L extends Location = Location
85
+ > (
86
+ providersWithName : Observable < { name : string ; provider : ProvideTextDocumentLocationSignature < P , L > } [ ] > ,
87
+ params : P
88
+ ) : Observable < { providerName : string ; location : L } [ ] > {
89
+ return providersWithName . pipe (
90
+ switchMap ( async providersWithName => {
91
+ const resultsByProvider = await Promise . all (
92
+ providersWithName . map ( async ( { provider, name } ) => {
93
+ const providerRes = await provider ( params ) . toPromise ( )
94
+ return flattenAndCompactNonNull ( [ providerRes ] ) . map ( loc => ( {
95
+ providerName : name ,
96
+ location : loc ,
97
+ } ) )
98
+ } )
99
+ )
100
+ const flattenedResults : { providerName : string ; location : L } [ ] = [ ]
101
+ for ( const providerResults of resultsByProvider ) {
102
+ for ( const res of providerResults ) {
103
+ flattenedResults . push ( res )
104
+ }
105
+ }
106
+ return flattenedResults
107
+ } )
108
+ )
109
+ }
110
+
65
111
/**
66
112
* Provides reference results from all extensions.
67
113
*
0 commit comments