Can I force IDEA to refresh its cached XSDs?

已回答

My plugin includes an XmlFileNSInfoProvider implementation that correlates namespaces for custom HTML elements to XSDs packaged within the plugin archive.  This all works great until I update those XSDs.  The new XSD contents are not offered for completions or tagged with references until I "nudge" the IDE by navigating into an element or attribute that was already present in the previous version.  Once I do that, it seems that IDEA updates its cache for the contents of that XSD.

I've tried to force the IDE to update itself by using FileContentUtil.reparseFiles() with the VirtualFiles for these XSDs, but that didn't seem to do the trick.  Any thoughts on how I can get IDEA to update its cached information about these XSDs without the user having to explicitly navigate into the packaged file in order to get things up-to-date?

Thanks much!

0

Sorry for the necrobump, but this problem is still occurring and still causing unexpected behavior. Any idea how I might be able to get the IDE to realize that its cached version of an XSD is stale and needs to be refreshed?

Thanks!

0

The info is cached under PsiModificationTracker, try to call

((PsiModificationTrackerImpl)PsiManager.getInstance(project).getModificationTracker()).incCounter();
0

Thanks, Dmitry. Doesn't almost everything in the project depend on that? Will that cause a full cache flush/rebuild? Just trying to figure out whether it's safe to do that every time the project is opened or if I need to track version numbers for my XSDs and only do that when an XSD is known to be updated.

0

It happens quite often, so a little bit more won't hurt :)

0

Hah! Fair enough. I'll add it to my project open listener and hopefully that will take care of it. Thanks!

0

Dmitry, that seems to have done the job nicely. Thanks much for the tip!

0

Hi, Dmitry. I realize it's been a while since we last discussed this, but the original issue seems to have come back. I noticed it first with JSON schema that I'm integrating via the JsonSchemaFileProvider EP, but also with XSDs. They're stale until you explicitly follow a working reference into the backing file, and then you can see the IDE actually refresh its notion of that file to the latest version included in the plugin. I'm still incrementing that modification tracker, so that doesn't seem to be doing it.

Any thoughts?

0

incCounter() is marked deprecated now. The comment says,

/**
* @deprecated use higher-level ways of dropping caches
* @see
com.intellij.util.FileContentUtilCore#reparseFiles
* @see
PsiManager#dropPsiCaches()
*/

please try those ways.

0

Thanks, Dmitry. I think I've found a viable workaround by finding the XML/JSON schema virtual file and forcing the virtual file manager to refresh it on project open. Do you see any down-side to that approach?

0

请先登录再写评论。