Repository navigation
fix: read the templates of a rebuilt LSP4IJ JAR at the next start of a development IDE, not the stale ones of the VFS - #2190
Merged
lagergren merged 2 commits intoNov 24, 2026
Conversation
…a development IDE, not the stale ones of the VFS LSP4IJ reads its LSP and DAP templates through JarFileSystem, whose files and content come from the VFS cache, which the IDE keeps from one start to the next. Only a refresh compares them with the JAR, and nothing refreshes the JAR of a plugin, since its class loader reads it directly. So a JAR rebuilt at the same path, as in runIde, kept giving its old templates, also after a restart. A post-startup activity now refreshes the JAR which holds the templates, once per IDE start, and only in a development build (IntelliJPlatformUtils.isDevMode()): a released LSP4IJ has its version in the name of its JAR, so a new version is read from a new path, and the IDE of a user does nothing new at startup. The activity runs in a background coroutine without the read lock, where a synchronous refresh is allowed. getTemplateRoot() still only finds the file: it runs in the constructor of the template services, possibly under the read lock, where a synchronous refresh is not allowed. The .jar file and its content are refreshed recursively, in one synchronous session. A refresh of the .jar file alone refreshes the content only of a JAR which the IDE has opened since it started, which a new start or a reloaded plugin hasn't. And a second session for the content could be overtaken by the asynchronous refresh which a change of the .jar file starts, and return before the content is new. Design proposed by @muescha in redhat-developer#2080. Fixes redhat-developer#1949
…nd only in a development build, and getTemplateRoot() never refreshes The tests build a JAR in a temporary directory, read it through JarFileSystem, rebuild it at the same path and close it, as a new start of the IDE has it: the templates are stale before the refresh and new after it. A second project doesn't refresh again, nor does an IDE outside a development build. And the template services, created under the read lock, neither refresh the JAR of LSP4IJ synchronously nor queue a refresh of it. Refs redhat-developer#1949
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2190 +/- ##
=======================================
Coverage 54.23% 54.24%
=======================================
Files 832 833 +1
Lines 35334 35351 +17
Branches 7286 7291 +5
=======================================
+ Hits 19163 19175 +12
+ Misses 13348 13347 -1
- Partials 2823 2829 +6 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This was referenced Nov 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1949
Design by @muescha, from the review of #2080, which is no longer on GitHub. This PR takes their proposal, with the
refresh limited to development builds, as agreed there.
What
After the LSP4IJ JAR is rebuilt at the same path, as in
runIdeor with a SNAPSHOT, Choose template... in the NewLanguage Server dialog and the DAP dialog keep showing the old templates, even after a restart.
ServerTemplateManager.getTemplateRoot()reads them throughJarFileSystem, whose content is the VFS cache, whichsurvives restarts. Nothing refreshes a plugin's JAR, since the plugin's class loader reads it directly, not through the
VFS.
#2080 refreshed the JAR in
getTemplateRoot()withrefreshAndFindFileByPath. That runs in the constructor of thetemplate services, which may be created under the read lock. There, a synchronous refresh logs "Do not perform a
synchronous refresh under read lock" and doesn't refresh.
Change
TemplateJarRefreshActivity(postStartupActivity,DumbAware) refreshes the templates' JAR, synchronously,once per IDE start:
AtomicBooleanmakes it run once, not once per project;IntelliJPlatformUtils.isDevMode(). A released LSP4IJ has its version in its JAR's name, so a newversion is read from a new path, and users' IDEs do nothing new at startup.
getTemplateRoot()still usesfindFileByPath, with a comment that it must never refresh..jarfile and the JAR root together (VfsUtil.markDirtyAndRefresh(false, true, true, localJar, jarRoot)), not two in a row:.jarfile alone refreshes the content only of a JAR that the IDE has opened since it started, andat a new start it usually hasn't. The content is refreshed because each file in a JAR has the
.jarfile's timestamp.
.jarfile makesVfsImplUtilrefresh its content again, asynchronously. Withtwo sessions, that refresh could scan first, and the second session would return before the changes are applied.
StartupManagerImplstarts the project activitiesof a plugin loaded dynamically for the projects already open. The reloaded plugin has a new class loader, so a new
flag, and
VfsImplUtildrops the plugin's open JARs when it is unloaded. So a reload refreshes like a new start.start, as today. The templates are only needed after a user action, so the refresh has long finished by then.
Tests
New
TemplateJarRefreshActivityTest(4 tests):JarFileSystem, then rebuilt at the same path withchanged content and an extra template folder. A new start is simulated by closing the JAR and keeping the VFS cache.
The templates are stale until
refreshOnceruns on a background thread without the read lock, and new after it.getTemplateRoot()never refreshes: creating aServerTemplateManagerunder a read action leaves dirty files ofLSP4IJ's JAR dirty.
Red-green:
.jarfile, they fail too.getTemplateRoot()fails the guard test with "Do not perform a synchronous refresh underread lock".
Results:
templates.*andlaunching.*tests pass on IC 2024.2, 2025.3 and IU 2026.3, with 91 each and 0 failures orskipped. The new tests also pass headless on all three.
Not checked by hand in
runIde, which needs a GUI: the restart, and the dynamic reload.Behaviour change
runIde), after the LSP4IJ JAR is rebuilt at the same path, the New Language Server and DAP dialogs keep showing the old templates from the VFS cache, even after a restart