swiftlang / vscode-swift

Visual Studio Code Extension for Swift
https://marketplace.visualstudio.com/items?itemName=sswg.swift-lang
Apache License 2.0
705 stars 47 forks source link

Swift terminal profile #914

Open award999 opened 1 week ago

award999 commented 1 week ago

Is your feature request related to a problem? Please describe. I've made the mistake a few times where I have select a toolchain in vscode and it has been built for via tasks. I then go to the integrated vscode terminal to issue to run some swift command that is a different version of swift.

Describe the solution you'd like You can provide different terminal profiles https://code.visualstudio.com/api/references/vscode-api#TerminalProfileProvider so we could provide a Swift terminal profile with selected toolchain in the PATH so that user can select this swift profile in settings, for example terminal.integrated.defaultProfile.osx

Describe alternatives you've considered N/A

Additional context N/A

matthewbastien commented 3 days ago

There's also the option of just adding to the terminal environment directly using the ExtensionContext:

context.environmentVariableCollection.clear();
context.environmentVariableCollection.prepend(
    "PATH",
    "/path/to/usr/bin:",
    { applyAtShellIntegration: true }
);
for (const variable in configuration.swiftEnvironmentVariables) {
    context.environmentVariableCollection.replace(
        variable,
        configuration.swiftEnvironmentVariables[variable],
        { applyAtShellIntegration: true }
    );
}

Using this approach the user will have the environment automatically populated in their VS Code terminal without having to launch a special profile. The only minor annoyance being that modifying certain variables (e.g. PATH) triggers a warning before the terminal will be updated:

Screenshot 2024-06-27 at 2 30 02 PM