I get the method (a `JSPropertyImpl` in my case - I'm using CoffeeScript), from a `FileEditorManager.selectionChanged` event like so:
val offset = editor.getCaretModel.getOffset()
val el = psiFile.getViewProvider.findElementAt(offset)
val method = PsiTreeUtil.getParentOfType(el, classOf[JSPropertyImpl])
My question is what is the best way to locate this `JSPropertyImpl` again?
My first idea is to send `psiFile.getVirtualFile.getCanonicalPath` and `method.getTextOffset` to the web client along with `method.getText`.
I could then look for open editors matching the canonical path and then use `psiFile.findElementAt(<text offset from client>)`.
I would prefer to be able to uniquely identify the JSPropertyImpl than relying on text offset of the element in a file. Is this possible?
In general there is no way to uniquely identify a PSI element. You can remember its path in the hierachy (meaning the names of its containing functions), but in JS this isn't a particularly reliable approach because of the loose structure of the PSI tree.
Thanks for the reponse Dmitry.
I am using the approach I mentioned above by sending `file path` and `text offset` to the client which then sends the same back. I am just using the `Document#replaceString(from, to, text)` method which is working okay.