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

create jbang script ux issues #21

Open
maxandersen opened this issue Jan 19, 2022 · 7 comments
Open

create jbang script ux issues #21

maxandersen opened this issue Jan 19, 2022 · 7 comments

Comments

@maxandersen
Copy link
Contributor

  1. cannot select location of the script
  2. defaults to agent where it should default to empty or hello
  3. the generated script is not opened so tricky to find in larger projects
@linux-china
Copy link
Contributor

linux-china commented Jan 23, 2022

Now it's some hard because JBang scripts were created by CLI, and lots of work for IDEA.

  • Start the process
  • Wait for files notification
  • Reload from disk
  • Scan the directory to get file list

My suggestion is to put some JBang templates under fileTemplates/internal directory and bundle into jbang.jar file, then plugin include this jar file, then just call following API, that's all.

 public static PsiFile createFileFromTemplate(@Nullable String name,
                                               @NotNull FileTemplate template,
                                               @NotNull PsiDirectory dir,
                                               @Nullable String defaultTemplateProperty,
                                               boolean openFile) 

We can use CLI to generate the scripts during project/module creation, and that's good. For opened project, we should choose fileTemplates to create JBang scripts, and it's normal way in IDEA.

Now we can have some options:

  • The plugin contains fileTemplates to create some JBang scripts
  • jbang.jar contains fileTemplates and plugin bundles the jar file
  • Use CLI to generate jbang scripts and UX is not good and lots of work.

@maxandersen
Copy link
Contributor Author

Not seeing that as a lot of work for the plug-in. It just need to run async via invoke later and we can add better output to jbang if necessary.

What is worse will be if jbang idea now starts having its own set of templates and have to be maintained. That is a lot more work imo.

@linux-china
Copy link
Contributor

linux-china commented Feb 9, 2022

Refresh the dest directory synchronously and open all new files now. It may be blocked for a while if dest directory contains lots of files.

VfsUtil.markDirtyAndRefresh(false, true, true, directory)
val fileEditorManager = FileEditorManager.getInstance(project)
//iterate all files and open new files
VfsUtil.iterateChildrenRecursively(
   directory,
   VirtualFileFilter.ALL
) {
    if (!it.isDirectory && !currentFiles.contains(it)) {
        fileEditorManager.openFile(it, true)
   }
 true
}

@maxandersen
Copy link
Contributor Author

Opening all new files is not a good approach IMO.

Just search for the file name given to the init; if found open if not select new files but don't open. Then you avoid any blocking operations.

@linux-china
Copy link
Contributor

linux-china commented Feb 11, 2022

@maxandersen a question, developers can use JBang template to generate mulit files, and input name just part of file names. For example:

"templates": {
    "Rocketmq": {
      "file-refs": {
        "src/{basename}Consumer.java": "templates/RocketmqConsumer.java.qute",
        "src/{basename}Provider.java": "templates/RocketmqProvider.java.qute",
        "src/application.properties": "templates/rocketmq-application.properties.qute"
      },
      "description": "Basic template for RocketMQ App"
    }
  }

If you input MyApp.java and no real file generated in this case. fileEditorManager.openFile(it, true) is not expensive, and just send a message to IDE and notify IDE to open files asynchronously.

@maxandersen
Copy link
Contributor Author

But not expected to have multiple files open. Annoying to users having to close what they don't need open.

@linux-china
Copy link
Contributor

Got. I will modify the logic and only open one new file by ext name match, and just let developers know that JBang script files have been created successfully.

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

No branches or pull requests

2 participants