Create new project#755
Conversation
| */ | ||
| export function register(ctx: WorkspaceContext) { | ||
| ctx.subscriptions.push( | ||
| vscode.commands.registerCommand("swift.createProject", () => createProject(ctx)), |
There was a problem hiding this comment.
createProject() has a few instances where it returns undefined. What's the experience for the user in these cases? Should createProject be providing guidance/errors to the user in the form of notifications?
There was a problem hiding this comment.
The places where createProject() returns undefined correspond to the user cancelling dialogs. I don't think we need any notifications in this case.
There was a problem hiding this comment.
👍 What's the behaviour from vscode for exceptions (e.g. the execSwift or mkdir fail)
There was a problem hiding this comment.
It pops up a modal with the error message from the exception.
There was a problem hiding this comment.
Have you verified what the message is for say mkdir failing? Would be good to make sure it is human readable.
adam-fowler
left a comment
There was a problem hiding this comment.
In general looks pretty good, I've added a few comments
| { | ||
| "title": "Swift", | ||
| "properties": { | ||
| "swift.openAfterCreateProject": { |
There was a problem hiding this comment.
Can we add an order value to this to define where it appears in the settings menu
There was a problem hiding this comment.
Done. I put it at the end of the settings since I can't imagine this being a high runner use case.
| /** | ||
| * A wrapper around {@link vscode.Progress} that allows for delaying progress reporting. | ||
| */ | ||
| class ProgressWrapper<T> implements vscode.Progress<T> { |
There was a problem hiding this comment.
Can we move the progress UI code to a separate file in the UI folder.
| // Prompt the user whether or not they want to open the newly created project | ||
| const isWorkspaceOpened = !!vscode.workspace.workspaceFolders; | ||
| const config = vscode.workspace.getConfiguration("swift"); | ||
| const openAfterCreate = config.get<string>("openAfterCreateProject"); |
There was a problem hiding this comment.
Can we add configuration settings to configuration.ts
|
|
||
| // Use swift package manager to initialize the swift project | ||
| await withDelayedProgress( | ||
| { |
There was a problem hiding this comment.
Given there is no progress reported here, any reason you can't use WorkspaceContext.statusItem.showStatusWhileRunning()
There was a problem hiding this comment.
I'd expect that 99% of the time we would never even show the notification. In my testing it never showed up unless I reduced the timeout. However, if it does take longer than expected, I want it to be a prominent notification rather than something hidden away in the status bar. That way users know that something is actually happening in the background.
That being said, this does add extra code that will need to be maintained. I'm not too strongly attached to this opinion and can just use showStatusWhileRunning() instead if that makes more sense to you.
| */ | ||
| export function register(ctx: WorkspaceContext) { | ||
| ctx.subscriptions.push( | ||
| vscode.commands.registerCommand("swift.createProject", () => createProject(ctx)), |
There was a problem hiding this comment.
Have you verified what the message is for say mkdir failing? Would be good to make sure it is human readable.
| */ | ||
| public async getProjectTemplates(): Promise<SwiftProjectTemplate[]> { | ||
| const { stdout } = await execSwift(["package", "init", "--help"], "default"); | ||
| const lines = stdout.split(/\r?\n/g); |
There was a problem hiding this comment.
This is some funky way to get project templates, but yeah can't see any other way of doing it.
I almost wonder if it is worthwhile rolling our own outside of SwiftPM. Would love to give users the ability to create their own templates. Maybe using Mustache templating to allow users to add in customisation. But that'd be for another task I think.
There was a problem hiding this comment.
Yeah I agree. I'd honestly like an option in Swift Package Manager to get these as JSON rather than doing the crazy command line parsing. However, we still need to support Swift versions <6.
|
@swift-server-bot test this please |
|
@swift-server-bot add to allowlist |
|
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 |
award999
left a comment
There was a problem hiding this comment.
a few minor comments :)
The output of |
adam-fowler
left a comment
There was a problem hiding this comment.
I think we are good here

Implementation of the feature request #754.
The workflow is as follows:
Swift: New Projectswift package init --help.swift package initis executed to create the project based on the given inputs.swift.openAfterCreateProjectsetting. This is essentially the same modal used by theGit: Clonecommand.I've also added a fairly basic test to make sure that the parsing of
swift package init --helpis 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.