Skip to content

Commit

Permalink
Merge pull request #33529 from maxandersen/openide
Browse files Browse the repository at this point in the history
X will open editor on current working directory as a fallback
  • Loading branch information
geoand authored May 23, 2023
2 parents 60a73e1 + 4b24140 commit b406ca7
Showing 1 changed file with 41 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,43 +142,47 @@ public void accept(Throwable throwable, StackTraceElement stackTraceElement) {
}

exceptionsConsoleContext.reset(
new ConsoleCommand('x', "Open last exception in IDE", new ConsoleCommand.HelpState(new Supplier<String>() {
@Override
public String get() {
return MessageFormat.RED;
}
}, new Supplier<String>() {
@Override
public String get() {
StackTraceElement throwable = lastUserCode.get();
if (throwable == null) {
return "none";
}
return throwable.getFileName() + ":" + throwable.getLineNumber();
}
}), new Runnable() {
@Override
public void run() {
StackTraceElement throwable = lastUserCode.get();
if (throwable == null) {
return;
}
String className = throwable.getClassName();
String file = throwable.getFileName();
if (className.contains(".")) {
file = className.substring(0, className.lastIndexOf('.') + 1).replace('.', File.separatorChar)
+ file;
}
Path fileName = Ide.findSourceFile(file);
if (fileName == null) {
log.error("Unable to find file: " + file);
return;
}
List<String> args = ideSupport.getIde().createFileOpeningArgs(fileName.toAbsolutePath().toString(),
"" + throwable.getLineNumber());
launchInIDE(ideSupport.getIde(), args);
}
}));
new ConsoleCommand('x', "Open last exception (or project) in IDE",
new ConsoleCommand.HelpState(new Supplier<String>() {
@Override
public String get() {
return MessageFormat.RED;
}
}, new Supplier<String>() {
@Override
public String get() {
StackTraceElement throwable = lastUserCode.get();
if (throwable == null) {
return "none";
}
return throwable.getFileName() + ":" + throwable.getLineNumber();
}
}), new Runnable() {
@Override
public void run() {
StackTraceElement throwable = lastUserCode.get();
if (throwable == null) {
launchInIDE(ideSupport.getIde(), List.of("."));
return;
}
String className = throwable.getClassName();
String file = throwable.getFileName();
if (className.contains(".")) {
file = className.substring(0, className.lastIndexOf('.') + 1).replace('.',
File.separatorChar)
+ file;
}
Path fileName = Ide.findSourceFile(file);
if (fileName == null) {
log.error("Unable to find file: " + file);
return;
}
List<String> args = ideSupport.getIde().createFileOpeningArgs(
fileName.toAbsolutePath().toString(),
"" + throwable.getLineNumber());
launchInIDE(ideSupport.getIde(), args);
}
}));
}

protected void launchInIDE(Ide ide, List<String> args) {
Expand Down

0 comments on commit b406ca7

Please sign in to comment.