Skip to content

Commit 5753b6b

Browse files
authored
Project Panel (#1382)
* Project Panel Convert the dependencies panel in to the new project panel. This rolls the dependencies up in to its own top level item in the tree, and places it along side Targets, Tasks, Commands and Snippets. Tasks, Commands and Snippets can be run directly from the panel, and update their icon to show their running status. Clicking a test target will run all the tests in the target.
1 parent 6790937 commit 5753b6b

31 files changed

+1302
-521
lines changed

assets/test/targets/Package.swift

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// swift-tools-version: 5.6
2+
// The swift-tools-version declares the minimum version of Swift required to build this package.
3+
4+
import PackageDescription
5+
6+
let package = Package(
7+
name: "targets",
8+
products: [
9+
.library(
10+
name: "LibraryTarget",
11+
targets: ["LibraryTarget"]
12+
),
13+
.executable(
14+
name: "ExecutableTarget",
15+
targets: ["ExecutableTarget"]
16+
),
17+
.plugin(
18+
name: "PluginTarget",
19+
targets: ["PluginTarget"]
20+
),
21+
],
22+
dependencies: [
23+
.package(url: "https://github.com/swiftlang/swift-markdown.git", branch: "main"),
24+
.package(path: "../defaultPackage"),
25+
],
26+
targets: [
27+
.target(
28+
name: "LibraryTarget"
29+
),
30+
.executableTarget(
31+
name: "ExecutableTarget"
32+
),
33+
.plugin(
34+
name: "PluginTarget",
35+
capability: .command(
36+
intent: .custom(verb: "testing", description: "A plugin for testing plugins")
37+
)
38+
),
39+
.testTarget(
40+
name: "TargetsTests",
41+
dependencies: ["LibraryTarget"]
42+
),
43+
.testTarget(
44+
name: "AnotherTests",
45+
dependencies: ["LibraryTarget"]
46+
),
47+
]
48+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import PackagePlugin
2+
import Foundation
3+
4+
@main
5+
struct MyCommandPlugin: CommandPlugin {
6+
func performCommand(context: PluginContext, arguments: [String]) throws {
7+
print("Plugin Target Hello World")
8+
}
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
print("Another Snippet Hello World")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
print("Snippet Hello World")

assets/test/targets/Sources/CommandPluginTarget/CommandPluginTarget.swift

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
print("Executable Target Hello World!")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// The Swift Programming Language
2+
// https://docs.swift.org/swift-book
3+
4+
public func foo() {
5+
print("foo")
6+
}
7+
public func bar() {
8+
print("bar")
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import LibraryTarget
2+
import XCTest
3+
4+
class AnotherTests: XCTestCase {
5+
func testExample() {
6+
bar()
7+
}
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import LibraryTarget
2+
import XCTest
3+
4+
class TargetsTests: XCTestCase {
5+
func testExample() {
6+
foo()
7+
}
8+
}

package.json

+89-16
Original file line numberDiff line numberDiff line change
@@ -222,12 +222,14 @@
222222
{
223223
"command": "swift.runSnippet",
224224
"title": "Run Swift Snippet",
225-
"category": "Swift"
225+
"category": "Swift",
226+
"icon": "$(play)"
226227
},
227228
{
228229
"command": "swift.debugSnippet",
229230
"title": "Debug Swift Snippet",
230-
"category": "Swift"
231+
"category": "Swift",
232+
"icon": "$(debug)"
231233
},
232234
{
233235
"command": "swift.runPluginTask",
@@ -266,8 +268,27 @@
266268
},
267269
{
268270
"command": "swift.runAllTestsParallel",
269-
"title": "Run All Tests in Parallel",
270-
"category": "Test"
271+
"title": "Run Tests in Parallel",
272+
"category": "Test",
273+
"icon": "$(testing-run-all-icon)"
274+
},
275+
{
276+
"command": "swift.runAllTests",
277+
"title": "Run Tests",
278+
"category": "Test",
279+
"icon": "$(testing-run-icon)"
280+
},
281+
{
282+
"command": "swift.debugAllTests",
283+
"title": "Debug Tests",
284+
"category": "Test",
285+
"icon": "$(testing-debug-icon)"
286+
},
287+
{
288+
"command": "swift.coverAllTests",
289+
"title": "Run Tests with Coverage",
290+
"category": "Test",
291+
"icon": "$(debug-coverage)"
271292
}
272293
],
273294
"configuration": [
@@ -910,6 +931,18 @@
910931
{
911932
"command": "swift.runAllTestsParallel",
912933
"when": "swift.isActivated"
934+
},
935+
{
936+
"command": "swift.runAllTests",
937+
"when": "swift.isActivated"
938+
},
939+
{
940+
"command": "swift.debugAllTests",
941+
"when": "swift.isActivated"
942+
},
943+
{
944+
"command": "swift.coverAllTests",
945+
"when": "swift.isActivated"
913946
}
914947
],
915948
"editor/context": [
@@ -971,50 +1004,90 @@
9711004
"view/title": [
9721005
{
9731006
"command": "swift.updateDependencies",
974-
"when": "view == packageDependencies",
1007+
"when": "view == projectPanel",
9751008
"group": "navigation@1"
9761009
},
9771010
{
9781011
"command": "swift.resolveDependencies",
979-
"when": "view == packageDependencies",
1012+
"when": "view == projectPanel",
9801013
"group": "navigation@2"
9811014
},
9821015
{
9831016
"command": "swift.resetPackage",
984-
"when": "view == packageDependencies",
1017+
"when": "view == projectPanel",
9851018
"group": "navigation@3"
9861019
},
9871020
{
9881021
"command": "swift.flatDependenciesList",
989-
"when": "view == packageDependencies && !swift.flatDependenciesList",
1022+
"when": "view == projectPanel && !swift.flatDependenciesList",
9901023
"group": "navigation@4"
9911024
},
9921025
{
9931026
"command": "swift.nestedDependenciesList",
994-
"when": "view == packageDependencies && swift.flatDependenciesList",
1027+
"when": "view == projectPanel && swift.flatDependenciesList",
9951028
"group": "navigation@5"
9961029
}
9971030
],
9981031
"view/item/context": [
9991032
{
10001033
"command": "swift.useLocalDependency",
1001-
"when": "view == packageDependencies && viewItem == remote"
1034+
"when": "view == projectPanel && viewItem == remote"
10021035
},
10031036
{
10041037
"command": "swift.uneditDependency",
1005-
"when": "view == packageDependencies && viewItem == editing"
1038+
"when": "view == projectPanel && viewItem == editing"
10061039
},
10071040
{
10081041
"command": "swift.openInWorkspace",
1009-
"when": "view == packageDependencies && viewItem == editing"
1042+
"when": "view == projectPanel && viewItem == editing"
10101043
},
10111044
{
10121045
"command": "swift.openInWorkspace",
1013-
"when": "view == packageDependencies && viewItem == local"
1046+
"when": "view == projectPanel && viewItem == local"
10141047
},
10151048
{
10161049
"command": "swift.openExternal",
1017-
"when": "view == packageDependencies && viewItem != local"
1050+
"when": "view == projectPanel && (viewItem == 'editing' || viewItem == 'remote')"
1051+
},
1052+
{
1053+
"command": "swift.run",
1054+
"when": "view == projectPanel && viewItem == 'runnable'",
1055+
"group": "inline@0"
1056+
},
1057+
{
1058+
"command": "swift.debug",
1059+
"when": "view == projectPanel && viewItem == 'runnable'",
1060+
"group": "inline@1"
1061+
},
1062+
{
1063+
"command": "swift.runSnippet",
1064+
"when": "view == projectPanel && viewItem == 'snippet_runnable'",
1065+
"group": "inline@0"
1066+
},
1067+
{
1068+
"command": "swift.debugSnippet",
1069+
"when": "view == projectPanel && viewItem == 'snippet_runnable'",
1070+
"group": "inline@1"
1071+
},
1072+
{
1073+
"command": "swift.runAllTests",
1074+
"when": "view == projectPanel && viewItem == 'test_runnable'",
1075+
"group": "inline@0"
1076+
},
1077+
{
1078+
"command": "swift.debugAllTests",
1079+
"when": "view == projectPanel && viewItem == 'test_runnable'",
1080+
"group": "inline@1"
1081+
},
1082+
{
1083+
"command": "swift.runAllTestsParallel",
1084+
"when": "view == projectPanel && viewItem == 'test_runnable'",
1085+
"group": "inline@2"
1086+
},
1087+
{
1088+
"command": "swift.coverAllTests",
1089+
"when": "view == projectPanel && viewItem == 'test_runnable'",
1090+
"group": "inline@3"
10181091
}
10191092
]
10201093
},
@@ -1211,8 +1284,8 @@
12111284
"views": {
12121285
"explorer": [
12131286
{
1214-
"id": "packageDependencies",
1215-
"name": "Package Dependencies",
1287+
"id": "projectPanel",
1288+
"name": "Swift Project",
12161289
"icon": "$(archive)",
12171290
"when": "swift.hasPackage"
12181291
}

src/PackageWatcher.ts

+12
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export class PackageWatcher {
2727
private packageFileWatcher?: vscode.FileSystemWatcher;
2828
private resolvedFileWatcher?: vscode.FileSystemWatcher;
2929
private workspaceStateFileWatcher?: vscode.FileSystemWatcher;
30+
private snippetWatcher?: vscode.FileSystemWatcher;
3031

3132
constructor(
3233
private folderContext: FolderContext,
@@ -41,6 +42,7 @@ export class PackageWatcher {
4142
this.packageFileWatcher = this.createPackageFileWatcher();
4243
this.resolvedFileWatcher = this.createResolvedFileWatcher();
4344
this.workspaceStateFileWatcher = this.createWorkspaceStateFileWatcher();
45+
this.snippetWatcher = this.createSnippetFileWatcher();
4446
}
4547

4648
/**
@@ -51,6 +53,7 @@ export class PackageWatcher {
5153
this.packageFileWatcher?.dispose();
5254
this.resolvedFileWatcher?.dispose();
5355
this.workspaceStateFileWatcher?.dispose();
56+
this.snippetWatcher?.dispose();
5457
}
5558

5659
private createPackageFileWatcher(): vscode.FileSystemWatcher {
@@ -87,6 +90,15 @@ export class PackageWatcher {
8790
return watcher;
8891
}
8992

93+
private createSnippetFileWatcher(): vscode.FileSystemWatcher {
94+
const watcher = vscode.workspace.createFileSystemWatcher(
95+
new vscode.RelativePattern(this.folderContext.folder, "Snippets/*.swift")
96+
);
97+
watcher.onDidCreate(async () => await this.handlePackageSwiftChange());
98+
watcher.onDidDelete(async () => await this.handlePackageSwiftChange());
99+
return watcher;
100+
}
101+
90102
/**
91103
* Handles a create or change event for **Package.swift**.
92104
*

src/SwiftPackage.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export interface Target {
4141
c99name: string;
4242
path: string;
4343
sources: string[];
44-
type: "executable" | "test" | "library" | "snippet";
44+
type: "executable" | "test" | "library" | "snippet" | "plugin";
4545
}
4646

4747
/** Swift Package Manager dependency */

0 commit comments

Comments
 (0)