Skip to content

Commit 1a21670

Browse files
error screen fixes, not sure why this was so overcomplicated before, now it's not
1 parent 371dcb1 commit 1a21670

File tree

5 files changed

+65
-79
lines changed

5 files changed

+65
-79
lines changed

src/main/java/dev/latvian/mods/kubejs/DevProperties.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
import dev.latvian.mods.kubejs.util.BaseProperties;
44

5+
import java.util.Locale;
6+
7+
import static dev.latvian.mods.kubejs.client.EditorExt.*;
8+
59
public class DevProperties extends BaseProperties {
610
private static DevProperties instance;
711

@@ -36,6 +40,7 @@ public static void reload() {
3640
public boolean strictTags;
3741
public boolean alwaysCaptureErrors;
3842
public boolean reloadOnFileSave;
43+
public String openUriFormat;
3944
public String kubedexSound;
4045

4146
private DevProperties() {
@@ -64,5 +69,13 @@ protected void load() {
6469
alwaysCaptureErrors = get("always_capture_errors", false);
6570
reloadOnFileSave = get("reload_on_file_save", false);
6671
kubedexSound = get("kubedex_sound", "entity.experience_orb.pickup");
72+
73+
var format = get("open_uri_format", "vscode");
74+
openUriFormat = switch (format.toLowerCase(Locale.ROOT)) {
75+
case "vscode" -> VSCODE;
76+
case "vscodium" -> VSCODIUM;
77+
case "vscode-oss" -> VSCODE_OSS;
78+
default -> format;
79+
};
6780
}
6881
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package dev.latvian.mods.kubejs.client;
2+
3+
import dev.latvian.mods.kubejs.DevProperties;
4+
import net.minecraft.Util;
5+
6+
import java.net.URI;
7+
import java.nio.file.Path;
8+
9+
public class EditorExt {
10+
public static final String VSCODE = vsLikeScheme("vscode");
11+
public static final String VSCODIUM = vsLikeScheme("vscodium");
12+
public static final String VSCODE_OSS = vsLikeScheme("vscode-oss");
13+
14+
private static String vsLikeScheme(String prefix) {
15+
return prefix + "://file{path}:{line}:{col}";
16+
}
17+
18+
public static boolean isKnownVSCode() {
19+
var custom = DevProperties.get().openUriFormat;
20+
return !custom.isEmpty() && (custom.equals(VSCODE) || custom.equals(VSCODIUM) || custom.equals(VSCODE_OSS));
21+
}
22+
23+
private static URI format(String scheme, Path path, int line, int column) {
24+
return URI.create(scheme
25+
.replace("{path}", path.toString())
26+
.replace("{line}", String.valueOf(line))
27+
.replace("{col}", String.valueOf(column))
28+
);
29+
}
30+
31+
public static void openFile(Path path, int line, int column) {
32+
var custom = DevProperties.get().openUriFormat;
33+
if (!custom.isBlank()) {
34+
Util.getPlatform().openUri(format(custom, path, line, column));
35+
} else {
36+
Util.getPlatform().openPath(path);
37+
}
38+
}
39+
}

src/main/java/dev/latvian/mods/kubejs/client/KubeJSClientEventHandler.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,6 @@ public class KubeJSClientEventHandler {
100100
public static void setupClient(FMLClientSetupEvent event) {
101101
KubeJS.PROXY = new KubeJSClient();
102102
event.enqueueWork(KubeJSClientEventHandler::setupClient0);
103-
104-
if (VSCodeExt.isInstalled()) {
105-
ConsoleJS.CLIENT.info("VSCode " + VSCodeExt.getVersion() + " detected");
106-
}
107103
}
108104

109105
@SubscribeEvent

src/main/java/dev/latvian/mods/kubejs/client/KubeJSErrorScreen.java

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -290,16 +290,15 @@ public void render(GuiGraphics g, int idx, int y, int x, int w, int h, int mx, i
290290
}
291291

292292
if (ln > 0) {
293-
if (VSCodeExt.isInstalled()) {
294-
var comp = Component.empty();
295-
comp.append("Double-click to Open in ");
293+
var comp = Component.empty();
294+
comp.append("Double-click to open file");
295+
296+
if (EditorExt.isKnownVSCode()) {
297+
comp.append(" in ");
296298
comp.append(TextIcons.icons("V."));
297299
comp.append(Component.literal("VSCode").withColor(0x22A7F2));
298-
lines.addAll(minecraft.font.split(comp, 1000));
299-
300-
} else {
301-
lines.add(FormattedCharSequence.forward("Double-click to Open File", Style.EMPTY));
302300
}
301+
lines.addAll(minecraft.font.split(comp, 1000));
303302
}
304303

305304
for (var line : line.sourceLines) {
@@ -365,20 +364,16 @@ public void open() {
365364
path = path.getParent();
366365
}
367366

368-
if (VSCodeExt.isInstalled()) {
369-
int ln = 1;
367+
int ln = 1;
370368

371-
for (var line : line.sourceLines) {
372-
if (line.line() > 0 && line.source().endsWith(".js")) {
373-
ln = line.line();
374-
break;
375-
}
369+
for (var line : line.sourceLines) {
370+
if (line.line() > 0 && line.source().endsWith(".js")) {
371+
ln = line.line();
372+
break;
376373
}
377-
378-
VSCodeExt.openFile(path, ln, 0);
379-
} else {
380-
errorList.screen.handleComponentClicked(Style.EMPTY.withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_FILE, path.toAbsolutePath().toString())));
381374
}
375+
376+
EditorExt.openFile(path, ln, 0);
382377
}
383378
}
384379
}

src/main/java/dev/latvian/mods/kubejs/client/VSCodeExt.java

Lines changed: 0 additions & 57 deletions
This file was deleted.

0 commit comments

Comments
 (0)