mirror of
https://github.com/Microsoft/vscode
synced 2024-08-28 05:19:39 +00:00
parent
536ea46187
commit
d1510288f0
|
@ -38,6 +38,8 @@ interface TypeScriptTaskDefinition extends vscode.TaskDefinition {
|
|||
class TscTaskProvider implements vscode.TaskProvider {
|
||||
|
||||
private readonly projectInfoRequestTimeout = 2000;
|
||||
private readonly findConfigFilesTimeout = 5000;
|
||||
|
||||
private autoDetect: AutoDetect = 'on';
|
||||
private readonly tsconfigProvider: TsConfigProvider;
|
||||
private readonly disposables: vscode.Disposable[] = [];
|
||||
|
@ -160,7 +162,7 @@ class TscTaskProvider implements vscode.TaskProvider {
|
|||
}
|
||||
|
||||
private async getTsConfigsInWorkspace(): Promise<TSConfig[]> {
|
||||
return Array.from(await this.tsconfigProvider.getConfigsForWorkspace());
|
||||
return Array.from(await this.tsconfigProvider.getConfigsForWorkspace({ timeout: this.findConfigFilesTimeout }));
|
||||
}
|
||||
|
||||
private static async getCommand(project: TSConfig): Promise<string> {
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as vscode from 'vscode';
|
||||
import { wait } from '../test/testUtils';
|
||||
|
||||
export interface TSConfig {
|
||||
readonly uri: vscode.Uri;
|
||||
|
@ -13,12 +14,13 @@ export interface TSConfig {
|
|||
}
|
||||
|
||||
export class TsConfigProvider {
|
||||
public async getConfigsForWorkspace(): Promise<Iterable<TSConfig>> {
|
||||
public async getConfigsForWorkspace(options?: { timeout: number }): Promise<Iterable<TSConfig>> {
|
||||
if (!vscode.workspace.workspaceFolders) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const configs = new Map<string, TSConfig>();
|
||||
for (const config of await vscode.workspace.findFiles('**/tsconfig*.json', '**/{node_modules,.*}/**')) {
|
||||
for (const config of await this.findConfigFiles(options)) {
|
||||
const root = vscode.workspace.getWorkspaceFolder(config);
|
||||
if (root) {
|
||||
configs.set(config.fsPath, {
|
||||
|
@ -31,4 +33,22 @@ export class TsConfigProvider {
|
|||
}
|
||||
return configs.values();
|
||||
}
|
||||
|
||||
private async findConfigFiles(options?: { timeout: number }): Promise<vscode.Uri[]> {
|
||||
const timeout = options?.timeout;
|
||||
const task = (token?: vscode.CancellationToken) => vscode.workspace.findFiles('**/tsconfig*.json', '**/{node_modules,.*}/**', undefined, token);
|
||||
|
||||
if (typeof timeout === 'number') {
|
||||
const cancel = new vscode.CancellationTokenSource();
|
||||
return Promise.race([
|
||||
task(cancel.token),
|
||||
wait(timeout).then(() => {
|
||||
cancel.cancel();
|
||||
return [];
|
||||
}),
|
||||
]);
|
||||
} else {
|
||||
return task();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue