Skip to content

Commit 763e312

Browse files
flofridayJozott00
authored andcommitted
cli: Improve format of printed paths
This also introduces better detection of the IntelliJ environment.
1 parent fab70fa commit 763e312

File tree

3 files changed

+86
-28
lines changed

3 files changed

+86
-28
lines changed

vadl-cli/main/vadl/cli/BaseCommand.java

Lines changed: 39 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import vadl.pass.PassManager;
5050
import vadl.pass.PassOrder;
5151
import vadl.pass.exception.DuplicatedPassKeyException;
52+
import vadl.utils.EditorUtils;
5253
import vadl.utils.SourceLocation;
5354
import vadl.viam.Specification;
5455

@@ -211,6 +212,37 @@ private Specification parseToVIAM() {
211212
return spec;
212213
}
213214

215+
protected void printDumps(String message) {
216+
if (ArtifactTracker.getDumpPaths().isEmpty()) {
217+
return;
218+
}
219+
220+
System.out.println(message);
221+
for (var path : ArtifactTracker.getDumpPaths()) {
222+
if (EditorUtils.isIntelliJIDE()) {
223+
var uri = path.toAbsolutePath().toUri();
224+
System.out.printf("\t- %s\n", uri);
225+
} else {
226+
System.out.printf("\t- %s\n", path);
227+
}
228+
}
229+
}
230+
231+
protected void printArtifacts(String message) {
232+
if (ArtifactTracker.getArtifactPathsPaths().isEmpty()) {
233+
return;
234+
}
235+
System.out.println(message);
236+
for (var path : ArtifactTracker.getArtifactPathsPaths()) {
237+
if (EditorUtils.isIntelliJIDE()) {
238+
var uri = path.toAbsolutePath().toUri();
239+
System.out.printf("\t- %s\n", uri);
240+
} else {
241+
System.out.printf("\t- %s\n", path);
242+
}
243+
}
244+
}
245+
214246
// lazy evaluated config, do NOT use this directly.
215247
// use getConfig() instead.
216248
@Nullable
@@ -266,14 +298,7 @@ public Integer call() {
266298
https://ea.complang.tuwien.ac.at/vadl/open-vadl/issues/new
267299
""");
268300

269-
if (!ArtifactTracker.getDumpPaths().isEmpty()) {
270-
var dumpMessage = "\nBefore the crash, the following dumps were generated:";
271-
System.out.println(dumpMessage);
272-
for (var path : ArtifactTracker.getDumpPaths()) {
273-
System.out.printf("\t- %s\n", path);
274-
}
275-
System.out.println("");
276-
}
301+
printDumps("\nBefore the crash, the following dumps were generated:");
277302

278303
// Dirty hack to avoid stdout and stderr getting mixed in IntelliJ (flushing wasn't enough).
279304
try {
@@ -296,25 +321,13 @@ public Integer call() {
296321
}
297322
}
298323

299-
if (!ArtifactTracker.getArtifactPathsPaths().isEmpty()) {
300-
var artifactMessage = returnVal == 0
301-
? "\nThe following artifacts were generated:"
302-
: "\nEven though some errors occurred, the following artifacts were generated:";
303-
System.out.println(artifactMessage);
304-
for (var path : ArtifactTracker.getArtifactPathsPaths()) {
305-
System.out.printf("\t- %s\n", path);
306-
}
307-
}
324+
printArtifacts(returnVal == 0
325+
? "\nThe following artifacts were generated:"
326+
: "\nEven though some errors occurred, the following artifacts were generated:");
308327

309-
if (!ArtifactTracker.getDumpPaths().isEmpty()) {
310-
var dumpMessage = returnVal == 0
311-
? "\nThe following dumps were generated:"
312-
: "\nEven though some errors occurred, the following dumps were generated:";
313-
System.out.println(dumpMessage);
314-
for (var path : ArtifactTracker.getDumpPaths()) {
315-
System.out.printf("\t- %s\n", path);
316-
}
317-
}
328+
printDumps(returnVal == 0
329+
? "\nThe following dumps were generated:"
330+
: "\nEven though some errors occurred, the following dumps were generated:");
318331

319332
return returnVal;
320333
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// SPDX-FileCopyrightText : © 2025 TU Wien <vadl@tuwien.ac.at>
2+
// SPDX-License-Identifier: GPL-3.0-or-later
3+
//
4+
// This program is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// This program is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with this program. If not, see <https://www.gnu.org/licenses/>.
16+
17+
package vadl.utils;
18+
19+
import java.util.Objects;
20+
import javax.annotation.Nullable;
21+
22+
/**
23+
* A file to work around the "quirks" of some editors and IDE's.
24+
*/
25+
public class EditorUtils {
26+
27+
@Nullable
28+
private static Boolean isIntelliJ = null;
29+
30+
/**
31+
* Detect whether the program is currently executing inside IntelliJ.
32+
*/
33+
public static boolean isIntelliJIDE() {
34+
if (isIntelliJ == null) {
35+
isIntelliJ = Objects.requireNonNullElse(System.getenv("TERMINAL_EMULATOR"), "")
36+
.equals("JetBrains-JediTerm")
37+
|| Objects.requireNonNullElse(System.getenv("XPC_SERVICE_NAME"), "")
38+
.startsWith("application.com.jetbrains")
39+
;
40+
}
41+
42+
return isIntelliJ;
43+
}
44+
}

vadl/main/vadl/utils/SourceLocation.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package vadl.utils;
1818

19+
import static vadl.utils.EditorUtils.isIntelliJIDE;
20+
1921
import java.io.IOException;
2022
import java.net.URI;
2123
import java.nio.file.Files;
@@ -173,8 +175,7 @@ public String toIDEString() {
173175

174176
String printablePath;
175177

176-
if (Objects.requireNonNullElse(System.getenv("TERMINAL_EMULATOR"), "")
177-
.equals("JetBrains-JediTerm") || this.uri.getScheme().equals("memory")) {
178+
if (isIntelliJIDE() || this.uri.getScheme().equals("memory")) {
178179
// IntelliJ integrated terminal needs special treatment
179180
printablePath = this.uri.toString();
180181
} else {

0 commit comments

Comments
 (0)