@@ -62,37 +62,30 @@ private OpenInCurrentIde() {
62
62
public static boolean openFile (File file , int lineNumber ) {
63
63
String absolutePath = file .getAbsolutePath ();
64
64
65
- Optional <Info > maybeIdeCommand = findIdeCommandInfo ();
66
- if (!maybeIdeCommand .isPresent ()) {
67
- getLogger ().debug ("Unable to detect IDE from process tree" );
68
- printProcessTree (msg -> getLogger ().debug (msg ));
69
- return false ;
70
- }
71
-
72
- Info processInfo = maybeIdeCommand .get ();
73
-
74
- if (isVSCode (processInfo )) {
65
+ IdeAndProcessInfo ideInfo = getIdeAndProcessInfo ();
66
+ if (ideInfo .ide == Ide .VSCODE ) {
75
67
return Open .open ("vscode://file" + absolutePath + ":" + lineNumber );
76
- } else if (isIdea ( processInfo ) ) {
68
+ } else if (ideInfo . ide == Ide . INTELLIJ ) {
77
69
try {
78
- run (getBinary (processInfo ), "--line" , lineNumber + "" ,
70
+ run (getBinary (ideInfo . processInfo ), "--line" , lineNumber + "" ,
79
71
absolutePath );
80
72
return true ;
81
73
} catch (Exception e ) {
82
74
getLogger ().error ("Unable to launch IntelliJ IDEA" , e );
83
75
}
84
76
85
- } else if (isEclipse ( processInfo ) ) {
77
+ } else if (ideInfo . ide == Ide . ECLIPSE ) {
86
78
if (OSUtils .isMac ()) {
87
79
try {
88
- run ("open" , "-a" , getBinary (processInfo ), absolutePath );
80
+ run ("open" , "-a" , getBinary (ideInfo .processInfo ),
81
+ absolutePath );
89
82
return true ;
90
83
} catch (Exception e ) {
91
84
getLogger ().error ("Unable to launch Eclipse" , e );
92
85
}
93
86
} else {
94
87
try {
95
- run (getBinary (processInfo ),
88
+ run (getBinary (ideInfo . processInfo ),
96
89
absolutePath + ":" + lineNumber );
97
90
return true ;
98
91
} catch (Exception e ) {
@@ -105,6 +98,41 @@ public static boolean openFile(File file, int lineNumber) {
105
98
106
99
}
107
100
101
+ public enum Ide {
102
+ ECLIPSE , VSCODE , INTELLIJ , OTHER
103
+ }
104
+
105
+ public record IdeAndProcessInfo (Ide ide , Info processInfo ) {
106
+ }
107
+
108
+ /**
109
+ * Gets the IDE and process info for the current process.
110
+ *
111
+ * @return the IDE and process info
112
+ */
113
+ public static IdeAndProcessInfo getIdeAndProcessInfo () {
114
+ Optional <Info > maybeIdeCommand = findIdeCommandInfo ();
115
+ if (!maybeIdeCommand .isPresent ()) {
116
+ getLogger ().debug ("Unable to detect IDE from process tree" );
117
+ printProcessTree (msg -> getLogger ().debug (msg ));
118
+ return new IdeAndProcessInfo (Ide .OTHER , null );
119
+ }
120
+
121
+ Info processInfo = maybeIdeCommand .get ();
122
+
123
+ Ide ide ;
124
+ if (isVSCode (processInfo )) {
125
+ ide = Ide .VSCODE ;
126
+ } else if (isIdea (processInfo )) {
127
+ ide = Ide .INTELLIJ ;
128
+ } else if (isEclipse (processInfo )) {
129
+ ide = Ide .ECLIPSE ;
130
+ } else {
131
+ ide = Ide .OTHER ;
132
+ }
133
+ return new IdeAndProcessInfo (ide , processInfo );
134
+ }
135
+
108
136
static String getBinary (Info info ) {
109
137
String cmd = info .command ().get ();
110
138
if (isIdea (info )) {
0 commit comments