|
5 | 5 | ******************************************************************************/ |
6 | 6 |
|
7 | 7 | import type { AstNode, DocumentBuilder, FileSystemProvider, LangiumDocument, LangiumDocumentFactory, LangiumDocuments, Module, Reference, ValidationChecks } from 'langium'; |
8 | | -import { AstUtils, DocumentState, TextDocument, URI, isOperationCancelled } from 'langium'; |
| 8 | +import { AstUtils, DocumentState, TextDocument, URI, isOperationCancelled, startCancelableOperation } from 'langium'; |
9 | 9 | import { createServicesForGrammar } from 'langium/grammar'; |
10 | 10 | import { describe, expect, test, vi, beforeEach, afterEach } from 'vitest'; |
11 | | -import { CancellationToken, CancellationTokenSource } from 'vscode-languageserver'; |
| 11 | +import { CancellationToken } from 'vscode-languageserver'; |
12 | 12 | import { fail } from 'assert'; |
13 | 13 | import type { LangiumServices, LangiumSharedServices, TextDocuments } from 'langium/lsp'; |
14 | 14 |
|
@@ -147,7 +147,7 @@ describe('DefaultDocumentBuilder', () => { |
147 | 147 | documents.addDocument(document2); |
148 | 148 |
|
149 | 149 | const builder = workspace.DocumentBuilder; |
150 | | - const tokenSource1 = new CancellationTokenSource(); |
| 150 | + const tokenSource1 = startCancelableOperation(); |
151 | 151 | builder.onBuildPhase(DocumentState.IndexedContent, () => { |
152 | 152 | tokenSource1.cancel(); |
153 | 153 | }); |
@@ -316,7 +316,7 @@ describe('DefaultDocumentBuilder', () => { |
316 | 316 | documents.addDocument(document); |
317 | 317 |
|
318 | 318 | const actual: string[] = []; |
319 | | - const cancelTokenSource = new CancellationTokenSource(); |
| 319 | + const cancelTokenSource = startCancelableOperation(); |
320 | 320 | function wait(state: DocumentState): void { |
321 | 321 | builder.onBuildPhase(state, async () => { |
322 | 322 | actual.push('B' + state); |
@@ -351,7 +351,7 @@ describe('DefaultDocumentBuilder', () => { |
351 | 351 | const document = documentFactory.fromString('', URI.parse('file:///test1.txt')); |
352 | 352 | documents.addDocument(document); |
353 | 353 |
|
354 | | - const cancelTokenSource = new CancellationTokenSource(); |
| 354 | + const cancelTokenSource = startCancelableOperation(); |
355 | 355 | builder.waitUntil(DocumentState.IndexedReferences, cancelTokenSource.token).then(() => { |
356 | 356 | fail('The test should fail here because the cancellation should reject the promise'); |
357 | 357 | }).catch(err => { |
@@ -413,7 +413,7 @@ describe('DefaultDocumentBuilder', () => { |
413 | 413 | documents.addDocument(document2); |
414 | 414 |
|
415 | 415 | const builder = services.shared.workspace.DocumentBuilder; |
416 | | - const tokenSource = new CancellationTokenSource(); |
| 416 | + const tokenSource = startCancelableOperation(); |
417 | 417 |
|
418 | 418 | const buildPhases = new Set<DocumentState>(); |
419 | 419 |
|
@@ -493,7 +493,7 @@ describe('DefaultDocumentBuilder', () => { |
493 | 493 | `, URI.parse('file:///test1.txt')); |
494 | 494 | documents.addDocument(document); |
495 | 495 |
|
496 | | - const tokenSource = new CancellationTokenSource(); |
| 496 | + const tokenSource = startCancelableOperation(); |
497 | 497 | const builder = workspace.DocumentBuilder; |
498 | 498 | builder.onBuildPhase(DocumentState.ComputedScopes, () => { |
499 | 499 | tokenSource.cancel(); |
@@ -636,7 +636,7 @@ describe('DefaultDocumentBuilder', () => { |
636 | 636 |
|
637 | 637 | expect(sortedDocs.slice(0, openDocumentCount).every(isDocumentOpen)).toBe(true); |
638 | 638 | expect(sortedDocs.slice(openDocumentCount).every(doc => !isDocumentOpen(doc))).toBe(true); |
639 | | - expect(endTime - startTime).toBeLessThan(1000); // Adjust this threshold as needed |
| 639 | + expect(endTime - startTime).toBeLessThan(1500); // Adjust this threshold as needed |
640 | 640 | }); |
641 | 641 |
|
642 | 642 | test('Sorting an empty list of documents', async () => { |
|
0 commit comments