@@ -2,7 +2,7 @@ import * as chai from 'chai';
2
2
import * as sinon from 'sinon' ;
3
3
import * as ts from 'typescript' ;
4
4
import { CompletionItemKind , CompletionList , DiagnosticSeverity , TextDocumentIdentifier , TextDocumentItem , WorkspaceEdit } from 'vscode-languageserver' ;
5
- import { Hover , Location , SignatureHelp , SymbolInformation , SymbolKind } from 'vscode-languageserver-types' ;
5
+ import { Command , Diagnostic , Hover , Location , SignatureHelp , SymbolInformation , SymbolKind } from 'vscode-languageserver-types' ;
6
6
import { LanguageClient , RemoteLanguageClient } from '../lang-handler' ;
7
7
import { TextDocumentContentParams , WorkspaceFilesParams } from '../request-type' ;
8
8
import { SymbolLocationInformation } from '../request-type' ;
@@ -2311,40 +2311,40 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor
2311
2311
} ) ;
2312
2312
} ) ;
2313
2313
2314
- describe ( 'textDocumentCodeAction()' , function ( this : TestContext ) {
2314
+ describe ( 'textDocumentCodeAction()' , function ( this : TestContext & ISuiteCallbackContext ) {
2315
2315
beforeEach ( initializeTypeScriptService ( createService , rootUri , new Map ( [
2316
- [ rootUri + 'package.json' , '{ " name": " mypkg" }' ] ,
2316
+ [ rootUri + 'package.json' , JSON . stringify ( { name : ' mypkg' } ) ] ,
2317
2317
[ rootUri + 'a.ts' , [
2318
2318
'class A {' ,
2319
- ' constructor () {' ,
2320
- ' missingThis = 33;' ,
2321
- ' }' ,
2319
+ '\tconstructor () {' ,
2320
+ '\t\tmissingThis = 33;' ,
2321
+ '\t }' ,
2322
2322
'}' ,
2323
2323
'const a = new A();'
2324
2324
] . join ( '\n' ) ]
2325
2325
] ) ) as any ) ;
2326
2326
2327
2327
afterEach ( shutdownService as any ) ;
2328
2328
2329
- it ( 'suggests a missing this' , async function ( this : TestContext ) {
2329
+ it ( 'suggests a missing this' , async function ( this : TestContext & ITestCallbackContext ) {
2330
2330
await this . service . textDocumentDidOpen ( {
2331
2331
textDocument : {
2332
2332
uri : rootUri + 'a.ts' ,
2333
2333
languageId : 'typescript' ,
2334
2334
text : [
2335
2335
'class A {' ,
2336
- ' missingThis : number;' ,
2337
- ' constructor () {' ,
2338
- ' missingThis = 33;' ,
2339
- ' }' ,
2336
+ '\tmissingThis : number;' ,
2337
+ '\tconstructor () {' ,
2338
+ '\t\tmissingThis = 33;' ,
2339
+ '\t }' ,
2340
2340
'}' ,
2341
2341
'const a = new A();'
2342
2342
] . join ( '\n' ) ,
2343
2343
version : 1
2344
2344
}
2345
2345
} ) ;
2346
2346
2347
- const firstDiagnostic = {
2347
+ const firstDiagnostic : Diagnostic = {
2348
2348
range : {
2349
2349
start : { line : 3 , character : 4 } ,
2350
2350
end : { line : 3 , character : 15 }
@@ -2354,7 +2354,7 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor
2354
2354
code : 2663 ,
2355
2355
source : 'ts'
2356
2356
} ;
2357
- const actions = await this . service . textDocumentCodeAction ( {
2357
+ const actions : Command [ ] = await this . service . textDocumentCodeAction ( {
2358
2358
textDocument : {
2359
2359
uri : rootUri + 'a.ts'
2360
2360
} ,
@@ -2363,31 +2363,24 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor
2363
2363
diagnostics : [ firstDiagnostic ]
2364
2364
}
2365
2365
} ) . toArray ( ) . map ( patches => apply ( null , patches ) ) . toPromise ( ) ;
2366
- assert . lengthOf ( actions , 1 ) ;
2367
- assert . sameDeepMembers ( actions , [
2368
- {
2369
- title : 'Add \'this.\' to unresolved variable.' ,
2370
- command : 'codeFix' ,
2371
- arguments : [
2372
- {
2373
- fileName : uri2path ( rootUri + 'a.ts' ) ,
2374
- textChanges : [
2375
- {
2376
- span : { start : 50 , length : 15 } ,
2377
- newText : '\t this.missingThis'
2378
- }
2379
- ]
2380
- }
2381
- ]
2382
- }
2383
- ] ) ;
2366
+ assert . deepEqual ( actions , [ {
2367
+ title : 'Add \'this.\' to unresolved variable.' ,
2368
+ command : 'codeFix' ,
2369
+ arguments : [ {
2370
+ fileName : uri2path ( rootUri + 'a.ts' ) ,
2371
+ textChanges : [ {
2372
+ span : { start : 49 , length : 13 } ,
2373
+ newText : '\t\tthis.missingThis'
2374
+ } ]
2375
+ } ]
2376
+ } ] ) ;
2384
2377
2385
- } as any ) ;
2386
- } as any ) ;
2378
+ } ) ;
2379
+ } ) ;
2387
2380
2388
- describe ( 'workspaceExecuteCommand()' , function ( this : TestContext ) {
2381
+ describe ( 'workspaceExecuteCommand()' , function ( this : TestContext & ISuiteCallbackContext ) {
2389
2382
beforeEach ( initializeTypeScriptService ( createService , rootUri , new Map ( [
2390
- [ rootUri + 'package.json' , '{ " name": " mypkg" }' ] ,
2383
+ [ rootUri + 'package.json' , JSON . stringify ( { name : ' mypkg' } ) ] ,
2391
2384
[ rootUri + 'a.ts' , [
2392
2385
'class A {' ,
2393
2386
' constructor() {' ,
@@ -2400,47 +2393,43 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor
2400
2393
2401
2394
afterEach ( shutdownService as any ) ;
2402
2395
2403
- it ( 'should return edits for a codeFix command ', async function ( this : TestContext ) {
2404
- const result = await this . service . workspaceExecuteCommand ( {
2405
- command : 'codeFix' ,
2406
- arguments : [
2407
- {
2396
+ describe ( ' codeFix', ( ) => {
2397
+ it ( 'should apply a WorkspaceEdit for the passed FileTextChanges' , async function ( this : TestContext & ITestCallbackContext ) {
2398
+ await this . service . workspaceExecuteCommand ( {
2399
+ command : 'codeFix' ,
2400
+ arguments : [ {
2408
2401
fileName : uri2path ( rootUri + 'a.ts' ) ,
2409
- textChanges : [
2410
- {
2411
- span : { start : 50 , length : 15 } ,
2412
- newText : '\t this.missingThis'
2413
- }
2414
- ]
2415
- }
2416
- ]
2417
- } ) . toArray ( ) . map ( patches => apply ( null , patches ) ) . toPromise ( ) ;
2418
-
2419
- assert . isUndefined ( result ) ;
2402
+ textChanges : [ {
2403
+ span : { start : 50 , length : 15 } ,
2404
+ newText : '\t\tthis.missingThis'
2405
+ } ]
2406
+ } ]
2407
+ } ) . toArray ( ) . map ( patches => apply ( null , patches ) ) . toPromise ( ) ;
2420
2408
2421
- sinon . assert . called ( this . client . workspaceApplyEdit ) ;
2422
- const workspaceEdit = this . client . workspaceApplyEdit . lastCall . args [ 0 ] ;
2423
- assert . deepEqual ( workspaceEdit , {
2424
- edit : {
2425
- changes : {
2426
- [ rootUri + 'a.ts' ] : [ {
2427
- newText : '\t this.missingThis' ,
2428
- range : {
2429
- end : {
2430
- character : 9 ,
2431
- line : 5
2432
- } ,
2433
- start : {
2434
- character : 0 ,
2435
- line : 3
2409
+ sinon . assert . calledOnce ( this . client . workspaceApplyEdit ) ;
2410
+ const workspaceEdit = this . client . workspaceApplyEdit . lastCall . args [ 0 ] ;
2411
+ assert . deepEqual ( workspaceEdit , {
2412
+ edit : {
2413
+ changes : {
2414
+ [ rootUri + 'a.ts' ] : [ {
2415
+ newText : '\t\tthis.missingThis' ,
2416
+ range : {
2417
+ end : {
2418
+ character : 9 ,
2419
+ line : 5
2420
+ } ,
2421
+ start : {
2422
+ character : 0 ,
2423
+ line : 3
2424
+ }
2436
2425
}
2437
- }
2438
- } ]
2426
+ } ]
2427
+ }
2439
2428
}
2440
- }
2429
+ } ) ;
2441
2430
} ) ;
2442
- } as any ) ;
2443
- } as any ) ;
2431
+ } ) ;
2432
+ } ) ;
2444
2433
2445
2434
describe ( 'Special file names' , function ( this : TestContext ) {
2446
2435
0 commit comments