How to make plugin hooking save? Follow
I just want to make the plugin.
When I save the file (.dart), it checks code by regex and put the wavy line.
I research how to hook when I save
I create a plugin project, I can't understand which for hook file by the selection of the menu below.
I just want to know how to make the first file for the program which hooking saving.
Please sign in to leave a comment.
You can use
FileDocumentManagerListenerand register your implementation in plugin.xml:
For an example you can look at intellij-community master branch in the
TrailingSpacesStripperclass or other classes which implement the
Thank you for replying.
I could put fileDocumentManagerListener inside of <extensions defaultExtensionNs="com.intellij">.
Do you mean this?
Yes, the defaultExtensionNs is required.
Yes the TrailingSpacesStripper.java uses FileDocumentListener. you don't need its particulars other than its implementation of the listener methods so you get an idea of what is expected by the IDE from extensions of this EP.
I added it in the plugin.xml
I create the SaveHook.java file in the src folder.
in the SaveHook.java I wrote like this. I guess it is the minimum code.
I wrote the code, "When I save, some error log will appear."
but, nothing happened.
"When I save, some error log will appear." It is a good sign because your hook is being called.
You will need to debug your code. You have to figure out what the error is because your plugin is causing it.
You cannot do everything in your hook there are limitations on what the IDE expects not to be done on a save operation. Take a look at the stack trace for the exception and it will probably give you a good idea what you did wrong.
First, I would not try using notifications or other IDE API's at first. Just print a message to the console which does not depend on IDE state so will always succeed without causing exceptions and you will see the output in the console tab of your debug session in the IDE when debugging your plugin.
> "When I save, some error log will appear." It is a good sign because your hook is being called.
It just explained about my code. Actually, nothing has happened.
Error log which I said was this.
I'm sorry for my English explanation was bad. in practice, no Exception and error have happened.
So, I can't find why it couldn't hook.
What do you think caused the Notification.ERROR to appear in the log, if not your hook?
Are you expecting a notification balloon?
Try to follow advice given. Do only System.out.println("beforeDocumentSaving") and System.out.println("beforeAllDocumentSaving") in your hook methods and nothing else. If it prints to the messages to the console then your hook is working.
You will have to figure out what you want to do in the hook and how you can do it within the IDE imposed limitations.
> Are you expecting a notification balloon?
Yes, I am. in the first, I want to try just save hooking.
I followed your advice.
It is my whole plugin.xml.
I put it in the src folder.
I wrote the printing code from yours.
I pushed [Run -> Debug 'Plugin'] on the menu bar.
And, new Intelli J and I save shortcut and also tried to chose [File -> Save All] on the menu.
But, nothing happened.
However, I also create a short-cut button Action program, it worked.
Try putting your hook into "com.shinriyo" package. I don't know if IDE will accept extensions with null package.
If you set a break point in one of the hook methods does it break there?
Also, keep in mind that nothing is saved if no files are modified. So you have to modify a file and then invoke save or save all.
OK. I thought log appears in plugin's console, doesn't it?
I thought log appears int test IDE's console.
Because, in the action which extends AnAction case, the log appears test IDE's console.
I also succeeded in run Notifications.
At last, I reached the starting line!!
Next, I make the code that checks in the file by regex and put the wavy line in it.
The console output appears in the IDE which is debugging your plugin. Good luck.
"beforeFileContentReload" method has "VirtualFile file" parameter, but "beforeDocumentSaving" doesn't have the parameter.
So, I can't use it.
I want to get an extension name, because I get only ".dart" file.
And next, I want to draw a wavy line. but, I can't find it in the developing document.