What is involved in building the "most recent" PSI of a file? Some changes seem to not register a new PSI...
Hello,
Context: A change to the file triggers AST -> PSI, and the new change is now included in your PSI.
My question is what is involved in triggering that change?
Sometimes the PSI is updated and other times the new change has not been incorporated in the PSI, and is still using the old one (cached).
An example should explains things more precisely:
Lets say I have a file with several import statements in it. Everything at this point is parsed correctly and my PSI is in sync with my file.
Here is some log info, where each line corresponds to an import Jython statement such as "import java.util.Map as Mappy" which is the 1st line below:
[ 58474] WARN - JythonCompletionContributor - loading: java.util.Map - Mappy
[ 58474] WARN - JythonCompletionContributor - loading: java.util.Set - Setty
[ 58490] WARN - JythonCompletionContributor - loading: java.util.List - Listy
[ 58490] WARN - JythonCompletionContributor - loading: java.util.ArrayList - ArrList
[ 58490] WARN - JythonCompletionContributor - loading: java.lang.Class - Classy
Now, in this file I type:
import java.util.LinkedList as Linky
And all that is picked up from this change, is "import java"
So, now the PSI and file are out of sync is one way of looking at it. Here is the new log outputted (see last line of log):
[ 58474] WARN - JythonCompletionContributor - loading: java.util.Map - Mappy
[ 58474] WARN - JythonCompletionContributor - loading: java.util.Set - Setty
[ 58490] WARN - JythonCompletionContributor - loading: java.util.List - Listy
[ 58490] WARN - JythonCompletionContributor - loading: java.util.ArrayList - ArrList
[ 58490] WARN - JythonCompletionContributor - loading: java.lang.Class - Classy
[ 58490] WARN - JythonCompletionContributor - loading: java - java
So to register the PSI to build again I make some changes to the whitespace around the typed import above. I will indent, dendent, hit "return" after the line and then the PSI finally has the whole statement typed:
[ 119104] WARN - JythonCompletionContributor - loading: java.util.Map - Mappy
[ 119104] WARN - JythonCompletionContributor - loading: java.util.Set - Setty
[ 119104] WARN - JythonCompletionContributor - loading: java.util.LinkedList - Linky
[ 119104] WARN - JythonCompletionContributor - loading: java.util.List - Listy
[ 119104] WARN - JythonCompletionContributor - loading: java.util.ArrayList - ArrList
[ 119104] WARN - JythonCompletionContributor - loading: java.lang.Class - Classy
Now the import statement is in the PSI completely, unfortunately though after some "finagling" (manipulating whitespace characters around the statmente so it registers/triggers building a new PSI).
My question then is what is involved triggering a change to build a PSI? Is the finagling necessary because sometimes the PSI generation gets "stuck." I am assuming it is getting "stuck" b/c I am not doing something correctly to trigger this rebuilding of the PSI on change.
I thought is might be related to how you structure you AST -> PSI during parsing. For the statement above (import java.util.LinkedList as Linky) I have attached a screen shot of it in the PSI Viewer tool.
Any help is appreciated! Thanks!
~Charlie
Attachment(s):
psi_ss.JPG
Please sign in to leave a comment.
Hello Charlie,
PsiDocumentManager.commitDocument() updates the PSI from text for a particular
file.
Note that this question is answered by the architectural overview document:
http://confluence.jetbrains.net/display/IDEADEV/IntelliJIDEAArchitectural+Overview
--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"