()
| 467 | } |
| 468 | |
| 469 | async function onSwitchHeaderSource(): Promise<void> { |
| 470 | const activeEditor: vscode.TextEditor | undefined = vscode.window.activeTextEditor; |
| 471 | if (!activeEditor || !util.isCpp(activeEditor.document)) { |
| 472 | return; |
| 473 | } |
| 474 | |
| 475 | let rootUri: vscode.Uri | undefined = clients.ActiveClient.RootUri; |
| 476 | const fileName: string = activeEditor.document.fileName; |
| 477 | |
| 478 | if (!rootUri) { |
| 479 | rootUri = vscode.Uri.file(path.dirname(fileName)); // When switching without a folder open. |
| 480 | } |
| 481 | |
| 482 | const switchHeaderSource: (token: vscode.CancellationToken) => Promise<void> = async (token: vscode.CancellationToken) => { |
| 483 | try { |
| 484 | let targetFileName: string = await clients.ActiveClient.requestSwitchHeaderSource(rootUri, fileName, token); |
| 485 | if (!targetFileName) { |
| 486 | return; |
| 487 | } |
| 488 | // If the targetFileName has a path that is a symlink target of a workspace folder, |
| 489 | // then replace the RootRealPath with the RootPath (the symlink path). |
| 490 | let targetFileNameReplaced: boolean = false; |
| 491 | clients.forEach(client => { |
| 492 | if (!targetFileNameReplaced && client.RootRealPath && client.RootPath !== client.RootRealPath |
| 493 | && targetFileName.startsWith(client.RootRealPath)) { |
| 494 | targetFileName = client.RootPath + targetFileName.substring(client.RootRealPath.length); |
| 495 | targetFileNameReplaced = true; |
| 496 | } |
| 497 | }); |
| 498 | const document: vscode.TextDocument = await vscode.workspace.openTextDocument(targetFileName); |
| 499 | await vscode.window.showTextDocument(document).then(undefined, logAndReturn.undefined); |
| 500 | } catch (e) { |
| 501 | if (e instanceof vscode.CancellationError) { |
| 502 | return; |
| 503 | } |
| 504 | throw e; |
| 505 | } |
| 506 | }; |
| 507 | |
| 508 | const tokenSource: vscode.CancellationTokenSource = new vscode.CancellationTokenSource(); |
| 509 | try { |
| 510 | const switchHeaderSourcePromise: Promise<void> = switchHeaderSource(tokenSource.token); |
| 511 | const showProgress: boolean = await new Promise<boolean>((resolve, reject) => { |
| 512 | const timer: NodeJS.Timeout = global.setTimeout(() => resolve(true), 2000); |
| 513 | void switchHeaderSourcePromise.then(() => { |
| 514 | clearTimeout(timer); |
| 515 | resolve(false); |
| 516 | }, (e) => { |
| 517 | clearTimeout(timer); |
| 518 | reject(e); |
| 519 | }); |
| 520 | }); |
| 521 | |
| 522 | if (!showProgress) { |
| 523 | await switchHeaderSourcePromise; |
| 524 | return; |
| 525 | } |
| 526 |
nothing calls this directly
no test coverage detected