Open maxandersen opened 2 years ago
Now it's some hard because JBang scripts were created by CLI, and lots of work for IDEA.
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:
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.
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
}
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.
@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.
But not expected to have multiple files open. Annoying to users having to close what they don't need open.
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.
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