I implemented a DocumentationProvider by extending the AbstractDocumentationProvider. Somewhere down the line I need to look up where the current cursor is, as I want to show the type of the element under the cursor. To achieve this I look up the text editor, get the selection model and the start and end position of that selection model. The editor I try to find through
FileEditorManager fileEditorManager = FileEditorManager.getInstance(
This seems to work, but I keep on getting a rather big stack trace, starting with Access is allowed from event dispatch thread only.
Okay, with what I know about Swing and Intellij, I understand that I am apparently not on the UI thread and need to be on the UI thread to execute this. So, I try to wrap the invocation of the function that contains fileEditorManager.getselectedtextEditor() in ApplicationManager.getApplication().invokeAndWait. But now I seem to get a little smaller stack trace, stating that 'Calling invokeAndWait from read-action leads to possible deadlock. '.
What does not seem to give stack traces is when I wrap the computation in a ApplicationManager.getApplication().invokeLater, but the thing is that that function is asynchronous, so then I don't see an easy way of returning the result, without resorting to thread synchronization primitives.
Can somebody point me in the correct direction for this?