Skip to content

Commit 3a7b448

Browse files
authored
Only show Swift tasks in the Project Panel (#1447)
* Only show Swift tasks in the Project Panel Scope tasks to currently open project and ensure they have a unique ID.
1 parent eb6ba7c commit 3a7b448

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

src/ui/ProjectPanelProvider.ts

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { FolderOperation } from "../WorkspaceContext";
2121
import contextKeys from "../contextKeys";
2222
import { Dependency, ResolvedDependency, Target } from "../SwiftPackage";
2323
import { SwiftPluginTaskProvider } from "../tasks/SwiftPluginTaskProvider";
24+
import { FolderContext } from "../FolderContext";
2425

2526
const LOADING_ICON = "loading~spin";
2627
/**
@@ -174,13 +175,14 @@ export class FileNode {
174175
class TaskNode {
175176
constructor(
176177
public type: string,
178+
public id: string,
177179
public name: string,
178180
private active: boolean
179181
) {}
180182

181183
toTreeItem(): vscode.TreeItem {
182184
const item = new vscode.TreeItem(this.name, vscode.TreeItemCollapsibleState.None);
183-
item.id = `${this.type}-${this.name}`;
185+
item.id = `${this.type}-${this.id}`;
184186
item.iconPath = new vscode.ThemeIcon(this.active ? LOADING_ICON : "play");
185187
item.contextValue = "task";
186188
item.accessibilityInformation = { label: this.name };
@@ -445,7 +447,12 @@ export class ProjectPanelProvider implements vscode.TreeDataProvider<TreeNode> {
445447
]
446448
: []),
447449
new HeaderNode("targets", "Targets", "book", this.wrapInAsync(this.targets.bind(this))),
448-
new HeaderNode("tasks", "Tasks", "debug-continue-small", this.tasks.bind(this)),
450+
new HeaderNode(
451+
"tasks",
452+
"Tasks",
453+
"debug-continue-small",
454+
this.tasks.bind(this, folderContext)
455+
),
449456
...(snippets.length > 0
450457
? [
451458
new HeaderNode("snippets", "Snippets", "notebook", () =>
@@ -508,16 +515,23 @@ export class ProjectPanelProvider implements vscode.TreeDataProvider<TreeNode> {
508515
);
509516
}
510517

511-
private async tasks(): Promise<TreeNode[]> {
518+
private async tasks(folderContext: FolderContext): Promise<TreeNode[]> {
512519
const tasks = await vscode.tasks.fetchTasks();
520+
513521
return (
514522
tasks
515523
// Plugin tasks are shown under the Commands header
516-
.filter(task => task.source !== "swift-plugin")
517-
.map(
524+
.filter(
518525
task =>
526+
task.definition.type === "swift" &&
527+
task.definition.cwd === folderContext.folder.fsPath &&
528+
task.source !== "swift-plugin"
529+
)
530+
.map(
531+
(task, i) =>
519532
new TaskNode(
520533
"task",
534+
`${task.definition.cwd}-${task.name}-${task.detail ?? ""}-${i}`,
521535
task.name,
522536
this.activeTasks.has(task.detail ?? task.name)
523537
)
@@ -531,9 +545,10 @@ export class ProjectPanelProvider implements vscode.TreeDataProvider<TreeNode> {
531545
const tasks = await provider.provideTasks(new vscode.CancellationTokenSource().token);
532546
return tasks
533547
.map(
534-
task =>
548+
(task, i) =>
535549
new TaskNode(
536550
"command",
551+
`${task.definition.cwd}-${task.name}-${task.detail ?? ""}-${i}`,
537552
task.name,
538553
this.activeTasks.has(task.detail ?? task.name)
539554
)

0 commit comments

Comments
 (0)