Skip to content

Commit 54c4a00

Browse files
committed
Enable cancellation support for imported file processing tasks
1 parent ccefc1d commit 54c4a00

2 files changed

Lines changed: 24 additions & 5 deletions

File tree

‎apps/editor/src/commands/select-imported-files-command/select-imported-files-command.ts‎

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,23 @@ export const select_imported_files_command = (
3232
starting_uris.map((u) => u.toString())
3333
)
3434

35+
let is_cancelled = false
36+
3537
await vscode.window.withProgress(
3638
{
3739
location: vscode.ProgressLocation.Notification,
38-
title: 'Processing imports...'
40+
title: 'Processing imports...',
41+
cancellable: true
3942
},
40-
async () => {
43+
async (progress, token) => {
4144
const queue: vscode.Uri[] = []
4245

4346
for (const starting_uri of starting_uris) {
44-
const imports = await get_imports_for_uri(starting_uri)
47+
if (token.isCancellationRequested) {
48+
is_cancelled = true
49+
break
50+
}
51+
const imports = await get_imports_for_uri(starting_uri, token)
4552
for (const uri_str of imports) {
4653
if (!visited_uris.has(uri_str)) {
4754
visited_uris.add(uri_str)
@@ -54,8 +61,12 @@ export const select_imported_files_command = (
5461
}
5562

5663
while (queue.length > 0) {
64+
if (token.isCancellationRequested) {
65+
is_cancelled = true
66+
break
67+
}
5768
const current_uri = queue.shift()!
58-
const imports = await get_imports_for_uri(current_uri)
69+
const imports = await get_imports_for_uri(current_uri, token)
5970
for (const uri_str of imports) {
6071
if (!visited_uris.has(uri_str)) {
6172
visited_uris.add(uri_str)
@@ -69,6 +80,10 @@ export const select_imported_files_command = (
6980
}
7081
)
7182

83+
if (is_cancelled) {
84+
return
85+
}
86+
7287
const valid_immediate = Array.from(immediate_uris).map((u) =>
7388
vscode.Uri.parse(u)
7489
)

‎apps/editor/src/commands/select-imported-files-command/utils/get-imports-for-uri.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import * as vscode from 'vscode'
22
import * as path from 'path'
33

44
export const get_imports_for_uri = async (
5-
document_uri: vscode.Uri
5+
document_uri: vscode.Uri,
6+
token?: vscode.CancellationToken
67
): Promise<string[]> => {
78
const found_uris = new Set<string>()
89
try {
@@ -235,6 +236,9 @@ export const get_imports_for_uri = async (
235236
}
236237

237238
for (const position of positions_to_check) {
239+
if (token?.isCancellationRequested) {
240+
break
241+
}
238242
try {
239243
const definitions = await vscode.commands.executeCommand<
240244
vscode.Location[] | vscode.LocationLink[]

0 commit comments

Comments
 (0)