Skip to content

Commit

Permalink
Merge pull request #80 from augustocdias/feature/nested_input
Browse files Browse the repository at this point in the history
Fix for nested input #79
  • Loading branch information
MarcelRobitaille authored Feb 8, 2024
2 parents 29e15b3 + 78b015f commit 1382782
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/lib/CommandHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,21 @@ export class CommandHandler {
}

protected resolveTaskToInput(taskId: string | undefined) {

// Find all objects where command is shellCommand.execute nested anywhere in the input object.
// It could be that the actual input being run is nested inside an input from another extension.
// See https://github.com/augustocdias/vscode-shell-command/issues/79
function *deepSearch(obj: any): Generator<Input> {

Check warning on line 195 in src/lib/CommandHandler.ts

View workflow job for this annotation

GitHub Actions / build

Unexpected any. Specify a different type
if (obj.command === "shellCommand.execute") {
yield obj;
}
for (let key in obj) {

Check failure on line 199 in src/lib/CommandHandler.ts

View workflow job for this annotation

GitHub Actions / build

'key' is never reassigned. Use 'const' instead
if (typeof obj[key] === 'object') {
yield* deepSearch(obj[key]);
}
}
}

function* getSectionInputs(section: "launch" | "tasks", folder?: vscode.WorkspaceFolder) {
const keys = folder
? ["workspaceFolderValue"] as const
Expand All @@ -197,8 +212,12 @@ export class CommandHandler {
const conf = vscode.workspace.getConfiguration(section, folder?.uri);
const env = conf.inspect<{ env: Record<string, string> }>("options")?.[key]?.env ?? {};
for (const input of conf.inspect<Input[]>("inputs")?.[key] || []) {
// Yield the input and assign the workspaceIndex.
yield { ...input, workspaceIndex: folder?.index ?? 0, env }

// Go through all the nested shellCommand.execute inputs.
for (const shellInput of deepSearch(input)) {
// Yield the input and assign the workspaceIndex.
yield { ...shellInput, workspaceIndex: folder?.index ?? 0, env }
}
}
}
}
Expand Down

0 comments on commit 1382782

Please sign in to comment.