@@ -18,25 +18,13 @@ import { CommentCompletionProviders } from "../../../src/editor/CommentCompletio
18
18
import { Workbench } from "../../../src/utilities/commands" ;
19
19
20
20
suite ( "CommentCompletion Test Suite" , ( ) => {
21
- let document : vscode . TextDocument | undefined ;
22
21
let provider : CommentCompletionProviders ;
23
22
24
23
setup ( ( ) => {
25
24
provider = new CommentCompletionProviders ( ) ;
26
25
} ) ;
27
26
28
- teardown ( async ( ) => {
29
- const editor = vscode . window . visibleTextEditors . find (
30
- editor => editor . document === document
31
- ) ;
32
-
33
- if ( editor && document ) {
34
- await vscode . window . showTextDocument ( document , editor . viewColumn ) ;
35
- await vscode . commands . executeCommand ( Workbench . ACTION_CLOSEALLEDITORS ) ;
36
- }
37
-
38
- provider . dispose ( ) ;
39
- } ) ;
27
+ teardown ( ( ) => provider . dispose ( ) ) ;
40
28
41
29
suite ( "Function Comment Completion" , ( ) => {
42
30
test ( "Completion on line that isn't a comment" , async ( ) => {
@@ -404,7 +392,13 @@ suite("CommentCompletion Test Suite", () => {
404
392
} ) ;
405
393
} ) ;
406
394
407
- suite ( "Document Comment Completion" , ( ) => {
395
+ suite ( "Document Comment Completion" , function ( ) {
396
+ setup ( function ( ) {
397
+ if ( process . platform === "linux" ) {
398
+ // Skip as these tests access the active test editor which will sometimes crash on Linux.
399
+ this . skip ( ) ;
400
+ }
401
+ } ) ;
408
402
test ( "Should not provide completions on first line" , async ( ) => {
409
403
const { document, positions } = await openDocument ( `1️⃣
410
404
public func foo() {}` ) ;
@@ -439,32 +433,28 @@ suite("CommentCompletion Test Suite", () => {
439
433
440
434
test ( "Should continue a documentation comment block on new line" , async ( ) => {
441
435
const { document, positions } = await openDocument ( `
442
- /// aaa
443
- 1️⃣
444
- public func foo() {}`) ;
436
+ /// aaa
437
+ 1️⃣
438
+ public func foo() {}` ) ;
445
439
446
440
const position = positions [ "1️⃣" ] ;
447
441
await provider . docCommentCompletion . provideCompletionItems ( document , position ) ;
448
442
449
- const newLine = document . getText (
450
- new vscode . Range ( position , position . translate ( 0 , 1000 ) )
451
- ) ;
443
+ const newLine = document . lineAt ( position . line ) . text ;
452
444
453
445
assert . strictEqual ( newLine , "/// " , "New line should continue the comment block" ) ;
454
446
} ) ;
455
447
456
448
test ( "Should continue a documentation comment when an existing comment line is split" , async ( ) => {
457
449
const { document, positions } = await openDocument ( `
458
- /// aaa
459
- 1️⃣// bbb
460
- public func foo() {}`) ;
450
+ /// aaa
451
+ 1️⃣// bbb
452
+ public func foo() {}` ) ;
461
453
462
454
const position = positions [ "1️⃣" ] ;
463
455
await provider . docCommentCompletion . provideCompletionItems ( document , position ) ;
464
456
465
- const newLine = document . getText (
466
- new vscode . Range ( position , position . translate ( 0 , 1000 ) )
467
- ) ;
457
+ const newLine = document . lineAt ( position . line ) . text ;
468
458
469
459
assert . strictEqual ( newLine , "/// bbb" , "New line should continue the comment block" ) ;
470
460
} ) ;
@@ -484,7 +474,7 @@ suite("CommentCompletion Test Suite", () => {
484
474
} ) ;
485
475
486
476
test ( "Should handle case when no active text editor" , async ( ) => {
487
- const { document, positions } = await openDocument ( `
477
+ const { document : doc , positions } = await openDocument ( `
488
478
/// aaa
489
479
1️⃣
490
480
public func foo() {}` ) ;
@@ -495,10 +485,7 @@ suite("CommentCompletion Test Suite", () => {
495
485
await vscode . commands . executeCommand ( Workbench . ACTION_CLOSEALLEDITORS ) ;
496
486
497
487
// This should not throw an error
498
- const items = await provider . docCommentCompletion . provideCompletionItems (
499
- document ,
500
- position
501
- ) ;
488
+ const items = await provider . docCommentCompletion . provideCompletionItems ( doc , position ) ;
502
489
503
490
assert . equal (
504
491
items ,
@@ -507,50 +494,6 @@ suite("CommentCompletion Test Suite", () => {
507
494
) ;
508
495
} ) ;
509
496
510
- test ( "Should specifically test continueExistingDocCommentBlock with no active editor" , async ( ) => {
511
- const { document, positions } = await openDocument ( `
512
- /// aaa
513
- 1️⃣
514
- public func foo() {}` ) ;
515
-
516
- const position = positions [ "1️⃣" ] ;
517
-
518
- // Close all editors to simulate no active text editor
519
- await vscode . commands . executeCommand ( Workbench . ACTION_CLOSEALLEDITORS ) ;
520
-
521
- // Store original activeTextEditor property
522
- const originalActiveTextEditor = Object . getOwnPropertyDescriptor (
523
- vscode . window ,
524
- "activeTextEditor"
525
- ) ;
526
-
527
- // Mock the activeTextEditor to be null for the specific method call
528
- Object . defineProperty ( vscode . window , "activeTextEditor" , {
529
- get : ( ) => null ,
530
- configurable : true ,
531
- } ) ;
532
-
533
- try {
534
- // Call the method directly to ensure the branch is covered
535
- await provider . docCommentCompletion [ "continueExistingDocCommentBlock" ] (
536
- document ,
537
- position
538
- ) ;
539
-
540
- // If we get here, the method didn't throw an error, which is what we want
541
- assert . ok ( true , "Method should not throw when there's no active editor" ) ;
542
- } finally {
543
- // Restore the original activeTextEditor property
544
- if ( originalActiveTextEditor ) {
545
- Object . defineProperty (
546
- vscode . window ,
547
- "activeTextEditor" ,
548
- originalActiveTextEditor
549
- ) ;
550
- }
551
- }
552
- } ) ;
553
-
554
497
test ( "Should handle when previous line has // but not ///" , async ( ) => {
555
498
const { document, positions } = await openDocument ( `
556
499
// aaa
@@ -641,8 +584,7 @@ suite("CommentCompletion Test Suite", () => {
641
584
return ;
642
585
}
643
586
644
- const column = lines [ line ] . indexOf ( str ) ;
645
- return new vscode . Position ( line , column ) ;
587
+ return new vscode . Position ( line , lines [ line ] . indexOf ( str ) ) ;
646
588
}
647
589
648
590
let purgedContent = content ;
@@ -669,9 +611,6 @@ suite("CommentCompletion Test Suite", () => {
669
611
670
612
await vscode . window . showTextDocument ( doc ) ;
671
613
672
- // Save the document so we can clean it up when the test finishes
673
- document = doc ;
674
-
675
614
return { document : doc , positions } ;
676
615
}
677
616
} ) ;
0 commit comments