@@ -8,97 +8,90 @@ import type { Point, TextEditor } from "atom"
8
8
9
9
import OutlineViewAdapter from "./outline-view-adapter"
10
10
11
- /** Public: Adapts the documentSymbolProvider of the language server to the Outline View supplied by Atom IDE UI. */
12
- export default class CallHierarchyAdapter {
13
- private _cancellationTokens = new WeakMap < LanguageClientConnection , CancellationTokenSource > ( )
11
+ const cancellationTokens = new WeakMap < LanguageClientConnection , CancellationTokenSource > ( )
14
12
15
- /**
16
- * Public: Determine whether this adapter can be used to adapt a language server based on the serverCapabilities
17
- * matrix containing a callHierarchyProvider.
18
- *
19
- * @param serverCapabilities The {ServerCapabilities} of the language server to consider.
20
- * @returns A {Boolean} indicating adapter can adapt the server based on the given serverCapabilities.
21
- */
22
- public static canAdapt ( serverCapabilities : ServerCapabilities ) : boolean {
23
- return Boolean ( serverCapabilities . callHierarchyProvider )
24
- }
25
-
26
- /** Corresponds to lsp's CallHierarchyPrepareRequest */
13
+ /**
14
+ * Public: Determine whether this adapter can be used to adapt a language server based on the serverCapabilities matrix
15
+ * containing a callHierarchyProvider.
16
+ *
17
+ * @param serverCapabilities The {ServerCapabilities} of the language server to consider.
18
+ * @returns A {Boolean} indicating adapter can adapt the server based on the given serverCapabilities.
19
+ */
20
+ export function canAdapt ( serverCapabilities : ServerCapabilities ) : boolean {
21
+ return Boolean ( serverCapabilities . callHierarchyProvider )
22
+ }
27
23
28
- /**
29
- * Public: Obtain the relationship between calling and called functions hierarchically. Corresponds to lsp's
30
- * CallHierarchyPrepareRequest.
31
- *
32
- * @param connection A {LanguageClientConnection} to the language server that provides highlights.
33
- * @param editor The Atom {TextEditor} containing the text associated with the calling.
34
- * @param position The Atom {Point} associated with the calling.
35
- * @param type The hierarchy type either incoming or outgoing.
36
- * @returns A {Promise} of an {CallHierarchy}.
37
- */
38
- async getCallHierarchy < T extends atomIde . CallHierarchyType > (
39
- connection : LanguageClientConnection ,
40
- editor : TextEditor ,
41
- point : Point ,
42
- type : T
43
- ) : Promise < atomIde . CallHierarchy < T > > {
44
- const results = await Utils . doWithCancellationToken ( connection , this . _cancellationTokens , ( cancellationToken ) =>
45
- connection . prepareCallHierarchy (
46
- {
47
- textDocument : Convert . editorToTextDocumentIdentifier ( editor ) ,
48
- position : Convert . pointToPosition ( point ) ,
49
- } ,
50
- cancellationToken
51
- )
52
- )
53
- return < CallHierarchyForAdapter < T > > {
54
- type,
55
- data : results ?. map ( convertCallHierarchyItem ) ?? [ ] ,
56
- itemAt ( num : number ) {
57
- if ( type === "incoming" ) {
58
- return < Promise < atomIde . CallHierarchy < T > > > this . adapter . getIncoming ( this . connection , this . data [ num ] . rawData )
59
- } else {
60
- return < Promise < atomIde . CallHierarchy < T > > > this . adapter . getOutgoing ( this . connection , this . data [ num ] . rawData )
61
- }
24
+ /**
25
+ * Public: Obtain the relationship between calling and called functions hierarchically. Corresponds to lsp's
26
+ * CallHierarchyPrepareRequest.
27
+ *
28
+ * @param connection A {LanguageClientConnection} to the language server that provides highlights.
29
+ * @param editor The Atom {TextEditor} containing the text associated with the calling.
30
+ * @param position The Atom {Point} associated with the calling.
31
+ * @param type The hierarchy type either incoming or outgoing.
32
+ * @returns A {Promise} of an {CallHierarchy}.
33
+ */
34
+ export async function getCallHierarchy < T extends atomIde . CallHierarchyType > (
35
+ connection : LanguageClientConnection ,
36
+ editor : TextEditor ,
37
+ point : Point ,
38
+ type : T
39
+ ) : Promise < atomIde . CallHierarchy < T > > {
40
+ const results = await Utils . doWithCancellationToken ( connection , cancellationTokens , ( cancellationToken ) =>
41
+ connection . prepareCallHierarchy (
42
+ {
43
+ textDocument : Convert . editorToTextDocumentIdentifier ( editor ) ,
44
+ position : Convert . pointToPosition ( point ) ,
62
45
} ,
63
- connection,
64
- adapter : this ,
65
- }
66
- }
67
- /** Corresponds to lsp's CallHierarchyIncomingCallsRequest. */
68
- async getIncoming (
69
- connection : LanguageClientConnection ,
70
- item : CallHierarchyItem
71
- ) : Promise < atomIde . CallHierarchy < "incoming" > > {
72
- const results = await Utils . doWithCancellationToken ( connection , this . _cancellationTokens , ( _cancellationToken ) =>
73
- connection . callHierarchyIncomingCalls ( { item } )
46
+ cancellationToken
74
47
)
75
- return < CallHierarchyForAdapter < "incoming" > > {
76
- type : "incoming" ,
77
- data : results ?. map ( ( res ) => convertCallHierarchyItem ( res . from ) ) ?? [ ] ,
78
- itemAt ( num : number ) {
79
- return this . adapter . getIncoming ( this . connection , this . data [ num ] . rawData )
80
- } ,
81
- connection,
82
- adapter : this ,
83
- }
48
+ )
49
+ return < CallHierarchyForAdapter < T > > {
50
+ type,
51
+ data : results ?. map ( convertCallHierarchyItem ) ?? [ ] ,
52
+ itemAt ( num : number ) {
53
+ if ( type === "incoming" ) {
54
+ return < Promise < atomIde . CallHierarchy < T > > > getIncoming ( this . connection , this . data [ num ] . rawData )
55
+ } else {
56
+ return < Promise < atomIde . CallHierarchy < T > > > getOutgoing ( this . connection , this . data [ num ] . rawData )
57
+ }
58
+ } ,
59
+ connection,
84
60
}
85
- /** Corresponds to lsp's CallHierarchyOutgoingCallsRequest. */
86
- async getOutgoing (
87
- connection : LanguageClientConnection ,
88
- item : CallHierarchyItem
89
- ) : Promise < atomIde . CallHierarchy < "outgoing" > > {
90
- const results = await Utils . doWithCancellationToken ( connection , this . _cancellationTokens , ( _cancellationToken ) =>
91
- connection . callHierarchyOutgoingCalls ( { item } )
92
- )
93
- return < CallHierarchyForAdapter < "outgoing" > > {
94
- type : "outgoing" ,
95
- data : results ?. map ( ( res ) => convertCallHierarchyItem ( res . to ) ) ?? [ ] ,
96
- itemAt ( num : number ) {
97
- return this . adapter . getOutgoing ( this . connection , this . data [ num ] . rawData )
98
- } ,
99
- connection,
100
- adapter : this ,
101
- }
61
+ }
62
+
63
+ /** Corresponds to lsp's CallHierarchyIncomingCallsRequest. */
64
+ async function getIncoming (
65
+ connection : LanguageClientConnection ,
66
+ item : CallHierarchyItem
67
+ ) : Promise < atomIde . CallHierarchy < "incoming" > > {
68
+ const results = await Utils . doWithCancellationToken ( connection , cancellationTokens , ( _cancellationToken ) =>
69
+ connection . callHierarchyIncomingCalls ( { item } )
70
+ )
71
+ return < CallHierarchyForAdapter < "incoming" > > {
72
+ type : "incoming" ,
73
+ data : results ?. map ( ( res ) => convertCallHierarchyItem ( res . from ) ) ?? [ ] ,
74
+ itemAt ( num : number ) {
75
+ return getIncoming ( this . connection , this . data [ num ] . rawData )
76
+ } ,
77
+ connection,
78
+ }
79
+ }
80
+ /** Corresponds to lsp's CallHierarchyOutgoingCallsRequest. */
81
+ async function getOutgoing (
82
+ connection : LanguageClientConnection ,
83
+ item : CallHierarchyItem
84
+ ) : Promise < atomIde . CallHierarchy < "outgoing" > > {
85
+ const results = await Utils . doWithCancellationToken ( connection , cancellationTokens , ( _cancellationToken ) =>
86
+ connection . callHierarchyOutgoingCalls ( { item } )
87
+ )
88
+ return < CallHierarchyForAdapter < "outgoing" > > {
89
+ type : "outgoing" ,
90
+ data : results ?. map ( ( res ) => convertCallHierarchyItem ( res . to ) ) ?? [ ] ,
91
+ itemAt ( num : number ) {
92
+ return getOutgoing ( this . connection , this . data [ num ] . rawData )
93
+ } ,
94
+ connection,
102
95
}
103
96
}
104
97
@@ -135,7 +128,6 @@ function symbolTagToEntityKind(symbol: number): atomIde.SymbolTagKind | null {
135
128
/** Extend CallHierarchy to include properties used inside the adapter */
136
129
interface CallHierarchyForAdapter < T extends atomIde . CallHierarchyType > extends atomIde . CallHierarchy < T > {
137
130
data : CallHierarchyItemForAdapter [ ]
138
- adapter : CallHierarchyAdapter
139
131
connection : LanguageClientConnection
140
132
}
141
133
0 commit comments