@@ -83,15 +83,16 @@ export default class Tokenizer {
83
83
return tokensArray . findIndex ( ( token ) => token . startIndex === targetToken . startIndex ) ;
84
84
}
85
85
86
- private getTokenLanguageType ( line : string , token : IToken ) {
87
- const rawContent = this . getRawTokenContent ( line , token ) ;
86
+ private getTokenLanguageType ( line : string , tokens : IToken [ ] , index : number ) {
87
+ const rawContent = this . getRawTokenContent ( line , tokens [ index ] ) ;
88
88
89
- return LanguageTypes [ rawContent as keyof typeof LanguageTypes ] || rawContent ;
89
+ const type = LanguageTypes [ rawContent as keyof typeof LanguageTypes ] || rawContent ;
90
+ return ( type === LanguageTypes . struct ? this . getRawTokenContent ( line , tokens [ index + 2 ] ) : type ) as LanguageTypes ;
90
91
}
91
92
92
93
private getConstantValue ( line : string , tokensArray : IToken [ ] ) {
93
94
const startIndex = tokensArray . findIndex ( ( token ) => token . scopes . includes ( LanguageScopes . assignationStatement ) ) ;
94
- const endIndex = tokensArray . length - 1 ;
95
+ const endIndex = tokensArray . findIndex ( ( token ) => token . scopes . includes ( LanguageScopes . terminatorStatement ) ) ;
95
96
96
97
return tokensArray
97
98
. filter ( ( _ , index ) => index > startIndex && index < endIndex )
@@ -145,7 +146,7 @@ export default class Tokenizer {
145
146
position : { line : lineIndex , character : token . startIndex } ,
146
147
identifier : this . getRawTokenContent ( line , token ) ,
147
148
tokenType : CompletionItemKind . TypeParameter ,
148
- valueType : this . getTokenLanguageType ( line , tokensArray [ tokenIndex - 2 ] ) ,
149
+ valueType : this . getTokenLanguageType ( line , tokensArray , tokenIndex - 2 ) ,
149
150
defaultValue : defaultValue . trim ( ) || undefined ,
150
151
} ;
151
152
} ) ;
@@ -155,7 +156,13 @@ export default class Tokenizer {
155
156
const comments : string [ ] = [ ] ;
156
157
157
158
let errorSafeIndex = Math . max ( index , 0 ) ;
158
- while ( tokensLines [ errorSafeIndex ] ?. at ( 0 ) ?. scopes . includes ( LanguageScopes . commentStatement ) ) {
159
+ while (
160
+ tokensLines [ errorSafeIndex ]
161
+ ?. at ( 0 )
162
+ ?. scopes . find (
163
+ ( scope ) => scope === LanguageScopes . commentStatement || scope === LanguageScopes . documentationCommentStatement
164
+ )
165
+ ) {
159
166
comments . unshift ( lines [ errorSafeIndex ] ) ;
160
167
errorSafeIndex -- ;
161
168
}
@@ -218,12 +225,12 @@ export default class Tokenizer {
218
225
if ( token . scopes . includes ( LanguageScopes . blockTermination ) ) {
219
226
scope . structComplexTokens . push ( currentStruct ) ;
220
227
currentStruct = null ;
221
- } else if ( lastIndex > 2 && ! token . scopes . includes ( LanguageScopes . blockDeclaraction ) ) {
228
+ } else if ( lastIndex > 0 && tokensArray [ 1 ] . scopes . includes ( LanguageScopes . type ) ) {
222
229
currentStruct . properties . push ( {
223
230
position : { line : lineIndex , character : tokensArray [ 3 ] . startIndex } ,
224
231
identifier : this . getRawTokenContent ( line , tokensArray [ 3 ] ) ,
225
232
tokenType : CompletionItemKind . Property ,
226
- valueType : this . getTokenLanguageType ( line , tokensArray [ 1 ] ) ,
233
+ valueType : this . getTokenLanguageType ( line , tokensArray , 1 ) ,
227
234
} ) ;
228
235
}
229
236
@@ -248,7 +255,7 @@ export default class Tokenizer {
248
255
position : { line : lineIndex , character : token . startIndex } ,
249
256
identifier : this . getRawTokenContent ( line , token ) ,
250
257
tokenType : CompletionItemKind . Constant ,
251
- valueType : this . getTokenLanguageType ( line , tokensArray [ tokenIndex - 2 ] ) ,
258
+ valueType : this . getTokenLanguageType ( line , tokensArray , tokenIndex - 2 ) ,
252
259
value : this . getConstantValue ( line , tokensArray ) ,
253
260
} ) ;
254
261
break ;
@@ -267,8 +274,8 @@ export default class Tokenizer {
267
274
tokenType : CompletionItemKind . Function ,
268
275
returnType :
269
276
tokenIndex === 0
270
- ? this . getTokenLanguageType ( lines [ lineIndex - 1 ] , tokensArrays [ lineIndex - 1 ] ! [ 0 ] )
271
- : this . getTokenLanguageType ( line , tokensArray [ tokenIndex - 2 ] ) ,
277
+ ? this . getTokenLanguageType ( lines [ lineIndex - 1 ] , tokensArrays [ lineIndex - 1 ] ! , 0 )
278
+ : this . getTokenLanguageType ( line , tokensArray , tokenIndex - 2 ) ,
272
279
params : this . getFunctionParams ( lineIndex , lines , tokensArrays ) ,
273
280
comments : this . getFunctionComments ( lines , tokensArrays , tokenIndex === 0 ? lineIndex - 2 : lineIndex - 1 ) ,
274
281
} ) ;
@@ -279,7 +286,8 @@ export default class Tokenizer {
279
286
// STRUCT
280
287
if (
281
288
token . scopes . includes ( LanguageScopes . structIdentifier ) &&
282
- ( lastToken . scopes . includes ( LanguageScopes . structIdentifier ) ||
289
+ ( ( lastToken . scopes . includes ( LanguageScopes . structIdentifier ) &&
290
+ tokensArrays [ lineIndex + 1 ] ?. at ( 0 ) ?. scopes . includes ( LanguageScopes . blockDeclaraction ) ) ||
283
291
lastToken . scopes . includes ( LanguageScopes . blockDeclaraction ) )
284
292
) {
285
293
currentStruct = {
@@ -355,7 +363,7 @@ export default class Tokenizer {
355
363
position : { line : lineIndex , character : token . startIndex } ,
356
364
identifier : this . getRawTokenContent ( line , token ) ,
357
365
tokenType : CompletionItemKind . Variable ,
358
- valueType : this . getTokenLanguageType ( line , tokensArray [ tokenIndex - 2 ] ) ,
366
+ valueType : this . getTokenLanguageType ( line , tokensArray , tokenIndex - 2 ) ,
359
367
} ) ;
360
368
361
369
let nextVariableToken ;
@@ -372,7 +380,7 @@ export default class Tokenizer {
372
380
position : { line : lineIndex , character : nextVariableToken . startIndex } ,
373
381
identifier : this . getRawTokenContent ( line , nextVariableToken ) ,
374
382
tokenType : CompletionItemKind . Variable ,
375
- valueType : this . getTokenLanguageType ( line , tokensArray [ tokenIndex - 2 ] ) ,
383
+ valueType : this . getTokenLanguageType ( line , tokensArray , tokenIndex - 2 ) ,
376
384
} ) ;
377
385
}
378
386
}
@@ -383,7 +391,7 @@ export default class Tokenizer {
383
391
position : { line : lineIndex , character : token . startIndex } ,
384
392
identifier : this . getRawTokenContent ( line , token ) ,
385
393
tokenType : CompletionItemKind . TypeParameter ,
386
- valueType : this . getTokenLanguageType ( line , tokensArray [ tokenIndex - 2 ] ) ,
394
+ valueType : this . getTokenLanguageType ( line , tokensArray , tokenIndex - 2 ) ,
387
395
} ) ;
388
396
}
389
397
@@ -400,8 +408,8 @@ export default class Tokenizer {
400
408
tokenType : CompletionItemKind . Function ,
401
409
returnType :
402
410
tokenIndex === 0
403
- ? this . getTokenLanguageType ( lines [ lineIndex - 1 ] , tokensArrays [ lineIndex - 1 ] ! [ 0 ] )
404
- : this . getTokenLanguageType ( line , tokensArray [ tokenIndex - 2 ] ) ,
411
+ ? this . getTokenLanguageType ( lines [ lineIndex - 1 ] , tokensArrays [ lineIndex - 1 ] ! , 0 )
412
+ : this . getTokenLanguageType ( line , tokensArray , tokenIndex - 2 ) ,
405
413
params : this . getFunctionParams ( lineIndex , lines , tokensArrays ) ,
406
414
comments : this . getFunctionComments ( lines , tokensArrays , tokenIndex === 0 ? lineIndex - 2 : lineIndex - 1 ) ,
407
415
} ) ;
0 commit comments