-
Notifications
You must be signed in to change notification settings - Fork 30.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pickup all TSConfigs in Workspace for TSC Build Task (#27306)
Follow up on #26079 Allows us to pick up all tsconfig files in a workspace for the build tasks
- Loading branch information
Showing
2 changed files
with
88 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
import * as vscode from 'vscode'; | ||
|
||
export default class TsConfigProvider extends vscode.Disposable { | ||
private readonly tsconfigs = new Set<string>(); | ||
|
||
private activated: boolean = false; | ||
private disposables: vscode.Disposable[] = []; | ||
|
||
constructor() { | ||
super(() => this.dispose()); | ||
} | ||
|
||
dispose(): void { | ||
this.disposables.forEach(d => d.dispose()); | ||
} | ||
|
||
public async getConfigsForWorkspace(): Promise<Iterable<string>> { | ||
if (!vscode.workspace.rootPath) { | ||
return []; | ||
} | ||
await this.ensureActivated(); | ||
return this.tsconfigs; | ||
} | ||
|
||
private async ensureActivated() { | ||
if (this.activated) { | ||
return this; | ||
} | ||
this.activated = true; | ||
|
||
for (const config of await TsConfigProvider.loadWorkspaceTsconfigs()) { | ||
this.tsconfigs.add(config.fsPath); | ||
} | ||
|
||
const configFileWatcher = vscode.workspace.createFileSystemWatcher('**/tsconfig*.json'); | ||
this.disposables.push(configFileWatcher); | ||
configFileWatcher.onDidCreate(this.handleProjectCreate, this, this.disposables); | ||
configFileWatcher.onDidDelete(this.handleProjectDelete, this, this.disposables); | ||
|
||
return this; | ||
} | ||
|
||
private static loadWorkspaceTsconfigs() { | ||
return vscode.workspace.findFiles('**/tsconfig*.json', '**/node_modules/**'); | ||
} | ||
|
||
private handleProjectCreate(e: vscode.Uri) { | ||
this.tsconfigs.add(e.fsPath); | ||
} | ||
|
||
private handleProjectDelete(e: vscode.Uri) { | ||
this.tsconfigs.delete(e.fsPath); | ||
} | ||
} |