11import { LspClient } from '../../lspClient/LspClient' ;
2+ import { CompletionList } from 'vscode-languageserver-types' ;
23import { OperationTester , OperationType } from './TesterTypes' ;
3- import { retryOperationWithPerformance } from './TesterUtils' ;
4+ import { retryOperationWithPerformance , nextDocumentVersion } from './TesterUtils' ;
45
56export class CompletionTester implements OperationTester {
67 constructor ( private readonly client : LspClient ) { }
78
8- private validateCompletionItems ( result : any , requiredLabels : string [ ] , context : string ) : void {
9- if ( ! result ?. items || ! Array . isArray ( result . items ) || result . items . length === 0 ) {
9+ private validateCompletionItems ( result : CompletionList | null , requiredLabels : string [ ] , context : string ) : void {
10+ if ( ! result ?. items || result . items . length === 0 ) {
1011 throw new Error ( `${ context } returned no items` ) ;
1112 }
1213
13- const labels = new Set ( result . items . map ( ( item : any ) => item . label as string ) ) ;
14+ const labels = new Set ( result . items . map ( ( item ) => item . label ) ) ;
1415 for ( const required of requiredLabels ) {
1516 if ( ! labels . has ( required ) ) {
1617 throw new Error ( `${ context } missing ${ required } ` ) ;
@@ -23,11 +24,12 @@ export class CompletionTester implements OperationTester {
2324 const basicTemplate = `AWSTemplateFormatVersion: '2010-09-09'
2425` ;
2526
26- await this . client . updateDocument ( uri , 4 , basicTemplate ) ;
27+ await this . client . updateDocument ( uri , nextDocumentVersion ( ) , basicTemplate ) ;
2728
2829 await retryOperationWithPerformance (
2930 ( ) => this . client . completion ( uri , 1 , 0 ) ,
30- ( result : any ) => this . validateCompletionItems ( result , [ 'Resources' , 'Parameters' ] , 'Top-level completion' ) ,
31+ ( result : CompletionList | null ) =>
32+ this . validateCompletionItems ( result , [ 'Resources' , 'Parameters' ] , 'Top-level completion' ) ,
3133 OperationType . COMPLETION ,
3234 ) ;
3335
@@ -39,7 +41,7 @@ Resources:
3941 Properties:
4042 ` ;
4143
42- await this . client . updateDocument ( uri , 5 , [
44+ await this . client . updateDocument ( uri , nextDocumentVersion ( ) , [
4345 {
4446 range : { start : { line : 1 , character : 0 } , end : { line : 1 , character : 0 } } ,
4547 text : resourceSection ,
@@ -48,7 +50,8 @@ Resources:
4850
4951 await retryOperationWithPerformance (
5052 ( ) => this . client . completion ( uri , 6 , 6 ) ,
51- ( result : any ) => this . validateCompletionItems ( result , [ 'BucketName' , 'Tags' ] , 'S3 bucket completion' ) ,
53+ ( result : CompletionList | null ) =>
54+ this . validateCompletionItems ( result , [ 'BucketName' , 'Tags' ] , 'S3 bucket completion' ) ,
5255 OperationType . COMPLETION ,
5356 ) ;
5457 }
0 commit comments