swiftlang / vscode-swift

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

Create new project #755

Closed matthewbastien closed 2 months ago

matthewbastien commented 2 months ago

Implementation of the feature request #754.

The workflow is as follows:

  1. User runs the command Swift: New Project
  2. A prompt appears to select the project type. Available project types are retrieved by parsing the output of swift package init --help.
  3. An open folder dialog appears to select the root folder for the new project.
  4. A quick input appears to enter a name for the project.
  5. The project folder is created on disk and swift package init is executed to create the project based on the given inputs.
  6. A modal appears asking whether or not the user would like to open the newly created folder in the current window or a new one. An automatic action for this step can be configured with the swift.openAfterCreateProject setting. This is essentially the same modal used by the Git: Clone command.

I've also added a fairly basic test to make sure that the parsing of swift package init --help is functioning as intended.

Feedback is greatly appreciated! This is my first commit to this project and I definitely don't know all the ins and outs to the code base.

adam-fowler commented 2 months ago

@swift-server-bot test this please

adam-fowler commented 2 months ago

@swift-server-bot add to allowlist

adam-fowler commented 2 months ago

CI is returning a bunch of errors for older versions of swift. New features can probably be gated on the last three versions of swift. Get it working for 5.8 if it works for all the earlier swift versions as well you are done. Otherwise Add a new contextKey newProjectAvailable in contextKeys.ts and use the contextKey to control availability of the command. At startup you can check the swift version and set it to false if the swift version is less than 5.8

matthewbastien commented 2 months ago

CI is returning a bunch of errors for older versions of swift. New features can probably be gated on the last three versions of swift. Get it working for 5.8 if it works for all the earlier swift versions as well you are done. Otherwise Add a new contextKey newProjectAvailable in contextKeys.ts and use the contextKey to control availability of the command. At startup you can check the swift version and set it to false if the swift version is less than 5.8

The output of swift package init --help changes pretty drastically in versions <5.8.0. I've added the context key for enablement of the command, but we still need to support users being able to create a project in cases where the Swift extension is not activated yet (e.g. when no workspace is open). As such, I've also added a swift.isActivated context key to detect this. An error is shown to the user if they try to use the create project command with an unsupported swift version.