@@ -38,7 +38,7 @@ import { updateDependencies } from "./commands/dependencies/update";
3838import { runPluginTask } from "./commands/runPluginTask" ;
3939import { runTestMultipleTimes } from "./commands/testMultipleTimes" ;
4040import { newSwiftFile } from "./commands/newFile" ;
41- import { runAllTests , runAllTestsParallel } from "./commands/runAllTests" ;
41+ import { runAllTests } from "./commands/runAllTests" ;
4242import { updateDependenciesViewList } from "./commands/dependencies/updateDepViewList" ;
4343import { runTask } from "./commands/runTask" ;
4444import { TestKind } from "./TestExplorer/TestKind" ;
@@ -84,6 +84,10 @@ export enum Commands {
8484 RUN_SNIPPET = "swift.runSnippet" ,
8585 DEBUG_SNIPPET = "swift.debugSnippet" ,
8686 PREVIEW_DOCUMENTATION = "swift.previewDocumentation" ,
87+ RUN_ALL_TESTS = "swift.runAllTests" ,
88+ RUN_ALL_TESTS_PARALLEL = "swift.runAllTestsParallel" ,
89+ DEBUG_ALL_TESTS = "swift.debugAllTests" ,
90+ COVER_ALL_TESTS = "swift.coverAllTests" ,
8791}
8892
8993/**
@@ -98,8 +102,12 @@ export function register(ctx: WorkspaceContext): vscode.Disposable[] {
98102 vscode . commands . registerCommand ( Commands . UPDATE_DEPENDENCIES , ( ) =>
99103 updateDependencies ( ctx )
100104 ) ,
101- vscode . commands . registerCommand ( Commands . RUN , target => runBuild ( ctx , target ) ) ,
102- vscode . commands . registerCommand ( Commands . DEBUG , target => debugBuild ( ctx , target ) ) ,
105+ vscode . commands . registerCommand ( Commands . RUN , target =>
106+ runBuild ( ctx , ...unwrapTreeItem ( target ) )
107+ ) ,
108+ vscode . commands . registerCommand ( Commands . DEBUG , target =>
109+ debugBuild ( ctx , ...unwrapTreeItem ( target ) )
110+ ) ,
103111 vscode . commands . registerCommand ( Commands . CLEAN_BUILD , ( ) => cleanBuild ( ctx ) ) ,
104112 vscode . commands . registerCommand ( Commands . RUN_TESTS_MULTIPLE_TIMES , item => {
105113 if ( ctx . currentFolder ) {
@@ -120,9 +128,11 @@ export function register(ctx: WorkspaceContext): vscode.Disposable[] {
120128 return openPackage ( ctx . toolchain . swiftVersion , ctx . currentFolder . folder ) ;
121129 }
122130 } ) ,
123- vscode . commands . registerCommand ( Commands . RUN_SNIPPET , target => runSnippet ( ctx , target ) ) ,
131+ vscode . commands . registerCommand ( Commands . RUN_SNIPPET , target =>
132+ runSnippet ( ctx , ...unwrapTreeItem ( target ) )
133+ ) ,
124134 vscode . commands . registerCommand ( Commands . DEBUG_SNIPPET , target =>
125- debugSnippet ( ctx , target )
135+ debugSnippet ( ctx , ... unwrapTreeItem ( target ) )
126136 ) ,
127137 vscode . commands . registerCommand ( Commands . RUN_PLUGIN_TASK , ( ) => runPluginTask ( ) ) ,
128138 vscode . commands . registerCommand ( Commands . RUN_TASK , name => runTask ( ctx , name ) ) ,
@@ -164,12 +174,20 @@ export function register(ctx: WorkspaceContext): vscode.Disposable[] {
164174 ) ,
165175 vscode . commands . registerCommand ( "swift.captureDiagnostics" , ( ) => captureDiagnostics ( ctx ) ) ,
166176 vscode . commands . registerCommand (
167- "swift.runAllTestsParallel" ,
168- async ( ) => await runAllTestsParallel ( ctx )
177+ Commands . RUN_ALL_TESTS_PARALLEL ,
178+ async item => await runAllTests ( ctx , TestKind . parallel , ... unwrapTreeItem ( item ) )
169179 ) ,
170180 vscode . commands . registerCommand (
171- "swift.runAllTests" ,
172- async ( testKind : TestKind ) => await runAllTests ( ctx , testKind )
181+ Commands . RUN_ALL_TESTS ,
182+ async item => await runAllTests ( ctx , TestKind . standard , ...unwrapTreeItem ( item ) )
183+ ) ,
184+ vscode . commands . registerCommand (
185+ Commands . DEBUG_ALL_TESTS ,
186+ async item => await runAllTests ( ctx , TestKind . debug , ...unwrapTreeItem ( item ) )
187+ ) ,
188+ vscode . commands . registerCommand (
189+ Commands . COVER_ALL_TESTS ,
190+ async item => await runAllTests ( ctx , TestKind . coverage , ...unwrapTreeItem ( item ) )
173191 ) ,
174192 vscode . commands . registerCommand (
175193 Commands . PREVIEW_DOCUMENTATION ,
@@ -183,3 +201,16 @@ export function register(ctx: WorkspaceContext): vscode.Disposable[] {
183201 ) ,
184202 ] ;
185203}
204+
205+ /**
206+ * Certain commands can be called via a vscode TreeView, which will pass a {@link CommandNode} object.
207+ * If the command is called via a command palette or other means, the target will be a string.
208+ */
209+ function unwrapTreeItem ( target ?: string | { args : string [ ] } ) : string [ ] {
210+ if ( typeof target === "object" && target !== null && "args" in target ) {
211+ return target . args ?? [ ] ;
212+ } else if ( typeof target === "string" ) {
213+ return [ target ] ;
214+ }
215+ return [ ] ;
216+ }
0 commit comments