Skip to content

Include environment when resolving plugin task #1727

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
### Fixed

- `Run multiple times...` and `Run until failure...` will now work when multiple tests are selected ([#1724](https://github.com/swiftlang/vscode-swift/pull/1724))
- Provide the Swift environment variables when resolving a `swift-plugin` task ([#1727](https://github.com/swiftlang/vscode-swift/pull/1727))

## 2.8.0 - 2025-07-14

Expand Down
1 change: 1 addition & 0 deletions src/tasks/SwiftPluginTaskProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ export class SwiftPluginTaskProvider implements vscode.TaskProvider {
"swift-plugin",
new SwiftExecution(swift, swiftArgs, {
cwd,
env: { ...configuration.swiftEnvironmentVariables, ...swiftRuntimeEnv() },
presentation: task.presentationOptions,
}),
task.problemMatchers
Expand Down
30 changes: 29 additions & 1 deletion test/unit-tests/tasks/SwiftPluginTaskProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ import { SwiftToolchain } from "../../../src/toolchain/toolchain";
import { SwiftExecution } from "../../../src/tasks/SwiftExecution";
import { Version } from "../../../src/utilities/version";
import { BuildFlags } from "../../../src/toolchain/BuildFlags";
import { instance, MockedObject, mockFn, mockObject } from "../../MockUtils";
import { instance, MockedObject, mockFn, mockGlobalValue, mockObject } from "../../MockUtils";
import { FolderContext } from "../../../src/FolderContext";
import configuration from "../../../src/configuration";

suite("SwiftPluginTaskProvider Unit Test Suite", () => {
let workspaceContext: MockedObject<WorkspaceContext>;
Expand Down Expand Up @@ -58,6 +59,14 @@ suite("SwiftPluginTaskProvider Unit Test Suite", () => {
});

suite("resolveTask", () => {
const configurationMock = mockGlobalValue(configuration, "swiftEnvironmentVariables");

setup(async () => {
configurationMock.setValue({
FOO: "bar",
});
});

test("uses SwiftExecution", async () => {
const taskProvider = new SwiftPluginTaskProvider(instance(workspaceContext));
const task = new vscode.Task(
Expand Down Expand Up @@ -295,5 +304,24 @@ suite("SwiftPluginTaskProvider Unit Test Suite", () => {
os.homedir(),
]);
});

test("provides environment", async () => {
const taskProvider = new SwiftPluginTaskProvider(instance(workspaceContext));
const task = new vscode.Task(
{
type: "swift",
args: [],
},
workspaceFolder,
"run PackageExe",
"swift"
);
const resolvedTask = taskProvider.resolveTask(
task,
new vscode.CancellationTokenSource().token
);
const swiftExecution = resolvedTask.execution as SwiftExecution;
assert.equal(swiftExecution.options.env?.FOO, "bar");
});
});
});