-
Notifications
You must be signed in to change notification settings - Fork 35
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
New setting to control creation of Artifact Id folder #197
Conversation
@CsCherrYY please take a look. |
|
||
let outputUri: vscode.Uri = metadata.defaults.targetFolder ? vscode.Uri.file(metadata.defaults.targetFolder) : await openDialogForFolder({ openLabel: LABEL_CHOOSE_FOLDER }); | ||
while (outputUri && await fse.pathExists(path.join(outputUri.fsPath, metadata.artifactId))) { | ||
const overrideChoice: string = await vscode.window.showWarningMessage(MESSAGE_EXISTING_FOLDER, OPTION_CONTINUE, OPTION_CHOOSE_ANOTHER_FOLDER); | ||
const projectLocation = metadata.createArtifactIdFolder ? path.join(outputUri.fsPath, metadata.artifactId) : outputUri.fsPath; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here when the user cancels the select folder dialog, outputUri
will be undefined, directly accessing outputUri.fsPath
would cause an error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe that would happen in the previous code as well, right? Not very experienced in TS.
Anyway, do you have a more specific recommendation for this? Or simply checking if the value is not undefined right after line 112 seems fine?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe that would happen in the previous code as well,
previous code is safe because it has a outputUri &&
before, so output.fsPath
will not be executed if outputUri is undefined.
Another reason not to use fsPath
is, for some virtual workspaces like Codespaces, there no filesystem and uri doesn's starts with scheme file:
.
Here you create variable projectLocation
only because you want to judge if it's an empty. I suggest to directly use vscode.workspace.fs.readDirectory(uri)
, which can also cover those virtual workspaces. And you don't need projectLocation
then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe my changes now are more aligned with Virtual Workspaces compatibility. Instead of using vscode.Uri.file()
, I've created them using .parse()
, as the former adds the scheme
to path
as well, for some weird reason.
When showing the project path in specifyOpenMethod()
, it'd be harder to read. Example:
{
"path": "/file:///Users/johndoe/projects/folder",
"scheme": "file"
}
By using vscode.Uri.parse("/Users/johndoe/projects/folder")
, this is the result:
{
"path": "/Users/johndoe/projects/folder",
"scheme": "file"
}
- config is now an enum, allowing future extensibility - removed all .fsPath calls and replaced them with pure vscode.Uri usage (with .path and .parse) - we don't rely on start.spring.io's `baseDir`param, creating the sub-folder directly (single-responsibility and dry) - other improvements, removing unnecessary variables and responsibility leaks out of `specifyTargetFolder`
I've done a bit of refactoring to simplify stuff. While applying the enum + removing .fsPath usage for my code, I noticed that without auxiliary variables, we'd have some issues dealing with While it was returned in So I chose to remove any output/destination folder attributions outside of Any unnecessary variables (as far as I remember) have been stripped out and the code is better now IMHO. Did some adjustments on URI usage for the rest of the code as well, limited to |
Yeah, I'm fairly new to extension development, so had to do some research with About extract-zip, on my Mac it created the directory on all of my tests, made sure it would before removing Will take a look later today, as soon as I get my hand on a Windows PC. @Eskibear just some last considerations on My judgment was that just defining If you guys prefer the previous behavior, just let me know. |
I'm ok with your way of doing this, just ensure this "parent folder" is correctly created, either leveraging extract-zip or do it by our own. So far the logic LGTM, and the only problem is the path issue mentioned above. I can help to investigate on Windows if I have time. |
So, I got my hands on a Windows PC and was able to debug the error you found, @Eskibear. Seems like using I understand compatibility with Virtual Workspaces is not going to be achieved by relying on this method, but we're basically dealing with file system stuff anyway, and What I think is the best way to go, is to just leave all URI manipulations in the old way, reversing back to Are you guys ok with this approach? If yes, I'll push a new commit with the changes. Side notes regarding zip-extractOne key thing to take into consideration when looking for virtual workspaces compatibility is zip-extract. It only works with a string for the path, and giving it anything different than Maybe in the future (assuming you guys agree with me on this matter), we could even bring in our own code to deal with I'm 100% interested in helping as much as I can on this refactor for virtual workspaces ;) |
An alternative way is to check the |
@brunovieira97 I agree that we use
I like the way you calculate BTW I just recall that virtual workspace is partially supported in this extension, and command"create a project" is hidden for virtual workspace. See #186 |
@CsCherrYY A good idea. But I prefer simplicity here in this PR. As mentioned above, we can do that in a different PR to fully support virtual workspace by refactoring all this. But before that, we should find a way to download and extract files in virtual workspace. |
That's the idea. I'll test everything on macOS + Windows here and push as soon as possible. |
Sorry for the delay, had a busy week. Just pushed a commit that reverts the URI changes so we can focus only on the actual feature, as discussed. I've tested the project creation flow on both Windows and macOS, with both setting values, and in all tests the behavior was correct. Feel free to do any further validation and let me know if anything else is needed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks!
New setting
spring.initializr.createArtifactIdFolder
to customize behavior of project creation.Since #75, the
baseDir
URL param is used and set to Artifact ID, causing the project to be generated inside a folder with the Artifact ID as its name. This setting allows the user to disable such behavior, generating the project in the selected folder directly. By default, the folder will be created, to preserve current functionality.If the Artifact Id folder creation is disabled, I've introduced a simple check to make sure the project destination directory is empty. If it's not, an alert will be shown to prevent overwriting existing files without user consent.
I've also included a minor fix that prevents the following notification to be shown if the generated project folder is already opened in VS Code.
Closes #169