-
Notifications
You must be signed in to change notification settings - Fork 138
/
Copy pathLocalResourceProvider.ts
62 lines (51 loc) · 2.93 KB
/
LocalResourceProvider.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { GenericTreeItem, type AzExtParentTreeItem, type AzExtTreeItem } from "@microsoft/vscode-azext-utils";
import { type WorkspaceResourceProvider } from "@microsoft/vscode-azext-utils/hostapi";
import { Disposable } from "vscode";
import { localize } from "./localize";
import { InitLocalProjectTreeItem } from "./tree/localProject/InitLocalProjectTreeItem";
import { InvalidLocalProjectTreeItem } from "./tree/localProject/InvalidLocalProjectTreeItem";
import { LocalProjectTreeItem } from "./tree/localProject/LocalProjectTreeItem";
import { treeUtils } from "./utils/treeUtils";
import { listLocalProjects, type LocalProjectInternal } from "./workspace/listLocalProjects";
export class FunctionsLocalResourceProvider implements WorkspaceResourceProvider {
public disposables: Disposable[] = [];
public async provideResources(parent: AzExtParentTreeItem): Promise<AzExtTreeItem[] | null | undefined> {
const children: AzExtTreeItem[] = [];
Disposable.from(...this._projectDisposables).dispose();
this._projectDisposables = [];
const localProjects = await listLocalProjects();
let hasLocalProject = false;
for (const project of localProjects.initializedProjects) {
const treeItem: LocalProjectTreeItem = new LocalProjectTreeItem(parent, project as LocalProjectInternal);
this._projectDisposables.push(treeItem);
children.push(treeItem);
}
for (const unintializedProject of localProjects.unintializedProjects) {
hasLocalProject = true;
children.push(new InitLocalProjectTreeItem(parent, unintializedProject.projectPath, unintializedProject.workspaceFolder));
}
for (const invalidProject of localProjects.invalidProjects) {
hasLocalProject = true;
children.push(new InvalidLocalProjectTreeItem(parent, invalidProject.projectPath, invalidProject.error, invalidProject.workspaceFolder));
}
if (!hasLocalProject && children.length === 0) {
const ti: GenericTreeItem = new GenericTreeItem(parent, {
label: localize('createFunctionLocally', 'Create New Project...'),
commandId: 'azureFunctions.createNewProject',
contextValue: 'createNewProject',
iconPath: treeUtils.getThemedIconPath('CreateNewProject')
});
ti.commandArgs = [];
children.push(ti);
}
return children;
}
private _projectDisposables: Disposable[] = [];
public dispose(): void {
Disposable.from(...this._projectDisposables).dispose();
}
}