brighterscript 0.70.4 → 0.71.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/DiagnosticMessages.d.ts +15 -2
- package/dist/DiagnosticMessages.js +14 -1
- package/dist/DiagnosticMessages.js.map +1 -1
- package/dist/LanguageServer.js +6 -1
- package/dist/LanguageServer.js.map +1 -1
- package/dist/Program.js +1 -1
- package/dist/Program.js.map +1 -1
- package/dist/Scope.js +17 -6
- package/dist/Scope.js.map +1 -1
- package/dist/astUtils/reflection.d.ts +2 -1
- package/dist/astUtils/reflection.js +5 -1
- package/dist/astUtils/reflection.js.map +1 -1
- package/dist/astUtils/visitors.d.ts +2 -1
- package/dist/astUtils/visitors.js.map +1 -1
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.d.ts +72 -6
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.js +392 -110
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.js.map +1 -1
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.spec.js +575 -0
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.spec.js.map +1 -1
- package/dist/bscPlugin/validation/ScopeValidator.d.ts +6 -0
- package/dist/bscPlugin/validation/ScopeValidator.js +70 -0
- package/dist/bscPlugin/validation/ScopeValidator.js.map +1 -1
- package/dist/parser/AstNode.spec.js +21 -0
- package/dist/parser/AstNode.spec.js.map +1 -1
- package/dist/parser/Expression.d.ts +25 -2
- package/dist/parser/Expression.js +41 -5
- package/dist/parser/Expression.js.map +1 -1
- package/dist/parser/Parser.js +25 -7
- package/dist/parser/Parser.js.map +1 -1
- package/dist/parser/tests/expression/AssociativeArrayLiterals.spec.js +70 -0
- package/dist/parser/tests/expression/AssociativeArrayLiterals.spec.js.map +1 -1
- package/dist/parser/tests/statement/Enum.spec.js +318 -0
- package/dist/parser/tests/statement/Enum.spec.js.map +1 -1
- package/package.json +2 -2
|
@@ -6,6 +6,7 @@ const Program_1 = require("../../Program");
|
|
|
6
6
|
const testHelpers_spec_1 = require("../../testHelpers.spec");
|
|
7
7
|
const util_1 = require("../../util");
|
|
8
8
|
const testHelpers_spec_2 = require("../../testHelpers.spec");
|
|
9
|
+
const CodeActionsProcessor_1 = require("./CodeActionsProcessor");
|
|
9
10
|
describe('CodeActionsProcessor', () => {
|
|
10
11
|
let program;
|
|
11
12
|
beforeEach(() => {
|
|
@@ -222,6 +223,42 @@ describe('CodeActionsProcessor', () => {
|
|
|
222
223
|
`import "pkg:/source/second.bs"`
|
|
223
224
|
]);
|
|
224
225
|
});
|
|
226
|
+
it('clears suggestedImports after process() so the same instance could be reused in the future', () => {
|
|
227
|
+
program.setFile('source/lib.bs', `
|
|
228
|
+
function doSomething()
|
|
229
|
+
end function
|
|
230
|
+
`);
|
|
231
|
+
program.setFile('components/comp1.xml', (0, testHelpers_spec_1.trim) `
|
|
232
|
+
<?xml version="1.0" encoding="utf-8" ?>
|
|
233
|
+
<component name="comp1" extends="Scene">
|
|
234
|
+
<script uri="comp1.bs" />
|
|
235
|
+
</component>
|
|
236
|
+
`);
|
|
237
|
+
const file = program.setFile('components/comp1.bs', `
|
|
238
|
+
sub init()
|
|
239
|
+
doSomething()
|
|
240
|
+
end sub
|
|
241
|
+
`);
|
|
242
|
+
program.validate();
|
|
243
|
+
const range = util_1.util.createRange(2, 24, 2, 24);
|
|
244
|
+
const event = {
|
|
245
|
+
program: program,
|
|
246
|
+
file: file,
|
|
247
|
+
range: range,
|
|
248
|
+
scopes: program.getScopesForFile(file),
|
|
249
|
+
diagnostics: program.getDiagnostics().filter(d => d.file === file && util_1.util.rangesIntersectOrTouch(d.range, range)),
|
|
250
|
+
codeActions: []
|
|
251
|
+
};
|
|
252
|
+
const processor = new CodeActionsProcessor_1.CodeActionsProcessor(event);
|
|
253
|
+
processor.process();
|
|
254
|
+
const firstCallTitles = event.codeActions.map(x => x.title).sort();
|
|
255
|
+
// Reset codeActions and call process() again on the same instance.
|
|
256
|
+
// If suggestedImports were NOT cleared, the second call would return no import suggestions.
|
|
257
|
+
event.codeActions = [];
|
|
258
|
+
processor.process();
|
|
259
|
+
const secondCallTitles = event.codeActions.map(x => x.title).sort();
|
|
260
|
+
(0, chai_config_spec_1.expect)(secondCallTitles).to.eql(firstCallTitles);
|
|
261
|
+
});
|
|
225
262
|
it('suggests files for second part of missing namespace', () => {
|
|
226
263
|
program.setFile('source/first.bs', `
|
|
227
264
|
namespace alpha
|
|
@@ -246,6 +283,119 @@ describe('CodeActionsProcessor', () => {
|
|
|
246
283
|
testGetCodeActions(file, util_1.util.createRange(3, 34, 3, 34), [`import "pkg:/source/second.bs"`]);
|
|
247
284
|
});
|
|
248
285
|
});
|
|
286
|
+
describe('Fix all: Auto fixable missing imports', () => {
|
|
287
|
+
it('offers fix-all when multiple unambiguous imports are missing', () => {
|
|
288
|
+
program.setFile('source/lib1.bs', `
|
|
289
|
+
function doSomething()
|
|
290
|
+
end function
|
|
291
|
+
`);
|
|
292
|
+
program.setFile('source/lib2.bs', `
|
|
293
|
+
function doSomethingElse()
|
|
294
|
+
end function
|
|
295
|
+
`);
|
|
296
|
+
program.setFile('components/MainScene.xml', (0, testHelpers_spec_1.trim) `<component name="MainScene"></component>`);
|
|
297
|
+
const file = program.setFile('components/MainScene.bs', `
|
|
298
|
+
sub init()
|
|
299
|
+
doSomething()
|
|
300
|
+
doSomethingElse()
|
|
301
|
+
end sub
|
|
302
|
+
`);
|
|
303
|
+
// doSome|thing()
|
|
304
|
+
testGetCodeActions(file, util_1.util.createRange(2, 26, 2, 26), [
|
|
305
|
+
`Fix all: Auto fixable missing imports`,
|
|
306
|
+
`import "pkg:/source/lib1.bs"`
|
|
307
|
+
]);
|
|
308
|
+
});
|
|
309
|
+
it('does not offer fix-all when only one import is missing', () => {
|
|
310
|
+
program.setFile('source/lib1.bs', `
|
|
311
|
+
function doSomething()
|
|
312
|
+
end function
|
|
313
|
+
`);
|
|
314
|
+
program.setFile('components/MainScene.xml', (0, testHelpers_spec_1.trim) `<component name="MainScene"></component>`);
|
|
315
|
+
const file = program.setFile('components/MainScene.bs', `
|
|
316
|
+
sub init()
|
|
317
|
+
doSomething()
|
|
318
|
+
end sub
|
|
319
|
+
`);
|
|
320
|
+
// doSome|thing()
|
|
321
|
+
testGetCodeActions(file, util_1.util.createRange(2, 26, 2, 26), [
|
|
322
|
+
`import "pkg:/source/lib1.bs"`
|
|
323
|
+
]);
|
|
324
|
+
});
|
|
325
|
+
it('excludes ambiguous names from fix-all', () => {
|
|
326
|
+
program.setFile('source/lib1.bs', `
|
|
327
|
+
function doSomething()
|
|
328
|
+
end function
|
|
329
|
+
`);
|
|
330
|
+
program.setFile('source/lib2.bs', `
|
|
331
|
+
function doSomething()
|
|
332
|
+
end function
|
|
333
|
+
`);
|
|
334
|
+
program.setFile('source/lib3.bs', `
|
|
335
|
+
function doSomethingUnambiguous()
|
|
336
|
+
end function
|
|
337
|
+
`);
|
|
338
|
+
program.setFile('components/MainScene.xml', (0, testHelpers_spec_1.trim) `<component name="MainScene"></component>`);
|
|
339
|
+
const file = program.setFile('components/MainScene.bs', `
|
|
340
|
+
sub init()
|
|
341
|
+
doSomething()
|
|
342
|
+
doSomethingUnambiguous()
|
|
343
|
+
end sub
|
|
344
|
+
`);
|
|
345
|
+
program.validate();
|
|
346
|
+
const actions = program.getCodeActions(file.srcPath, util_1.util.createRange(2, 26, 2, 26));
|
|
347
|
+
// fix-all only has the unambiguous import, not doSomething (which has 2 options)
|
|
348
|
+
const fixAll = actions.find(a => a.title === 'Fix all: Auto fixable missing imports');
|
|
349
|
+
(0, chai_config_spec_1.expect)(fixAll).to.be.undefined;
|
|
350
|
+
});
|
|
351
|
+
it('includes class imports in fix-all', () => {
|
|
352
|
+
program.setFile('source/lib1.bs', `
|
|
353
|
+
function doSomething()
|
|
354
|
+
end function
|
|
355
|
+
`);
|
|
356
|
+
program.setFile('source/MyClass.bs', `
|
|
357
|
+
class MyClass
|
|
358
|
+
end class
|
|
359
|
+
`);
|
|
360
|
+
program.setFile('components/MainScene.xml', (0, testHelpers_spec_1.trim) `<component name="MainScene"></component>`);
|
|
361
|
+
const file = program.setFile('components/MainScene.bs', `
|
|
362
|
+
sub init()
|
|
363
|
+
doSomething()
|
|
364
|
+
obj = new MyClass()
|
|
365
|
+
end sub
|
|
366
|
+
`);
|
|
367
|
+
// doSome|thing()
|
|
368
|
+
testGetCodeActions(file, util_1.util.createRange(2, 26, 2, 26), [
|
|
369
|
+
`Fix all: Auto fixable missing imports`,
|
|
370
|
+
`import "pkg:/source/lib1.bs"`
|
|
371
|
+
]);
|
|
372
|
+
});
|
|
373
|
+
it('deduplicates when multiple missing names resolve to the same file', () => {
|
|
374
|
+
program.setFile('source/lib1.bs', `
|
|
375
|
+
function doSomething()
|
|
376
|
+
end function
|
|
377
|
+
function doSomethingElse()
|
|
378
|
+
end function
|
|
379
|
+
`);
|
|
380
|
+
program.setFile('source/lib2.bs', `
|
|
381
|
+
function doThird()
|
|
382
|
+
end function
|
|
383
|
+
`);
|
|
384
|
+
program.setFile('components/MainScene.xml', (0, testHelpers_spec_1.trim) `<component name="MainScene"></component>`);
|
|
385
|
+
const file = program.setFile('components/MainScene.bs', `
|
|
386
|
+
sub init()
|
|
387
|
+
doSomething()
|
|
388
|
+
doSomethingElse()
|
|
389
|
+
doThird()
|
|
390
|
+
end sub
|
|
391
|
+
`);
|
|
392
|
+
program.validate();
|
|
393
|
+
const actions = program.getCodeActions(file.srcPath, util_1.util.createRange(2, 26, 2, 26));
|
|
394
|
+
const fixAll = actions.find(a => a.title === 'Fix all: Auto fixable missing imports');
|
|
395
|
+
// lib1.bs and lib2.bs — only 2 changes despite 3 missing names
|
|
396
|
+
(0, chai_config_spec_1.expect)(Object.values(fixAll.edit.changes)[0]).to.have.lengthOf(2);
|
|
397
|
+
});
|
|
398
|
+
});
|
|
249
399
|
it('suggests imports at very start and very end of diagnostic', () => {
|
|
250
400
|
program.setFile('source/first.bs', `
|
|
251
401
|
namespace alpha
|
|
@@ -275,6 +425,26 @@ describe('CodeActionsProcessor', () => {
|
|
|
275
425
|
// return tr|ue
|
|
276
426
|
testGetCodeActions(file, util_1.util.createRange(3, 29, 3, 29), [`Convert sub to function`, `Remove return value`]);
|
|
277
427
|
});
|
|
428
|
+
it('suggests converting sub to function with inline body', () => {
|
|
429
|
+
const file = program.setFile('source/main.brs', `
|
|
430
|
+
sub test() : print "onItemContentChange"
|
|
431
|
+
return true
|
|
432
|
+
end sub
|
|
433
|
+
`);
|
|
434
|
+
// return tr|ue
|
|
435
|
+
testGetCodeActions(file, util_1.util.createRange(2, 28, 2, 28), [`Convert sub to function`, `Remove return value`]);
|
|
436
|
+
// verify only the `sub` and `end sub` keywords are replaced, not the `: print ...` inline body
|
|
437
|
+
program.validate();
|
|
438
|
+
const actions = program.getCodeActions(file.srcPath, util_1.util.createRange(2, 28, 2, 28));
|
|
439
|
+
const convertAction = actions.find(a => a.title === 'Convert sub to function');
|
|
440
|
+
const changes = Object.values(convertAction.edit.changes)[0];
|
|
441
|
+
// change[0] replaces `sub` keyword only
|
|
442
|
+
(0, chai_config_spec_1.expect)(changes[0].range).to.eql(util_1.util.createRange(1, 16, 1, 19));
|
|
443
|
+
(0, chai_config_spec_1.expect)(changes[0].newText).to.eql('function');
|
|
444
|
+
// change[1] replaces `end sub` keyword only
|
|
445
|
+
(0, chai_config_spec_1.expect)(changes[1].range).to.eql(util_1.util.createRange(3, 16, 3, 23));
|
|
446
|
+
(0, chai_config_spec_1.expect)(changes[1].newText).to.eql('end function');
|
|
447
|
+
});
|
|
278
448
|
it('suggests deleting the return type from void function', () => {
|
|
279
449
|
const file = program.setFile('source/main.brs', `
|
|
280
450
|
function test() as void
|
|
@@ -285,6 +455,62 @@ describe('CodeActionsProcessor', () => {
|
|
|
285
455
|
// return tr|ue
|
|
286
456
|
testGetCodeActions(file, util_1.util.createRange(3, 29, 3, 29), [`Remove return type from function declaration`, `Remove return value`]);
|
|
287
457
|
});
|
|
458
|
+
it('suggests deleting only the return type from void function with inline body', () => {
|
|
459
|
+
const file = program.setFile('source/main.brs', `
|
|
460
|
+
function test() as void : print "onItemContentChange"
|
|
461
|
+
return "test"
|
|
462
|
+
end function
|
|
463
|
+
`);
|
|
464
|
+
// return |"test"
|
|
465
|
+
testGetCodeActions(file, util_1.util.createRange(2, 28, 2, 28), [`Remove return type from function declaration`, `Remove return value`]);
|
|
466
|
+
// verify only ` as void` is deleted, not the `: print ...` inline body
|
|
467
|
+
program.validate();
|
|
468
|
+
const actions = program.getCodeActions(file.srcPath, util_1.util.createRange(2, 28, 2, 28));
|
|
469
|
+
const removeTypeAction = actions.find(a => a.title === 'Remove return type from function declaration');
|
|
470
|
+
const changes = Object.values(removeTypeAction.edit.changes)[0];
|
|
471
|
+
// range should span ` as void` only, starting after `)` and ending at the close of `void`
|
|
472
|
+
(0, chai_config_spec_1.expect)(changes[0].range).to.eql(util_1.util.createRange(1, 31, 1, 39));
|
|
473
|
+
});
|
|
474
|
+
it('offers fix-all when multiple void-return violations exist in the file', () => {
|
|
475
|
+
const file = program.setFile('source/main.brs', `
|
|
476
|
+
sub test1()
|
|
477
|
+
return true
|
|
478
|
+
end sub
|
|
479
|
+
sub test2()
|
|
480
|
+
return false
|
|
481
|
+
end sub
|
|
482
|
+
`);
|
|
483
|
+
// return tr|ue (first violation)
|
|
484
|
+
testGetCodeActions(file, util_1.util.createRange(2, 27, 2, 27), [
|
|
485
|
+
`Convert sub to function`,
|
|
486
|
+
`Fix all: Remove void return values`,
|
|
487
|
+
`Remove return value`
|
|
488
|
+
]);
|
|
489
|
+
});
|
|
490
|
+
it('does not offer fix-all when only one void-return violation exists', () => {
|
|
491
|
+
const file = program.setFile('source/main.brs', `
|
|
492
|
+
sub test1()
|
|
493
|
+
return true
|
|
494
|
+
end sub
|
|
495
|
+
sub test2()
|
|
496
|
+
end sub
|
|
497
|
+
`);
|
|
498
|
+
// return tr|ue
|
|
499
|
+
testGetCodeActions(file, util_1.util.createRange(2, 27, 2, 27), [`Convert sub to function`, `Remove return value`]);
|
|
500
|
+
});
|
|
501
|
+
it('does not duplicate fix-all when multiple violations are at the cursor range', () => {
|
|
502
|
+
const file = program.setFile('source/main.brs', `
|
|
503
|
+
sub test1()
|
|
504
|
+
return true
|
|
505
|
+
end sub
|
|
506
|
+
sub test2()
|
|
507
|
+
return false
|
|
508
|
+
end sub
|
|
509
|
+
`);
|
|
510
|
+
program.validate();
|
|
511
|
+
const actions = program.getCodeActions(file.srcPath, util_1.util.createRange(2, 20, 4, 20));
|
|
512
|
+
(0, chai_config_spec_1.expect)(actions.filter(a => a.title === 'Fix all: Remove void return values')).to.have.lengthOf(1);
|
|
513
|
+
});
|
|
288
514
|
});
|
|
289
515
|
describe('typed function/sub empty return', () => {
|
|
290
516
|
it('suggests deleting the return value and converting the sub to a function', () => {
|
|
@@ -297,6 +523,23 @@ describe('CodeActionsProcessor', () => {
|
|
|
297
523
|
// ret|urn
|
|
298
524
|
testGetCodeActions(file, util_1.util.createRange(3, 23, 3, 23), [`Add void return type to function declaration`, `Convert function to sub`]);
|
|
299
525
|
});
|
|
526
|
+
it('suggests adding void return type to function with inline body', () => {
|
|
527
|
+
const file = program.setFile('source/main.brs', `
|
|
528
|
+
function test() : print "onItemContentChange"
|
|
529
|
+
return
|
|
530
|
+
end function
|
|
531
|
+
`);
|
|
532
|
+
// ret|urn
|
|
533
|
+
testGetCodeActions(file, util_1.util.createRange(2, 23, 2, 23), [`Add void return type to function declaration`, `Convert function to sub`]);
|
|
534
|
+
// verify ` as void` is inserted after `)`, not after the inline body
|
|
535
|
+
program.validate();
|
|
536
|
+
const actions = program.getCodeActions(file.srcPath, util_1.util.createRange(2, 23, 2, 23));
|
|
537
|
+
const addVoidAction = actions.find(a => a.title === 'Add void return type to function declaration');
|
|
538
|
+
const changes = Object.values(addVoidAction.edit.changes)[0];
|
|
539
|
+
// insert position should be immediately after `)`, before ` : print ...`
|
|
540
|
+
(0, chai_config_spec_1.expect)(changes[0].range).to.eql(util_1.util.createRange(1, 31, 1, 31));
|
|
541
|
+
(0, chai_config_spec_1.expect)(changes[0].newText).to.eql(' as void');
|
|
542
|
+
});
|
|
300
543
|
it('suggests deleting the return type from void function', () => {
|
|
301
544
|
const file = program.setFile('source/main.brs', `
|
|
302
545
|
sub test() as integer
|
|
@@ -307,6 +550,338 @@ describe('CodeActionsProcessor', () => {
|
|
|
307
550
|
// ret|urn
|
|
308
551
|
testGetCodeActions(file, util_1.util.createRange(3, 23, 3, 23), [`Remove return type from sub declaration`]);
|
|
309
552
|
});
|
|
553
|
+
it('suggests deleting only the return type from sub with inline body', () => {
|
|
554
|
+
const file = program.setFile('source/main.brs', `
|
|
555
|
+
sub test() as integer : print "onItemContentChange"
|
|
556
|
+
return
|
|
557
|
+
end sub
|
|
558
|
+
`);
|
|
559
|
+
// ret|urn
|
|
560
|
+
testGetCodeActions(file, util_1.util.createRange(2, 23, 2, 23), [`Remove return type from sub declaration`]);
|
|
561
|
+
// verify only ` as integer` is deleted, not the `: print ...` inline body
|
|
562
|
+
program.validate();
|
|
563
|
+
const actions = program.getCodeActions(file.srcPath, util_1.util.createRange(2, 23, 2, 23));
|
|
564
|
+
const removeTypeAction = actions.find(a => a.title === 'Remove return type from sub declaration');
|
|
565
|
+
const changes = Object.values(removeTypeAction.edit.changes)[0];
|
|
566
|
+
// range should span ` as integer` only, starting after `)` and ending at the close of `integer`
|
|
567
|
+
(0, chai_config_spec_1.expect)(changes[0].range).to.eql(util_1.util.createRange(1, 26, 1, 37));
|
|
568
|
+
});
|
|
569
|
+
it('offers fix-all for multiple subs with return types', () => {
|
|
570
|
+
const file = program.setFile('source/main.brs', `
|
|
571
|
+
sub test1() as integer
|
|
572
|
+
return
|
|
573
|
+
end sub
|
|
574
|
+
sub test2() as string
|
|
575
|
+
return
|
|
576
|
+
end sub
|
|
577
|
+
`);
|
|
578
|
+
// ret|urn (first violation)
|
|
579
|
+
testGetCodeActions(file, util_1.util.createRange(2, 24, 2, 24), [
|
|
580
|
+
`Fix all: Remove return type from sub declarations`,
|
|
581
|
+
`Remove return type from sub declaration`
|
|
582
|
+
]);
|
|
583
|
+
});
|
|
584
|
+
it('offers fix-all for multiple functions with missing return types', () => {
|
|
585
|
+
const file = program.setFile('source/main.brs', `
|
|
586
|
+
function test1()
|
|
587
|
+
return
|
|
588
|
+
end function
|
|
589
|
+
function test2()
|
|
590
|
+
return
|
|
591
|
+
end function
|
|
592
|
+
`);
|
|
593
|
+
// ret|urn (first violation)
|
|
594
|
+
testGetCodeActions(file, util_1.util.createRange(2, 24, 2, 24), [
|
|
595
|
+
`Add void return type to function declaration`,
|
|
596
|
+
`Convert function to sub`,
|
|
597
|
+
`Fix all: Add void return type to function declarations`
|
|
598
|
+
]);
|
|
599
|
+
});
|
|
600
|
+
it('does not offer fix-all when only one non-void-return violation exists', () => {
|
|
601
|
+
const file = program.setFile('source/main.brs', `
|
|
602
|
+
sub test1() as integer
|
|
603
|
+
return
|
|
604
|
+
end sub
|
|
605
|
+
`);
|
|
606
|
+
// ret|urn
|
|
607
|
+
testGetCodeActions(file, util_1.util.createRange(2, 24, 2, 24), [`Remove return type from sub declaration`]);
|
|
608
|
+
});
|
|
609
|
+
it('deduplicates fix-all changes when one function has multiple bare returns', () => {
|
|
610
|
+
const file = program.setFile('source/main.brs', `
|
|
611
|
+
sub test1() as integer
|
|
612
|
+
return
|
|
613
|
+
return
|
|
614
|
+
end sub
|
|
615
|
+
sub test2() as string
|
|
616
|
+
return
|
|
617
|
+
end sub
|
|
618
|
+
`);
|
|
619
|
+
program.validate();
|
|
620
|
+
const actions = program.getCodeActions(file.srcPath, util_1.util.createRange(2, 24, 2, 24));
|
|
621
|
+
const fixAll = actions.find(a => a.title === 'Fix all: Remove return type from sub declarations');
|
|
622
|
+
// Two unique functions → two changes (not three)
|
|
623
|
+
(0, chai_config_spec_1.expect)(Object.values(fixAll.edit.changes)[0]).to.have.lengthOf(2);
|
|
624
|
+
});
|
|
625
|
+
});
|
|
626
|
+
describe('referencedFileDoesNotExist', () => {
|
|
627
|
+
it('offers to remove the script import line', () => {
|
|
628
|
+
const file = program.setFile('components/comp1.xml', (0, testHelpers_spec_1.trim) `
|
|
629
|
+
<?xml version="1.0" encoding="utf-8" ?>
|
|
630
|
+
<component name="comp1" extends="Scene">
|
|
631
|
+
<script type="text/brightscript" uri="pkg:/source/missing.brs" />
|
|
632
|
+
</component>
|
|
633
|
+
`);
|
|
634
|
+
// uri="pkg:/source/missing.brs" is on line 2
|
|
635
|
+
testGetCodeActions(file, util_1.util.createRange(2, 50, 2, 50), ['Remove script import']);
|
|
636
|
+
});
|
|
637
|
+
it('deletes the entire script tag line', () => {
|
|
638
|
+
const file = program.setFile('components/comp1.xml', (0, testHelpers_spec_1.trim) `
|
|
639
|
+
<?xml version="1.0" encoding="utf-8" ?>
|
|
640
|
+
<component name="comp1" extends="Scene">
|
|
641
|
+
<script type="text/brightscript" uri="pkg:/source/missing.brs" />
|
|
642
|
+
</component>
|
|
643
|
+
`);
|
|
644
|
+
program.validate();
|
|
645
|
+
(0, testHelpers_spec_1.expectCodeActions)(() => {
|
|
646
|
+
program.getCodeActions(file.srcPath, util_1.util.createRange(2, 50, 2, 50));
|
|
647
|
+
}, [{
|
|
648
|
+
title: 'Remove script import',
|
|
649
|
+
kind: 'quickfix',
|
|
650
|
+
changes: [{
|
|
651
|
+
type: 'delete',
|
|
652
|
+
filePath: (0, util_1.standardizePath) `${testHelpers_spec_2.rootDir}/components/comp1.xml`,
|
|
653
|
+
range: util_1.util.createRange(2, 0, 3, 0)
|
|
654
|
+
}]
|
|
655
|
+
}]);
|
|
656
|
+
});
|
|
657
|
+
it('offers fix-all when multiple missing imports exist', () => {
|
|
658
|
+
const file = program.setFile('components/comp1.xml', (0, testHelpers_spec_1.trim) `
|
|
659
|
+
<?xml version="1.0" encoding="utf-8" ?>
|
|
660
|
+
<component name="comp1" extends="Scene">
|
|
661
|
+
<script type="text/brightscript" uri="pkg:/source/missing1.brs" />
|
|
662
|
+
<script type="text/brightscript" uri="pkg:/source/missing2.brs" />
|
|
663
|
+
</component>
|
|
664
|
+
`);
|
|
665
|
+
testGetCodeActions(file, util_1.util.createRange(2, 50, 2, 50), [
|
|
666
|
+
'Fix all: Remove script imports',
|
|
667
|
+
'Remove script import'
|
|
668
|
+
]);
|
|
669
|
+
});
|
|
670
|
+
});
|
|
671
|
+
describe('unnecessaryScriptImportInChildFromParent', () => {
|
|
672
|
+
it('offers to remove the redundant script import', () => {
|
|
673
|
+
program.setFile('components/parent.xml', (0, testHelpers_spec_1.trim) `
|
|
674
|
+
<?xml version="1.0" encoding="utf-8" ?>
|
|
675
|
+
<component name="ParentScene" extends="Scene">
|
|
676
|
+
<script type="text/brightscript" uri="pkg:/source/lib.brs" />
|
|
677
|
+
</component>
|
|
678
|
+
`);
|
|
679
|
+
program.setFile('source/lib.brs', '');
|
|
680
|
+
const file = program.setFile('components/child.xml', (0, testHelpers_spec_1.trim) `
|
|
681
|
+
<?xml version="1.0" encoding="utf-8" ?>
|
|
682
|
+
<component name="ChildScene" extends="ParentScene">
|
|
683
|
+
<script type="text/brightscript" uri="pkg:/source/lib.brs" />
|
|
684
|
+
</component>
|
|
685
|
+
`);
|
|
686
|
+
// uri on line 2 of child.xml
|
|
687
|
+
testGetCodeActions(file, util_1.util.createRange(2, 50, 2, 50), ['Remove redundant script import']);
|
|
688
|
+
});
|
|
689
|
+
it('offers fix-all when multiple redundant imports exist', () => {
|
|
690
|
+
program.setFile('components/parent.xml', (0, testHelpers_spec_1.trim) `
|
|
691
|
+
<?xml version="1.0" encoding="utf-8" ?>
|
|
692
|
+
<component name="ParentScene" extends="Scene">
|
|
693
|
+
<script type="text/brightscript" uri="pkg:/source/lib1.brs" />
|
|
694
|
+
<script type="text/brightscript" uri="pkg:/source/lib2.brs" />
|
|
695
|
+
</component>
|
|
696
|
+
`);
|
|
697
|
+
program.setFile('source/lib1.brs', '');
|
|
698
|
+
program.setFile('source/lib2.brs', '');
|
|
699
|
+
const file = program.setFile('components/child.xml', (0, testHelpers_spec_1.trim) `
|
|
700
|
+
<?xml version="1.0" encoding="utf-8" ?>
|
|
701
|
+
<component name="ChildScene" extends="ParentScene">
|
|
702
|
+
<script type="text/brightscript" uri="pkg:/source/lib1.brs" />
|
|
703
|
+
<script type="text/brightscript" uri="pkg:/source/lib2.brs" />
|
|
704
|
+
</component>
|
|
705
|
+
`);
|
|
706
|
+
testGetCodeActions(file, util_1.util.createRange(2, 50, 2, 50), [
|
|
707
|
+
'Fix all: Remove redundant script imports',
|
|
708
|
+
'Remove redundant script import'
|
|
709
|
+
]);
|
|
710
|
+
});
|
|
711
|
+
});
|
|
712
|
+
describe('unnecessaryCodebehindScriptImport', () => {
|
|
713
|
+
it('offers to remove the unnecessary codebehind import', () => {
|
|
714
|
+
const file = program.setFile('components/comp1.xml', (0, testHelpers_spec_1.trim) `
|
|
715
|
+
<?xml version="1.0" encoding="utf-8" ?>
|
|
716
|
+
<component name="comp1" extends="Scene">
|
|
717
|
+
<script type="text/brightscript" uri="pkg:/components/comp1.brs" />
|
|
718
|
+
</component>
|
|
719
|
+
`);
|
|
720
|
+
program.setFile('components/comp1.brs', '');
|
|
721
|
+
// uri on line 2
|
|
722
|
+
testGetCodeActions(file, util_1.util.createRange(2, 50, 2, 50), ['Remove unnecessary codebehind import']);
|
|
723
|
+
});
|
|
724
|
+
});
|
|
725
|
+
describe('scriptImportCaseMismatch', () => {
|
|
726
|
+
it('offers to fix the casing of the script import path', () => {
|
|
727
|
+
const file = program.setFile('components/comp1.xml', (0, testHelpers_spec_1.trim) `
|
|
728
|
+
<?xml version="1.0" encoding="utf-8" ?>
|
|
729
|
+
<component name="comp1" extends="Scene">
|
|
730
|
+
<script type="text/brightscript" uri="pkg:/SOURCE/lib.brs" />
|
|
731
|
+
</component>
|
|
732
|
+
`);
|
|
733
|
+
program.setFile('source/lib.brs', '');
|
|
734
|
+
testGetCodeActions(file, util_1.util.createRange(2, 50, 2, 50), ['Fix script import path casing']);
|
|
735
|
+
});
|
|
736
|
+
it('replaces the URI value with the correctly-cased path', () => {
|
|
737
|
+
const file = program.setFile('components/comp1.xml', (0, testHelpers_spec_1.trim) `
|
|
738
|
+
<?xml version="1.0" encoding="utf-8" ?>
|
|
739
|
+
<component name="comp1" extends="Scene">
|
|
740
|
+
<script type="text/brightscript" uri="pkg:/SOURCE/lib.brs" />
|
|
741
|
+
</component>
|
|
742
|
+
`);
|
|
743
|
+
program.setFile('source/lib.brs', '');
|
|
744
|
+
program.validate();
|
|
745
|
+
const actions = program.getCodeActions(file.srcPath, util_1.util.createRange(2, 50, 2, 50));
|
|
746
|
+
const fix = actions.find(a => a.title === 'Fix script import path casing');
|
|
747
|
+
const changes = Object.values(fix.edit.changes)[0];
|
|
748
|
+
(0, chai_config_spec_1.expect)(changes[0].newText).to.equal('pkg:/source/lib.brs');
|
|
749
|
+
});
|
|
750
|
+
it('offers fix-all when multiple case-mismatched imports exist', () => {
|
|
751
|
+
const file = program.setFile('components/comp1.xml', (0, testHelpers_spec_1.trim) `
|
|
752
|
+
<?xml version="1.0" encoding="utf-8" ?>
|
|
753
|
+
<component name="comp1" extends="Scene">
|
|
754
|
+
<script type="text/brightscript" uri="pkg:/SOURCE/lib1.brs" />
|
|
755
|
+
<script type="text/brightscript" uri="pkg:/SOURCE/lib2.brs" />
|
|
756
|
+
</component>
|
|
757
|
+
`);
|
|
758
|
+
program.setFile('source/lib1.brs', '');
|
|
759
|
+
program.setFile('source/lib2.brs', '');
|
|
760
|
+
testGetCodeActions(file, util_1.util.createRange(2, 50, 2, 50), [
|
|
761
|
+
'Fix all: Fix script import path casing',
|
|
762
|
+
'Fix script import path casing'
|
|
763
|
+
]);
|
|
764
|
+
});
|
|
765
|
+
it('offers to fix the casing of a relative script import path', () => {
|
|
766
|
+
const file = program.setFile('components/comp1.xml', (0, testHelpers_spec_1.trim) `
|
|
767
|
+
<?xml version="1.0" encoding="utf-8" ?>
|
|
768
|
+
<component name="comp1" extends="Scene">
|
|
769
|
+
<script type="text/brightscript" uri="LIB.brs" />
|
|
770
|
+
</component>
|
|
771
|
+
`);
|
|
772
|
+
program.setFile('components/lib.brs', '');
|
|
773
|
+
testGetCodeActions(file, util_1.util.createRange(2, 45, 2, 45), ['Fix script import path casing']);
|
|
774
|
+
});
|
|
775
|
+
it('replaces a relative URI with the correctly-cased relative path', () => {
|
|
776
|
+
const file = program.setFile('components/comp1.xml', (0, testHelpers_spec_1.trim) `
|
|
777
|
+
<?xml version="1.0" encoding="utf-8" ?>
|
|
778
|
+
<component name="comp1" extends="Scene">
|
|
779
|
+
<script type="text/brightscript" uri="LIB.brs" />
|
|
780
|
+
</component>
|
|
781
|
+
`);
|
|
782
|
+
program.setFile('components/lib.brs', '');
|
|
783
|
+
program.validate();
|
|
784
|
+
const actions = program.getCodeActions(file.srcPath, util_1.util.createRange(2, 45, 2, 45));
|
|
785
|
+
const fix = actions.find(a => a.title === 'Fix script import path casing');
|
|
786
|
+
const changes = Object.values(fix.edit.changes)[0];
|
|
787
|
+
(0, chai_config_spec_1.expect)(changes[0].newText).to.equal('lib.brs');
|
|
788
|
+
});
|
|
789
|
+
it('replaces a cross-directory relative URI with the correctly-cased relative path', () => {
|
|
790
|
+
const file = program.setFile('components/sub/comp1.xml', (0, testHelpers_spec_1.trim) `
|
|
791
|
+
<?xml version="1.0" encoding="utf-8" ?>
|
|
792
|
+
<component name="comp1" extends="Scene">
|
|
793
|
+
<script type="text/brightscript" uri="../utils/HELPER.brs" />
|
|
794
|
+
</component>
|
|
795
|
+
`);
|
|
796
|
+
program.setFile('components/utils/helper.brs', '');
|
|
797
|
+
program.validate();
|
|
798
|
+
const actions = program.getCodeActions(file.srcPath, util_1.util.createRange(2, 50, 2, 50));
|
|
799
|
+
const fix = actions.find(a => a.title === 'Fix script import path casing');
|
|
800
|
+
const changes = Object.values(fix.edit.changes)[0];
|
|
801
|
+
(0, chai_config_spec_1.expect)(changes[0].newText).to.equal('../utils/helper.brs');
|
|
802
|
+
});
|
|
803
|
+
});
|
|
804
|
+
describe('missingOverrideKeyword', () => {
|
|
805
|
+
it('offers to add the override keyword', () => {
|
|
806
|
+
program.setFile('components/comp1.xml', (0, testHelpers_spec_1.trim) `<component name="comp1" extends="Scene"></component>`);
|
|
807
|
+
const file = program.setFile('components/comp1.bs', `
|
|
808
|
+
class Animal
|
|
809
|
+
function speak()
|
|
810
|
+
end function
|
|
811
|
+
end class
|
|
812
|
+
class Dog extends Animal
|
|
813
|
+
function speak()
|
|
814
|
+
end function
|
|
815
|
+
end class
|
|
816
|
+
`);
|
|
817
|
+
// "function speak()" in Dog — diagnostic starts at the function keyword on line 6
|
|
818
|
+
testGetCodeActions(file, util_1.util.createRange(6, 20, 6, 20), [`Add missing 'override' keyword`]);
|
|
819
|
+
});
|
|
820
|
+
it('inserts override before the function keyword', () => {
|
|
821
|
+
program.setFile('components/comp1.xml', (0, testHelpers_spec_1.trim) `<component name="comp1" extends="Scene"></component>`);
|
|
822
|
+
const file = program.setFile('components/comp1.bs', `
|
|
823
|
+
class Animal
|
|
824
|
+
function speak()
|
|
825
|
+
end function
|
|
826
|
+
end class
|
|
827
|
+
class Dog extends Animal
|
|
828
|
+
function speak()
|
|
829
|
+
end function
|
|
830
|
+
end class
|
|
831
|
+
`);
|
|
832
|
+
program.validate();
|
|
833
|
+
const actions = program.getCodeActions(file.srcPath, util_1.util.createRange(6, 20, 6, 20));
|
|
834
|
+
const fix = actions.find(a => a.title === `Add missing 'override' keyword`);
|
|
835
|
+
const changes = Object.values(fix.edit.changes)[0];
|
|
836
|
+
(0, chai_config_spec_1.expect)(changes[0].newText).to.equal('override ');
|
|
837
|
+
});
|
|
838
|
+
it('offers fix-all when multiple methods are missing override', () => {
|
|
839
|
+
program.setFile('components/comp1.xml', (0, testHelpers_spec_1.trim) `<component name="comp1" extends="Scene"></component>`);
|
|
840
|
+
const file = program.setFile('components/comp1.bs', `
|
|
841
|
+
class Animal
|
|
842
|
+
function speak()
|
|
843
|
+
end function
|
|
844
|
+
function move()
|
|
845
|
+
end function
|
|
846
|
+
end class
|
|
847
|
+
class Dog extends Animal
|
|
848
|
+
function speak()
|
|
849
|
+
end function
|
|
850
|
+
function move()
|
|
851
|
+
end function
|
|
852
|
+
end class
|
|
853
|
+
`);
|
|
854
|
+
testGetCodeActions(file, util_1.util.createRange(8, 20, 8, 20), [
|
|
855
|
+
`Add missing 'override' keyword`,
|
|
856
|
+
`Fix all: Add missing 'override' keywords`
|
|
857
|
+
]);
|
|
858
|
+
});
|
|
859
|
+
});
|
|
860
|
+
describe('cannotUseOverrideKeywordOnConstructorFunction', () => {
|
|
861
|
+
it('offers to remove override from constructor', () => {
|
|
862
|
+
const file = program.setFile('source/main.bs', `
|
|
863
|
+
class Dog
|
|
864
|
+
override function new()
|
|
865
|
+
end function
|
|
866
|
+
end class
|
|
867
|
+
`);
|
|
868
|
+
// "override" is on line 2
|
|
869
|
+
testGetCodeActions(file, util_1.util.createRange(2, 20, 2, 20), [`Remove 'override' from constructor`]);
|
|
870
|
+
});
|
|
871
|
+
it('deletes the override keyword and trailing space', () => {
|
|
872
|
+
const file = program.setFile('source/main.bs', `
|
|
873
|
+
class Dog
|
|
874
|
+
override function new()
|
|
875
|
+
end function
|
|
876
|
+
end class
|
|
877
|
+
`);
|
|
878
|
+
program.validate();
|
|
879
|
+
const actions = program.getCodeActions(file.srcPath, util_1.util.createRange(2, 20, 2, 20));
|
|
880
|
+
const fix = actions.find(a => a.title === `Remove 'override' from constructor`);
|
|
881
|
+
const changes = Object.values(fix.edit.changes)[0];
|
|
882
|
+
// range covers "override " (8 chars + 1 space)
|
|
883
|
+
(0, chai_config_spec_1.expect)(changes[0].range.start.character).to.equal(changes[0].range.end.character - 9);
|
|
884
|
+
});
|
|
310
885
|
});
|
|
311
886
|
});
|
|
312
887
|
//# sourceMappingURL=CodeActionsProcessor.spec.js.map
|