fix(java): stop Show Usages waiting seconds on the configuration index after a change

After any Java change, the configuration index was rebuilt from scratch on the next Show
Usages, resolving every dependency's Spring metadata (thousands of Spring Boot properties)
to library members again, and Show Usages waited for it: 15-20 seconds in a Spring Boot +
MyBatis project.

- The Java extension (1.8.0) keeps each dependency JAR's metadata entries across rebuilds
  until the JAR's timestamp/size or the project's classpath changes.
- Show Usages shows the Java usages as soon as they are found and adds the configuration
  ones when the index takes longer.

Closes #1898
This commit is contained in:
l0ng-ai committed 2026-11-07 22:35:10 +08:00
1 parent f96ca468a8
commit c0717358df
9 files changed
+131 -7

No files matched your search

+8
View File
@@ -244,6 +244,14 @@ try:
while not query('added.size')['locations']:
assert time.monotonic() < deadline, 'a new source on disk did not reach the index'
time.sleep(0.2)
# That rebuild reused the library's metadata; a changed archive is read again.
assert query('vendor.port')['locations'], 'a source rebuild lost the library metadata'
metadata['properties'].append({'name': 'vendor.speed', 'type': 'java.lang.Integer', 'sourceType': 'vendor.LibrarySettings'})
with zipfile.ZipFile(library, 'w') as z:
z.write(classes / 'vendor/LibrarySettings.class', 'vendor/LibrarySettings.class')
z.writestr('META-INF/spring-configuration-metadata.json', json.dumps(metadata))
assert query('vendor.speed')['locations'], 'a changed library archive kept its old metadata'
assert query('vendor.port')['locations']
# Unsaved changes must replace old keys, and closing must restore disk keys.
changed = source.replace('prefix="app"', 'prefix="edited"').replace('${app.time-out:30}', '${edited.timeout:30}')
send({'jsonrpc': '2.0', 'method': 'textDocument/didChange', 'params': {'textDocument': {'uri': file.as_uri(), 'version': 2}, 'contentChanges': [{'text': changed}]}})