"Also, document instances not linked to any virtual files can be created temporarily, for example, to represent the contents of a text editor field in a dialog."
What's the recommended method to do this (both 5.1 and 6.0 API)?
Any changes done to the content of PSI files are reflected in documents,
I think I've seen a change between the behavior in 5.x and 6.0: In 5.0, inside a WriteAction, PSI changes have been directly commited to the document, whereas in 6.0 the changes (and their formatting) seem to be deferred until the WriteAction completes. Which means, that e.g. if doing some PSI manipulation, the offsets returned from PSI elements will not be correct Document offsets until after the WriteAction, and after it, the PSI elements may not be valid any more (due to formatting). Did I get this right?
If you need to commit a change to the document prior to the write action being complete (like if you need to make multiple edits and need to recalculate the offsets of subsequent elements) use this code after each edit (like a call to insertString())
Please write how do we create new PSI elements, and how do we move them. When I try to remove XmlTag elements from parent tag, sort them and add them again I get assertion error, because they are not valid anymore.
I think it would benifit the documentation if you added performAction method of AnAction runs on the EVT in the threading section and how to check if your running on the EVT.
If both are valid, then it should be the same object. If one of them is obsolete (has become invalid), then it will be different from the currently valid PsiFile.
14 Comments
Anonymous
Oh yeah, this ROCKS! Woo Hoo! High quality documentation of the Plug-in architecture.... get your fork, because you're going to eat it, Eclipse.
Anonymous
"Also, document instances not linked to any virtual files can be created temporarily, for example, to represent the contents of a text editor field in a dialog."
What's the recommended method to do this (both 5.1 and 6.0 API)?
Dmitry Jemerov
EditorFactory.createDocument(). That hasn't changed between 5.1 and 6.0.
Sascha Weinreuter
I think I've seen a change between the behavior in 5.x and 6.0: In 5.0, inside a WriteAction, PSI changes have been directly commited to the document, whereas in 6.0 the changes (and their formatting) seem to be deferred until the WriteAction completes. Which means, that e.g. if doing some PSI manipulation, the offsets returned from PSI elements will not be correct Document offsets until after the WriteAction, and after it, the PSI elements may not be valid any more (due to formatting). Did I get this right?
Dmitry Jemerov
This is correct, and this will be documented in detail in the section covering PSI elements (currently unwritten).
Michael Parmeley
If you need to commit a change to the document prior to the write action being complete (like if you need to make multiple edits and need to recalculate the offsets of subsequent elements) use this code after each edit (like a call to insertString())
Jay
I only want to say that this really important and awaited documentation was last updated more than 4 months ago.
Dear Dmitry, please continue!
Bernard Labno
Please write how do we create new PSI elements, and how do we move them. When I try to remove XmlTag elements from parent tag, sort them and add them again I get assertion error, because they are not valid anymore.
Dmitry Jemerov
Please ask plugin development questions in the forum at http://devnet.jetbrains.net/community/idea/open_api_and_plugin_development
Toby
Is it worth mentioning in the threading section that the
performAction
method ofAnAction
runs on the EVT?Also, is there a way to detect if the current thread is the EVT? Something like SwingUtilities.isEventDispatchThread or SWT's display.getThread()?
Yann Cébron
Please ask plugin development questions in the forum at http://devnet.jetbrains.net/community/idea/open_api_and_plugin_development
Toby
Sorry, let me rephrase...
I think it would benifit the documentation if you added
performAction
method ofAnAction
runs on the EVT in the threading section and how to check if your running on the EVT.Alexey Dmitriev
Am I right that if 2 PSIFile's represent one file in one project, then it'll the same object? If not will they equal?
Peter Gromov
If both are valid, then it should be the same object. If one of them is obsolete (has become invalid), then it will be different from the currently valid PsiFile.