Can you add additional FILE_DOCUMENT_SYNC events "doneSaving", etc. ?

I'm asking this here because I don't see an issues list on the github repo for IntelliJ CE.

I recently created a JetBrains plugin to handle EditorConfig files, and I found that it would be useful to have an event fired after each file is done saving. This could mean adding methods like "doneSavingDocument" and "doneSavingAllDocuments". I added these for my purposes in my plugin by registering an alternative implementation of FileDocumentManager, but it would be nice if I (or other plugin developers) didn't have to do that. Does this sound like a good idea, or am I missing a better way of doing what I'm doing?

On a similar note, I think it would be useful for PropertyChangeListeners to be able to watch for changes to EditorSettings like "tabWidth". In fact, it looks maybe this used to exist in EditorSettingsExternalizable? Because currently EditorSettingsExternalizable has a private PropertyChangeSupport field, but it is never used to fire property change events when its properties change.

If others agree that these events would be useful, I'm happy to submit a pull request in the Community Edition on github.

3 comments

Hi Kevin,

I've looked at the EditorConfig plugin code, and it seems to be doing things in an unnecessarily complicated way. The separators used by IntelliJ IDEA to write out a document are stored in the userdata of the corresponding virtual file, and if you need to change them, you can simply do so directly instead of hooking into the save event and writing the file to disk twice, which hurts the performance and also impacts external file watcher tools such as Guard. See LoadTextUtil.changeLineSeparators() for the correct way to do that.

Since the tab size for a file comes from the code style settings and not from the editor settings, I don't see how a listener on EditorSettingsExternalizable could help you in any way.

0

Hi Dmitry,

Handling newlines was definitely something I struggled with, and I agree the current solution is not ideal. I was actually using LoadTextUtil.changeLineSeparators() earlier, but that was throwing a "method not found" exception in another IDE (I think WebStorm). Should this method be present in all recent versions of JetBrains editors? Maybe I can go back to getting that method to work.

Also, you're right, I meant stripTrailingSpaces and ensureLinefeedAtEOF as the things to monitor with a property change listener. However, my need to do that is really a workaround for not having a "done saving" event fired after every document is saved.

Aside from the newline issue, I have a general for knowing when files are done being saved so I can modify settings applied on save. I mentioned this in my other post, but it I am generally trying to wrap saves the same way IntelliJ's internal "saveAsIs" method works:

store old setting
apply editorconfig setting
[save happens]
revert to old setting

0

The changeLineSeparators() API is fairly new, so it may not be available in the version of WebStorm that you tested it with. It should be there in WebStorm 6.

0

Please sign in to leave a comment.