Skip to content

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 into
redhat-developer:mainfrom
lagergren:fix/templates-refresh-the-rebuilt-plugin-jar
Nov 24, 2026
Merged

lagergren merged 2 commits into
redhat-developer:mainfrom
lagergren:fix/templates-refresh-the-rebuilt-plugin-jar

Conversation

@lagergren

Copy link
Copy Markdown
Collaborator

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 runIde or with a SNAPSHOT, Choose template... in the New
Language Server dialog and the DAP dialog keep showing the old templates, even after a restart.
ServerTemplateManager.getTemplateRoot() reads them through JarFileSystem, whose content is the VFS cache, which
survives 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() with refreshAndFindFileByPath. That runs in the constructor of the
template 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

  • New TemplateJarRefreshActivity (postStartupActivity, DumbAware) refreshes the templates' JAR, synchronously,
    once per IDE start:
    • it runs in a project activity's coroutine, where no read lock is held;
    • an AtomicBoolean makes it run once, not once per project;
    • it runs only when IntelliJPlatformUtils.isDevMode(). A released LSP4IJ has its version in its JAR's name, so a new
      version is read from a new path, and users' IDEs do nothing new at startup.
  • getTemplateRoot() still uses findFileByPath, with a comment that it must never refresh.
  • One refresh session for the .jar file and the JAR root together (VfsUtil.markDirtyAndRefresh(false, true, true, localJar, jarRoot)), not two in a row:
    • A refresh of the .jar file alone refreshes the content only of a JAR that the IDE has opened since it started, and
      at a new start it usually hasn't. The content is refreshed because each file in a JAR has the .jar file's time
      stamp.
    • If the JAR is open, a change of the .jar file makes VfsImplUtil refresh its content again, asynchronously. With
      two sessions, that refresh could scan first, and the second session would return before the changes are applied.
  • Dynamic reload: once a project's startup activities have run, StartupManagerImpl starts the project activities
    of a plugin loaded dynamically for the projects already open. The reloaded plugin has a new class loader, so a new
    flag, and VfsImplUtil drops the plugin's open JARs when it is unloaded. So a reload refreshes like a new start.
  • What it doesn't change: a template service created before the refresh keeps the old templates until the next
    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):

  • Main test: a JAR built in a temp directory is read through JarFileSystem, then rebuilt at the same path with
    changed 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 refreshOnce runs on a background thread without the read lock, and new after it.
  • Once: a second run doesn't refresh.
  • Not in dev mode: nothing is refreshed.
  • getTemplateRoot() never refreshes: creating a ServerTemplateManager under a read action leaves dirty files of
    LSP4IJ's JAR dirty.

Red-green:

  • Without the refresh, the main and once tests fail.
  • Refreshing only the .jar file, they fail too.
  • A synchronous refresh in getTemplateRoot() fails the guard test with "Do not perform a synchronous refresh under
    read lock".

Results:

Not checked by hand in runIde, which needs a GUI: the restart, and the dynamic reload.

Behaviour change

Before After
In a development IDE (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 At the next start or plugin reload of a development IDE, they show the rebuilt JAR's templates. A released LSP4IJ does nothing new at startup

…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
@lagergren lagergren added this to the 0.30.2 milestone Nov 24, 2026
@lagergren lagergren added the bug Something isn't working label Nov 24, 2026
@coderabbitai

coderabbitai Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Bug Fixes
    • Development builds now refresh LSP and DAP templates at startup, so changes to rebuilt templates are reflected in the IDE. This refresh happens once per IDE start and does not affect regular non-development builds.

A post-startup activity attempts to refresh the template JAR once per IDE start in development mode. getTemplateRoot() does not refresh the JAR. Tests cover refreshed contents, non-development behavior, and template lookup under a read lock.

Changes: Template JAR refresh

Layer / File(s) Summary
Development startup refresh and validation
src/main/java/com/redhat/devtools/lsp4ij/templates/TemplateJarRefreshActivity.java, src/main/java/com/redhat/devtools/lsp4ij/templates/ServerTemplateManager.java, src/main/resources/META-INF/plugin.xml, src/test/java/com/redhat/devtools/lsp4ij/templates/TemplateJarRefreshActivityTest.java
A registered post-startup activity attempts a VFS refresh once in development mode. It marks the local JAR and recursive JAR-root content dirty before refreshing. getTemplateRoot() documents that it does not refresh the JAR. Tests cover rebuilt contents, non-development mode, and lookup under a read lock.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Medium

Sequence Diagram(s)

sequenceDiagram
  participant ProjectStartup
  participant TemplateJarRefreshActivity
  participant ServerTemplateManager
  participant VirtualFileSystem
  ProjectStartup->>TemplateJarRefreshActivity: execute(project)
  TemplateJarRefreshActivity->>TemplateJarRefreshActivity: check development mode and call refreshOnce
  TemplateJarRefreshActivity->>ServerTemplateManager: obtain template resource root
  ServerTemplateManager-->>TemplateJarRefreshActivity: return resource root path or null
  TemplateJarRefreshActivity->>VirtualFileSystem: mark JAR and recursive contents dirty, then refresh
Loading

Suggested reviewers: angelozerr

Merge Risk: Minimal · up to 1c143

This change refreshes the template JAR once at startup in development IDEs so rebuilt templates appear. Released builds are unaffected. No merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the primary change: a rebuilt LSP4IJ JAR's templates are read at the next development IDE start instead of the stale VFS cache. The changeset adds a startup activity that refreshes the…
Description check Passed The description states the problem, the design, the dev-mode restriction, the once-per-start behavior, the tests, and the behavior change. It matches the changeset (TemplateJarRefreshActivity, getTemp…
Linked Issues check Passed Issue #1949 reports that Choose template... shows stale templates after the LSP4IJ JAR is rebuilt at the same path, because ServerTemplateManager.getTemplateRoot() reads through JarFileSystem and the …
Out of Scope Changes check Passed All changes relate to the issue objective. TemplateJarRefreshActivity.java contains the refresh logic and its once-per-start and dev-mode gating. ServerTemplateManager.java changes only a comment on g…
Full details: Title check

Explanation

The title names the primary change: a rebuilt LSP4IJ JAR's templates are read at the next development IDE start instead of the stale VFS cache. The changeset adds a startup activity that refreshes the JAR, documents that getTemplateRoot() must not refresh, and adds tests. The title is specific and matches the objectives. It is long (117 characters), which is a minor concern for a concise title.

Full details: Description check

Explanation

The description states the problem, the design, the dev-mode restriction, the once-per-start behavior, the tests, and the behavior change. It matches the changeset (TemplateJarRefreshActivity, getTemplateRoot() comment, new tests) and the linked issue #1949.

Full details: Linked Issues check

Explanation

Issue #1949 reports that Choose template... shows stale templates after the LSP4IJ JAR is rebuilt at the same path, because ServerTemplateManager.getTemplateRoot() reads through JarFileSystem and the VFS cache is not refreshed. The issue suggests refreshing the JAR root before reading. The PR implements this. New TemplateJarRefreshActivity (registered as a post-startup activity in plugin.xml) calls VfsUtil.markDirtyAndRefresh(false, true, true, localJar, jarRoot) once per IDE start, only when IntelliJPlatformUtils.isDevMode() is true. The refresh runs in a project activity, so no read lock is held. getTemplateRoot() keeps findFileByPath and carries a comment that it must not refresh, which avoids the read-lock refresh problem described in the PR. The issue scope (rebuilt snapshot or runIde) matches the dev-only gate. The new TemplateJarRefreshActivityTest covers the rebuilt-JAR case, the once-only behavior, the dev-mode gate, and the no-refresh guard. Restart and dynamic-reload behavior are not verified by automated tests in the reviewed evidence, but the PR states they were not checked by hand; these are behavioral claims, not separate coding requirements of the issue.

Full details: Out of Scope Changes check

Explanation

All changes relate to the issue objective. TemplateJarRefreshActivity.java contains the refresh logic and its once-per-start and dev-mode gating. ServerTemplateManager.java changes only a comment on getTemplateRoot() that documents the no-refresh rule, with no executable change. plugin.xml registers the activity. TemplateJarRefreshActivityTest.java tests the refresh behavior. No unrelated functional change is visible in the summary or the inspected files.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 865cbd3f-0cd9-424e-8654-455edc264d04
Commits

Reviewing files that changed from the base of the PR and between 084bf75 and 1c14321.

Files selected for processing: 4

  • src/main/java/com/redhat/devtools/lsp4ij/templates/ServerTemplateManager.java
  • src/main/java/com/redhat/devtools/lsp4ij/templates/TemplateJarRefreshActivity.java
  • src/main/resources/META-INF/plugin.xml
  • src/test/java/com/redhat/devtools/lsp4ij/templates/TemplateJarRefreshActivityTest.java

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 0 remain after this review.

@codecov

codecov Bot commented Nov 24, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 64.70588% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 54.24%. Comparing base (084bf75) to head (1c14321).

Files with missing lines Patch % Lines
...s/lsp4ij/templates/TemplateJarRefreshActivity.java 64.70% 3 Missing and 3 partials ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Templates can come from a stale VFS cache after the plugin JAR is rebuilt

1 participant