Skip to content
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

Adding support for creating sbt files #659

Open
wants to merge 3 commits into
base: idea241.x
Choose a base branch
from

Conversation

Sa1to
Copy link
Contributor

@Sa1to Sa1to commented Apr 11, 2024

@azdrojowa123 azdrojowa123 self-requested a review April 12, 2024 08:53
@azdrojowa123
Copy link
Contributor

azdrojowa123 commented Apr 12, 2024

My suspicion is that most of the users create build.sbt and plugins.sbt files. Maybe when the user selects to create an sbt file, we can display a dropdown list from which he will be able to choose whether he wants to create an build.sbt or plugins.sbt file. Or he will be able to enter his own name as if he wanted to create some custom file. Similar as it is done for javascript file (but they allow you to create files with different extensions, and we would give users the same extension but just different names )
Screenshot 2024-04-12 at 11 11 47
What do you think @unkarjedy ?

@unkarjedy
Copy link
Member

@azdrojowa123

I agree that it would be a more convenient UX.
Though I don't know if the current API supports it.

I created a similar feature request in IntelliJ some time ago:
https://youtrack.jetbrains.com/issue/IDEA-306704/project-view-provide-a-way-to-create-quickly-special-files-via-New-in-this-Directory-action
Though it's not completely the same.

It would be nice to have a look if the existing API allows to have some predefined file names in the dropdown list when you select "Sbt file" template

@unkarjedy
Copy link
Member

@unkarjedy
Copy link
Member

My suspicion is that most of the users create build.sbt and plugins.sbt files.

Also some notes:

  • I guess users mostly don't create build.sbt files because they already exist once you create an SBT project or open an existing one. So it's mostly applicable to plugins.sbt file
  • We shouldn't suggest a file name if the file already exists in the selected directory

@azdrojowa123
Copy link
Contributor

azdrojowa123 commented Apr 12, 2024

I guess users mostly don't create build.sbt files because they already exist once you create an SBT project or open an existing one. So it's mostly applicable to plugins.sbt file

I think that it might be possible to create build.sbt files e.g. when someone creates a multi build project or build.sbt file in the project directory (such a file exists, for example, in our ultimate repository)

We shouldn't suggest a file name if the file already exists in the selected directory

Really good note, I agree

@Sa1to
Copy link
Contributor Author

Sa1to commented Apr 19, 2024

I was trying to use CreateFromTemplateActionBase to use dialog with different file kinds like when you create scala class
Screenshot 2024-04-19 at 12 53 01 but it is difficult to add default text for each file kind. I am suggesting create separate actions for build.sbt, plugin.sbt and sbt file with custom name, and put them in dropdown like this
Screenshot 2024-04-18 at 17 52 27

@azdrojowa123
Copy link
Contributor

@Sa1to for me this PR is not working :(
I mean build.sbt and plugin.sbt are not being generated correctly


import javax.swing.Icon

abstract class NewPredefinedSbtFileAction(@NlsActions.ActionText title: String, @NlsActions.ActionDescription description: String, icon: Icon, fileName: String) extends CreateFromTemplateActionBase(title, description, icon) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this line with class parameters is too long. Each parameter should be in a separate line. The same like in methods.
Screenshot 2024-05-15 at 17 55 00


abstract class NewPredefinedSbtFileAction(@NlsActions.ActionText title: String, @NlsActions.ActionDescription description: String, icon: Icon, fileName: String) extends CreateFromTemplateActionBase(title, description, icon) {

override def getTemplate(project: Project, dir: PsiDirectory): FileTemplate = FileTemplateManager.getDefaultInstance.getInternalTemplate(ScalaBundle.message("newclassorfile.menu.action.sbt.text"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FileTemplateManager.getDefaultInstance.getInternalTemplate(ScalaBundle.message("newclassorfile.menu.action.sbt.text")) should be in a new line. It is not readable in IDE

override def getTargetDirectory(dataContext: DataContext, view: IdeView): PsiDirectory = {
val directories: Array[PsiDirectory] = view.getDirectories
directories.find(directory => directory.findFile(fileName + ".sbt") != null).exists(dir => {
Messages.showErrorDialog(CommonDataKeys.PROJECT.getData(dataContext),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

each operation on directories should be in a new line

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exists takes a predicate as a parameter. What's your predicate here?

Icons.SBT_FILE,
ScalaBundle.message("newclassorfile.menu.action.build.sbt.defaultName")
) {
protected override def getAttributesDefaults(dataContext: DataContext): AttributesDefaults = new AttributesDefaults(ScalaBundle.message("newclassorfile.menu.action.build.sbt.defaultName")).withFixedName(true)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new AttributesDefaults(ScalaBundle.message("newclassorfile.menu.action.build.sbt.defaultName")).withFixedName(true) should be in a new line

Icons.SBT_FILE
) {

override def getTemplate(project: Project, dir: PsiDirectory): FileTemplate = FileTemplateManager.getDefaultInstance.getInternalTemplate(ScalaBundle.message("newclassorfile.menu.action.sbt.text"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FileTemplateManager.getDefaultInstance.getInternalTemplate(ScalaBundle.message("newclassorfile.menu.action.sbt.text")) should be in a new line

Icons.SBT_FILE,
ScalaBundle.message("newclassorfile.menu.action.plugin.sbt.defaultName")
) {
protected override def getAttributesDefaults(dataContext: DataContext): AttributesDefaults = new AttributesDefaults(ScalaBundle.message("newclassorfile.menu.action.plugin.sbt.defaultName")).withFixedName(true)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the same comment about the new line as above

@unkarjedy
Copy link
Member

Do I understand that only cosmetic/formatting fixes are left and everything works?

@azdrojowa123
Copy link
Contributor

As I remember yes.
@Sa1to could you fix these cosmetic changes and recheck if everything works?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants