mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-27 00:04:42 +00:00
Refresh pack listings before building workspace schemas
IrisData.get hands back a shared instance whose file listings outlive edits, so a studio update or datapack ingest regenerated schemas that still offered removed keys and missed new ones.
This commit is contained in:
1 parent
aaa5e05cf0
commit
3c6dc52b8e
3 files changed
+41
No files matched your search
+2
@@ -97,6 +97,8 @@ public final class ModdedWorkspaceGenerator {
|
||||
|
||||
private static JSONArray buildSchemas(IrisData data, boolean immediateSchemas, List<CompletableFuture<String>> schemaWrites) {
|
||||
JSONArray schemas = new JSONArray();
|
||||
// The shared instance keeps its file listings across edits, so files added, moved or removed since would be missing.
|
||||
data.clearLists();
|
||||
|
||||
for (ResourceLoader<?> loader : data.getLoaders().v()) {
|
||||
if (loader.supportsSchemas()) {
|
||||
|
||||
@@ -181,6 +181,8 @@ public class IrisCodeWorkspace {
|
||||
List<JSONObject> schemaEntries = new ArrayList<>();
|
||||
List<CompletableFuture<String>> schemaWrites = new ArrayList<>();
|
||||
IrisData dm = IrisData.get(project.getPath());
|
||||
// The shared instance keeps its file listings across edits, so files added, moved or removed since would be missing.
|
||||
dm.clearLists();
|
||||
for (ResourceLoader<?> resourceLoader : dm.getLoaders().v()) {
|
||||
if (resourceLoader.supportsSchemas()) {
|
||||
schemaEntries.add(resourceLoader.schemaMapping());
|
||||
|
||||
@@ -26,10 +26,12 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
@@ -155,6 +157,41 @@ public class IrisCodeWorkspaceTest {
|
||||
Files.readString(unrelatedWorkspace.toPath(), StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void reopeningAfterAFileMoveOffersTheNewKeyAndChangesZedsSchemaHash() throws Exception {
|
||||
File pack = temporaryFolder.newFolder("moved-biome");
|
||||
Path biomes = Files.createDirectories(pack.toPath().resolve("biomes"));
|
||||
Files.writeString(biomes.resolve("before-move.json"), "{}", StandardCharsets.UTF_8);
|
||||
IrisSettings.get().getStudio().setEditor(StudioEditor.NONE);
|
||||
IrisCodeWorkspace workspace = new IrisCodeWorkspace(new IrisProject(pack));
|
||||
workspace.prepareAndOpenEditor();
|
||||
data = IrisData.get(pack);
|
||||
String hashBefore = zedSchemaHash(pack);
|
||||
assertTrue(schemasMention(pack, "before-move"));
|
||||
|
||||
Files.move(biomes.resolve("before-move.json"), biomes.resolve("after-move.json"));
|
||||
workspace.prepareAndOpenEditor();
|
||||
|
||||
assertTrue("The refreshed schemas must offer the moved file's new key", schemasMention(pack, "after-move"));
|
||||
assertFalse("The refreshed schemas must stop offering the old key", schemasMention(pack, "before-move"));
|
||||
assertNotEquals("Zed must see a settings change so it reloads the schemas", hashBefore, zedSchemaHash(pack));
|
||||
}
|
||||
|
||||
private static boolean schemasMention(File pack, String key) throws Exception {
|
||||
try (Stream<Path> schemaFiles = Files.walk(pack.toPath().resolve(".iris/schema"))) {
|
||||
return schemaFiles.filter(Files::isRegularFile)
|
||||
.anyMatch(file -> readQuietly(file).contains("\"" + key + "\""));
|
||||
}
|
||||
}
|
||||
|
||||
private static String readQuietly(Path file) {
|
||||
try {
|
||||
return Files.readString(file, StandardCharsets.UTF_8);
|
||||
} catch (Exception e) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
private static String zedSchemaHash(File pack) throws Exception {
|
||||
JSONObject settings = new JSONObject(Files.readString(pack.toPath().resolve(".zed/settings.json"), StandardCharsets.UTF_8));
|
||||
return settings.getJSONObject("lsp").getJSONObject("json-language-server").getJSONObject("settings").getString("irisSchemaHash");
|
||||
|
||||
Reference in new issue
Block a user