plugin development: DocumentationProvider for CLion

    Here is a clion plugin that worked in early clion eaps : It's a simple plugin that formats code documentations.

    After several updates of clion, this plugin doesn't work any more. I forked this plugin trying to figure out how to make it work again. But I failed. It seems CLion just ignores this plugin and never runs it.

    Any idea ?

thank you !


W L (not sure about the name, sorry),
I haven't investigated the cause, but you did a good job with the plugin!

Just wanted to ask, why the build-in replacement info functionality isn't enough?
Screenshot 2015-01-05 23.27.37.png


"W L" is OK. :)

When a macro is complex, I wanna see the formatted expansion, not the raw version.

I reported this issue on with a screenshot:

However it seems that you guys are busy fixing higher priority issues, so I tried to fix it myself.


By 'clion never runs the plugin' do you mean that it's not in the list of plugins in settings?
Is it recognised, when you launch it from IntelliJ IDEA in debug mode?


I looked into this problem further and found clion actually recognized this plugin and loaded it successfully. But there are still some problems.

My implementation inherits DocumentationProvider class and has 5 methods: getQuickNavigateInfo, getUrlFor, generateDoc, getDocumentationElementForLookupItem and getDocumentationElementForLink. I set breakpoints inside every method. Then I started debugging, just found that only the breakpoint in "getUrlFor" worked. Others didn't. I tried both "Ctrl + Q" and "Ctrl + MouseOver". It didn't help.


with the help of IDEA, i finally found out that the plugin should be registerered like this:

<lang.documentationProvider language="ObjectiveC" implementationClass="com.github.itechbear.macroexpansion.provider.MacroDocumentationProvider" order="first" />
though IDEA will highlight "ObjectiveC " as unknown language. Now these breakpoints work!

Now i'm stuck in read/write problems. In order to format the replacement text, this plugin creates a virtual file, formats it, get its text and deletes it later. But the idea plugin platform doesn't allow this action.


What exactly is happening in this case?
Just a wild guess: you probably need to wrap the code in ApplicationManager.getApplication().runWritteAction() (details).


It said something like "try to write in a read thread, dead-lock is comming...."

I tried both ApplicationManager.getApplication().runWriteAction() and ApplicationManager.getApplication().invokeLater(), and they didn't help.

My code was like this:

// WriteRunnable  implements Runnable. notifyall() is called at the end of WriteRunnable::run();
WriteRunnable runnable = new WriteRunnable();

1. in the main thread of the plugin:

2. in the main thread of the plugin:

Both of the two methods failed.


The original message is:


It happened when the plugin tried to run the following code:

new WriteCommandAction.Simple<String>(project, psiFile) {
    protected void run
() throws Throwable {
        CodeStyleManager.getInstance(project).reformat(psiFile, false);

The nature of the problem is very simple: you are trying to acquire a write-lock while holding onto a read-lock. This is doomed to failure, because attempt to acquire the write-lock will wait until all read-locks are released, and at the same time the thread that acquired read-lock is waiting for the WriteAction to complete.

There are many ways to solve this synchronization issue: release the read lock prior to invoking the write action, invokeLater() and don't wait for its completion, etc.


Thanks for your explaination. I've turned to clang-format :-)


Please sign in to leave a comment.