1- import * as vscode from ' vscode' ;
1+ import * as vscode from " vscode" ;
22
3- import { DocumentInfo , DocumentInfoProvider , MethodInfo } from './documentInfoProvider' ;
4- import { SymbolProvider , SymbolTree } from './languages/symbolProvider' ;
5- import { Token } from './languages/tokens' ;
3+ import {
4+ DocumentInfo ,
5+ DocumentInfoProvider ,
6+ MethodInfo
7+ } from "./documentInfoProvider" ;
8+ import { SymbolProvider , SymbolTree } from "./languages/symbolProvider" ;
9+ import { Token } from "./languages/tokens" ;
610
711export interface Definition {
8- document : vscode . TextDocument
9- location : vscode . Location
12+ document : vscode . TextDocument ;
13+ location : vscode . Location ;
1014}
1115
1216export type DefinitionWithTokens = Definition & {
13- tokens : Token [ ]
17+ tokens : Token [ ] ;
1418} ;
1519
1620export class CodeInspector {
17-
18- public async getExecuteDefinitionMethodInfo (
21+ public async getExecuteDefinitionMethodInfo (
1922 usageDocument : vscode . TextDocument ,
2023 usagePosition : vscode . Position ,
21- documentInfoProvider : DocumentInfoProvider ,
24+ documentInfoProvider : DocumentInfoProvider
2225 ) : Promise < MethodInfo | undefined > {
23- const definition = await this . getDefinition ( usageDocument , usagePosition ) ;
26+ const definition = await this . getDefinition (
27+ usageDocument ,
28+ usagePosition
29+ ) ;
2430 if ( ! definition ) {
2531 return ;
2632 }
2733
28- const docInfo = await documentInfoProvider . getDocumentInfo ( definition . document ) ;
34+ const docInfo = await documentInfoProvider . getDocumentInfo (
35+ definition . document
36+ ) ;
2937 if ( ! docInfo ) {
3038 return ;
3139 }
3240
33- const methodInfo = docInfo . methods . firstOrDefault ( m => m . range . contains ( definition . location . range . end ) ) ;
41+ const methodInfo = docInfo . methods . firstOrDefault ( ( m ) =>
42+ m . range . contains ( definition . location . range . end )
43+ ) ;
3444 return methodInfo ;
3545 }
3646
3747 public async getDocumentInfo (
3848 usageDocument : vscode . TextDocument ,
3949 usagePosition : vscode . Position ,
40- documentInfoProvider : DocumentInfoProvider ,
50+ documentInfoProvider : DocumentInfoProvider
4151 ) : Promise < DocumentInfo | undefined > {
42- const definition = await this . getDefinition ( usageDocument , usagePosition ) ;
43- if ( ! definition )
44- return ;
52+ const definition = await this . getDefinition (
53+ usageDocument ,
54+ usagePosition
55+ ) ;
56+ if ( ! definition ) return ;
4557
46- const docInfo = await documentInfoProvider . getDocumentInfo ( definition . document ) ;
58+ const docInfo = await documentInfoProvider . getDocumentInfo (
59+ definition . document
60+ ) ;
4761 return docInfo ;
4862 }
4963
5064 public async getDefinitionWithTokens (
5165 usageDocument : vscode . TextDocument ,
5266 usagePosition : vscode . Position ,
53- symbolProvider : SymbolProvider ,
67+ symbolProvider : SymbolProvider
5468 ) : Promise < DefinitionWithTokens | undefined > {
55- const definition = await this . getDefinition ( usageDocument , usagePosition ) ;
69+ const definition = await this . getDefinition (
70+ usageDocument ,
71+ usagePosition
72+ ) ;
5673 if ( ! definition ) {
5774 return ;
5875 }
@@ -61,18 +78,22 @@ public async getExecuteDefinitionMethodInfo(
6178 return { ...definition , tokens } ;
6279 }
6380
64- public async getTypeFromSymbolProvider ( usageDocument : vscode . TextDocument ,
81+ public async getTypeFromSymbolProvider (
82+ usageDocument : vscode . TextDocument ,
6583 usagePosition : vscode . Position ,
66- symbolProvider : SymbolProvider , traceTypePredicate : ( traceToken : Token ) => boolean ) : Promise < string | undefined > {
84+ symbolProvider : SymbolProvider ,
85+ traceTypePredicate : ( traceToken : Token ) => boolean
86+ ) : Promise < string | undefined > {
6787 const definition = await this . getType ( usageDocument , usagePosition ) ;
6888 if ( ! definition ) {
6989 return ;
7090 }
7191
7292 const tokens = await symbolProvider . getTokens ( definition . document ) ;
7393
74-
75- const traceDefToken = tokens . find ( x => x . range . intersection ( definition . location . range ) ) ;
94+ const traceDefToken = tokens . find ( ( x ) =>
95+ x . range . intersection ( definition . location . range )
96+ ) ;
7697 if ( ! traceDefToken ) {
7798 return ;
7899 }
@@ -85,9 +106,13 @@ public async getExecuteDefinitionMethodInfo(
85106
86107 public async getType (
87108 usageDocument : vscode . TextDocument ,
88- usagePosition : vscode . Position ,
109+ usagePosition : vscode . Position
89110 ) : Promise < Definition | undefined > {
90- const results : any [ ] = await vscode . commands . executeCommand ( "vscode.executeTypeDefinitionProvider" , usageDocument . uri , usagePosition ) ;
111+ const results : any [ ] = await vscode . commands . executeCommand (
112+ "vscode.executeTypeDefinitionProvider" ,
113+ usageDocument . uri ,
114+ usagePosition
115+ ) ;
91116 if ( ! results ?. length || ! results [ 0 ] . uri || ! results [ 0 ] . range ) {
92117 return ;
93118 }
@@ -100,7 +125,7 @@ public async getExecuteDefinitionMethodInfo(
100125
101126 return {
102127 document,
103- location,
128+ location
104129 } ;
105130 }
106131
@@ -109,9 +134,9 @@ public async getExecuteDefinitionMethodInfo(
109134 // const location = <vscode.Location>value;
110135 // return {
111136 // originSelectionRange: definitionLink.originSelectionRange
112- // ? new vscode.Range(definitionLink.originSelectionRange.start.line,
113- // definitionLink.originSelectionRange.start.character,
114- // definitionLink.originSelectionRange.end.line,
137+ // ? new vscode.Range(definitionLink.originSelectionRange.start.line,
138+ // definitionLink.originSelectionRange.start.character,
139+ // definitionLink.originSelectionRange.end.line,
115140 // definitionLink.originSelectionRange.end.character)
116141 // : undefined,
117142 // uri: definitionLink.targetUri ? definitionLink.targetUri : location.uri,
@@ -124,9 +149,13 @@ public async getExecuteDefinitionMethodInfo(
124149
125150 private async getDefinition (
126151 usageDocument : vscode . TextDocument ,
127- usagePosition : vscode . Position ,
152+ usagePosition : vscode . Position
128153 ) : Promise < Definition | undefined > {
129- const results : any [ ] = await vscode . commands . executeCommand ( 'vscode.executeDefinitionProvider' , usageDocument . uri , usagePosition ) ;
154+ const results : any [ ] = await vscode . commands . executeCommand (
155+ "vscode.executeDefinitionProvider" ,
156+ usageDocument . uri ,
157+ usagePosition
158+ ) ;
130159
131160 if ( ! results ?. length ) {
132161 return ;
@@ -137,7 +166,12 @@ public async getExecuteDefinitionMethodInfo(
137166 let location = < vscode . Location > value ;
138167
139168 //in some cases for example js language the return value is of type DefinitionLink
140- location = new vscode . Location ( definitionLink . targetUri ? definitionLink . targetUri : location . uri , definitionLink . targetSelectionRange ? definitionLink . targetSelectionRange : location . range ) ;
169+ location = new vscode . Location (
170+ definitionLink . targetUri ? definitionLink . targetUri : location . uri ,
171+ definitionLink . targetSelectionRange
172+ ? definitionLink . targetSelectionRange
173+ : location . range
174+ ) ;
141175
142176 const document = await vscode . workspace . openTextDocument ( location . uri ) ;
143177 if ( ! document ) {
@@ -146,15 +180,19 @@ public async getExecuteDefinitionMethodInfo(
146180
147181 return {
148182 document,
149- location,
183+ location
150184 } ;
151185 }
152186
153187 public async getDeclaration (
154188 usageDocument : vscode . TextDocument ,
155- usagePosition : vscode . Position ,
189+ usagePosition : vscode . Position
156190 ) : Promise < Definition | undefined > {
157- const results : any [ ] = await vscode . commands . executeCommand ( "vscode.executeDefinitionProvider" , usageDocument . uri , usagePosition ) ;
191+ const results : any [ ] = await vscode . commands . executeCommand (
192+ "vscode.executeDefinitionProvider" ,
193+ usageDocument . uri ,
194+ usagePosition
195+ ) ;
158196 if ( ! results ?. length ) {
159197 return ;
160198 }
@@ -170,11 +208,14 @@ public async getExecuteDefinitionMethodInfo(
170208
171209 return {
172210 document,
173- location,
211+ location
174212 } ;
175213 }
176214
177- public * getAllSymbolsOfKind ( symbolTrees : SymbolTree [ ] | undefined , kind : vscode . SymbolKind ) : Generator < SymbolTree > {
215+ public * getAllSymbolsOfKind (
216+ symbolTrees : SymbolTree [ ] | undefined ,
217+ kind : vscode . SymbolKind
218+ ) : Generator < SymbolTree > {
178219 if ( ! symbolTrees ) {
179220 return ;
180221 }
@@ -183,17 +224,26 @@ public async getExecuteDefinitionMethodInfo(
183224 if ( symbolTree . kind === kind ) {
184225 yield symbolTree ;
185226 }
186- yield * this . getAllSymbolsOfKind ( symbolTree . children as SymbolTree [ ] | undefined , kind ) ;
227+ yield * this . getAllSymbolsOfKind (
228+ symbolTree . children as SymbolTree [ ] | undefined ,
229+ kind
230+ ) ;
187231 }
188232 }
189233
190234 public async derivesFrom (
191235 definition : DefinitionWithTokens ,
192236 ancestorName : string ,
193237 symbolProvider : SymbolProvider ,
194- findParentToken : ( tokens : Token [ ] , position : vscode . Position ) => Token | undefined ,
238+ findParentToken : (
239+ tokens : Token [ ] ,
240+ position : vscode . Position
241+ ) => Token | undefined
195242 ) : Promise < boolean > {
196- const parentToken = findParentToken ( definition . tokens , definition . location . range . start ) ;
243+ const parentToken = findParentToken (
244+ definition . tokens ,
245+ definition . location . range . start
246+ ) ;
197247 if ( ! parentToken ) {
198248 return false ;
199249 }
@@ -202,12 +252,18 @@ public async getExecuteDefinitionMethodInfo(
202252 return true ;
203253 }
204254
205- const parentInfo = await this . getDefinitionWithTokens ( definition . document , parentToken . range . start , symbolProvider ) ;
255+ const parentInfo = await this . getDefinitionWithTokens (
256+ definition . document ,
257+ parentToken . range . start ,
258+ symbolProvider
259+ ) ;
206260 if ( ! parentInfo ) {
207261 return false ;
208262 }
209263
210- const parentSymbolTree = await symbolProvider . getSymbolTree ( parentInfo . document ) ;
264+ const parentSymbolTree = await symbolProvider . getSymbolTree (
265+ parentInfo . document
266+ ) ;
211267 if ( ! parentSymbolTree ) {
212268 return false ;
213269 }
@@ -216,7 +272,7 @@ public async getExecuteDefinitionMethodInfo(
216272 parentInfo ,
217273 ancestorName ,
218274 symbolProvider ,
219- findParentToken ,
275+ findParentToken
220276 ) ;
221277 return parentDerivesFromAncestor ;
222278 }
0 commit comments