@@ -2,7 +2,8 @@ import { setInterval, clearInterval } from 'timers';
2
2
import * as vscode from 'vscode' ;
3
3
import { AnalyticsProvider , CodeObjectSummary , MethodCodeObjectSummary } from './analyticsProvider' ;
4
4
import { Logger } from "./logger" ;
5
- import { SymbolProvider , Token , TokenType } from './languages/symbolProvider' ;
5
+ import { SymbolProvider } from './languages/symbolProvider' ;
6
+ import { Token , TokenType } from './languages/tokens' ;
6
7
import { Dictionary , Future } from './utils' ;
7
8
import { EndpointInfo , SpanInfo , SymbolInfo , CodeObjectInfo } from './languages/extractors' ;
8
9
import { InstrumentationInfo } from './EditorHelper' ;
@@ -84,33 +85,38 @@ export class DocumentInfoProvider implements vscode.Disposable
84
85
private async addOrUpdateDocumentInfo ( doc : vscode . TextDocument ) : Promise < DocumentInfo | undefined >
85
86
{
86
87
const docRelativePath = doc . uri . toModulePath ( ) ;
87
- if ( ! docRelativePath || ! this . symbolProvider . supportsDocument ( doc ) )
88
+ if ( ! docRelativePath || ! this . symbolProvider . supportsDocument ( doc ) ) {
88
89
return undefined ;
90
+ }
89
91
90
92
let document = this . _documents [ docRelativePath ] ;
91
- if ( ! document )
92
- {
93
+ if ( ! document ) {
93
94
document = this . _documents [ docRelativePath ] = new DocumentInfoContainer ( ) ;
94
95
}
95
96
96
97
let latestVersionInfo = document . versions [ doc . version ] ;
97
- if ( ! latestVersionInfo )
98
- {
98
+ if ( ! latestVersionInfo ) {
99
99
latestVersionInfo = document . versions [ doc . version ] = new Future < DocumentInfo > ( ) ;
100
100
101
- try
102
- {
101
+ try {
103
102
Logger . trace ( `Starting building DocumentInfo for "${ docRelativePath } " v${ doc . version } ` ) ;
104
- const symbolInfos = await this . symbolProvider . getMethods ( doc ) ;
103
+ const symbolTrees = await this . symbolProvider . getSymbolTree ( doc ) ;
104
+ const symbolInfos = await this . symbolProvider . getMethods ( doc , symbolTrees ) ;
105
105
const tokens = await this . symbolProvider . getTokens ( doc ) ;
106
- const endpoints = await this . symbolProvider . getEndpoints ( doc , symbolInfos , tokens ) ;
106
+ const endpoints = await this . symbolProvider . getEndpoints ( doc , symbolInfos , tokens , symbolTrees , this ) ;
107
107
const spans = await this . symbolProvider . getSpans ( doc , symbolInfos , tokens ) ;
108
- const methods = this . createMethodInfos ( doc , symbolInfos , tokens , spans , endpoints ) ;
109
- const summaries = new CodeObjectSummeryAccessor ( await this . analyticsProvider . getSummaries ( methods . map ( s => s . idWithType ) . concat ( endpoints . map ( e => e . idWithType ) ) . concat ( spans . map ( s => s . idWithType ) ) ) ) ;
110
- const lines = this . createLineInfos ( doc , summaries , methods ) ;
108
+ const methodInfos = this . createMethodInfos ( doc , symbolInfos , tokens , spans , endpoints ) ;
109
+ const summaries = new CodeObjectSummaryAccessor (
110
+ await this . analyticsProvider . getSummaries (
111
+ methodInfos . map ( s => s . idWithType )
112
+ . concat ( endpoints . map ( e => e . idWithType ) )
113
+ . concat ( spans . map ( s => s . idWithType ) )
114
+ )
115
+ ) ;
116
+ const lines = this . createLineInfos ( doc , summaries , methodInfos ) ;
111
117
latestVersionInfo . value = {
112
118
summaries,
113
- methods,
119
+ methods : methodInfos ,
114
120
lines,
115
121
tokens,
116
122
endpoints,
@@ -119,10 +125,9 @@ export class DocumentInfoProvider implements vscode.Disposable
119
125
} ;
120
126
Logger . trace ( `Finished building DocumentInfo for "${ docRelativePath } " v${ doc . version } ` ) ;
121
127
}
122
- catch ( e )
123
- {
128
+ catch ( e ) {
124
129
latestVersionInfo . value = {
125
- summaries : new CodeObjectSummeryAccessor ( [ ] ) ,
130
+ summaries : new CodeObjectSummaryAccessor ( [ ] ) ,
126
131
methods : [ ] ,
127
132
lines : [ ] ,
128
133
tokens : [ ] ,
@@ -136,19 +141,21 @@ export class DocumentInfoProvider implements vscode.Disposable
136
141
137
142
return latestVersionInfo . value ;
138
143
}
139
- else
140
- {
144
+ else {
141
145
return await latestVersionInfo . wait ( ) ;
142
146
}
143
147
}
144
148
145
- private createMethodInfos ( document : vscode . TextDocument , symbols : SymbolInfo [ ] , tokens : Token [ ] ,
146
- spans : SpanInfo [ ] , endpoints : EndpointInfo [ ] ) : MethodInfo [ ]
147
- {
149
+ private createMethodInfos (
150
+ document : vscode . TextDocument ,
151
+ symbols : SymbolInfo [ ] ,
152
+ tokens : Token [ ] ,
153
+ spans : SpanInfo [ ] ,
154
+ endpoints : EndpointInfo [ ] ,
155
+ ) : MethodInfo [ ] {
148
156
let methods : MethodInfo [ ] = [ ] ;
149
157
150
- for ( let symbol of symbols )
151
- {
158
+ for ( let symbol of symbols ) {
152
159
const method = new MethodInfo (
153
160
symbol . id ,
154
161
symbol . name ,
@@ -164,22 +171,22 @@ export class DocumentInfoProvider implements vscode.Disposable
164
171
methods . push ( method ) ;
165
172
166
173
const methodTokens = tokens . filter ( t => symbol . range . contains ( t . range . start ) ) ;
167
- for ( let token of methodTokens )
168
- {
174
+ for ( let token of methodTokens ) {
169
175
const name = token . text ; // document.getText(token.range);
170
176
171
- if ( ( token . type === TokenType . method || token . type == TokenType . function )
172
- && ! method . nameRange
173
- && name === symbol . name )
174
- {
177
+ if (
178
+ ( token . type === TokenType . method || token . type === TokenType . function || token . type === TokenType . member )
179
+ && ! method . nameRange
180
+ && name === symbol . name
181
+ ) {
175
182
method . nameRange = token . range ;
176
183
}
177
184
178
- if ( token . type == TokenType . parameter )
179
- {
180
- if ( method . parameters . any ( p => p . name == name ) )
185
+ if ( token . type === TokenType . parameter ) {
186
+ if ( method . parameters . any ( p => p . name === name ) ) {
181
187
continue ;
182
-
188
+ }
189
+
183
190
method . parameters . push ( { name, range : token . range , token } ) ;
184
191
}
185
192
}
@@ -188,7 +195,7 @@ export class DocumentInfoProvider implements vscode.Disposable
188
195
return methods ;
189
196
}
190
197
191
- public createLineInfos ( document : vscode . TextDocument , codeObjectSummaries : CodeObjectSummeryAccessor , methods : MethodInfo [ ] ) : LineInfo [ ]
198
+ public createLineInfos ( document : vscode . TextDocument , codeObjectSummaries : CodeObjectSummaryAccessor , methods : MethodInfo [ ] ) : LineInfo [ ]
192
199
{
193
200
const lineInfos : LineInfo [ ] = [ ] ;
194
201
for ( let method of methods )
@@ -258,15 +265,15 @@ class DocumentInfoContainer
258
265
259
266
export interface DocumentInfo
260
267
{
261
- summaries : CodeObjectSummeryAccessor ;
268
+ summaries : CodeObjectSummaryAccessor ;
262
269
methods : MethodInfo [ ] ;
263
270
lines : LineInfo [ ] ;
264
271
tokens : Token [ ] ;
265
272
endpoints : EndpointInfo [ ] ;
266
273
spans : SpanInfo [ ] ;
267
274
uri : vscode . Uri ;
268
275
}
269
- export class CodeObjectSummeryAccessor {
276
+ export class CodeObjectSummaryAccessor {
270
277
constructor ( private _codeObejctSummeries : CodeObjectSummary [ ] ) { }
271
278
272
279
public get < T extends CodeObjectSummary > ( type : { new ( ) : T ; } , codeObjectId : string ) : T | undefined
0 commit comments